1 /*
2  * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "thermal_level_event_system_test.h"
17 
18 #include <common_event_data.h>
19 #include <common_event_manager.h>
20 #include <common_event_publish_info.h>
21 #include <common_event_subscriber.h>
22 #include <common_event_support.h>
23 #include <condition_variable>
24 #include <mutex>
25 #include <thread>
26 #ifdef BATTERY_MANAGER_ENABLE
27 #include "battery_info.h"
28 #endif
29 #include "thermal_level_info.h"
30 #include "thermal_log.h"
31 #include "thermal_mgr_client.h"
32 #include "thermal_mgr_listener.h"
33 
34 #define private   public
35 #define protected public
36 #include "thermal_service.h"
37 #include "thermal_srv_config_parser.h"
38 #include "v1_1/ithermal_interface.h"
39 #include "v1_1/thermal_types.h"
40 #undef private
41 #undef protected
42 
43 using namespace testing::ext;
44 using namespace OHOS::PowerMgr;
45 using namespace OHOS;
46 using namespace std;
47 using namespace OHOS::AAFwk;
48 using namespace OHOS::EventFwk;
49 using namespace OHOS::HDI::Thermal::V1_1;
50 using namespace Security::AccessToken;
51 using Security::AccessToken::AccessTokenID;
52 
53 namespace {
54 std::condition_variable g_callbackCV;
55 std::mutex g_mutex;
56 constexpr int64_t TIME_OUT = 1;
57 bool g_callbackTriggered = false;
58 const std::string SYSTEM_THERMAL_SERVICE_CONFIG_PATH = "/system/etc/thermal_config/thermal_service_config.xml";
59 sptr<ThermalService> g_service = nullptr;
60 } // namespace
61 
62 const char *g_perms[] = { "ohos.permission.PUBLISH_SYSTEM_COMMON_EVENT",
63                           "ohos.permission.POWER_OPTIMIZATION" };
64 uint64_t g_token;
65 AccessTokenID ThermalLevelEventSystemTest::tokenID_ = 0;
66 
67 NativeTokenInfoParams infoInstance = {
68     .dcapsNum = 0,
69     .permsNum = 1,
70     .aclsNum = 0,
71     .dcaps = nullptr,
72     .perms = g_perms,
73     .acls = nullptr,
74     .processName = "ThermalLevelEventSystemTest",
75     .aplStr = "system_basic",
76 };
77 
Notify()78 static void Notify()
79 {
80     std::unique_lock<std::mutex> lock(g_mutex);
81     g_callbackTriggered = true;
82     lock.unlock();
83     g_callbackCV.notify_one();
84 }
85 
Wait()86 static void Wait()
87 {
88     std::unique_lock<std::mutex> lock(g_mutex);
89     g_callbackCV.wait_for(lock, std::chrono::seconds(TIME_OUT), [] { return g_callbackTriggered; });
90     EXPECT_TRUE(g_callbackTriggered);
91     g_callbackTriggered = false;
92 }
93 
PublishChangedEvent(int32_t capacity,int32_t chargerCurrent)94 static bool PublishChangedEvent(int32_t capacity, int32_t chargerCurrent)
95 {
96 #ifdef BATTERY_MANAGER_ENABLE
97     Want want;
98     want.SetParam(BatteryInfo::COMMON_EVENT_KEY_CAPACITY, capacity);
99     want.SetParam(
100         BatteryInfo::COMMON_EVENT_KEY_CHARGE_STATE, static_cast<int32_t>(BatteryChargeState::CHARGE_STATE_ENABLE));
101     want.SetAction(CommonEventSupport::COMMON_EVENT_BATTERY_CHANGED);
102     CommonEventData data;
103     data.SetWant(want);
104     CommonEventPublishInfo publishInfo;
105     publishInfo.SetOrdered(false);
106     bool isSuccess = CommonEventManager::PublishCommonEvent(data, publishInfo);
107 
108     Want wantInner;
109     wantInner.SetParam(BatteryInfo::COMMON_EVENT_KEY_PLUGGED_NOW_CURRENT, chargerCurrent);
110     wantInner.SetAction(BatteryInfo::COMMON_EVENT_BATTERY_CHANGED_INNER);
111     data.SetWant(wantInner);
112     bool isSuccessInner = CommonEventManager::PublishCommonEvent(data, publishInfo);
113 
114     return isSuccess && isSuccessInner;
115 #endif
116     return true;
117 }
118 
119 class CommonEventThermalLevel1Test : public CommonEventSubscriber {
120 public:
121     CommonEventThermalLevel1Test() = default;
122     explicit CommonEventThermalLevel1Test(const CommonEventSubscribeInfo& subscriberInfo);
123     virtual ~CommonEventThermalLevel1Test() = default;
124     virtual void OnReceiveEvent(const CommonEventData& data);
125     static shared_ptr<CommonEventThermalLevel1Test> RegisterEvent();
126 };
127 
CommonEventThermalLevel1Test(const CommonEventSubscribeInfo & subscriberInfo)128 CommonEventThermalLevel1Test::CommonEventThermalLevel1Test(const CommonEventSubscribeInfo& subscriberInfo)
129     : CommonEventSubscriber(subscriberInfo)
130 {
131 }
132 
133 class CommonEventThermalLevel2Test : public CommonEventSubscriber {
134 public:
135     CommonEventThermalLevel2Test() = default;
136     explicit CommonEventThermalLevel2Test(const CommonEventSubscribeInfo& subscriberInfo);
137     virtual ~CommonEventThermalLevel2Test() = default;
138     virtual void OnReceiveEvent(const CommonEventData& data);
139     static shared_ptr<CommonEventThermalLevel2Test> RegisterEvent();
140 };
141 
CommonEventThermalLevel2Test(const CommonEventSubscribeInfo & subscriberInfo)142 CommonEventThermalLevel2Test::CommonEventThermalLevel2Test(const CommonEventSubscribeInfo& subscriberInfo)
143     : CommonEventSubscriber(subscriberInfo)
144 {
145 }
146 
147 class CommonEventThermalLevel3Test : public CommonEventSubscriber {
148 public:
149     CommonEventThermalLevel3Test() = default;
150     explicit CommonEventThermalLevel3Test(const CommonEventSubscribeInfo& subscriberInfo);
151     virtual ~CommonEventThermalLevel3Test() = default;
152     virtual void OnReceiveEvent(const CommonEventData& data);
153     static shared_ptr<CommonEventThermalLevel3Test> RegisterEvent();
154 };
155 
CommonEventThermalLevel3Test(const CommonEventSubscribeInfo & subscriberInfo)156 CommonEventThermalLevel3Test::CommonEventThermalLevel3Test(const CommonEventSubscribeInfo& subscriberInfo)
157     : CommonEventSubscriber(subscriberInfo)
158 {
159 }
160 
161 class CommonEventThermalIdleTrueTest : public CommonEventSubscriber {
162 public:
163     CommonEventThermalIdleTrueTest() = default;
164     explicit CommonEventThermalIdleTrueTest(const CommonEventSubscribeInfo& subscriberInfo);
165     virtual ~CommonEventThermalIdleTrueTest() = default;
166     virtual void OnReceiveEvent(const CommonEventData& data);
167     static shared_ptr<CommonEventThermalIdleTrueTest> RegisterEvent();
168 };
169 
CommonEventThermalIdleTrueTest(const CommonEventSubscribeInfo & subscriberInfo)170 CommonEventThermalIdleTrueTest::CommonEventThermalIdleTrueTest(const CommonEventSubscribeInfo& subscriberInfo)
171     : CommonEventSubscriber(subscriberInfo)
172 {
173 }
174 
175 class CommonEventThermalIdleFalseTest : public CommonEventSubscriber {
176 public:
177     CommonEventThermalIdleFalseTest() = default;
178     explicit CommonEventThermalIdleFalseTest(const CommonEventSubscribeInfo& subscriberInfo);
179     virtual ~CommonEventThermalIdleFalseTest() = default;
180     virtual void OnReceiveEvent(const CommonEventData& data);
181     static shared_ptr<CommonEventThermalIdleFalseTest> RegisterEvent();
182 };
183 
CommonEventThermalIdleFalseTest(const CommonEventSubscribeInfo & subscriberInfo)184 CommonEventThermalIdleFalseTest::CommonEventThermalIdleFalseTest(const CommonEventSubscribeInfo& subscriberInfo)
185     : CommonEventSubscriber(subscriberInfo)
186 {
187 }
188 
OnReceiveEvent(const CommonEventData & data)189 void CommonEventThermalLevel1Test::OnReceiveEvent(const CommonEventData& data)
190 {
191     THERMAL_HILOGD(LABEL_TEST, "CommonEventThermalLevel1Test: OnReceiveEvent Enter");
192     int32_t invalidLevel = -1;
193     std::string key = ToString(static_cast<int32_t>(ThermalCommonEventCode::CODE_THERMAL_LEVEL_CHANGED));
194     int32_t level = data.GetWant().GetIntParam(key, invalidLevel);
195     GTEST_LOG_(INFO) << "thermal level: " << level;
196     Notify();
197     EXPECT_EQ(level, static_cast<int32_t>(ThermalLevel::NORMAL)) << "get thermal level failed";
198 }
199 
OnReceiveEvent(const CommonEventData & data)200 void CommonEventThermalLevel2Test::OnReceiveEvent(const CommonEventData& data)
201 {
202     THERMAL_HILOGD(LABEL_TEST, "CommonEventThermalLevel2Test: OnReceiveEvent Enter");
203     int32_t invalidLevel = -1;
204     std::string key = ToString(static_cast<int32_t>(ThermalCommonEventCode::CODE_THERMAL_LEVEL_CHANGED));
205     int32_t level = data.GetWant().GetIntParam(key, invalidLevel);
206     GTEST_LOG_(INFO) << "thermal level: " << level;
207     Notify();
208     EXPECT_EQ(level, static_cast<int32_t>(ThermalLevel::WARM)) << "get thermal level failed";
209 }
210 
OnReceiveEvent(const CommonEventData & data)211 void CommonEventThermalLevel3Test::OnReceiveEvent(const CommonEventData& data)
212 {
213     THERMAL_HILOGD(LABEL_TEST, "CommonEventThermalLevel3Test: OnReceiveEvent Enter");
214     int32_t invalidLevel = -1;
215     std::string key = ToString(static_cast<int32_t>(ThermalCommonEventCode::CODE_THERMAL_LEVEL_CHANGED));
216     int32_t level = data.GetWant().GetIntParam(key, invalidLevel);
217     GTEST_LOG_(INFO) << "thermal level: " << level;
218     Notify();
219     EXPECT_EQ(level, static_cast<int32_t>(ThermalLevel::HOT)) << "get thermal level failed";
220 }
221 
OnReceiveEvent(const CommonEventData & data)222 void CommonEventThermalIdleTrueTest::OnReceiveEvent(const CommonEventData& data)
223 {
224     THERMAL_HILOGD(LABEL_TEST, "CommonEventThermalIdleTrueTest: OnReceiveEvent Enter");
225     bool invalidState = false;
226     std::string key = ToString(static_cast<uint32_t>(ChargeIdleEventCode::EVENT_CODE_CHARGE_IDLE_STATE));
227     bool getState = data.GetWant().GetBoolParam(key, invalidState);
228     GTEST_LOG_(INFO) << "charger state: " << getState;
229     Notify();
230     EXPECT_EQ(getState, true) << "get charger state failed";
231 }
232 
OnReceiveEvent(const CommonEventData & data)233 void CommonEventThermalIdleFalseTest::OnReceiveEvent(const CommonEventData& data)
234 {
235     THERMAL_HILOGD(LABEL_TEST, "CommonEventThermalIdleFalseTest: OnReceiveEvent Enter");
236     bool invalidState = true;
237     std::string key = ToString(static_cast<uint32_t>(ChargeIdleEventCode::EVENT_CODE_CHARGE_IDLE_STATE));
238     bool getState = data.GetWant().GetBoolParam(key, invalidState);
239     GTEST_LOG_(INFO) << "charger state: " << getState;
240     Notify();
241     EXPECT_EQ(getState, false) << "get charger state failed";
242 }
243 
RegisterEvent()244 shared_ptr<CommonEventThermalLevel1Test> CommonEventThermalLevel1Test::RegisterEvent()
245 {
246     THERMAL_HILOGD(LABEL_TEST, "RegisterEvent: Regist Subscriber Start");
247     int32_t retryTimes = 2;
248     bool succeed = false;
249     MatchingSkills matchingSkills;
250     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_THERMAL_LEVEL_CHANGED);
251     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
252     auto subscriberPtr = std::make_shared<CommonEventThermalLevel1Test>(subscribeInfo);
253     for (int32_t tryTimes = 0; tryTimes < retryTimes; tryTimes++) {
254         succeed = CommonEventManager::SubscribeCommonEvent(subscriberPtr);
255     }
256     if (!succeed) {
257         THERMAL_HILOGD(COMP_SVC, "Failed to register subscriber");
258         return nullptr;
259     }
260     return subscriberPtr;
261 }
262 
RegisterEvent()263 shared_ptr<CommonEventThermalLevel2Test> CommonEventThermalLevel2Test::RegisterEvent()
264 {
265     THERMAL_HILOGD(LABEL_TEST, "RegisterEvent: Regist Subscriber Start");
266     int32_t retryTimes = 2;
267     bool succeed = false;
268     MatchingSkills matchingSkills;
269     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_THERMAL_LEVEL_CHANGED);
270     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
271     auto subscriberPtr = std::make_shared<CommonEventThermalLevel2Test>(subscribeInfo);
272     for (int32_t tryTimes = 0; tryTimes < retryTimes; tryTimes++) {
273         succeed = CommonEventManager::SubscribeCommonEvent(subscriberPtr);
274     }
275     if (!succeed) {
276         THERMAL_HILOGD(COMP_SVC, "Failed to register subscriber");
277         return nullptr;
278     }
279     return subscriberPtr;
280 }
281 
RegisterEvent()282 shared_ptr<CommonEventThermalLevel3Test> CommonEventThermalLevel3Test::RegisterEvent()
283 {
284     THERMAL_HILOGD(LABEL_TEST, "RegisterEvent: Regist Subscriber Start");
285     int32_t retryTimes = 2;
286     bool succeed = false;
287     MatchingSkills matchingSkills;
288     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_THERMAL_LEVEL_CHANGED);
289     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
290     auto subscriberPtr = std::make_shared<CommonEventThermalLevel3Test>(subscribeInfo);
291     for (int32_t tryTimes = 0; tryTimes < retryTimes; tryTimes++) {
292         succeed = CommonEventManager::SubscribeCommonEvent(subscriberPtr);
293     }
294     if (!succeed) {
295         THERMAL_HILOGD(COMP_SVC, "Failed to register subscriber");
296         return nullptr;
297     }
298     return subscriberPtr;
299 }
300 
RegisterEvent()301 shared_ptr<CommonEventThermalIdleTrueTest> CommonEventThermalIdleTrueTest::RegisterEvent()
302 {
303     THERMAL_HILOGD(LABEL_TEST, "RegisterEvent: Regist Subscriber Start");
304     int32_t retryTimes = 2;
305     bool succeed = false;
306     MatchingSkills matchingSkills;
307     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CHARGE_IDLE_MODE_CHANGED);
308     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
309     auto subscriberPtr = std::make_shared<CommonEventThermalIdleTrueTest>(subscribeInfo);
310     for (int32_t tryTimes = 0; tryTimes < retryTimes; tryTimes++) {
311         succeed = CommonEventManager::SubscribeCommonEvent(subscriberPtr);
312     }
313     if (!succeed) {
314         THERMAL_HILOGD(COMP_SVC, "Failed to register subscriber");
315         return nullptr;
316     }
317     return subscriberPtr;
318 }
319 
RegisterEvent()320 shared_ptr<CommonEventThermalIdleFalseTest> CommonEventThermalIdleFalseTest::RegisterEvent()
321 {
322     THERMAL_HILOGD(LABEL_TEST, "RegisterEvent: Regist Subscriber Start");
323     int32_t retryTimes = 2;
324     bool succeed = false;
325     MatchingSkills matchingSkills;
326     matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_CHARGE_IDLE_MODE_CHANGED);
327     CommonEventSubscribeInfo subscribeInfo(matchingSkills);
328     auto subscriberPtr = std::make_shared<CommonEventThermalIdleFalseTest>(subscribeInfo);
329     for (int32_t tryTimes = 0; tryTimes < retryTimes; tryTimes++) {
330         succeed = CommonEventManager::SubscribeCommonEvent(subscriberPtr);
331     }
332     if (!succeed) {
333         THERMAL_HILOGD(COMP_SVC, "Failed to register subscriber");
334         return nullptr;
335     }
336     return subscriberPtr;
337 }
338 
SetUpTestCase()339 void ThermalLevelEventSystemTest::SetUpTestCase()
340 {
341     g_service = ThermalService::GetInstance();
342     g_service->InitSystemTestModules();
343     g_service->OnStart();
344     g_service->InitStateMachine();
345     g_token = GetSelfTokenID();
346     tokenID_ = GetAccessTokenId(&infoInstance);
347     ASSERT_NE(0, tokenID_);
348     ASSERT_EQ(0, SetSelfTokenID(tokenID_));
349     AccessTokenKit::ReloadNativeTokenInfo();
350 }
351 
TearDownTestCase()352 void ThermalLevelEventSystemTest::TearDownTestCase()
353 {
354     g_service->OnStop();
355     AccessTokenKit::DeleteToken(tokenID_);
356     SetSelfTokenID(g_token);
357 }
358 
TearDown()359 void ThermalLevelEventSystemTest::TearDown()
360 {
361     g_service->SetScene("");
362     HdfThermalCallbackInfo event;
363     ThermalZoneInfo info1;
364     info1.type = "battery";
365     info1.temp = 0;
366     event.info.push_back(info1);
367     g_service->HandleThermalCallbackEvent(event);
368     g_callbackTriggered = false;
369 }
370 
371 
372 namespace {
373 /*
374  * @tc.number: ThermalLevelEventSystemTest001
375  * @tc.name: ThermalLevelEventSystemTest
376  * @tc.desc: Verify the receive the level common event
377  */
378 HWTEST_F (ThermalLevelEventSystemTest, ThermalLevelEventSystemTest001, TestSize.Level0)
379 {
380     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest001: Start");
381     shared_ptr<CommonEventThermalLevel1Test> subscriber = CommonEventThermalLevel1Test::RegisterEvent();
382     HdfThermalCallbackInfo event;
383     ThermalZoneInfo info1;
384     info1.type = "battery";
385     info1.temp = 40600;
386     event.info.push_back(info1);
387     g_service->HandleThermalCallbackEvent(event);
388     Wait();
389     CommonEventManager::UnSubscribeCommonEvent(subscriber);
390     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest001: End");
391 }
392 
393 /*
394  * @tc.number: ThermalLevelEventSystemTest002
395  * @tc.name: ThermalLevelEventSystemTest
396  * @tc.desc: Verify the receive the level common event
397  */
398 HWTEST_F (ThermalLevelEventSystemTest, ThermalLevelEventSystemTest002, TestSize.Level0)
399 {
400     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest002: Start");
401     shared_ptr<CommonEventThermalLevel2Test> subscriber = CommonEventThermalLevel2Test::RegisterEvent();
402     HdfThermalCallbackInfo event;
403     ThermalZoneInfo info1;
404     info1.type = "battery";
405     info1.temp = 43600;
406     event.info.push_back(info1);
407     g_service->HandleThermalCallbackEvent(event);
408     Wait();
409     CommonEventManager::UnSubscribeCommonEvent(subscriber);
410     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest002: End");
411 }
412 
413 /*
414  * @tc.number: ThermalLevelEventSystemTest003
415  * @tc.name: ThermalLevelEventSystemTest
416  * @tc.desc: Verify the receive the level common event
417  */
418 HWTEST_F (ThermalLevelEventSystemTest, ThermalLevelEventSystemTest003, TestSize.Level0)
419 {
420     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest003: Start");
421     shared_ptr<CommonEventThermalLevel3Test> subscriber = CommonEventThermalLevel3Test::RegisterEvent();
422     HdfThermalCallbackInfo event;
423     ThermalZoneInfo info1;
424     info1.type = "battery";
425     info1.temp = 46600;
426     event.info.push_back(info1);
427     g_service->HandleThermalCallbackEvent(event);
428     Wait();
429     CommonEventManager::UnSubscribeCommonEvent(subscriber);
430     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest003: End");
431 }
432 
433 /*
434  * @tc.number: ThermalLevelEventSystemTest004
435  * @tc.name: ThermalLevelEventSystemTest
436  * @tc.desc: Verify the receive the idle common event
437  */
438 HWTEST_F (ThermalLevelEventSystemTest, ThermalLevelEventSystemTest004, TestSize.Level0)
439 {
440     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest004: Start");
441     int32_t batteryCapacity = 90;
442     int32_t chargerCurrent = 1100;
443     int32_t invalid = 0;
444     system("hidumper -s 3302 -a -u");
445     EXPECT_TRUE(PublishChangedEvent(batteryCapacity, invalid));
446     sleep(TIME_OUT);
447     shared_ptr<CommonEventThermalIdleTrueTest> subscriber = CommonEventThermalIdleTrueTest::RegisterEvent();
448     EXPECT_TRUE(PublishChangedEvent(batteryCapacity, chargerCurrent));
__anon9db40d560402null449     thread t([&] {
450         CommonEventData data;
451         Want want;
452         auto code = static_cast<uint32_t>(ChargeIdleEventCode::EVENT_CODE_CHARGE_IDLE_STATE);
453         want.SetParam(ToString(code), true);
454         data.SetWant(want);
455         sleep(TIME_OUT / 10); // 100ms
456         subscriber->OnReceiveEvent(data); // mock for receive event
457     });
458     Wait();
459     t.join();
460     CommonEventManager::UnSubscribeCommonEvent(subscriber);
461     system("hidumper -s 3302 -a -r");
462     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest004: End");
463 }
464 
465 /*
466  * @tc.number: ThermalLevelEventSystemTest005
467  * @tc.name: ThermalLevelEventSystemTest
468  * @tc.desc: Verify the receive the idle common event
469  */
470 HWTEST_F (ThermalLevelEventSystemTest, ThermalLevelEventSystemTest005, TestSize.Level0)
471 {
472     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest005: Start");
473     int32_t lastBatteryCapacity = 90;
474     int32_t lastChargerCurrent = 1100;
475     int32_t batteryCapacity = 70;
476     int32_t chargerCurrent = 900;
477     system("hidumper -s 3302 -a -u");
478     EXPECT_TRUE(PublishChangedEvent(lastBatteryCapacity, lastChargerCurrent));
479     sleep(TIME_OUT);
480     shared_ptr<CommonEventThermalIdleFalseTest> subscriber = CommonEventThermalIdleFalseTest::RegisterEvent();
481     EXPECT_TRUE(PublishChangedEvent(batteryCapacity, chargerCurrent));
__anon9db40d560502null482     thread t([&] {
483         CommonEventData data;
484         Want want;
485         auto code = static_cast<uint32_t>(ChargeIdleEventCode::EVENT_CODE_CHARGE_IDLE_STATE);
486         want.SetParam(ToString(code), false);
487         data.SetWant(want);
488         sleep(TIME_OUT / 10); // 100ms
489         subscriber->OnReceiveEvent(data); // mock for receive event
490     });
491     Wait();
492     t.join();
493     CommonEventManager::UnSubscribeCommonEvent(subscriber);
494     system("hidumper -s 3302 -a -r");
495     THERMAL_HILOGD(LABEL_TEST, "ThermalLevelEventSystemTest005: End");
496 }
497 } // namespace
498