• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "hisysevent_wrote_result_check.h"
17 
18 #include <functional>
19 #include <iosfwd>
20 #include <limits>
21 #include <string>
22 #include <thread>
23 #include <unistd.h>
24 #include <vector>
25 
26 #include "gtest/gtest-message.h"
27 #include "gtest/gtest-test-part.h"
28 #include "gtest/hwext/gtest-ext.h"
29 #include "gtest/hwext/gtest-tag.h"
30 #include "hilog/log.h"
31 
32 #include "def.h"
33 #include "hisysevent.h"
34 #include "hisysevent_base_manager.h"
35 #include "hisysevent_manager.h"
36 #include "hisysevent_record.h"
37 #include "hisysevent_query_callback.h"
38 #include "hisysevent_listener.h"
39 #ifdef HIVIEWDFX_HITRACE_ENABLED_FOR_TEST
40 #include "hitrace/trace.h"
41 #endif
42 #include "ret_code.h"
43 #include "rule_type.h"
44 
45 #undef LOG_DOMAIN
46 #define LOG_DOMAIN 0xD002D08
47 
48 #undef LOG_TAG
49 #define LOG_TAG "HISYSEVENTTEST_WRITE_RESULT_CHECK_TEST"
50 
51 using namespace testing::ext;
52 using namespace OHOS::HiviewDFX;
53 
54 namespace {
55 constexpr char DOMAIN[] = "KERNEL_VENDOR";
56 constexpr char EVENT_NAME[] = "POWER_KEY";
57 constexpr char PARAM_KEY[] = "key";
58 constexpr int ARRAY_TOTAL_CNT = 3;
59 constexpr int FIRST_ITEM_INDEX = 0;
60 constexpr int SECOND_ITEM_INDEX = 1;
61 constexpr int THIRD_ITEM_INDEX = 2;
62 constexpr int USLEEP_DURATION = 1000000;
63 constexpr int EVENT_QUERY_CNT = 1000;
64 constexpr long long DEFAULT_TIME_STAMP = -1;
65 
66 class Watcher : public HiSysEventListener {
67 public:
Watcher(std::function<bool (std::shared_ptr<HiSysEventRecord>)> assertFunc)68     explicit Watcher(std::function<bool(std::shared_ptr<HiSysEventRecord>)> assertFunc)
69     {
70         assertFunc_ = assertFunc;
71     }
72 
~Watcher()73     virtual ~Watcher() {}
74 
OnEvent(std::shared_ptr<HiSysEventRecord> sysEvent)75     void OnEvent(std::shared_ptr<HiSysEventRecord> sysEvent) final
76     {
77         if (sysEvent == nullptr || assertFunc_ == nullptr) {
78             return;
79         }
80         ASSERT_TRUE(assertFunc_(sysEvent));
81     }
82 
OnServiceDied()83     void OnServiceDied() final
84     {
85         HILOG_DEBUG(LOG_CORE, "OnServiceDied");
86     }
87 
88 private:
89     std::function<bool(std::shared_ptr<HiSysEventRecord>)> assertFunc_;
90 };
91 
92 class Querier : public HiSysEventQueryCallback {
93 public:
Querier(std::function<bool (std::shared_ptr<std::vector<HiSysEventRecord>>)> onQueryHandleFunc)94     explicit Querier(std::function<bool(std::shared_ptr<std::vector<HiSysEventRecord>>)> onQueryHandleFunc)
95     {
96         onQueryHandleFunc_ = onQueryHandleFunc;
97     }
98 
~Querier()99     virtual ~Querier() {}
100 
OnQuery(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents)101     void OnQuery(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents)
102     {
103         matched |= onQueryHandleFunc_(sysEvents);
104     }
105 
OnComplete(int32_t reason,int32_t total)106     void OnComplete(int32_t reason, int32_t total)
107     {
108         ASSERT_TRUE(matched);
109     }
110 
111 private:
112     std::function<bool(std::shared_ptr<std::vector<HiSysEventRecord>>)> onQueryHandleFunc_;
113     bool matched = false;
114 };
115 
Sleep()116 void Sleep()
117 {
118     usleep(USLEEP_DURATION);
119 }
120 
QueryAndComparedSysEvent(std::shared_ptr<Querier> querier)121 void QueryAndComparedSysEvent(std::shared_ptr<Querier> querier)
122 {
123     struct OHOS::HiviewDFX::QueryArg args(DEFAULT_TIME_STAMP, DEFAULT_TIME_STAMP, EVENT_QUERY_CNT);
124     std::vector<OHOS::HiviewDFX::QueryRule> queryRules;
125     std::vector<std::string> eventNames {EVENT_NAME};
126     OHOS::HiviewDFX::QueryRule rule(DOMAIN, eventNames);
127     queryRules.emplace_back(rule);
128     auto ret = OHOS::HiviewDFX::HiSysEventManager::Query(args, queryRules, querier);
129     ASSERT_TRUE(ret == SUCCESS);
130 }
131 
132 template<typename T>
WriteAndWatchThenQuery(std::shared_ptr<Watcher> watcher,std::shared_ptr<Querier> querier,T & val)133 void WriteAndWatchThenQuery(std::shared_ptr<Watcher> watcher, std::shared_ptr<Querier> querier, T& val)
134 {
135     OHOS::HiviewDFX::ListenerRule listenerRule(DOMAIN, EVENT_NAME, "",
136         OHOS::HiviewDFX::RuleType::WHOLE_WORD);
137     std::vector<OHOS::HiviewDFX::ListenerRule> sysRules;
138     sysRules.emplace_back(listenerRule);
139     auto ret = OHOS::HiviewDFX::HiSysEventManager::AddListener(watcher, sysRules);
140     ASSERT_TRUE(ret == SUCCESS);
141     ret = HiSysEventWrite(DOMAIN, EVENT_NAME, HiSysEvent::EventType::FAULT, PARAM_KEY,
142         val);
143     ASSERT_TRUE(ret == SUCCESS);
144     Sleep();
145     ret = OHOS::HiviewDFX::HiSysEventManager::RemoveListener(watcher);
146     ASSERT_TRUE(ret == SUCCESS);
147     QueryAndComparedSysEvent(querier);
148 }
149 
IsContains(const std::string & total,const std::string & part)150 bool IsContains(const std::string& total, const std::string& part)
151 {
152     if (total.empty() || part.empty()) {
153         return false;
154     }
155     return total.find(part) != std::string::npos;
156 }
157 
CompareEventQueryResultWithPattern(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents,const std::string & pattern)158 bool CompareEventQueryResultWithPattern(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents,
159     const std::string& pattern)
160 {
161     if (sysEvents == nullptr) {
162         return false;
163     }
164     auto matched = false;
165     for (auto sysEvent : *sysEvents) {
166         std::string eventJsonStr = sysEvent.AsJson();
167         auto comparedRet = IsContains(eventJsonStr, pattern);
168         matched |= comparedRet;
169         if (matched) {
170             break;
171         }
172     }
173     return matched;
174 }
175 }
176 
SetUpTestCase(void)177 void HiSysEventWroteResultCheckTest::SetUpTestCase(void)
178 {
179 }
180 
TearDownTestCase(void)181 void HiSysEventWroteResultCheckTest::TearDownTestCase(void)
182 {
183 }
184 
SetUp(void)185 void HiSysEventWroteResultCheckTest::SetUp(void)
186 {
187 }
188 
TearDown(void)189 void HiSysEventWroteResultCheckTest::TearDown(void)
190 {
191 }
192 
193 /**
194  * @tc.name: HiSysEventWroteResultCheckTest001
195  * @tc.desc: Write sysevent with bool parameter
196  * @tc.type: FUNC
197  * @tc.require: issueI76V6J
198  */
199 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest001, TestSize.Level1)
200 {
201     Sleep();
202     bool val = true;
__anon9d12b01b0202(std::shared_ptr<HiSysEventRecord> sysEvent) 203     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
204         if (sysEvent == nullptr) {
205             return false;
206         }
207         int64_t ret;
208         sysEvent->GetParamValue(PARAM_KEY, ret);
209         return ret == static_cast<int>(val);
210     });
__anon9d12b01b0302(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 211     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
212         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":1,");
213     });
214     WriteAndWatchThenQuery(watcher, querier, val);
215 }
216 
217 /**
218  * @tc.name: HiSysEventWroteResultCheckTest002
219  * @tc.desc: Write sysevent with int64_t parameter
220  * @tc.type: FUNC
221  * @tc.require: issueI76V6J
222  */
223 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest002, TestSize.Level1)
224 {
225     Sleep();
226     int64_t val = -18888888882321;
__anon9d12b01b0402(std::shared_ptr<HiSysEventRecord> sysEvent) 227     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
228         if (sysEvent == nullptr) {
229             return false;
230         }
231         int64_t ret;
232         sysEvent->GetParamValue(PARAM_KEY, ret);
233         return ret == val;
234     });
__anon9d12b01b0502(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 235     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
236         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":-18888888882321,");
237     });
238     WriteAndWatchThenQuery(watcher, querier, val);
239 }
240 
241 /**
242  * @tc.name: HiSysEventWroteResultCheckTest003
243  * @tc.desc: Write sysevent with uint64_t parameter
244  * @tc.type: FUNC
245  * @tc.require: issueI76V6J
246  */
247 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest003, TestSize.Level1)
248 {
249     Sleep();
250     uint64_t val = 18888888882326141;
__anon9d12b01b0602(std::shared_ptr<HiSysEventRecord> sysEvent) 251     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
252         if (sysEvent == nullptr) {
253             return false;
254         }
255         uint64_t ret;
256         sysEvent->GetParamValue(PARAM_KEY, ret);
257         return ret == val;
258     });
__anon9d12b01b0702(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 259     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
260         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":18888888882326141,");
261     });
262     WriteAndWatchThenQuery(watcher, querier, val);
263 }
264 
265 /**
266  * @tc.name: HiSysEventWroteResultCheckTest004
267  * @tc.desc: Write sysevent with double parameter
268  * @tc.type: FUNC
269  * @tc.require: issueI76V6J
270  */
271 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest004, TestSize.Level1)
272 {
273     Sleep();
274     double val = 30949.374;
__anon9d12b01b0802(std::shared_ptr<HiSysEventRecord> sysEvent) 275     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
276         if (sysEvent == nullptr) {
277             return false;
278         }
279         std::string eventJsonStr = sysEvent->AsJson();
280         return IsContains(eventJsonStr, "\"key\":30949.4,");
281     });
__anon9d12b01b0902(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 282     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
283         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":30949.4,");
284     });
285     WriteAndWatchThenQuery(watcher, querier, val);
286 }
287 
288 /**
289  * @tc.name: HiSysEventWroteResultCheckTest005
290  * @tc.desc: Write sysevent with string parameter
291  * @tc.type: FUNC
292  * @tc.require: issueI76V6J
293  */
294 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest005, TestSize.Level1)
295 {
296     Sleep();
297     std::string val = "value";
__anon9d12b01b0a02(std::shared_ptr<HiSysEventRecord> sysEvent) 298     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
299         if (sysEvent == nullptr) {
300             return false;
301         }
302         std::string ret;
303         sysEvent->GetParamValue(PARAM_KEY, ret);
304         return ret == val;
305     });
__anon9d12b01b0b02(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 306     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
307         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":\"value\"");
308     });
309     WriteAndWatchThenQuery(watcher, querier, val);
310 }
311 
312 /**
313  * @tc.name: HiSysEventWroteResultCheckTest006
314  * @tc.desc: Write sysevent with bool array parameter
315  * @tc.type: FUNC
316  * @tc.require: issueI76V6J
317  */
318 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest006, TestSize.Level1)
319 {
320     Sleep();
321     std::vector<bool> val = {
322         true,
323         false,
324         true
325     };
__anon9d12b01b0c02(std::shared_ptr<HiSysEventRecord> sysEvent) 326     auto watcher = std::make_shared<Watcher>([&val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
327         if (sysEvent == nullptr) {
328             return false;
329         }
330         std::vector<int64_t> ret;
331         sysEvent->GetParamValue(PARAM_KEY, ret);
332         return (ret.size() == ARRAY_TOTAL_CNT) && (val[FIRST_ITEM_INDEX] == ret[FIRST_ITEM_INDEX]) &&
333             (val[SECOND_ITEM_INDEX] == ret[SECOND_ITEM_INDEX]) && (val[THIRD_ITEM_INDEX] == ret[THIRD_ITEM_INDEX]);
334     });
__anon9d12b01b0d02(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 335     auto querier =std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
336         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":[1,0,1]");
337     });
338     WriteAndWatchThenQuery(watcher, querier, val);
339 }
340 
341 /**
342  * @tc.name: HiSysEventWroteResultCheckTest007
343  * @tc.desc: Write sysevent with int64_t array parameter
344  * @tc.type: FUNC
345  * @tc.require: issueI76V6J
346  */
347 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest007, TestSize.Level1)
348 {
349     Sleep();
350     std::vector<int64_t> val = {
351         std::numeric_limits<int64_t>::min(),
352         std::numeric_limits<int64_t>::max(),
353         -3333333333333333333,
354     };
__anon9d12b01b0e02(std::shared_ptr<HiSysEventRecord> sysEvent) 355     auto watcher = std::make_shared<Watcher>([&val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
356         if (sysEvent == nullptr) {
357             return false;
358         }
359         std::vector<int64_t> ret;
360         sysEvent->GetParamValue(PARAM_KEY, ret);
361         return (ret.size() == ARRAY_TOTAL_CNT) && (val[FIRST_ITEM_INDEX] == ret[FIRST_ITEM_INDEX]) &&
362             (val[SECOND_ITEM_INDEX] == ret[SECOND_ITEM_INDEX]) && (val[THIRD_ITEM_INDEX] == ret[THIRD_ITEM_INDEX]);
363     });
__anon9d12b01b0f02(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 364     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
365         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":[" +
366             std::to_string(std::numeric_limits<int64_t>::min()) + "," +
367             std::to_string(std::numeric_limits<int64_t>::max()) + ",-3333333333333333333]");
368     });
369     WriteAndWatchThenQuery(watcher, querier, val);
370 }
371 
372 /**
373  * @tc.name: HiSysEventWroteResultCheckTest008
374  * @tc.desc: Write sysevent with uint64_t array parameter
375  * @tc.type: FUNC
376  * @tc.require: issueI76V6J
377  */
378 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest008, TestSize.Level1)
379 {
380     Sleep();
381     std::vector<uint64_t> val = {
382         std::numeric_limits<uint64_t>::min(),
383         std::numeric_limits<uint64_t>::max(),
384         3333333333333333333,
385     };
__anon9d12b01b1002(std::shared_ptr<HiSysEventRecord> sysEvent) 386     auto watcher = std::make_shared<Watcher>([&val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
387         if (sysEvent == nullptr) {
388             return false;
389         }
390         std::vector<uint64_t> ret;
391         sysEvent->GetParamValue(PARAM_KEY, ret);
392         return (ret.size() == ARRAY_TOTAL_CNT) && (val[FIRST_ITEM_INDEX] == ret[FIRST_ITEM_INDEX]) &&
393             (val[SECOND_ITEM_INDEX] == ret[SECOND_ITEM_INDEX]) && (val[THIRD_ITEM_INDEX] == ret[THIRD_ITEM_INDEX]);
394     });
__anon9d12b01b1102(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 395     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
396         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":[" +
397             std::to_string(std::numeric_limits<uint64_t>::min()) + "," +
398             std::to_string(std::numeric_limits<uint64_t>::max()) + ",3333333333333333333]");
399     });
400     WriteAndWatchThenQuery(watcher, querier, val);
401 }
402 
403 /**
404  * @tc.name: HiSysEventWroteResultCheckTest009
405  * @tc.desc: Write sysevent with double array parameter
406  * @tc.type: FUNC
407  * @tc.require: issueI76V6J
408  */
409 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest009, TestSize.Level1)
410 {
411     Sleep();
412     std::vector<double> val = {
413         1.5,
414         2.5,
415         100.374,
416     };
__anon9d12b01b1202(std::shared_ptr<HiSysEventRecord> sysEvent) 417     auto watcher = std::make_shared<Watcher>([&val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
418         if (sysEvent == nullptr) {
419             return false;
420         }
421         std::string eventJsonStr = sysEvent->AsJson();
422         return IsContains(eventJsonStr, "\"key\":[1.5,2.5,100.374],");
423     });
__anon9d12b01b1302(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 424     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
425         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":[1.5,2.5,100.374]");
426     });
427     WriteAndWatchThenQuery(watcher, querier, val);
428 }
429 
430 /**
431  * @tc.name: HiSysEventWroteResultCheckTest010
432  * @tc.desc: Write sysevent with string array parameter
433  * @tc.type: FUNC
434  * @tc.require: issueI76V6J
435  */
436 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest010, TestSize.Level1)
437 {
438     Sleep();
439     std::vector<std::string> val = {
440         "value1\n\r",
441         "value2\n\r",
442         "value3\n\r",
443     };
__anon9d12b01b1402(std::shared_ptr<HiSysEventRecord> sysEvent) 444     auto watcher = std::make_shared<Watcher>([&val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
445         if (sysEvent == nullptr) {
446             return false;
447         }
448         std::vector<std::string> ret;
449         sysEvent->GetParamValue(PARAM_KEY, ret);
450         return (ret.size() == ARRAY_TOTAL_CNT) && (ret[FIRST_ITEM_INDEX] == "value1\n\r") &&
451             (ret[SECOND_ITEM_INDEX] == "value2\n\r") && (ret[THIRD_ITEM_INDEX] == "value3\n\r");
452     });
__anon9d12b01b1502(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 453     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
454         return CompareEventQueryResultWithPattern(sysEvents,
455             "\"key\":[\"value1\\n\\r\",\"value2\\n\\r\",\"value3\\n\\r\"]");
456     });
457     WriteAndWatchThenQuery(watcher, querier, val);
458 }
459 
460 /**
461  * @tc.name: HiSysEventWroteResultCheckTest011
462  * @tc.desc: Write sysevent with float parameter
463  * @tc.type: FUNC
464  * @tc.require: issueI76V6J
465  */
466 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest011, TestSize.Level1)
467 {
468     Sleep();
469     float val = 230.47;
__anon9d12b01b1602(std::shared_ptr<HiSysEventRecord> sysEvent) 470     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
471         if (sysEvent == nullptr) {
472             return false;
473         }
474         std::string eventJsonStr = sysEvent->AsJson();
475         return IsContains(eventJsonStr, "\"key\":230.47,");
476     });
__anon9d12b01b1702(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 477     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
478         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":230.47");
479     });
480     WriteAndWatchThenQuery(watcher, querier, val);
481 }
482 
483 /**
484  * @tc.name: HiSysEventWroteResultCheckTest012
485  * @tc.desc: Write sysevent with float array parameter
486  * @tc.type: FUNC
487  * @tc.require: issueI76V6J
488  */
489 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest012, TestSize.Level1)
490 {
491     Sleep();
492     std::vector<float> val = {
493         1.1,
494         2.2,
495         3.5,
496         4,
497     };
__anon9d12b01b1802(std::shared_ptr<HiSysEventRecord> sysEvent) 498     auto watcher = std::make_shared<Watcher>([&val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
499         if (sysEvent == nullptr) {
500             return false;
501         }
502         std::string eventJsonStr = sysEvent->AsJson();
503         return IsContains(eventJsonStr, "\"key\":[1.1,2.2,3.5,4],");
504     });
__anon9d12b01b1902(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 505     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
506         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":[1.1,2.2,3.5,4]");
507     });
508     WriteAndWatchThenQuery(watcher, querier, val);
509 }
510 
511 #ifdef HIVIEWDFX_HITRACE_ENABLED_FOR_TEST
512 /**
513  * @tc.name: HiSysEventWroteResultCheckTest013
514  * @tc.desc: Write sysevent after begin hitracechain
515  * @tc.type: FUNC
516  * @tc.require: issueI76V6J
517  */
518 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest013, TestSize.Level1)
519 {
520     Sleep();
521     std::string val = "with valid hitracechain";
522     auto traceId = HiTraceChain::Begin("TestCase1", HITRACE_FLAG_INCLUDE_ASYNC | HITRACE_FLAG_DONOT_CREATE_SPAN);
__anon9d12b01b1a02(std::shared_ptr<HiSysEventRecord> sysEvent) 523     auto watcher = std::make_shared<Watcher>([&val, &traceId] (std::shared_ptr<HiSysEventRecord> sysEvent) {
524         if (sysEvent == nullptr) {
525             return false;
526         }
527         return (traceId.GetFlags() == sysEvent->GetTraceFlag()) && (traceId.GetChainId() == sysEvent->GetTraceId());
528     });
__anon9d12b01b1b02(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 529     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
530         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":\"with valid hitracechain\",");
531     });
532     WriteAndWatchThenQuery(watcher, querier, val);
533     HiTraceChain::End(traceId);
534 }
535 #endif
536 
537 /**
538  * @tc.name: HiSysEventWroteResultCheckTest014
539  * @tc.desc: Write sysevent with negative double parameter
540  * @tc.type: FUNC
541  * @tc.require: issueI76V6J
542  */
543 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest014, TestSize.Level1)
544 {
545     Sleep();
546     double val = -3.5;
__anon9d12b01b1c02(std::shared_ptr<HiSysEventRecord> sysEvent) 547     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
548         if (sysEvent == nullptr) {
549             return false;
550         }
551         std::string eventJsonStr = sysEvent->AsJson();
552         return IsContains(eventJsonStr, "\"key\":-3.5,");
553     });
__anon9d12b01b1d02(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 554     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
555         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":-3.5,");
556     });
557     WriteAndWatchThenQuery(watcher, querier, val);
558 }
559 
560 /**
561  * @tc.name: HiSysEventWroteResultCheckTest015
562  * @tc.desc: Write sysevent with empty array
563  * @tc.type: FUNC
564  * @tc.require: issueI76V6J
565  */
566 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest015, TestSize.Level1)
567 {
568     Sleep();
569     std::vector<float> val;
__anon9d12b01b1e02(std::shared_ptr<HiSysEventRecord> sysEvent) 570     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
571         if (sysEvent == nullptr) {
572             return false;
573         }
574         std::string eventJsonStr = sysEvent->AsJson();
575         return IsContains(eventJsonStr, "\"key\":[],");
576     });
__anon9d12b01b1f02(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 577     auto querier = std::make_shared<Querier>([] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
578         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":[]");
579     });
580     WriteAndWatchThenQuery(watcher, querier, val);
581 }
582 
583 /**
584  * @tc.name: HiSysEventWroteResultCheckTest016
585  * @tc.desc: Write sysevent with maximum int64_t value
586  * @tc.type: FUNC
587  * @tc.require: issueI76V6J
588  */
589 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest016, TestSize.Level1)
590 {
591     Sleep();
592     int64_t val = std::numeric_limits<int64_t>::max();
__anon9d12b01b2002(std::shared_ptr<HiSysEventRecord> sysEvent) 593     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
594         if (sysEvent == nullptr) {
595             return false;
596         }
597         int64_t ret;
598         sysEvent->GetParamValue(PARAM_KEY, ret);
599         return ret == val;
600     });
__anon9d12b01b2102(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 601     auto querier = std::make_shared<Querier>([val] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
602         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":" +
603             std::to_string(val));
604     });
605     WriteAndWatchThenQuery(watcher, querier, val);
606 }
607 
608 /**
609  * @tc.name: HiSysEventWroteResultCheckTest017
610  * @tc.desc: Write sysevent with minimum int64_t value
611  * @tc.type: FUNC
612  * @tc.require: issueI76V6J
613  */
614 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest017, TestSize.Level1)
615 {
616     Sleep();
617     int64_t val = std::numeric_limits<int64_t>::min();
__anon9d12b01b2202(std::shared_ptr<HiSysEventRecord> sysEvent) 618     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
619         if (sysEvent == nullptr) {
620             return false;
621         }
622         int64_t ret;
623         sysEvent->GetParamValue(PARAM_KEY, ret);
624         return ret == val;
625     });
__anon9d12b01b2302(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 626     auto querier = std::make_shared<Querier>([val] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
627         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":" +
628             std::to_string(val));
629     });
630     WriteAndWatchThenQuery(watcher, querier, val);
631 }
632 
633 /**
634  * @tc.name: HiSysEventWroteResultCheckTest018
635  * @tc.desc: Write sysevent with maximum uint64_t value
636  * @tc.type: FUNC
637  * @tc.require: issueI76V6J
638  */
639 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest018, TestSize.Level1)
640 {
641     Sleep();
642     uint64_t val = std::numeric_limits<uint64_t>::max();
__anon9d12b01b2402(std::shared_ptr<HiSysEventRecord> sysEvent) 643     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
644         if (sysEvent == nullptr) {
645             return false;
646         }
647         uint64_t ret;
648         sysEvent->GetParamValue(PARAM_KEY, ret);
649         return ret == val;
650     });
__anon9d12b01b2502(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 651     auto querier = std::make_shared<Querier>([val] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
652         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":" +
653             std::to_string(val));
654     });
655     WriteAndWatchThenQuery(watcher, querier, val);
656 }
657 
658 /**
659  * @tc.name: HiSysEventWroteResultCheckTest019
660  * @tc.desc: Write sysevent with minimum uint64_t value
661  * @tc.type: FUNC
662  * @tc.require: issueI76V6J
663  */
664 HWTEST_F(HiSysEventWroteResultCheckTest, HiSysEventWroteResultCheckTest019, TestSize.Level1)
665 {
666     Sleep();
667     uint64_t val = std::numeric_limits<uint64_t>::min();
__anon9d12b01b2602(std::shared_ptr<HiSysEventRecord> sysEvent) 668     auto watcher = std::make_shared<Watcher>([val] (std::shared_ptr<HiSysEventRecord> sysEvent) {
669         if (sysEvent == nullptr) {
670             return false;
671         }
672         uint64_t ret;
673         sysEvent->GetParamValue(PARAM_KEY, ret);
674         return ret == val;
675     });
__anon9d12b01b2702(std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) 676     auto querier = std::make_shared<Querier>([val] (std::shared_ptr<std::vector<HiSysEventRecord>> sysEvents) {
677         return CompareEventQueryResultWithPattern(sysEvents, "\"key\":" +
678             std::to_string(val));
679     });
680     WriteAndWatchThenQuery(watcher, querier, val);
681 }