• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 "sys_event_service_ohos_test.h"
17 
18 #include <cstdlib>
19 #include <semaphore.h>
20 #include <string>
21 #include <vector>
22 
23 #include "ash_mem_utils.h"
24 #include "event.h"
25 #include "event_query_wrapper_builder.h"
26 #include "compliant_event_checker.h"
27 #include "file_util.h"
28 #include "hiview_global.h"
29 #include "if_system_ability_manager.h"
30 #include "ipc_skeleton.h"
31 #include "iquery_sys_event_callback.h"
32 #include "iservice_registry.h"
33 #include "isys_event_callback.h"
34 #include "isys_event_service.h"
35 #include "query_argument.h"
36 #include "query_sys_event_callback_proxy.h"
37 #include "parameter_ex.h"
38 #include "plugin.h"
39 #include "ret_code.h"
40 #include "running_status_log_util.h"
41 #include "string_ex.h"
42 #include "sys_event.h"
43 #include "sys_event_rule.h"
44 #include "sys_event_service_adapter.h"
45 #include "sys_event_service_ohos.h"
46 #include "system_ability.h"
47 #include "string_ex.h"
48 #include "string_util.h"
49 #include "sys_event_callback_proxy.h"
50 #include "sys_event_service_stub.h"
51 #include "time_util.h"
52 
53 using namespace std;
54 
55 namespace OHOS {
56 namespace HiviewDFX {
57 namespace {
58 constexpr char TEST_LOG_DIR[] = "/data/test/sys_event_ohos_test/";
59 const std::vector<int> EVENT_TYPES = {1, 2, 3, 4}; // FAULT = 1, STATISTIC = 2 SECURITY = 3, BEHAVIOR = 4
60 
61 class TestSysEventServiceStub : public SysEventServiceStub {
62 public:
TestSysEventServiceStub()63     TestSysEventServiceStub() {}
~TestSysEventServiceStub()64     virtual ~TestSysEventServiceStub() {}
65 
AddListener(const std::vector<SysEventRule> & rules,const sptr<ISysEventCallback> & callback)66     ErrCode AddListener(const std::vector<SysEventRule>& rules, const sptr<ISysEventCallback>& callback)
67     {
68         return 0;
69     }
70 
RemoveListener(const sptr<ISysEventCallback> & callback)71     ErrCode RemoveListener(const sptr<ISysEventCallback>& callback)
72     {
73         return 0;
74     }
75 
Query(const QueryArgument & queryArgument,const std::vector<SysEventQueryRule> & rules,const sptr<IQuerySysEventCallback> & callback)76     ErrCode Query(const QueryArgument& queryArgument, const std::vector<SysEventQueryRule>& rules,
77         const sptr<IQuerySysEventCallback>& callback)
78     {
79         return 0;
80     }
81 
AddSubscriber(const std::vector<SysEventQueryRule> & rules,int64_t & funcResult)82     ErrCode AddSubscriber(const std::vector<SysEventQueryRule> &rules, int64_t& funcResult)
83     {
84         return TimeUtil::GetMilliseconds();
85     }
86 
RemoveSubscriber()87     ErrCode RemoveSubscriber()
88     {
89         return 0;
90     }
91 
Export(const QueryArgument & queryArgument,const std::vector<SysEventQueryRule> & rules,int64_t & funcResult)92     ErrCode Export(const QueryArgument &queryArgument, const std::vector<SysEventQueryRule> &rules, int64_t& funcResult)
93     {
94         return TimeUtil::GetMilliseconds();
95     }
96 
97 public:
98     enum Code {
99         DEFAULT = -1,
100         ADD_SYS_EVENT_LISTENER = 0,
101         REMOVE_SYS_EVENT_LISTENER,
102         QUERY_SYS_EVENT,
103         SET_DEBUG_MODE,
104         ADD_SYS_EVENT_SUBSCRIBER,
105         REMOVE_SYS_EVENT_SUBSCRIBER,
106         EXPORT_SYS_EVENT
107     };
108 };
109 
110 class HiviewTestContext : public HiviewContext {
111 public:
GetHiViewDirectory(DirectoryType type __UNUSED)112     std::string GetHiViewDirectory(DirectoryType type __UNUSED)
113     {
114         return TEST_LOG_DIR;
115     }
116 };
117 
GetLogDir()118 std::string GetLogDir()
119 {
120     std::string workPath = HiviewGlobal::GetInstance()->GetHiViewDirectory(
121         HiviewContext::DirectoryType::WORK_DIRECTORY);
122     if (workPath.back() != '/') {
123         workPath = workPath + "/";
124     }
125     std::string logDestDir = workPath + "sys_event_log/";
126     if (!FileUtil::FileExists(logDestDir)) {
127         FileUtil::ForceCreateDirectory(logDestDir, FileUtil::FILE_PERM_770);
128     }
129     return logDestDir;
130 }
131 }
132 
SetUpTestCase()133 void SysEventServiceOhosTest::SetUpTestCase() {}
134 
TearDownTestCase()135 void SysEventServiceOhosTest::TearDownTestCase() {}
136 
SetUp()137 void SysEventServiceOhosTest::SetUp() {}
138 
TearDown()139 void SysEventServiceOhosTest::TearDown()
140 {
141     (void)FileUtil::ForceRemoveDirectory(TEST_LOG_DIR);
142 }
143 
144 /**
145  * @tc.name: SysEventServiceAdapterTest
146  * @tc.desc: test apis of SysEventServiceAdapter
147  * @tc.type: FUNC
148  * @tc.require: issueI62BDW
149  */
150 HWTEST_F(SysEventServiceOhosTest, SysEventServiceAdapterTest, testing::ext::TestSize.Level3)
151 {
152     OHOS::HiviewDFX::SysEventServiceAdapter::StartService(nullptr);
153     std::shared_ptr<SysEvent> sysEvent = nullptr;
154     OHOS::HiviewDFX::SysEventServiceAdapter::OnSysEvent(sysEvent);
155     SysEventCreator sysEventCreator("DEMO", "EVENT_NAME", SysEventCreator::FAULT);
156     std::vector<int> values = {1, 2, 3};
157     sysEventCreator.SetKeyValue("KEY", values);
158     sysEvent = std::make_shared<SysEvent>("test", nullptr, sysEventCreator);
159     OHOS::HiviewDFX::SysEventServiceAdapter::OnSysEvent(sysEvent);
160     ASSERT_TRUE(true);
161 }
162 
163 /**
164  * @tc.name: TestSysEventService001
165  * @tc.desc: SysEventServiceStub test
166  * @tc.type: FUNC
167  * @tc.require: issueI62WJT
168  */
169 HWTEST_F(SysEventServiceOhosTest, TestSysEventService001, testing::ext::TestSize.Level1)
170 {
171     SysEventServiceStub* sysEventService = new(std::nothrow) TestSysEventServiceStub();
172     MessageParcel data, reply;
173     MessageOption option;
174     sysEventService->OnRemoteRequest(TestSysEventServiceStub::Code::DEFAULT, data, reply, option);
175     ASSERT_TRUE(true);
176     sysEventService->OnRemoteRequest(TestSysEventServiceStub::Code::ADD_SYS_EVENT_LISTENER, data, reply, option);
177     ASSERT_TRUE(true);
178     sysEventService->OnRemoteRequest(TestSysEventServiceStub::Code::REMOVE_SYS_EVENT_LISTENER, data, reply,
179         option);
180     ASSERT_TRUE(true);
181     sysEventService->OnRemoteRequest(TestSysEventServiceStub::Code::QUERY_SYS_EVENT, data, reply, option);
182     ASSERT_TRUE(true);
183     sysEventService->OnRemoteRequest(TestSysEventServiceStub::Code::SET_DEBUG_MODE, data, reply, option);
184     ASSERT_TRUE(true);
185 }
186 
187 /**
188  * @tc.name: TestSysEventService002
189  * @tc.desc: SysEventServiceStub test
190  * @tc.type: FUNC
191  * @tc.require: SR000I1G42
192  */
193 HWTEST_F(SysEventServiceOhosTest, TestSysEventService002, testing::ext::TestSize.Level1)
194 {
195     SysEventServiceStub* sysEventService = new(std::nothrow) TestSysEventServiceStub();
196     MessageParcel data, reply;
197     MessageOption option;
198     sysEventService->OnRemoteRequest(TestSysEventServiceStub::Code::ADD_SYS_EVENT_SUBSCRIBER, data, reply, option);
199     ASSERT_TRUE(true);
200     sysEventService->OnRemoteRequest(TestSysEventServiceStub::Code::REMOVE_SYS_EVENT_SUBSCRIBER, data, reply, option);
201     ASSERT_TRUE(true);
202     sysEventService->OnRemoteRequest(TestSysEventServiceStub::Code::EXPORT_SYS_EVENT, data, reply, option);
203     ASSERT_TRUE(true);
204 }
205 
206 /**
207  * @tc.name: MarshallingTAndUnmarshallingTest
208  * @tc.desc: Unmarshalling test
209  * @tc.type: FUNC
210  * @tc.require: issueI62WJT
211  */
212 HWTEST_F(SysEventServiceOhosTest, MarshallingTAndUnmarshallingTest, testing::ext::TestSize.Level1)
213 {
214     long long defaultTimeStap = -1;
215     int queryCount = 10;
216     OHOS::HiviewDFX::QueryArgument argument(defaultTimeStap, defaultTimeStap, queryCount);
217     MessageParcel parcel1;
218     auto ret = argument.Marshalling(parcel1);
219     ASSERT_TRUE(ret);
220     QueryArgument* argsPtr = argument.Unmarshalling(parcel1);
221     ASSERT_TRUE(argsPtr != nullptr && argsPtr->maxEvents == 10 && argsPtr->beginTime == -1);
222     OHOS::HiviewDFX::SysEventRule rule("DOMAIN1", "EVENT_NAME2", "TAG3", OHOS::HiviewDFX::RuleType::WHOLE_WORD);
223     MessageParcel parcel2;
224     ret = rule.Marshalling(parcel2);
225     ASSERT_TRUE(ret);
226     OHOS::HiviewDFX::SysEventRule* rulePtr = rule.Unmarshalling(parcel2);
227     ASSERT_TRUE(rulePtr != nullptr && rulePtr->domain == "DOMAIN1" &&
228         rulePtr->eventName == "EVENT_NAME2" && rulePtr->tag == "TAG3");
229 
230     std::vector<std::string> eventNames { "EVENT_NAME1", "EVENT_NAME2" };
231     OHOS::HiviewDFX::SysEventQueryRule eventQueryRule("DOMAIN", eventNames);
232     MessageParcel parcel3;
233     ret = eventQueryRule.Marshalling(parcel3);
234     ASSERT_TRUE(ret);
235     OHOS::HiviewDFX::SysEventQueryRule* eventQueryRulePtr = eventQueryRule.Unmarshalling(parcel3);
236     ASSERT_TRUE(eventQueryRulePtr != nullptr && eventQueryRulePtr->domain == "DOMAIN" &&
237         eventQueryRulePtr->eventList.size() == 2 && eventQueryRulePtr->eventList[0] == "EVENT_NAME1");
238 }
239 
240 /**
241  * @tc.name: ConditionParserTest01
242  * @tc.desc: Test apis of ConditionParser
243  * @tc.type: FUNC
244  * @tc.require: issueI62WJT
245  */
246 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest01, testing::ext::TestSize.Level1)
247 {
248     OHOS::HiviewDFX::ConditionParser parser;
249     EventStore::Cond cond;
250     std::string condStr = R"~({"version":"V1", "condition":{"and":[{"param":"NAME", "op":"=",
251         "value":"SysEventService"}]}})~";
252     auto ret = parser.ParseCondition(condStr, cond);
253     ASSERT_TRUE(ret);
254 }
255 
256 /**
257  * @tc.name: ConditionParserTest02
258  * @tc.desc: Test apis of ConditionParser
259  * @tc.type: FUNC
260  * @tc.require: issueI62WJT
261  */
262 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest02, testing::ext::TestSize.Level1)
263 {
264     OHOS::HiviewDFX::ConditionParser parser;
265     EventStore::Cond cond;
266     std::string condStr2 = R"~({"version":"V1", "condition":{"and":[{"param":"NAME", "op":"=",
267         "value":"SysEventService"}, {"param":"uid_", "op":"=", "value":1201}]}})~";
268     auto ret = parser.ParseCondition(condStr2, cond);
269     ASSERT_TRUE(ret);
270 }
271 
272 /**
273  * @tc.name: ConditionParserTest03
274  * @tc.desc: Test apis of ConditionParser
275  * @tc.type: FUNC
276  * @tc.require: issueI62WJT
277  */
278 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest03, testing::ext::TestSize.Level1)
279 {
280     OHOS::HiviewDFX::ConditionParser parser;
281     EventStore::Cond cond;
282     std::string condStr3 = R"~({"version":"V1", "condition":{"and":[{"param":"type_", "op":">", "value":0},
283         {"param":"uid_", "op":"=", "value":1201}]}})~";
284     auto ret = parser.ParseCondition(condStr3, cond);
285     ASSERT_TRUE(ret);
286 }
287 
288 /**
289  * @tc.name: ConditionParserTest04
290  * @tc.desc: Test apis of ConditionParser
291  * @tc.type: FUNC
292  * @tc.require: issueI62WJT
293  */
294 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest04, testing::ext::TestSize.Level1)
295 {
296     OHOS::HiviewDFX::ConditionParser parser;
297     EventStore::Cond cond;
298     std::string condStr4 = R"~({"version":"V1", "condition":{"and":[{"param1":"type_", "op":">", "value":0},
299         {"param2":"uid_", "op":"=", "value":1201}]}})~";
300     auto ret = parser.ParseCondition(condStr4, cond);
301     ASSERT_TRUE(!ret);
302 }
303 
304 /**
305  * @tc.name: ConditionParserTest05
306  * @tc.desc: Test apis of ConditionParser
307  * @tc.type: FUNC
308  * @tc.require: issueI62WJT
309  */
310 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest05, testing::ext::TestSize.Level1)
311 {
312     OHOS::HiviewDFX::ConditionParser parser;
313     EventStore::Cond cond;
314     std::string condSt5 = R"~({"version":"V1", "condition":{"and":[{"param":"", "op":">", "value":0},
315         {"param":"", "op":"=", "value":1201}]}})~";
316     auto ret = parser.ParseCondition(condSt5, cond);
317     ASSERT_TRUE(!ret);
318 }
319 
320 /**
321  * @tc.name: ConditionParserTest06
322  * @tc.desc: Test apis of ConditionParser
323  * @tc.type: FUNC
324  * @tc.require: issueI62WJT
325  */
326 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest06, testing::ext::TestSize.Level1)
327 {
328     OHOS::HiviewDFX::ConditionParser parser;
329     EventStore::Cond cond;
330     std::string condSt6 = R"~({"version":"V1", "condition":{"and":[{"param":"type_", "op1":">", "value":0},
331         {"param":"uid_", "op2":"=", "value":1201}]}})~";
332     auto ret = parser.ParseCondition(condSt6, cond);
333     ASSERT_TRUE(!ret);
334 }
335 
336 /**
337  * @tc.name: ConditionParserTest07
338  * @tc.desc: Test apis of ConditionParser
339  * @tc.type: FUNC
340  * @tc.require: issueI62WJT
341  */
342 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest07, testing::ext::TestSize.Level1)
343 {
344     OHOS::HiviewDFX::ConditionParser parser;
345     EventStore::Cond cond;
346     std::string condSt7 = R"~({"version":"V1", "condition":{"and":[{"param":"type_", "op":">", "value11":0},
347         {"param":"uid_", "op":"=", "value2":1201}]}})~";
348     auto ret = parser.ParseCondition(condSt7, cond);
349     ASSERT_TRUE(!ret);
350 }
351 
352 /**
353  * @tc.name: ConditionParserTest08
354  * @tc.desc: Test apis of ConditionParser
355  * @tc.type: FUNC
356  * @tc.require: issueI62WJT
357  */
358 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest08, testing::ext::TestSize.Level1)
359 {
360     OHOS::HiviewDFX::ConditionParser parser;
361     EventStore::Cond cond;
362     std::string condStr8 = R"~({"version":"V1", "condition":{"and":[{"param":"type_", "op":">", "value":[]},
363         {"param":"uid_", "op":"=", "value":[]}]}})~";
364     auto ret = parser.ParseCondition(condStr8, cond);
365     ASSERT_TRUE(!ret);
366 }
367 
368 /**
369  * @tc.name: ConditionParserTest09
370  * @tc.desc: Test apis of ConditionParser
371  * @tc.type: FUNC
372  * @tc.require: issueI62WJT
373  */
374 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest09, testing::ext::TestSize.Level1)
375 {
376     OHOS::HiviewDFX::ConditionParser parser;
377     EventStore::Cond cond;
378     std::string condStr9 = R"~({"version":"V1", "condition1":{"and":[{"param":"type_", "op":">", "value":0},
379         {"param":"uid_", "op":"=", "value":1201}]}})~";
380     auto ret = parser.ParseCondition(condStr9, cond);
381     ASSERT_TRUE(!ret);
382 }
383 
384 /**
385  * @tc.name: ConditionParserTest10
386  * @tc.desc: Test apis of ConditionParser
387  * @tc.type: FUNC
388  * @tc.require: issueI62WJT
389  */
390 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest10, testing::ext::TestSize.Level1)
391 {
392     OHOS::HiviewDFX::ConditionParser parser;
393     EventStore::Cond cond;
394     std::string condStr10 = R"~({"version":"V1", "condition":1})~";
395     auto ret = parser.ParseCondition(condStr10, cond);
396     ASSERT_TRUE(!ret);
397 }
398 
399 /**
400  * @tc.name: ConditionParserTest11
401  * @tc.desc: Test apis of ConditionParser
402  * @tc.type: FUNC
403  * @tc.require: issueI62WJT
404  */
405 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest11, testing::ext::TestSize.Level1)
406 {
407     OHOS::HiviewDFX::ConditionParser parser;
408     EventStore::Cond cond;
409     std::string condStr11 = R"~({"version":"V2", "condition":{"and":[{"param1":"type_", "op":">", "value":0},
410         {"param2":"uid_", "op":"=", "value":1201}]}})~";
411     auto ret = parser.ParseCondition(condStr11, cond);
412     ASSERT_TRUE(!ret);
413 }
414 
415 /**
416  * @tc.name: ConditionParserTest12
417  * @tc.desc: Test apis of ConditionParser
418  * @tc.type: FUNC
419  * @tc.require: issueI62WJT
420  */
421 HWTEST_F(SysEventServiceOhosTest, ConditionParserTest12, testing::ext::TestSize.Level1)
422 {
423     OHOS::HiviewDFX::ConditionParser parser;
424     EventStore::Cond cond;
425     auto ret = parser.ParseCondition("", cond);
426     ASSERT_FALSE(ret);
427 }
428 
429 /**
430  * @tc.name: QueryWrapperTest01
431  * @tc.desc: BUild query wrapper with all event types
432  * @tc.type: FUNC
433  * @tc.require: issueI62WJT
434  */
435 HWTEST_F(SysEventServiceOhosTest, QueryWrapperTest01, testing::ext::TestSize.Level1)
436 {
437     HiviewTestContext hiviewTestContext;
438     HiviewGlobal::CreateInstance(hiviewTestContext);
439     QueryArgument queryArgument1(-1, -1, 10);
440     auto queryWrapperBuilder1 = std::make_shared<EventQueryWrapperBuilder>(queryArgument1);
441     QueryArgument queryArgument2(-1, -1, 10, 1, 20);
442     auto queryWrapperBuilder2 = std::make_shared<EventQueryWrapperBuilder>(queryArgument2);
443     auto queryWrapper1 = queryWrapperBuilder1->Build();
444     ASSERT_TRUE(queryWrapper1 != nullptr);
445     auto queryWrapper2 = queryWrapperBuilder2->Build();
446     ASSERT_TRUE(queryWrapper2 != nullptr);
447 
448     ASSERT_FALSE(queryWrapperBuilder1->IsValid());
449     ASSERT_FALSE(queryWrapperBuilder2->IsValid());
450     queryWrapperBuilder1->Append("DOMAIN1", "EVENTNAME1", 0, "");
451     queryWrapperBuilder2->Append("DOMAIN2", "EVENTNAME2", 0, "");
452     ASSERT_TRUE(queryWrapperBuilder1->IsValid());
453     ASSERT_TRUE(queryWrapperBuilder2->IsValid());
454 }
455 
456 /**
457  * @tc.name: QueryWrapperTest02
458  * @tc.desc: BUild query wrapper with domain, event name and event type.
459  * @tc.type: FUNC
460  * @tc.require: issueI62WJT
461  */
462 HWTEST_F(SysEventServiceOhosTest, QueryWrapperTest02, testing::ext::TestSize.Level1)
463 {
464     HiviewTestContext hiviewTestContext;
465     HiviewGlobal::CreateInstance(hiviewTestContext);
466     QueryArgument queryArgument1(-1, -1, 10);
467     auto queryWrapperBuilder = std::make_shared<EventQueryWrapperBuilder>(queryArgument1);
468     queryWrapperBuilder->Append("DOMAIN1", "EVENTNAME1", 1, R"~({"version":"V1", "condition":
469         {"and":[{"param":"NAME", "op":"=", "value":"SysEventService"}]}})~");
470     queryWrapperBuilder->Append("DOMAIN2", "EVENTNAME2", 3, R"~({"version":"V1", "condition":
471         {"and":[{"param":"NAME", "op":"=", "value":"SysEventService"}]}})~");
472     auto queryWrapper = queryWrapperBuilder->Build();
473     ASSERT_TRUE(queryWrapper != nullptr);
474 }
475 
476 /**
477  * @tc.name: RunningStatusLogUtil001
478  * @tc.desc: test apis of RunningStatusLogUtil.
479  * @tc.type: FUNC
480  * @tc.require: issueICJ952
481  */
482 HWTEST_F(SysEventServiceOhosTest, RunningStatusLogUtil001, testing::ext::TestSize.Level1)
483 {
484     HiviewTestContext hiviewTestContext;
485     HiviewGlobal::CreateInstance(hiviewTestContext);
486 
487     std::vector<SysEventRule> eventRules;
488     OHOS::HiviewDFX::SysEventRule eventRule("DOMAIN1", "EVENT_NAME2", "TAG3", OHOS::HiviewDFX::RuleType::WHOLE_WORD);
489     eventRules.emplace_back(eventRule);
490     RunningStatusLogUtil::LogTooManyWatchRules(eventRules);
491     int limit = 22; // 22 is a test value
492     RunningStatusLogUtil::LogTooManyWatchers(limit);
493 
494     std::vector<SysEventQueryRule> eventQueryRules;
495     std::vector<std::string> eventNames { "EVENT_NAME1", "EVENT_NAME2" };
496     OHOS::HiviewDFX::SysEventQueryRule eventQueryRule("DOMAIN", eventNames);
497     eventQueryRules.emplace_back(eventQueryRule);
498     RunningStatusLogUtil::LogTooManyQueryRules(eventQueryRules);
499     RunningStatusLogUtil::LogTooManyEvents(limit);
500 
501     std::vector<std::string> allLogFiles;
502     FileUtil::GetDirFiles(GetLogDir(), allLogFiles);
503     ASSERT_GE(allLogFiles.size(), 0);
504 }
505 
506 /**
507  * @tc.name: CompliantEventChecker001
508  * @tc.desc: test apis of CompliantEventChecker.
509  * @tc.type: FUNC
510  * @tc.require: issueICJ952
511  */
512 HWTEST_F(SysEventServiceOhosTest, CompliantEventChecker001, testing::ext::TestSize.Level1)
513 {
514     int secureEnabledVal = 1;
515     bool isSecureEnabeled = (Parameter::GetInteger("const.secure", secureEnabledVal) == secureEnabledVal);
516 
517     CompliantEventChecker checker;
518     if (!isSecureEnabeled) {
519         ASSERT_TRUE(checker.IsCompliantEvent("NO_CFG_DOMAIN", "NO_CFG_NAME"));
520     } else {
521         ASSERT_FALSE(checker.IsCompliantEvent("NO_CFG_DOMAIN", "NO_CFG_NAME"));
522         ASSERT_FALSE(checker.IsCompliantEvent("AAFWK", "NO_CFG_NAME"));
523         ASSERT_TRUE(checker.IsCompliantEvent("AAFWK", "ABILITY_ONACTIVE"));
524         ASSERT_TRUE(checker.IsCompliantEvent("PERFORMANCE", "NO_CFG_NAME"));
525     }
526 }
527 
528 /**
529  * @tc.name: SysEventServiceOhosInstanceTest001
530  * @tc.desc: test apis of SysEventServiceOhos.
531  * @tc.type: FUNC
532  * @tc.require: issueICJ952
533  */
534 HWTEST_F(SysEventServiceOhosTest, SysEventServiceOhosInstanceTest001, testing::ext::TestSize.Level1)
535 {
536     auto service = SysEventServiceOhos::GetInstance();
537     ASSERT_NE(service, nullptr);
538 
539     std::vector<SysEventRule> eventRules;
540     OHOS::HiviewDFX::SysEventRule eventRule("DOMAIN1", "EVENT_NAME2", "TAG3", OHOS::HiviewDFX::RuleType::WHOLE_WORD);
541     ASSERT_LT(service->AddListener(eventRules, nullptr), 0);
542     ASSERT_LT(service->RemoveListener(nullptr), 0);
543 
544     int64_t defaultTimeStap = -1;
545     int queryCount = 10;
546     OHOS::HiviewDFX::QueryArgument argument(defaultTimeStap, defaultTimeStap, queryCount);
547     std::vector<SysEventQueryRule> eventQueryRules;
548     std::vector<std::string> eventNames { "EVENT_NAME1", "EVENT_NAME2" };
549     OHOS::HiviewDFX::SysEventQueryRule eventQueryRule("DOMAIN", eventNames);
550 
551     eventQueryRules.emplace_back(eventQueryRule);
552     ASSERT_LT(service->Query(argument, eventQueryRules, nullptr), 0);
553 }
554 
555 /**
556  * @tc.name: SysEventServiceOhosInstanceTest002
557  * @tc.desc: test apis of SysEventServiceOhos.
558  * @tc.type: FUNC
559  * @tc.require: issueICJ952
560  */
561 HWTEST_F(SysEventServiceOhosTest, SysEventServiceOhosInstanceTest002, testing::ext::TestSize.Level1)
562 {
563     auto service = SysEventServiceOhos::GetInstance();
564     ASSERT_NE(service, nullptr);
565 
566     std::vector<SysEventQueryRule> eventQueryRules;
567     std::vector<std::string> eventNames { "EVENT_NAME1", "EVENT_NAME2" };
568     OHOS::HiviewDFX::SysEventQueryRule eventQueryRule("DOMAIN", eventNames);
569     eventQueryRules.emplace_back(eventQueryRule);
570 
571     int64_t funcResult = 0;
572     ASSERT_LT(service->AddSubscriber(eventQueryRules, funcResult), 0);
573     ASSERT_LT(service->RemoveSubscriber(), 0);
574 
575     long long defaultTimeStap = -1;
576     int queryCount = 10;
577     OHOS::HiviewDFX::QueryArgument argument(defaultTimeStap, defaultTimeStap, queryCount);
578     ASSERT_LT(service->Export(argument, eventQueryRules, funcResult), 0);
579 }
580 
581 /**
582  * @tc.name: SysEventServiceOhosInstanceTest003
583  * @tc.desc: test apis of SysEventServiceOhos.
584  * @tc.type: FUNC
585  * @tc.require: issueICJ952
586  */
587 HWTEST_F(SysEventServiceOhosTest, SysEventServiceOhosInstanceTest003, testing::ext::TestSize.Level1)
588 {
589     auto service = SysEventServiceOhos::GetInstance();
590     ASSERT_NE(service, nullptr);
591 
592     int32_t testFd1 = -3; // -3 is a invalid value
593     std::vector<std::u16string> args;
594     ASSERT_LE(service->Dump(testFd1, args), -1); // -1 is expected value to compare
595     int32_t testFd2 = 10; // 10 is a test value
596     ASSERT_LE(service->Dump(testFd2, args), 0);
597 }
598 
599 /**
600  * @tc.name: SysEventServiceOhosInstanceTest004
601  * @tc.desc: test apis of SysEventServiceOhos.
602  * @tc.type: FUNC
603  * @tc.require: issueICJ952
604  */
605 HWTEST_F(SysEventServiceOhosTest, SysEventServiceOhosInstanceTest004, testing::ext::TestSize.Level1)
606 {
607     auto service = SysEventServiceOhos::GetInstance();
608     ASSERT_NE(service, nullptr);
609 
610     const std::string eventStr = R"~({"domain_":"DEMO","name_":"NAME1","type_":1,"tz_":"+0800","time_":1620271291188,
611         "pid_":6527, "tid_":6527, "traceid_":"f0ed6160bb2df4b", "spanid_":"10", "pspanid_":"20", "trace_flag_":4})~";
612     auto sysEvent = std::make_shared<SysEvent>("SysEventSource", nullptr, eventStr);
613     service->OnSysEvent(sysEvent);
614     wptr<IRemoteObject> remote = nullptr;
615     service->OnRemoteDied(remote);
616     service->SetWorkLoop(nullptr);
617 }
618 } // namespace HiviewDFX
619 } // namespace OHOS