• 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 
16 #include <fcntl.h>
17 #include <hwext/gtest-ext.h>
18 #include <hwext/gtest-tag.h>
19 #include <string>
20 #include <unordered_map>
21 
22 #include "cpu_filter.h"
23 #include "parser/bytrace_parser/bytrace_event_parser.h"
24 #include "parser/bytrace_parser/bytrace_parser.h"
25 #include "parser/common_types.h"
26 #include "securec.h"
27 #include "trace_streamer_selector.h"
28 
29 using namespace testing::ext;
30 using namespace SysTuning::TraceStreamer;
31 namespace SysTuning {
32 namespace TraceStreamer {
33 const uint32_t G_BUF_SIZE = 1024;
34 // TestSuite:
35 class EventParserTest : public ::testing::Test {
36 public:
SetUp()37     void SetUp()
38     {
39         stream_.InitFilter();
40     }
41 
TearDown()42     void TearDown()
43     {
44         if (access(dbPath_.c_str(), F_OK) == 0) {
45             remove(dbPath_.c_str());
46         }
47     }
48 
49 public:
50     TraceStreamerSelector stream_ = {};
51     const std::string dbPath_ = "/data/resource/out.db";
52 };
53 
54 /**
55  * @tc.name: ParseLine
56  * @tc.desc: Parse a complete sched_switch event in bytrace format
57  * @tc.type: FUNC
58  */
59 HWTEST_F(EventParserTest, ParseLine, TestSize.Level1)
60 {
61     TS_LOGI("test4-1");
62     BytraceLine bytraceLine;
63     bytraceLine.ts = 1616439852302;
64     bytraceLine.pid = 1;
65     bytraceLine.cpu = 0;
66     bytraceLine.task = "ACCS0-2716";
67     bytraceLine.pidStr = "12";
68     bytraceLine.tGidStr = "12";
69     bytraceLine.eventName = "sched_switch";
70     ArgsMap args;
71     args.insert(std::make_pair("prev_comm", "ACCS0"));
72     args.insert(std::make_pair("prev_pid", "2716"));
73     args.insert(std::make_pair("prev_prio", "120"));
74     args.insert(std::make_pair("prev_state", "R"));
75     args.insert(std::make_pair("next_comm", "kworker/0:0"));
76     args.insert(std::make_pair("next_pid", "8326"));
77     args.insert(std::make_pair("next_prio", "120"));
78     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
79     int result = eventParser.ParseDataItem(bytraceLine, args, 2519);
80     EXPECT_EQ(result, true);
81     stream_.streamFilters_->cpuFilter_->FinishCpuEvent();
82     auto readStatIndex = stream_.traceDataCache_->GetConstSchedSliceData().EndStatesData()[0];
83     EXPECT_EQ(TASK_RUNNABLE, readStatIndex);
84     auto realTimeStamp = stream_.traceDataCache_->GetConstSchedSliceData().TimeStamData()[0];
85     EXPECT_TRUE(bytraceLine.ts == realTimeStamp);
86     auto realCpu = stream_.traceDataCache_->GetConstSchedSliceData().CpusData()[0];
87     EXPECT_TRUE(bytraceLine.cpu == realCpu);
88 }
89 
90 /**
91  * @tc.name: ParseLineNotEnoughArgs
92  * @tc.desc: Parse a sched_switch event which has not enough args in bytrace format
93  * @tc.type: FUNC
94  */
95 HWTEST_F(EventParserTest, ParseLineNotEnoughArgs, TestSize.Level1)
96 {
97     TS_LOGI("test4-1");
98     BytraceLine bytraceLine;
99     bytraceLine.ts = 1616439852302;
100     bytraceLine.pid = 1;
101     bytraceLine.cpu = 0;
102     bytraceLine.task = "ACCS0-2716";
103     bytraceLine.pidStr = "12";
104     bytraceLine.tGidStr = "12";
105     bytraceLine.eventName = "sched_switch";
106     ArgsMap args;
107     args.insert(std::make_pair("prev_prio", "120"));
108     args.insert(std::make_pair("prev_state", "R"));
109     args.insert(std::make_pair("next_comm", "kworker/0:0"));
110     args.insert(std::make_pair("next_pid", "8326"));
111     args.insert(std::make_pair("next_prio", "120"));
112     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
113     int result = eventParser.ParseDataItem(bytraceLine, args, 2519);
114 
115     EXPECT_EQ(result, false);
116 }
117 
118 /**
119  * @tc.name: ParseLineUnCognizableEventname
120  * @tc.desc: Parse a UnCognizable Eventname event in bytrace format
121  * @tc.type: FUNC
122  */
123 HWTEST_F(EventParserTest, ParseLineUnCognizableEventname, TestSize.Level1)
124 {
125     TS_LOGI("test4-2");
126     BytraceLine bytraceLine;
127     bytraceLine.ts = 1616439852302;
128     bytraceLine.pid = 1;
129     bytraceLine.cpu = 0;
130     bytraceLine.task = "ACCS0-2716";
131     bytraceLine.pidStr = "12";
132     bytraceLine.tGidStr = "12";
133     bytraceLine.eventName = "ThisEventNameDoNotExist"; // UnRecognizable event name
134     ArgsMap args;
135     args.insert(std::make_pair("prev_comm", "ACCS0"));
136     args.insert(std::make_pair("prev_pid", "2716"));
137     args.insert(std::make_pair("prev_prio", "120"));
138     args.insert(std::make_pair("prev_state", "R"));
139     args.insert(std::make_pair("next_comm", "kworker/0:0"));
140     args.insert(std::make_pair("next_pid", "8326"));
141     args.insert(std::make_pair("next_prio", "120"));
142     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
143     int result = eventParser.ParseDataItem(bytraceLine, args, 2519);
144 
145     EXPECT_EQ(result, false);
146 }
147 
148 /**
149  * @tc.name: ParseSchedSwitchNoArgs
150  * @tc.desc: Parse a SchedSwitch event which has no args in bytrace format
151  * @tc.type: FUNC
152  */
153 HWTEST_F(EventParserTest, ParseSchedSwitchNoArgs, TestSize.Level1)
154 {
155     TS_LOGI("test4-4");
156     BytraceLine bytraceLine;
157     bytraceLine.ts = 1616439852302;
158     bytraceLine.pid = 1;
159     bytraceLine.cpu = 0;
160     bytraceLine.task = "ACCS0-2716";
161     bytraceLine.pidStr = "12";
162     bytraceLine.tGidStr = "12";
163     bytraceLine.eventName = "sched_switch";
164     ArgsMap args;
165     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
166     int result = eventParser.ParseDataItem(bytraceLine, args, 2519);
167 
168     EXPECT_EQ(result, false);
169 }
170 
171 /**
172  * @tc.name: ParseSchedWakeupNoArgs
173  * @tc.desc: Parse a SchedWakeup event which has no args in bytrace format
174  * @tc.type: FUNC
175  */
176 HWTEST_F(EventParserTest, ParseSchedWakeupNoArgs, TestSize.Level1)
177 {
178     TS_LOGI("test4-4");
179     BytraceLine bytraceLine;
180     bytraceLine.ts = 1616439852302;
181     bytraceLine.pid = 1;
182     bytraceLine.cpu = 0;
183     bytraceLine.task = "ACCS0-2716";
184     bytraceLine.pidStr = "12";
185     bytraceLine.tGidStr = "12";
186     bytraceLine.eventName = "sched_wakeup";
187     ArgsMap args;
188     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
189     int result = eventParser.ParseDataItem(bytraceLine, args, 2519);
190 
191     EXPECT_EQ(result, false);
192 }
193 
194 /**
195  * @tc.name: ParseTracingMarkWriteC
196  * @tc.desc: Parse a TracingMarkWrite C event
197  * @tc.type: FUNC
198  */
199 HWTEST_F(EventParserTest, ParseTracingMarkWriteC, TestSize.Level1)
200 {
201     TS_LOGI("test4-7");
202 
203     const uint8_t str[] =
204         "ACCS0-2716  ( 2519) [000] ...1 174330.284808: tracing_mark_write: C|2519|Heap size (KB)|2906\n";
205     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
206     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
207         EXPECT_TRUE(false);
208         return;
209     }
210     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
211     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
212     bytraceParser.WaitForParserEnd();
213 
214     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
215     stream_.traceDataCache_->ExportDatabase(dbPath_);
216     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
217 }
218 
219 /**
220  * @tc.name: ParseTracingMarkWriteBE
221  * @tc.desc: Parse a TracingMarkWrite BE event
222  * @tc.type: FUNC
223  */
224 HWTEST_F(EventParserTest, ParseTracingMarkWriteBE, TestSize.Level1)
225 {
226     TS_LOGI("test4-8");
227     const uint8_t str[] =
228         "system-1298 ( 1298) [001] ...1 174330.287420: tracing_mark_write: B|1298|Choreographer#doFrame\n \
229             system - 1298(1298)[001]... 1 174330.287622 : tracing_mark_write : E | 1298\n"; // E | 1298 wrong format
230     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
231     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
232         EXPECT_TRUE(false);
233         return;
234     }
235     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
236     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
237     bytraceParser.WaitForParserEnd();
238 
239     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
240     EXPECT_EQ(bytraceParser.ParsedTraceInvalidLines(), static_cast<const unsigned int>(1));
241     stream_.traceDataCache_->ExportDatabase(dbPath_);
242     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
243 }
244 
245 /**
246  * @tc.name: ParseTracingMarkWriteSF
247  * @tc.desc: Parse a TracingMarkWrite SF event
248  * @tc.type: FUNC
249  */
250 HWTEST_F(EventParserTest, ParseTracingMarkWriteSF, TestSize.Level1)
251 {
252     TS_LOGI("test4-9");
253 
254     const uint8_t str[] =
255         "system-1298 ( 1298) [001] ...1 174330.287478: tracing_mark_write: S|1298|animator:\
256             translateX|18888109\n system-1298(1298)[001]... 1 174330.287514 : tracing_mark_write : \
257             F | 1298 | animator : translateX | 18888109\n";
258     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
259     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
260         EXPECT_TRUE(false);
261         return;
262     }
263     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
264     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
265     bytraceParser.WaitForParserEnd();
266 
267     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
268     EXPECT_EQ(bytraceParser.ParsedTraceInvalidLines(), static_cast<const unsigned int>(1));
269     stream_.traceDataCache_->ExportDatabase(dbPath_);
270     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
271 }
272 
273 /**
274  * @tc.name: ParseTracingMarkWriteErrorPoint
275  * @tc.desc: Parse a TracingMarkWrite event with error point info
276  * @tc.type: FUNC
277  */
278 HWTEST_F(EventParserTest, ParseTracingMarkWriteErrorPoint, TestSize.Level1)
279 {
280     TS_LOGI("test4-10");
281     const uint8_t str[] =
282         "system-1298  ( 1298) [001] ...1 174330.287478: tracing_mark_write: G|1298|animator: \
283             translateX|18888109\n system-1298(1298)[001]... 1 174330.287514 : tracing_mark_write : \
284             F | 1298 | animator : translateX | 18888109\n";
285     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
286     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
287         EXPECT_TRUE(false);
288         return;
289     }
290     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
291     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
292     bytraceParser.WaitForParserEnd();
293 
294     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
295     EXPECT_EQ(bytraceParser.ParsedTraceInvalidLines(), static_cast<const unsigned int>(1));
296     stream_.traceDataCache_->ExportDatabase(dbPath_);
297     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
298 }
299 
300 /**
301  * @tc.name: ParseCpuIdle
302  * @tc.desc: Parse a CpuIdle event
303  * @tc.type: FUNC
304  */
305 HWTEST_F(EventParserTest, ParseCpuIdle, TestSize.Level1)
306 {
307     TS_LOGI("test4-14");
308     const uint8_t str[] = "<idle>-0     (-----) [003] d..2 174330.280761: cpu_idle: state=2 cpu_id=3\n";
309     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
310     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
311         EXPECT_TRUE(false);
312         return;
313     }
314     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
315     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
316     bytraceParser.WaitForParserEnd();
317 
318     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
319     stream_.traceDataCache_->ExportDatabase(dbPath_);
320     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
321 }
322 
323 /**
324  * @tc.name: ParseIrqHandlerEntry
325  * @tc.desc: Parse a IrqHandlerEntry event
326  * @tc.type: FUNC
327  */
328 HWTEST_F(EventParserTest, ParseIrqHandlerEntry, TestSize.Level1)
329 {
330     TS_LOGI("test4-15");
331     const uint8_t str[] =
332         "ACCS0-2716  ( 2519) [000] d.h1 174330.280362: irq_handler_entry: irq=19 name=408000.qcom,cpu-bwmon\n";
333     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
334     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
335         EXPECT_TRUE(false);
336         return;
337     }
338     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
339     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
340     bytraceParser.WaitForParserEnd();
341 
342     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
343     stream_.traceDataCache_->ExportDatabase(dbPath_);
344     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
345 }
346 
347 /**
348  * @tc.name: ParseIrqHandlerExit
349  * @tc.desc: Parse a IrqHandlerExit event
350  * @tc.type: FUNC
351  */
352 HWTEST_F(EventParserTest, ParseIrqHandlerExit, TestSize.Level1)
353 {
354     TS_LOGI("test4-16");
355     const uint8_t str[] =
356         "ACCS0-2716  ( 2519) [000] d.h1 174330.280382: irq_handler_exit: irq=19 ret=handled\n";
357     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
358     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
359         EXPECT_TRUE(false);
360         return;
361     }
362     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
363     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
364     bytraceParser.WaitForParserEnd();
365 
366     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
367     stream_.traceDataCache_->ExportDatabase(dbPath_);
368     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
369 }
370 
371 /**
372  * @tc.name: ParseSchedWaking
373  * @tc.desc: Parse a SchedWaking event
374  * @tc.type: FUNC
375  */
376 HWTEST_F(EventParserTest, ParseSchedWaking, TestSize.Level1)
377 {
378     TS_LOGI("test4-17");
379     const uint8_t str[] =
380         "ACCS0-2716  ( 2519) [000] d..5 174330.280567: sched_waking: \
381             comm=Binder:924_6 pid=1332 prio=120 target_cpu=000\n";
382     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
383     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
384         EXPECT_TRUE(false);
385         return;
386     }
387     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
388     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
389     bytraceParser.WaitForParserEnd();
390     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
391     stream_.traceDataCache_->ExportDatabase(dbPath_);
392     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
393 }
394 
395 /**
396  * @tc.name: ParseSchedWakeup
397  * @tc.desc: Parse a SchedWakeup event
398  * @tc.type: FUNC
399  */
400 HWTEST_F(EventParserTest, ParseSchedWakeup, TestSize.Level1)
401 {
402     TS_LOGI("test4-18");
403     const uint8_t str[] =
404         "ACCS0-2716  ( 2519) [000] d..6 174330.280575: sched_wakeup: \
405             comm=Binder:924_6 pid=1332 prio=120 target_cpu=000\n";
406     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
407     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
408         EXPECT_TRUE(false);
409         return;
410     }
411     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
412     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
413     bytraceParser.WaitForParserEnd();
414 
415     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
416     stream_.traceDataCache_->ExportDatabase(dbPath_);
417     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
418 }
419 
420 /**
421  * @tc.name: ParseTraceEventClockSync
422  * @tc.desc: Parse a TraceEventClockSync event
423  * @tc.type: FUNC
424  */
425 HWTEST_F(EventParserTest, ParseTraceEventClockSync, TestSize.Level1)
426 {
427     TS_LOGI("test4-19");
428     const uint8_t str[] =
429         "sampletrace-12728 (12728) [003] ...1 174330.280300: tracing_mark_write: \
430             trace_event_clock_sync:parent_ts=23139.998047\n";
431     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
432     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
433         EXPECT_TRUE(false);
434         return;
435     }
436     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
437     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
438     bytraceParser.WaitForParserEnd();
439 
440     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
441     stream_.traceDataCache_->ExportDatabase(dbPath_);
442     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
443 }
444 
445 /**
446  * @tc.name: ParseSchedSwitch
447  * @tc.desc: Parse a SchedSwitch event
448  * @tc.type: FUNC
449  */
450 HWTEST_F(EventParserTest, ParseSchedSwitch, TestSize.Level1)
451 {
452     TS_LOGI("test4-27");
453     const uint8_t str[] =
454         "ACCS0-2716  ( 2519) [000] d..3 174330.289220: sched_switch: prev_comm=ACCS0 prev_pid=2716 prev_prio=120 \
455             prev_state=R+ ==> next_comm=Binder:924_6 next_pid=1332 next_prio=120\n";
456     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
457     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
458         EXPECT_TRUE(false);
459         return;
460     }
461     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
462     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
463     bytraceParser.WaitForParserEnd();
464 
465     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
466     stream_.traceDataCache_->ExportDatabase(dbPath_);
467     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
468 }
469 
470 /**
471  * @tc.name: ParseTaskRename
472  * @tc.desc: Parse a TaskRename event
473  * @tc.type: FUNC
474  */
475 HWTEST_F(EventParserTest, ParseTaskRename, TestSize.Level1)
476 {
477     TS_LOGI("test4-28");
478     const uint8_t str[] =
479         "<...>-2093  (-----) [001] ...2 174332.792290: task_rename: pid=12729 oldcomm=perfd \
480             newcomm=POSIX timer 249 oom_score_adj=-1000\n";
481     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
482     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
483         EXPECT_TRUE(false);
484         return;
485     }
486     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
487     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
488     bytraceParser.WaitForParserEnd();
489 
490     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
491     stream_.traceDataCache_->ExportDatabase(dbPath_);
492     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
493 }
494 
495 /**
496  * @tc.name: ParseTaskNewtask
497  * @tc.desc: Parse a TaskNewtask event
498  * @tc.type: FUNC
499  */
500 HWTEST_F(EventParserTest, ParseTaskNewtask, TestSize.Level1)
501 {
502     TS_LOGI("test4-29");
503     const uint8_t str[] =
504         "<...>-2     (-----) [003] ...1 174332.825588: task_newtask: pid=12730 \
505             comm=kthreadd clone_flags=800711 oom_score_adj=0\n";
506     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
507     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
508         EXPECT_TRUE(false);
509         return;
510     }
511     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
512     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
513     bytraceParser.WaitForParserEnd();
514 
515     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
516     stream_.traceDataCache_->ExportDatabase(dbPath_);
517     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
518 }
519 
520 /**
521  * @tc.name: ParseWorkqueueExecuteStart
522  * @tc.desc: Parse a WorkqueueExecuteStart event
523  * @tc.type: FUNC
524  */
525 HWTEST_F(EventParserTest, ParseWorkqueueExecuteStart, TestSize.Level1)
526 {
527     TS_LOGI("test4-30");
528     const uint8_t str[] =
529         "<...>-12180 (-----) [001] ...1 174332.827595: workqueue_execute_start: \
530             work struct 0000000000000000: function pm_runtime_work\n";
531     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
532     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
533         EXPECT_TRUE(false);
534         return;
535     }
536     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
537     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
538     bytraceParser.WaitForParserEnd();
539 
540     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
541     stream_.traceDataCache_->ExportDatabase(dbPath_);
542     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
543 }
544 
545 /**
546  * @tc.name: ParseWorkqueueExecuteEnd
547  * @tc.desc: Parse a WorkqueueExecuteEnd event
548  * @tc.type: FUNC
549  */
550 HWTEST_F(EventParserTest, ParseWorkqueueExecuteEnd, TestSize.Level1)
551 {
552     TS_LOGI("test4-31");
553     const uint8_t str[] =
554         "<...>-12180 (-----) [001] ...1 174332.828056: workqueue_execute_end: work struct 0000000000000000\n";
555     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
556     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
557         EXPECT_TRUE(false);
558         return;
559     }
560     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
561     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
562     bytraceParser.WaitForParserEnd();
563 
564     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
565     stream_.traceDataCache_->ExportDatabase(dbPath_);
566     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
567 }
568 
569 /**
570  * @tc.name: ParsDistribute
571  * @tc.desc: Parse a Distribute event
572  * @tc.type: FUNC
573  */
574 HWTEST_F(EventParserTest, ParsDistribute, TestSize.Level1)
575 {
576     TS_LOGI("test4-31-1");
577     const uint8_t str[] =
578         "system-1298 ( 1298) [001] ...1 174330.287420: tracing_mark_write: B|1298|[8b00e96b2,2,1]:C$#decodeFrame$#"
579         "{\"Process\":\"DecodeVideoFrame\",\"frameTimestamp\":37313484466} \
580             system - 1298(1298)[001]... 1 174330.287622 : tracing_mark_write : E | 1298 \n";
581     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
582     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
583         EXPECT_TRUE(false);
584         return;
585     }
586     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
587     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
588     bytraceParser.WaitForParserEnd();
589 
590     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
591     stream_.traceDataCache_->ExportDatabase(dbPath_);
592     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
593     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().Size() == 1);
594     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().ChainIds()[0] == "8b00e96b2");
595     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().SpanIds()[0] == "2");
596     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().ParentSpanIds()[0] == "1");
597     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().Flags()[0] == "C");
598 }
599 
600 /**
601  * @tc.name: ParsPairsOfDistributeEvent
602  * @tc.desc: Parse a pair of Distribute event
603  * @tc.type: FUNC
604  */
605 HWTEST_F(EventParserTest, ParsPairsOfDistributeEvent, TestSize.Level1)
606 {
607     TS_LOGI("test4-31-2");
608     const uint8_t str[] =
609         "system-1298 ( 1298) [001] ...1 174330.287420: tracing_mark_write: B|1298|[8b00e96b2,2,1]:C$#decodeFrame$#"
610         "{\"Process\":\"DecodeVideoFrame\",\"frameTimestamp\":37313484466} \
611             system - 1298(1298)[001]... 1 174330.287622 : tracing_mark_write : E | 1298 \n"
612         "startVC-7601 ( 7601) [002] ...1 174330.387420: tracing_mark_write: B|7601|[8b00e96b2,2,1]:S$#startVCFrame$#"
613         "{\"Process\":\"DecodeVideoFrame\",\"frameTimestamp\":37313484466} \
614             startVC-7601 (7601)[002]... 1 174330.487622 : tracing_mark_write : E | 7601 \n";
615     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
616     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
617         EXPECT_TRUE(false);
618         return;
619     }
620     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
621     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
622     bytraceParser.WaitForParserEnd();
623 
624     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(2));
625     stream_.traceDataCache_->ExportDatabase(dbPath_);
626     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
627     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().Size() == 2);
628     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().ChainIds()[0] == "8b00e96b2");
629     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().SpanIds()[0] == "2");
630     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().ParentSpanIds()[0] == "1");
631     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().Flags()[0] == "C");
632     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().ChainIds()[1] == "8b00e96b2");
633     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().SpanIds()[1] == "2");
634     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().ParentSpanIds()[1] == "1");
635     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().Flags()[1] == "S");
636 }
637 
638 /**
639  * @tc.name: ParsDistributeWithNoFlag
640  * @tc.desc: Parse a Distribute event with no flag
641  * @tc.type: FUNC
642  */
643 HWTEST_F(EventParserTest, ParsDistributeWithNoFlag, TestSize.Level1)
644 {
645     TS_LOGI("test4-31-3");
646     const uint8_t str[] =
647         "system-1298 ( 1298) [001] ...1 174330.287420: tracing_mark_write: B|1298|[8b00e96b2,2,1]$#decodeFrame$#"
648         "{\"Process\":\"DecodeVideoFrame\",\"frameTimestamp\":37313484466} \
649             system - 1298(1298)[001]... 1 174330.287622 : tracing_mark_write : E | 1298 \n";
650     auto buf = std::make_unique<uint8_t[]>(G_BUF_SIZE);
651     if (memcpy_s(buf.get(), G_BUF_SIZE, str, sizeof(str))) {
652         EXPECT_TRUE(false);
653         return;
654     }
655     BytraceParser bytraceParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
656     bytraceParser.ParseTraceDataSegment(std::move(buf), G_BUF_SIZE);
657     bytraceParser.WaitForParserEnd();
658 
659     EXPECT_EQ(bytraceParser.ParsedTraceValidLines(), static_cast<const unsigned int>(1));
660     stream_.traceDataCache_->ExportDatabase(dbPath_);
661     EXPECT_TRUE(access(dbPath_.c_str(), F_OK) == 0);
662     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().Size() == 1);
663     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().ChainIds()[0] == "8b00e96b2");
664     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().SpanIds()[0] == "2");
665     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().ParentSpanIds()[0] == "1");
666     EXPECT_TRUE(stream_.traceDataCache_->GetConstInternalSlicesData().Flags()[0] == "");
667 }
668 
669 /**
670  * @tc.name: ParseSchedSwitchByInitParam
671  * @tc.desc: Parse a SchedSwitch event
672  * @tc.type: FUNC
673  */
674 HWTEST_F(EventParserTest, ParseSchedSwitchByInitParam, TestSize.Level1)
675 {
676     TS_LOGI("test4-32");
677     BytraceLine bytraceLine;
678     static std::unordered_map<std::string, std::string> args{{"prev_comm", "ACCS0"}, {"next_comm", "HeapTaskDaemon"},
679                                                              {"prev_prio", "120"},   {"next_prio", "124"},
680                                                              {"prev_pid", "2716"},   {"next_pid", "2532"},
681                                                              {"prev_state", "S"}};
682     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
683     int result = eventParser.SchedSwitchEvent(args, bytraceLine);
684 
685     EXPECT_EQ(result, true);
686 }
687 
688 /**
689  * @tc.name: ParseSchedSwitchByAbnormalInitParam
690  * @tc.desc: Parse a SchedSwitch event with some Null parameter
691  * @tc.type: FUNC
692  */
693 HWTEST_F(EventParserTest, ParseSchedSwitchByAbnormalInitParam, TestSize.Level1)
694 {
695     TS_LOGI("test4-33");
696     BytraceLine bytraceLine;
697     static std::unordered_map<std::string, std::string> args{{"prev_comm", "ACCS0"}, {"next_comm", "HeapTaskDaemon"},
698                                                              {"prev_prio", ""},      {"next_prio", ""},
699                                                              {"prev_pid", ""},       {"next_pid", ""},
700                                                              {"prev_state", "S"}};
701     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
702     int result = eventParser.SchedSwitchEvent(args, bytraceLine);
703 
704     EXPECT_EQ(result, false);
705 }
706 
707 /**
708  * @tc.name: ParseTaskRenameEventByInitParam
709  * @tc.desc: Parse a TaskRename event
710  * @tc.type: FUNC
711  */
712 HWTEST_F(EventParserTest, ParseTaskRenameByInitParam, TestSize.Level1)
713 {
714     TS_LOGI("test4-34");
715     BytraceLine bytraceLine;
716     static std::unordered_map<std::string, std::string> args{{"newcomm", "POSIX"}, {"pid", "8542"}};
717     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
718     int result = eventParser.TaskRenameEvent(args, bytraceLine);
719 
720     EXPECT_EQ(result, true);
721 }
722 
723 /**
724  * @tc.name: ParseTaskNewtaskByInitParam
725  * @tc.desc: Parse a TaskNew event
726  * @tc.type: FUNC
727  */
728 HWTEST_F(EventParserTest, ParseTaskNewtaskByInitParam, TestSize.Level1)
729 {
730     TS_LOGI("test4-35");
731     BytraceLine bytraceLine;
732     bytraceLine.tGidStr = "12";
733     static std::unordered_map<std::string, std::string> args{{"comm", "POSIX"}, {"pid", "8542"}, {"clone_flags", "1"}};
734     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
735     int result = eventParser.TaskNewtaskEvent(args, bytraceLine);
736 
737     EXPECT_EQ(result, true);
738 }
739 
740 /**
741  * @tc.name: ParseTracingMarkWriteByInitParam
742  * @tc.desc: Parse a TracingMarkWriteEvent event
743  * @tc.type: FUNC
744  */
745 HWTEST_F(EventParserTest, ParseTracingMarkWriteByInitParam, TestSize.Level1)
746 {
747     TS_LOGI("test4-36");
748     BytraceLine bytraceLine;
749     bytraceLine.ts = 1616439852302;
750     bytraceLine.pid = 1;
751     bytraceLine.argsStr = "vec=9 [action=RCU]";
752     static std::unordered_map<std::string, std::string> args{};
753     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
754     int result = eventParser.TracingMarkWriteEvent(args, bytraceLine);
755 
756     EXPECT_EQ(result, true);
757 }
758 
759 /**
760  * @tc.name: ParseSchedWakeupByInitParam
761  * @tc.desc: Parse a SchedWakeup event
762  * @tc.type: FUNC
763  */
764 HWTEST_F(EventParserTest, ParseSchedWakeupByInitParam, TestSize.Level1)
765 {
766     TS_LOGI("test4-37");
767     BytraceLine bytraceLine;
768     bytraceLine.ts = 1616439852302;
769     bytraceLine.pid = 1;
770     static std::unordered_map<std::string, std::string> args{{"pid", "1200"}, {"target_cpu", "1"}};
771     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
772     int result = eventParser.SchedWakeupEvent(args, bytraceLine);
773 
774     EXPECT_EQ(result, true);
775 }
776 
777 /**
778  * @tc.name: ParseSchedWakeupByAbromalInitParam
779  * @tc.desc: Parse a SchedWakeup event
780  * @tc.type: FUNC
781  */
782 HWTEST_F(EventParserTest, ParseSchedWakeupByAbromalInitParam, TestSize.Level1)
783 {
784     TS_LOGI("test4-38");
785     BytraceLine bytraceLine;
786     bytraceLine.ts = 1616439852302;
787     bytraceLine.pid = 1;
788     static std::unordered_map<std::string, std::string> args{{"pid", ""}, {"target_cpu", "1"}};
789     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
790     int result = eventParser.SchedWakeupEvent(args, bytraceLine);
791 
792     EXPECT_EQ(result, false);
793 }
794 
795 /**
796  * @tc.name: ParseSchedWakingByInitParam
797  * @tc.desc: Parse a SchedWaking event
798  * @tc.type: FUNC
799  */
800 HWTEST_F(EventParserTest, ParseSchedWakingByInitParam, TestSize.Level1)
801 {
802     TS_LOGI("test4-39");
803     BytraceLine bytraceLine;
804     bytraceLine.ts = 1616439852302;
805     bytraceLine.pid = 1;
806     static std::unordered_map<std::string, std::string> args{{"pid", "1200"}, {"target_cpu", "1"}};
807     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
808     int result = eventParser.SchedWakingEvent(args, bytraceLine);
809 
810     EXPECT_EQ(result, true);
811 }
812 
813 /**
814  * @tc.name: ParseSchedWakingByAbnormalInitParam
815  * @tc.desc: Parse a SchedWaking event
816  * @tc.type: FUNC
817  */
818 HWTEST_F(EventParserTest, ParseSchedWakingByAbnormalInitParam, TestSize.Level1)
819 {
820     TS_LOGI("test4-40");
821     BytraceLine bytraceLine;
822     bytraceLine.ts = 1616439852302;
823     bytraceLine.pid = 1;
824     static std::unordered_map<std::string, std::string> args{{"pid", ""}, {"target_cpu", "1"}};
825     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
826     int result = eventParser.SchedWakingEvent(args, bytraceLine);
827 
828     EXPECT_EQ(result, false);
829 }
830 
831 /**
832  * @tc.name: ParseCpuIdleByInitParam
833  * @tc.desc: Parse a CpuIdle event
834  * @tc.type: FUNC
835  */
836 HWTEST_F(EventParserTest, ParseCpuIdleByInitParam, TestSize.Level1)
837 {
838     TS_LOGI("test4-41");
839     BytraceLine bytraceLine;
840     bytraceLine.ts = 1616439852302;
841     bytraceLine.eventName = "POSIX";
842     static std::unordered_map<std::string, std::string> args{{"cpu_id", "3"}, {"state", "4294967295"}};
843     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
844     int result = eventParser.CpuIdleEvent(args, bytraceLine);
845 
846     EXPECT_EQ(result, true);
847 }
848 
849 /**
850  * @tc.name: ParseCpuIdleByAbnormalInitParam
851  * @tc.desc: Parse a CpuIdle event
852  * @tc.type: FUNC
853  */
854 HWTEST_F(EventParserTest, ParseCpuIdleByAbnormalInitParam, TestSize.Level1)
855 {
856     TS_LOGI("test4-42");
857     BytraceLine bytraceLine;
858     bytraceLine.ts = 1616439852302;
859     bytraceLine.eventName = "POSIX";
860     static std::unordered_map<std::string, std::string> args{{"cpu_id", ""}, {"state", "4294967295"}};
861     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
862     int result = eventParser.CpuIdleEvent(args, bytraceLine);
863 
864     EXPECT_EQ(result, false);
865 }
866 
867 /**
868  * @tc.name: ParseCpuFrequencyNormal
869  * @tc.desc: Parse a CpuFrequency event normally
870  * @tc.type: FUNC
871  */
872 HWTEST_F(EventParserTest, ParseCpuFrequencyNormal, TestSize.Level1)
873 {
874     TS_LOGI("test4-44");
875     BytraceLine bytraceLine;
876     bytraceLine.ts = 1616439852302;
877     bytraceLine.eventName = "POSIX";
878     static std::unordered_map<std::string, std::string> args{{"cpu_id", "3"}, {"state", "4294967295"}};
879     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
880     int result = eventParser.CpuFrequencyEvent(args, bytraceLine);
881 
882     EXPECT_EQ(result, true);
883 }
884 
885 /**
886  * @tc.name: ParseCpuFrequencyByAbnormalInitEmptyCpuId
887  * @tc.desc: Parse a CpuFrequency event
888  * @tc.type: FUNC
889  */
890 HWTEST_F(EventParserTest, ParseCpuFrequencyByAbnormalInitEmptyCpuId, TestSize.Level1)
891 {
892     TS_LOGI("test4-45");
893     BytraceLine bytraceLine;
894     bytraceLine.ts = 1616439852302;
895     bytraceLine.eventName = "POSIX";
896     static std::unordered_map<std::string, std::string> args{{"cpu_id", ""}, {"state", "4294967295"}};
897     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
898     int result = eventParser.CpuFrequencyEvent(args, bytraceLine);
899 
900     EXPECT_EQ(result, false);
901 }
902 
903 /**
904  * @tc.name: ParseCpuFrequencyByAbnormalInitEmptyStateValue
905  * @tc.desc: Parse a CpuFrequency event, empty state value
906  * @tc.type: FUNC
907  */
908 HWTEST_F(EventParserTest, ParseCpuFrequencyByAbnormalInitEmptyStateValue, TestSize.Level1)
909 {
910     TS_LOGI("test4-46");
911     BytraceLine bytraceLine;
912     bytraceLine.ts = 1616439852302;
913     bytraceLine.eventName = "POSIX";
914     static std::unordered_map<std::string, std::string> args{{"cpu_id", "3"}, {"state", ""}};
915     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
916     int result = eventParser.CpuFrequencyEvent(args, bytraceLine);
917 
918     EXPECT_EQ(result, false);
919 }
920 
921 /**
922  * @tc.name: ParseWorkqueueExecuteStartByInitParam
923  * @tc.desc: Parse a WorkqueueExecuteStart event
924  * @tc.type: FUNC
925  */
926 HWTEST_F(EventParserTest, ParseWorkqueueExecuteStartByInitParam, TestSize.Level1)
927 {
928     TS_LOGI("test4-47");
929     BytraceLine bytraceLine;
930     bytraceLine.ts = 1616439852302;
931     bytraceLine.pid = 1355;
932     bytraceLine.argsStr = "vec=9 [action=RCU]";
933     static std::unordered_map<std::string, std::string> args{};
934     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
935     int result = eventParser.WorkqueueExecuteStartEvent(args, bytraceLine);
936 
937     EXPECT_EQ(result, true);
938 }
939 
940 /**
941  * @tc.name: ParseWorkqueueExecuteEndByInitParam
942  * @tc.desc: Parse a WorkqueueExecuteEnd event
943  * @tc.type: FUNC
944  */
945 HWTEST_F(EventParserTest, ParseWorkqueueExecuteEndByInitParam, TestSize.Level1)
946 {
947     TS_LOGI("test4-48");
948     BytraceLine bytraceLine;
949     bytraceLine.ts = 1616439852302;
950     bytraceLine.pid = 1355;
951     static std::unordered_map<std::string, std::string> args{};
952     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
953     int result = eventParser.WorkqueueExecuteEndEvent(args, bytraceLine);
954 
955     EXPECT_EQ(result, false);
956 }
957 
958 /**
959  * @tc.name: CheckTracePoint
960  * @tc.desc: Judge whether the "tracepoint information conforming to the specification" in a text format conforms to the
961  * tracepoint specification
962  * @tc.type: FUNC
963  */
964 HWTEST_F(EventParserTest, CheckTracePoint, TestSize.Level1)
965 {
966     TS_LOGI("test4-49");
967     std::string str("B|924|FullSuspendCheck");
968     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
969     int result = eventParser.printEventParser_.CheckTracePoint(str);
970 
971     EXPECT_TRUE(result == SUCCESS);
972 }
973 
974 /**
975  * @tc.name: CheckTracePointEmptyString
976  * @tc.desc: Judge whether the Empty string conforms to the tracepoint specification
977  * @tc.type: FUNC
978  */
979 HWTEST_F(EventParserTest, CheckTracePointEmptyString, TestSize.Level1)
980 {
981     TS_LOGI("test4-50");
982     std::string str("");
983     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
984     int result = eventParser.printEventParser_.CheckTracePoint(str);
985 
986     EXPECT_TRUE(result == ERROR);
987 }
988 
989 /**
990  * @tc.name: CheckTracePointNoSplit
991  * @tc.desc: Judge whether the string No Split conforms to the tracepoint specification
992  * @tc.type: FUNC
993  */
994 HWTEST_F(EventParserTest, CheckTracePointNoSplit, TestSize.Level1)
995 {
996     TS_LOGI("test4-51");
997     std::string str("trace_event_clock_sync");
998     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
999     int result = eventParser.printEventParser_.CheckTracePoint(str);
1000 
1001     EXPECT_TRUE(result == ERROR);
1002 }
1003 
1004 /**
1005  * @tc.name: CheckTracePointMultiType
1006  * @tc.desc: Judge whether the  string has multipul Case type conforms to the tracepoint specification
1007  * @tc.type: FUNC
1008  */
1009 HWTEST_F(EventParserTest, CheckTracePointMultiType, TestSize.Level1)
1010 {
1011     TS_LOGI("test4-52");
1012     std::string str("BECSF|924|FullSuspendCheck");
1013     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1014     int result = eventParser.printEventParser_.CheckTracePoint(str);
1015 
1016     EXPECT_TRUE(result == ERROR);
1017 }
1018 
1019 /**
1020  * @tc.name: CheckTracePointCheckSingleCharacter
1021  * @tc.desc: Check whether a single character conforms to tracepoint format
1022  * @tc.type: FUNC
1023  */
1024 HWTEST_F(EventParserTest, CheckTracePointCheckSingleCharacter, TestSize.Level1)
1025 {
1026     TS_LOGI("test4-53");
1027     std::string str("X");
1028     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1029     int result = eventParser.printEventParser_.CheckTracePoint(str);
1030 
1031     EXPECT_TRUE(result == ERROR);
1032 }
1033 
1034 /**
1035  * @tc.name: CheckTracePointCheckErrorSplit
1036  * @tc.desc: Check error split
1037  * @tc.type: FUNC
1038  */
1039 HWTEST_F(EventParserTest, CheckTracePointCheckErrorSplit, TestSize.Level1)
1040 {
1041     TS_LOGI("test4-54");
1042     std::string str("B&924|FullSuspendCheck");
1043     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1044     int result = eventParser.printEventParser_.CheckTracePoint(str);
1045 
1046     EXPECT_TRUE(result == ERROR);
1047 }
1048 
1049 /**
1050  * @tc.name: GetTracePoint
1051  * @tc.desc: Test GetTracePoint interface
1052  * @tc.type: FUNC
1053  */
1054 HWTEST_F(EventParserTest, GetTracePoint, TestSize.Level1)
1055 {
1056     TS_LOGI("test4-55");
1057     TracePoint point;
1058     std::string str("B|924|SuspendThreadByThreadId suspended Binder:924_8 id=39");
1059     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1060     int result = eventParser.printEventParser_.GetTracePoint(str, point);
1061 
1062     EXPECT_TRUE(result == SUCCESS);
1063 }
1064 
1065 /**
1066  * @tc.name: GetTracePointParseEmptyString
1067  * @tc.desc: Test GetTracePoint interface parse empty string
1068  * @tc.type: FUNC
1069  */
1070 HWTEST_F(EventParserTest, GetTracePointParseEmptyString, TestSize.Level1)
1071 {
1072     TS_LOGI("test4-56");
1073     TracePoint point;
1074     std::string str("");
1075     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1076     int result = eventParser.printEventParser_.GetTracePoint(str, point);
1077 
1078     EXPECT_TRUE(result == ERROR);
1079 }
1080 
1081 /**
1082  * @tc.name: GetTracePointParseErrorSubEventType
1083  * @tc.desc: Test GetTracePoint interface parse error Sub event type
1084  * @tc.type: FUNC
1085  */
1086 HWTEST_F(EventParserTest, GetTracePointParseErrorSubEventType, TestSize.Level1)
1087 {
1088     TS_LOGI("test4-57");
1089     TracePoint point;
1090     std::string str("X|924|SuspendThreadByThreadId suspended Binder:924_8 id=39");
1091     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1092     int result = eventParser.printEventParser_.GetTracePoint(str, point);
1093 
1094     EXPECT_TRUE(result == ERROR);
1095 }
1096 
1097 /**
1098  * @tc.name: GetThreadGroupId
1099  * @tc.desc: Test GetThreadGroupId interface
1100  * @tc.type: FUNC
1101  */
1102 HWTEST_F(EventParserTest, GetThreadGroupId, TestSize.Level1)
1103 {
1104     TS_LOGI("test4-58");
1105     size_t length{0};
1106     std::string str("E|924");
1107     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1108     int result = eventParser.printEventParser_.GetThreadGroupId(str, length);
1109 
1110     EXPECT_TRUE(result == 924);
1111 }
1112 
1113 /**
1114  * @tc.name: GetThreadGroupIdParseErrorPid
1115  * @tc.desc: Test GetThreadGroupId interface parse error pid
1116  * @tc.type: FUNC
1117  */
1118 HWTEST_F(EventParserTest, GetThreadGroupIdParseErrorPid, TestSize.Level1)
1119 {
1120     TS_LOGI("test4-59");
1121     size_t length{0};
1122     std::string str("E|abc");
1123     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1124     int result = eventParser.printEventParser_.GetThreadGroupId(str, length);
1125 
1126     EXPECT_TRUE(result == ERROR);
1127 }
1128 
1129 /**
1130  * @tc.name: HandlerB
1131  * @tc.desc: Test HandlerB interface
1132  * @tc.type: FUNC
1133  */
1134 HWTEST_F(EventParserTest, HandlerB, TestSize.Level1)
1135 {
1136     TS_LOGI("test4-60");
1137     size_t length{3};
1138     TracePoint outPoint;
1139     std::string str("B|924|HID::ISensors::batch::client");
1140     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1141     int result = eventParser.printEventParser_.HandlerB(str, outPoint, length);
1142 
1143     EXPECT_TRUE(result == SUCCESS);
1144 }
1145 
1146 /**
1147  * @tc.name: HandlerB
1148  * @tc.desc: Test HandlerBAbnormal interface using Abnormal format
1149  * @tc.type: FUNC
1150  */
1151 HWTEST_F(EventParserTest, HandlerBAbnormal, TestSize.Level1)
1152 {
1153     TS_LOGI("test4-61");
1154     size_t length{3};
1155     TracePoint outPoint;
1156     std::string str("B|924|");
1157     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1158     int result = eventParser.printEventParser_.HandlerB(str, outPoint, length);
1159 
1160     EXPECT_TRUE(result == ERROR);
1161 }
1162 
1163 /**
1164  * @tc.name: HandlerCsf
1165  * @tc.desc: Test HandlerCSF interface
1166  * @tc.type: FUNC
1167  */
1168 HWTEST_F(EventParserTest, HandlerCsf, TestSize.Level1)
1169 {
1170     TS_LOGI("test4-62");
1171     size_t length{4};
1172     TracePoint outPoint;
1173     std::string str("C|2519|Heap size (KB)|2363");
1174     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1175     int result = eventParser.printEventParser_.HandlerCSF(str, outPoint, length);
1176 
1177     EXPECT_TRUE(result == SUCCESS);
1178 }
1179 
1180 /**
1181  * @tc.name: HandlerCsfParseEmptyString
1182  * @tc.desc: Parse empty string using HandlerCSF interface
1183  * @tc.type: FUNC
1184  */
1185 HWTEST_F(EventParserTest, HandlerCsfParseEmptyString, TestSize.Level1)
1186 {
1187     TS_LOGI("test4-63");
1188     size_t length{4};
1189     TracePoint outPoint;
1190     std::string str("");
1191     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1192     int result = eventParser.printEventParser_.HandlerCSF(str, outPoint, length);
1193 
1194     EXPECT_TRUE(result == ERROR);
1195 }
1196 
1197 /**
1198  * @tc.name: HandlerCsfParseErrorFormate
1199  * @tc.desc: Parse "C|2519|Heap size (KB)|" using HandlerCSF interface
1200  * @tc.type: FUNC
1201  */
1202 HWTEST_F(EventParserTest, HandlerCsfParseErrorFormate, TestSize.Level1)
1203 {
1204     TS_LOGI("test4-64");
1205     size_t length{4};
1206     TracePoint outPoint;
1207     std::string str("C|2519|Heap size (KB)|");
1208     BytraceEventParser eventParser(stream_.traceDataCache_.get(), stream_.streamFilters_.get());
1209     int result = eventParser.printEventParser_.HandlerCSF(str, outPoint, length);
1210 
1211     EXPECT_TRUE(result == ERROR);
1212 }
1213 } // namespace TraceStreamer
1214 } // namespace SysTuning
1215