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