• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 #include <gtest/gtest.h>
16 
17 #include "bootstage.h"
18 #include "init_jobs_internal.h"
19 #include "init_log.h"
20 #include "init_param.h"
21 #include "init_utils.h"
22 #include "init_hashmap.h"
23 #include "loop_event.h"
24 #include "param_manager.h"
25 #include "param_stub.h"
26 #include "param_utils.h"
27 #include "securec.h"
28 #include "trigger_checker.h"
29 #include "trigger_manager.h"
30 
31 using namespace testing::ext;
32 using namespace std;
33 
34 static const int triggerBuffer = 512;
35 static uint32_t g_execCmdId = 0;
36 static int g_matchTrigger = 0;
37 static char g_matchTriggerName[triggerBuffer] = { 0 };
BootStateChange(int start,const char * content)38 static void BootStateChange(int start, const char *content)
39 {
40     UNUSED(content);
41     return;
42 }
43 
TestCmdExec(const TriggerNode * trigger,const char * content,uint32_t size)44 static int TestCmdExec(const TriggerNode *trigger, const char *content, uint32_t size)
45 {
46     PARAM_CHECK(trigger != nullptr, return -1, "Invalid trigger");
47     PARAM_LOGI("DoTriggerExecute_ trigger type: %d %s", trigger->type, GetTriggerName(trigger));
48     PARAM_CHECK(trigger->type <= TRIGGER_UNKNOW, return -1, "Invalid trigger type %d", trigger->type);
49     CommandNode *cmd = GetNextCmdNode(reinterpret_cast<const JobNode *>(trigger), nullptr);
50     while (cmd != nullptr) {
51         g_execCmdId = cmd->cmdKeyIndex;
52         cmd = GetNextCmdNode(reinterpret_cast<const JobNode *>(trigger), cmd);
53     }
54     return 0;
55 }
56 
TestTriggerExecute(TriggerNode * trigger,const char * content,uint32_t size)57 static int TestTriggerExecute(TriggerNode *trigger, const char *content, uint32_t size)
58 {
59     JobNode *node = reinterpret_cast<JobNode *>(trigger);
60     int ret = memcpy_s(g_matchTriggerName, (int)sizeof(g_matchTriggerName) - 1, node->name, strlen(node->name));
61     EXPECT_EQ(ret, 0);
62     g_matchTriggerName[strlen(node->name)] = '\0';
63     g_matchTrigger++;
64     return 0;
65 }
66 
Test_JobParseHook(JOB_PARSE_CTX * jobParseCtx)67 static void Test_JobParseHook(JOB_PARSE_CTX *jobParseCtx)
68 {
69     return;
70 }
71 
72 class TriggerUnitTest : public ::testing::Test {
73 public:
TriggerUnitTest()74     TriggerUnitTest() {}
~TriggerUnitTest()75     virtual ~TriggerUnitTest() {}
76 
SetUp()77     void SetUp()
78     {
79         SetTestPermissionResult(0);
80     }
TearDown()81     void TearDown() {}
TestBody()82     void TestBody() {}
83 
ParseInitCfg(const char * configFile)84     int ParseInitCfg(const char *configFile)
85     {
86         char *fileBuf = ReadFileToBuf(configFile);
87         INIT_ERROR_CHECK(fileBuf != nullptr, return -1, "Failed to read file content %s", configFile);
88         cJSON *fileRoot = cJSON_Parse(fileBuf);
89         INIT_ERROR_CHECK(fileRoot != nullptr, return -1, "Failed to parse json file %s", configFile);
90         ParseTriggerConfig(fileRoot, nullptr, nullptr);
91         cJSON_Delete(fileRoot);
92         free(fileBuf);
93         fileBuf = nullptr;
94         return 0;
95     }
96 
TestLoadTrigger()97     int TestLoadTrigger()
98     {
99         RegisterBootStateChange(BootStateChange);
100         InitAddJobParseHook(Test_JobParseHook);
101 
102         int cmdKeyIndex = 0;
103         const char *matchCmd = GetMatchCmd("setparam aaaa aaaa", &cmdKeyIndex);
104         printf("cmd %d \n", matchCmd != nullptr);
105         EXPECT_NE(matchCmd, nullptr);
106 
107         ReadConfig();
108         ParseInitCfg(STARTUP_INIT_UT_PATH "/trigger_test.cfg");
109         // trigger
110         PostTrigger(EVENT_TRIGGER_BOOT, "pre-init", strlen("pre-init"));
111         PostTrigger(EVENT_TRIGGER_BOOT, "init", strlen("init"));
112         PostTrigger(EVENT_TRIGGER_BOOT, "post-init", strlen("post-init"));
113         LE_DoAsyncEvent(LE_GetDefaultLoop(), GetTriggerWorkSpace()->eventHandle);
114         return 0;
115     }
116 
GetTriggerHeader(int type)117     TriggerHeader *GetTriggerHeader(int type)
118     {
119         return &GetTriggerWorkSpace()->triggerHead[type];
120     }
121 
AddTrigger(int type,const char * name,const char * condition,uint32_t size)122     JobNode *AddTrigger(int type, const char *name, const char *condition, uint32_t size)
123     {
124         return UpdateJobTrigger(GetTriggerWorkSpace(), type, condition, name);
125     }
126 
TestAddTriggerForBoot()127     int TestAddTriggerForBoot()
128     {
129         JobNode *node = AddTrigger(TRIGGER_BOOT, "init-later", "", 0);
130         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), "init-later");
131         EXPECT_EQ(node, trigger);
132         if (trigger == nullptr) {
133             return -1;
134         }
135         EXPECT_EQ(strcmp(trigger->name, "init-later"), 0);
136 
137         // add command
138         int cmdIndex = 0;
139         GetMatchCmd("reboot ", &cmdIndex);
140         int ret = AddCommand(trigger, cmdIndex, nullptr, nullptr);
141         EXPECT_EQ(ret, 0);
142         ret = AddCommand(trigger, cmdIndex, "update: aaaaaaa", nullptr);
143         EXPECT_EQ(ret, 0);
144         return 0;
145     }
146 
TestAddTriggerForParm()147     int TestAddTriggerForParm()
148     {
149         const char *triggerName = "param:test_param.000";
150         int id = 0;
151         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, "test_param.000=1", 0);
152         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
153         GetTriggerHeader(TRIGGER_PARAM)->compareData(reinterpret_cast<struct tagTriggerNode_ *>(trigger), &id);
154         EXPECT_EQ(trigger, node);
155         if (trigger == nullptr) {
156             return -1;
157         }
158         EXPECT_EQ(strcmp(trigger->name, triggerName), 0);
159 
160         // add command
161         int cmdIndex = 0;
162         GetMatchCmd("reboot ", &cmdIndex);
163         int ret = AddCommand(trigger, cmdIndex, nullptr, nullptr);
164         EXPECT_EQ(ret, 0);
165         ret = AddCommand(trigger, cmdIndex, "update: aaaaaaa", nullptr);
166         EXPECT_EQ(ret, 0);
167         return 0;
168     }
169 
TestParamEvent()170     int TestParamEvent()
171     {
172         PostParamTrigger(EVENT_TRIGGER_PARAM, "net.tcp.default_init_rwnd", "60");
173         const char *sysctrl = "ohos.startup.powerctrl=reboot, shutdown";
174         PostTrigger(EVENT_TRIGGER_PARAM, sysctrl, strlen(sysctrl));
175         PostParamTrigger(EVENT_TRIGGER_PARAM, "ohos.startup.powerctrl", "reboot, shutdown");
176 
177         const char *startCmd = "ohos.ctl.start=hdc -t";
178         PostTrigger(EVENT_TRIGGER_PARAM, startCmd, strlen(startCmd));
179         PostParamTrigger(EVENT_TRIGGER_PARAM, "ohos.ctl.start", "hdc -t");
180 
181         const char *stopCmd = "ohos.ctl.stop=hdc -t";
182         PostTrigger(EVENT_TRIGGER_PARAM, stopCmd, strlen(stopCmd));
183         PostParamTrigger(EVENT_TRIGGER_PARAM, "ohos.ctl.stop", "hdc -t");
184         return 0;
185     }
186 
TestBootEvent(const char * boot)187     int TestBootEvent(const char *boot)
188     {
189         PostTrigger(EVENT_TRIGGER_BOOT, boot, strlen(boot));
190         return 0;
191     }
192 
TestCheckParamTrigger1()193     int TestCheckParamTrigger1()
194     {
195         const char *triggerName = "param:test_param.111";
196         const char *param = "test_param.aaa.111.2222";
197         const char *value = "1";
198         char buffer[triggerBuffer];
199         int ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param, value);
200         EXPECT_GE(ret, 0);
201         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, buffer, 0);
202         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
203         EXPECT_EQ(trigger, node);
204 
205         g_matchTrigger = 0;
206         ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param, "2");
207         EXPECT_GE(ret, 0);
208         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, buffer, strlen(buffer), TestTriggerExecute);
209         EXPECT_EQ(0, g_matchTrigger);
210 
211         g_matchTrigger = 0;
212         ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param, value);
213         EXPECT_GE(ret, 0);
214         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, buffer, strlen(buffer), TestTriggerExecute);
215         EXPECT_EQ(1, g_matchTrigger);
216         EXPECT_EQ(0, strcmp(triggerName, g_matchTriggerName));
217 
218         // check for bug
219         g_matchTrigger = 0;
220         ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", "2222", value);
221         EXPECT_GE(ret, 0);
222         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, buffer, strlen(buffer), TestTriggerExecute);
223         EXPECT_EQ(0, g_matchTrigger);
224 
225         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM_WATCH, buffer, strlen(buffer), TestTriggerExecute);
226         return 0;
227     }
228 
TestCheckParamTrigger2()229     int TestCheckParamTrigger2()
230     {
231         const char *triggerName = "param:test_param.222";
232         const char *param = "test_param.aaa.222.2222";
233         char buffer[triggerBuffer];
234         int ret = sprintf_s(buffer, sizeof(buffer), "%s=*", param);
235         EXPECT_GE(ret, 0);
236         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, buffer, 0);
237         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
238         EXPECT_EQ(trigger, node);
239 
240         g_matchTrigger = 0;
241         ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param, "2");
242         EXPECT_GE(ret, 0);
243         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, buffer, strlen(buffer), TestTriggerExecute);
244         EXPECT_EQ(1, g_matchTrigger);
245         EXPECT_EQ(0, strcmp(triggerName, g_matchTriggerName));
246 
247         g_matchTrigger = 0;
248         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, param, strlen(param), TestTriggerExecute);
249         EXPECT_EQ(1, g_matchTrigger);
250         EXPECT_EQ(0, strcmp(triggerName, g_matchTriggerName));
251         return 0;
252     }
253 
TestCheckParamTrigger3()254     int TestCheckParamTrigger3()
255     {
256         const char *triggerName = "param:test_param.333";
257         const char *param1 = "test_param.aaa.333.2222=1";
258         const char *param2 = "test_param.aaa.333.3333=2";
259         char buffer[triggerBuffer];
260         int ret = sprintf_s(buffer, sizeof(buffer), "%s || %s", param1, param2);
261         EXPECT_GE(ret, 0);
262         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, buffer, 0);
263         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
264         EXPECT_EQ(trigger, node);
265 
266         g_matchTrigger = 0;
267         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, param1, strlen(param1), TestTriggerExecute);
268         EXPECT_EQ(1, g_matchTrigger);
269         EXPECT_EQ(0, strcmp(triggerName, g_matchTriggerName));
270 
271         g_matchTrigger = 0;
272         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, param2, strlen(param2), TestTriggerExecute);
273         EXPECT_EQ(1, g_matchTrigger);
274         EXPECT_EQ(0, strcmp(triggerName, g_matchTriggerName));
275         return 0;
276     }
277 
TestCheckParamTrigger4()278     int TestCheckParamTrigger4()
279     {
280         const char *triggerName = "param:test_param.444";
281         const char *param1 = "test_param.aaa.444.2222";
282         const char *param2 = "test_param.aaa.444.3333";
283         char buffer[triggerBuffer];
284         int ret = sprintf_s(buffer, sizeof(buffer), "%s=%s && %s=%s", param1, "1", param2, "2");
285         EXPECT_GE(ret, 0);
286         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, buffer, 0);
287         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
288         EXPECT_EQ(trigger, node);
289         DoJobNow(triggerName);
290         ClearTrigger(nullptr, 0);
291         g_matchTrigger = 0;
292         SystemWriteParam(param1, "1");
293         ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param1, "1");
294         EXPECT_GE(ret, 0);
295         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, buffer, strlen(buffer), TestTriggerExecute);
296         EXPECT_EQ(0, g_matchTrigger);
297 
298         SystemWriteParam(param2, "2");
299         g_matchTrigger = 0;
300         ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param2, "2");
301         EXPECT_GE(ret, 0);
302         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, buffer, strlen(buffer), TestTriggerExecute);
303         EXPECT_EQ(1, g_matchTrigger);
304         EXPECT_EQ(0, strcmp(triggerName, g_matchTriggerName));
305         return 0;
306     }
307 
308     // test for trigger aaaa:test_param.aaa 被加入unknown执行
TestCheckParamTrigger5()309     int TestCheckParamTrigger5()
310     {
311         const char *triggerName = "aaaa:test_param.aaa";
312         const char *param1 = "test_param.aaa.aaa.2222";
313         const char *param2 = "test_param.aaa.aaa.3333";
314         char buffer[triggerBuffer];
315         int ret = sprintf_s(buffer, sizeof(buffer), "aaaa && %s=%s && %s=%s", param1, "1", param2, "2");
316         EXPECT_GE(ret, 0);
317         JobNode *node = AddTrigger(TRIGGER_UNKNOW, triggerName, buffer, 0);
318         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
319         EXPECT_EQ(trigger, node);
320 
321         g_matchTrigger = 0;
322         SystemWriteParam(param1, "1");
323         ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param1, "1");
324         EXPECT_GE(ret, 0);
325         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_PARAM, buffer, strlen(buffer), TestTriggerExecute);
326         EXPECT_EQ(0, g_matchTrigger);
327 
328         SystemWriteParam(param2, "2");
329         g_matchTrigger = 0;
330         CheckTrigger(GetTriggerWorkSpace(), TRIGGER_UNKNOW, "aaaa", strlen("aaaa"), TestTriggerExecute);
331         EXPECT_EQ(1, g_matchTrigger);
332         EXPECT_EQ(0, strcmp(triggerName, g_matchTriggerName));
333         return 0;
334     }
335 
TestComputeCondition(const char * condition)336     int TestComputeCondition(const char *condition)
337     {
338         u_int32_t size = strlen(condition) + CONDITION_EXTEND_LEN;
339         char *prefix = reinterpret_cast<char *>(malloc(size));
340         if (prefix == nullptr) {
341             printf("prefix is null.\n");
342             return -1;
343         }
344         ConvertInfixToPrefix(condition, prefix, size);
345         printf("prefix %s \n", prefix);
346         free(prefix);
347         return 0;
348     }
349 
350     // 普通的属性trigger
TestExecuteParamTrigger1()351     int TestExecuteParamTrigger1()
352     {
353         const char *triggerName = "aaaa:test_param.eee";
354         const char *param = "test_param.eee.aaa.1111";
355         const char *value = "eee";
356         char buffer[triggerBuffer];
357         int ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param, value);
358         EXPECT_GE(ret, 0);
359         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, buffer, 0);
360         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
361         EXPECT_EQ(trigger, node);
362 
363         const uint32_t cmdIndex = 100;
364         ret = AddCommand(trigger, cmdIndex, value, nullptr);
365         EXPECT_EQ(ret, 0);
366         // 修改命令为测试执行
367         RegisterTriggerExec(TRIGGER_PARAM, TestCmdExec);
368         SystemWriteParam(param, value);
369         LE_DoAsyncEvent(LE_GetDefaultLoop(), GetTriggerWorkSpace()->eventHandle);
370         EXPECT_EQ(g_execCmdId, cmdIndex);
371         return 0;
372     }
373 
TestExecuteParamTrigger2()374     int TestExecuteParamTrigger2()
375     {
376         const char *triggerName = "param:test_param.dddd";
377         const char *param = "test_param.dddd.aaa.2222";
378         const char *value = "2222";
379         char buffer[triggerBuffer];
380         int ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param, value);
381         EXPECT_GE(ret, 0);
382         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, buffer, 0);
383         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
384         EXPECT_EQ(trigger, node);
385         const uint32_t cmdIndex = 102;
386         ret = AddCommand(trigger, cmdIndex, value, nullptr);
387         EXPECT_EQ(ret, 0);
388         RegisterTriggerExec(TRIGGER_PARAM, TestCmdExec);
389         SystemWriteParam(param, value);
390         LE_DoAsyncEvent(LE_GetDefaultLoop(), GetTriggerWorkSpace()->eventHandle);
391         EXPECT_EQ(g_execCmdId, cmdIndex);
392         return 0;
393     }
394 
395     // 测试执行后立刻删除
TestExecuteParamTrigger3()396     int TestExecuteParamTrigger3()
397     {
398         const char *triggerName = "param:test_param.3333";
399         const char *param = "test_param.dddd.aaa.3333";
400         const char *value = "3333";
401         char buffer[triggerBuffer];
402         int ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param, value);
403         EXPECT_GE(ret, 0);
404         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, buffer, 0);
405         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
406         EXPECT_EQ(trigger, node);
407         if (trigger == nullptr) {
408             return -1;
409         }
410         const uint32_t cmdIndex = 103;
411         ret = AddCommand(trigger, cmdIndex, value, nullptr);
412         EXPECT_EQ(ret, 0);
413         TRIGGER_SET_FLAG(trigger, TRIGGER_FLAGS_ONCE);
414         SystemWriteParam(param, value);
415 
416         RegisterTriggerExec(TRIGGER_PARAM, TestCmdExec);
417         LE_DoAsyncEvent(LE_GetDefaultLoop(), GetTriggerWorkSpace()->eventHandle);
418         EXPECT_EQ(g_execCmdId, cmdIndex);
419         trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
420         if (trigger != nullptr) {
421             EXPECT_EQ(1, 0);
422         }
423         return 0;
424     }
425 
426     // 测试删除队列中的trigger
TestExecuteParamTrigger4()427     int TestExecuteParamTrigger4()
428     {
429         const char *triggerName = "param:test_param.4444";
430         const char *param = "test_param.dddd.aaa.4444";
431         const char *value = "4444";
432         char buffer[triggerBuffer];
433         int ret = sprintf_s(buffer, sizeof(buffer), "%s=%s", param, value);
434         EXPECT_GE(ret, 0);
435         JobNode *node = AddTrigger(TRIGGER_PARAM, triggerName, buffer, 0);
436         JobNode *trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
437         EXPECT_EQ(trigger, node);
438         if (trigger == nullptr) {
439             return -1;
440         }
441         const uint32_t cmdIndex = 105;
442         ret = AddCommand(trigger, cmdIndex, value, nullptr);
443         EXPECT_EQ(ret, 0);
444         TRIGGER_SET_FLAG(trigger, TRIGGER_FLAGS_ONCE);
445         SystemWriteParam(param, value);
446 
447         RegisterTriggerExec(TRIGGER_PARAM, TestCmdExec);
448         FreeTrigger(GetTriggerWorkSpace(), reinterpret_cast<TriggerNode *>(trigger));
449         LE_DoAsyncEvent(LE_GetDefaultLoop(), GetTriggerWorkSpace()->eventHandle);
450         EXPECT_NE(g_execCmdId, cmdIndex);
451         trigger = GetTriggerByName(GetTriggerWorkSpace(), triggerName);
452         if (trigger != nullptr) {
453             EXPECT_EQ(1, 0);
454         }
455         return 0;
456     }
457 
458     // 测试执行后检查子trigger执行
TestExecuteParamTrigger5()459     int TestExecuteParamTrigger5()
460     {
461         const char *boot = "boot2";
462         const char *triggerName = "boot2:test_param.5555";
463         const char *param = "test_param.dddd.aaa.5555";
464         const char *value = "5555";
465         JobNode *trigger = AddTrigger(TRIGGER_BOOT, boot, nullptr, 0);
466         const int testCmdIndex = 1105;
467         int ret = AddCommand(trigger, testCmdIndex, value, nullptr);
468         EXPECT_EQ(ret, 0);
469         if (trigger == nullptr) {
470             return -1;
471         }
472         TRIGGER_SET_FLAG(trigger, TRIGGER_FLAGS_SUBTRIGGER);
473 
474         char buffer[triggerBuffer];
475         ret = sprintf_s(buffer, sizeof(buffer), "boot2 && %s=%s", param, value);
476         EXPECT_GE(ret, 0);
477         trigger = AddTrigger(TRIGGER_UNKNOW, triggerName, buffer, 0);
478         const int testCmdIndex2 = 105;
479         ret = AddCommand(trigger, testCmdIndex2, value, nullptr);
480 
481         RegisterTriggerExec(TRIGGER_UNKNOW, TestCmdExec);
482         SystemWriteParam(param, value);
483 
484         TestBootEvent(boot);
485         LE_DoAsyncEvent(LE_GetDefaultLoop(), GetTriggerWorkSpace()->eventHandle);
486         EXPECT_EQ(g_execCmdId, (uint32_t)testCmdIndex2);
487         return 0;
488     }
489 
TestDumpTrigger()490     int TestDumpTrigger()
491     {
492         (void)AddCompleteJob("param:ohos.servicectrl.display", "ohos.servicectrl.display=*", "display system");
493         DoTriggerExec("param:ohos.servicectrl.display");
494         return 0;
495     }
496 };
497 
498 HWTEST_F(TriggerUnitTest, TestLoadTrigger, TestSize.Level0)
499 {
500     TriggerUnitTest test;
501     test.TestLoadTrigger();
502 }
503 
504 HWTEST_F(TriggerUnitTest, TestBootEvent, TestSize.Level0)
505 {
506     TriggerUnitTest test;
507     test.TestBootEvent("pre-init");
508     test.TestBootEvent("init");
509     test.TestBootEvent("post-init");
510     test.TestBootEvent("early-init");
511 }
512 
513 HWTEST_F(TriggerUnitTest, TestAddTriggerForBoot, TestSize.Level0)
514 {
515     TriggerUnitTest test;
516     test.TestAddTriggerForBoot();
517 }
518 
519 HWTEST_F(TriggerUnitTest, TestAddTriggerForParm, TestSize.Level0)
520 {
521     TriggerUnitTest test;
522     test.TestAddTriggerForParm();
523 }
524 
525 HWTEST_F(TriggerUnitTest, TestCheckParamTrigger1, TestSize.Level0)
526 {
527     TriggerUnitTest test;
528     test.TestCheckParamTrigger1();
529 }
530 
531 HWTEST_F(TriggerUnitTest, TestCheckParamTrigger2, TestSize.Level0)
532 {
533     TriggerUnitTest test;
534     test.TestCheckParamTrigger2();
535 }
536 
537 HWTEST_F(TriggerUnitTest, TestCheckParamTrigger3, TestSize.Level0)
538 {
539     TriggerUnitTest test;
540     test.TestCheckParamTrigger3();
541 }
542 
543 HWTEST_F(TriggerUnitTest, TestCheckParamTrigger4, TestSize.Level0)
544 {
545     TriggerUnitTest test;
546     test.TestCheckParamTrigger4();
547 }
548 
549 HWTEST_F(TriggerUnitTest, TestCheckParamTrigger5, TestSize.Level0)
550 {
551     TriggerUnitTest test;
552     test.TestCheckParamTrigger5();
553 }
554 
555 HWTEST_F(TriggerUnitTest, TestParamEvent, TestSize.Level0)
556 {
557     TriggerUnitTest test;
558     test.TestParamEvent();
559 }
560 
561 HWTEST_F(TriggerUnitTest, ComputerCondition, TestSize.Level0)
562 {
563     TriggerUnitTest test;
564     test.TestComputeCondition("aaa=111||aaa=222||aaa=333");
565     test.TestComputeCondition("aaa=111||aaa=222&&aaa=333");
566     test.TestComputeCondition("(aaa=111||aaa=222)&&aaa=333");
567     test.TestComputeCondition("aaa=111||(aaa=222&&aaa=333)");
568 }
569 
570 HWTEST_F(TriggerUnitTest, TestExecuteParamTrigger1, TestSize.Level0)
571 {
572     TriggerUnitTest test;
573     test.TestExecuteParamTrigger1();
574 }
575 
576 HWTEST_F(TriggerUnitTest, TestExecuteParamTrigger2, TestSize.Level0)
577 {
578     TriggerUnitTest test;
579     test.TestExecuteParamTrigger2();
580 }
581 
582 HWTEST_F(TriggerUnitTest, TestExecuteParamTrigger3, TestSize.Level0)
583 {
584     TriggerUnitTest test;
585     test.TestExecuteParamTrigger3();
586 }
587 
588 HWTEST_F(TriggerUnitTest, TestExecuteParamTrigger4, TestSize.Level0)
589 {
590     TriggerUnitTest test;
591     test.TestExecuteParamTrigger4();
592 }
593 
594 HWTEST_F(TriggerUnitTest, TestExecuteParamTrigger5, TestSize.Level0)
595 {
596     TriggerUnitTest test;
597     test.TestExecuteParamTrigger5();
598 }
599 
600 HWTEST_F(TriggerUnitTest, TestExecuteParamTrigger6, TestSize.Level0)
601 {
602     TriggerUnitTest test;
603     test.TestDumpTrigger();
604 
605 }
606