1 /* 2 * Copyright (c) Huawei Technologies Co., Ltd. 2023. All rights reserved. 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 <hwext/gtest-ext.h> 17 #include <hwext/gtest-tag.h> 18 19 #include "frame_filter.h" 20 #include "process_filter.h" 21 #include "trace_streamer_selector.h" 22 23 using namespace testing::ext; 24 using namespace SysTuning::TraceStreamer; 25 namespace SysTuning { 26 namespace TraceStreamer { 27 const uint64_t START_TS = 1; 28 const uint32_t PID1 = 156; 29 const uint32_t TID1 = 248; 30 const uint64_t EXPECTED_START = 5; 31 const uint64_t EXPECTED_END = 10; 32 const uint32_t VSYNC_ID = 1; 33 const uint32_t CALLSTACK_SLICE_ID = 1; 34 const uint32_t CALLSTACK_SLICE_ID2 = 1; 35 const uint64_t RS_START_TS = 5; 36 const uint32_t RS_PID = 2; 37 const uint32_t RS_TID = 2; 38 const uint64_t RS_EXPECTED_START = 6; 39 const uint64_t RS_EXPECTED_END = 11; 40 const uint32_t RS_VSYNC_ID = 2; 41 const uint32_t RS_CALLSTACK_SLICE_ID = 2; 42 const size_t SON_THREAD_DATA_INDEX = 2; 43 const uint8_t INVALID_DATA = 2; 44 45 class FrameFilterTest : public ::testing::Test { 46 public: SetUp()47 void SetUp() 48 { 49 stream_.InitFilter(); 50 } 51 TearDown()52 void TearDown() {} 53 54 public: 55 TraceStreamerSelector stream_ = {}; 56 }; 57 58 /** 59 * @tc.name: AppVsyncNoFrameNum 60 * @tc.desc: app's vsync event no frameNum 61 * @tc.type: FUNC 62 */ 63 HWTEST_F(FrameFilterTest, AppVsyncNoFrameNum, TestSize.Level1) 64 { 65 TS_LOGI("test6-1"); 66 // ut 1 no frameNum 67 // app ---------------VSYNCStart------------------End---uint64_t ts, 68 BytraceLine line = {START_TS, TID1}; 69 line.tgid = PID1; 70 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 71 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line, EXPECTED_START, EXPECTED_END, VSYNC_ID, 72 CALLSTACK_SLICE_ID); 73 const uint64_t END_TS = 10; 74 auto res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid); 75 EXPECT_FALSE(res); 76 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Flags()[0], 2); // actural frame, no frameNum 77 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Flags()[1], 2); // expect frame, no frameNum 78 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->TimeStampData()[0], START_TS); // actural frame 79 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->TimeStampData()[1], EXPECTED_START); // expect frame 80 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[0], END_TS - START_TS); // actural frame 81 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[1], EXPECTED_END - EXPECTED_START); // expect frame 82 } 83 84 /** 85 * @tc.name: AppVsyncHasFrameNum 86 * @tc.desc: app's vsync event has frameNum 87 * @tc.type: FUNC 88 */ 89 HWTEST_F(FrameFilterTest, AppVsyncHasFrameNum, TestSize.Level1) 90 { 91 TS_LOGI("test6-2"); 92 // ut 2 has frameNum 93 // app -----VSYNCStart------------------End--- 94 // -----------------frameNum-------------- 95 BytraceLine line = {START_TS, TID1}; 96 line.tgid = PID1; 97 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 98 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line, EXPECTED_START, EXPECTED_END, VSYNC_ID, 99 CALLSTACK_SLICE_ID); 100 const uint64_t FRAME_TS = 5; 101 const uint32_t FRAME_NUM = 1; 102 bool res = stream_.streamFilters_->frameFilter_->BeginRSTransactionData(itid, FRAME_NUM, itid); 103 EXPECT_TRUE(res); 104 const uint64_t END_TS = 10; 105 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid); 106 EXPECT_TRUE(res); 107 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Flags()[0], 0); // actural frame, no frameNum 108 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Flags()[1], 255); // expect frame, no frameNum 109 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->TimeStampData()[0], START_TS); // actural frame 110 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->TimeStampData()[1], EXPECTED_START); // expect frame 111 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[0], END_TS - START_TS); // actural frame 112 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[1], EXPECTED_END - EXPECTED_START); // expect frame 113 EXPECT_EQ(stream_.streamFilters_->frameFilter_->dstRenderSlice_[itid][FRAME_NUM].get()->startTs_, START_TS); 114 } 115 /** 116 * @tc.name: RSVsyncHasFrameNum 117 * @tc.desc: RS's vsync event has no frameNum 118 * @tc.type: FUNC 119 */ 120 HWTEST_F(FrameFilterTest, RSVsyncHasNoFrameNum, TestSize.Level1) 121 { 122 TS_LOGI("test6-3"); 123 // ut3 RS no frame 124 // RS ---------------VSYNCStart------------------End--- 125 BytraceLine line = {START_TS, TID1}; 126 line.tgid = PID1; 127 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 128 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line, EXPECTED_START, EXPECTED_END, VSYNC_ID, 129 CALLSTACK_SLICE_ID); 130 auto res = stream_.streamFilters_->frameFilter_->MarkRSOnDoCompositionEvent(itid); 131 EXPECT_TRUE(res); 132 const uint64_t END_TS = 10; 133 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid); 134 EXPECT_TRUE(res); 135 EXPECT_TRUE(stream_.streamFilters_->frameFilter_->vsyncRenderSlice_[itid].begin()->get()->isRsMainThread_ == true); 136 } 137 138 /** 139 * @tc.name: RSVsyncHasFrameNumNotMatched 140 * @tc.desc: RS's vsync event has frameNum,but not matched 141 * @tc.type: FUNC 142 */ 143 HWTEST_F(FrameFilterTest, RSVsyncHasFrameNumNotMatched, TestSize.Level1) 144 { 145 TS_LOGI("test6-4"); 146 // ut4 RS has frame, bu not matched 147 // RS -----VSYNCStart------------------End--- 148 // -----------frameNum------------------- 149 BytraceLine line = {START_TS, TID1}; 150 line.tgid = PID1; 151 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 152 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line, EXPECTED_START, EXPECTED_END, VSYNC_ID, 153 CALLSTACK_SLICE_ID); 154 auto res = stream_.streamFilters_->frameFilter_->MarkRSOnDoCompositionEvent(itid); 155 EXPECT_TRUE(res); 156 157 const uint32_t SOURCE_ITID1 = 2; 158 const uint32_t SOURCE_FRAME_NUM = 1; 159 std::vector<FrameFilter::FrameMap> frames; 160 frames.push_back({SOURCE_ITID1, SOURCE_FRAME_NUM}); 161 stream_.streamFilters_->frameFilter_->BeginProcessCommandUni(itid, frames, 0); 162 const uint64_t END_TS = 10; 163 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid); 164 EXPECT_TRUE(res); 165 EXPECT_TRUE(stream_.streamFilters_->frameFilter_->vsyncRenderSlice_[itid].begin()->get()->isRsMainThread_ == true); 166 EXPECT_TRUE(stream_.traceDataCache_->GetFrameSliceData()->Srcs()[0].empty() == true); 167 } 168 169 /** 170 * @tc.name: RSVsyncHasGpu 171 * @tc.desc: RS's vsync event has gpu 172 * @tc.type: FUNC 173 */ 174 HWTEST_F(FrameFilterTest, RSVsyncHasGpu, TestSize.Level1) 175 { 176 TS_LOGI("test6-5"); 177 // ut5 RS has gpu inner 178 // RS -----VSYNCStart------------------End--- 179 // --------------gpuStart----gpuEnd---------- 180 BytraceLine line = {START_TS, TID1}; 181 line.tgid = PID1; 182 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 183 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line, EXPECTED_START, EXPECTED_END, VSYNC_ID, 184 CALLSTACK_SLICE_ID); 185 auto res = stream_.streamFilters_->frameFilter_->MarkRSOnDoCompositionEvent(itid); 186 EXPECT_TRUE(res); 187 188 const uint32_t SOURCE_ITID1 = 2; 189 const uint32_t SOURCE_FRAME_NUM = 1; 190 std::vector<FrameFilter::FrameMap> frames; 191 frames.push_back({SOURCE_ITID1, SOURCE_FRAME_NUM}); 192 stream_.streamFilters_->frameFilter_->BeginProcessCommandUni(itid, frames, 0); 193 const uint64_t END_TS = 10; 194 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid); 195 EXPECT_TRUE(res); 196 EXPECT_TRUE( 197 (stream_.streamFilters_->frameFilter_->vsyncRenderSlice_[itid].begin()->get()->isRsMainThread_ == true)); 198 EXPECT_TRUE(stream_.traceDataCache_->GetFrameSliceData()->Srcs()[0].empty() == true); 199 } 200 201 /** 202 * @tc.name: RSVsyncHasGpuCross 203 * @tc.desc: RS's vsync event has gpu 204 * @tc.type: FUNC 205 */ 206 HWTEST_F(FrameFilterTest, RSVsyncHasGpuCross, TestSize.Level1) 207 { 208 TS_LOGI("test6-6"); 209 // ut6 RS has gpu later 210 // RS -----VSYNCStart------------------End------------ 211 // ------------------------------gpuStart----gpuEnd--- 212 BytraceLine line = {START_TS, TID1}; 213 line.tgid = PID1; 214 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 215 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line, EXPECTED_START, EXPECTED_END, VSYNC_ID, 216 CALLSTACK_SLICE_ID); 217 auto res = stream_.streamFilters_->frameFilter_->MarkRSOnDoCompositionEvent(itid); 218 EXPECT_TRUE(res); 219 const uint64_t GPU_START_TS = 3; 220 stream_.streamFilters_->frameFilter_->StartFrameQueue(GPU_START_TS, itid); 221 const uint64_t END_TS = 10; 222 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid); 223 EXPECT_TRUE(res); 224 225 const uint64_t GPU_END_TS = 15; 226 res = stream_.streamFilters_->frameFilter_->EndFrameQueue(GPU_END_TS, itid); 227 228 EXPECT_TRUE(res); 229 EXPECT_TRUE( 230 (stream_.streamFilters_->frameFilter_->vsyncRenderSlice_[itid].begin()->get()->isRsMainThread_ == true)); 231 EXPECT_TRUE(stream_.traceDataCache_->GetFrameSliceData()->Durs()[0] == GPU_END_TS - START_TS); 232 } 233 234 /** 235 * @tc.name: RSVsyncHasGpu2Slices 236 * @tc.desc: RS's vsync event has gpu, two slice across 237 * @tc.type: FUNC 238 */ 239 HWTEST_F(FrameFilterTest, RSVsyncHasGpu2Slices, TestSize.Level1) 240 { 241 TS_LOGI("test6-7"); 242 // ut7 RS two slice across 243 // RS -----VSYNCStart------------------End-----VSYNCStart------------------End-------- 244 // --------------gpuStart------------------------------gpuEnd---------gpuStart----gpuEnd------ 245 BytraceLine line1 = {START_TS, TID1}; 246 line1.tgid = PID1; 247 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 248 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line1, EXPECTED_START, EXPECTED_END, VSYNC_ID, 249 CALLSTACK_SLICE_ID); 250 auto res = stream_.streamFilters_->frameFilter_->MarkRSOnDoCompositionEvent(itid); 251 EXPECT_TRUE(res); 252 const uint64_t GPU_START_TS = 3; 253 stream_.streamFilters_->frameFilter_->StartFrameQueue(GPU_START_TS, itid); 254 const uint64_t END_TS = 10; 255 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid); 256 EXPECT_TRUE(res); 257 258 const uint64_t START_TS2 = 4; 259 const uint64_t EXPECTED_START2 = 6; 260 const uint64_t EXPECTED_END2 = 11; 261 const uint32_t VSYNC_ID2 = 2; 262 const uint32_t CALLSTACK_SLICE_ID2 = 2; 263 BytraceLine line2 = {START_TS2, TID1}; 264 line2.tgid = PID1; 265 auto itid2 = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 266 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line2, EXPECTED_START2, EXPECTED_END2, VSYNC_ID2, 267 CALLSTACK_SLICE_ID2); 268 res = stream_.streamFilters_->frameFilter_->MarkRSOnDoCompositionEvent(itid2); 269 EXPECT_TRUE(res); 270 271 const uint64_t GPU_END_TS = 15; 272 res = stream_.streamFilters_->frameFilter_->EndFrameQueue(GPU_END_TS, itid2); 273 274 const uint64_t GPU_START_TS2 = 16; 275 stream_.streamFilters_->frameFilter_->StartFrameQueue(GPU_START_TS2, itid2); 276 const uint64_t END_TS2 = 18; 277 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS2, itid2); 278 279 const uint64_t GPU_END_TS2 = 20; 280 res = stream_.streamFilters_->frameFilter_->EndFrameQueue(GPU_END_TS2, itid2); 281 282 EXPECT_TRUE(res); 283 EXPECT_TRUE( 284 (stream_.streamFilters_->frameFilter_->vsyncRenderSlice_[itid].begin()->get()->isRsMainThread_ == true)); 285 EXPECT_TRUE(stream_.traceDataCache_->GetFrameSliceData()->Durs()[0] == GPU_END_TS - START_TS); 286 EXPECT_TRUE(stream_.traceDataCache_->GetFrameSliceData()->Durs()[2] == GPU_END_TS2 - START_TS2); 287 EXPECT_TRUE(stream_.streamFilters_->frameFilter_->vsyncRenderSlice_.size() == 1); 288 } 289 290 /** 291 * @tc.name: RSVsyncHasGpu2Slices 292 * @tc.desc: RS's vsync event has gpu, two slice across 293 * @tc.type: FUNC 294 */ 295 HWTEST_F(FrameFilterTest, SliceFromAppToRS, TestSize.Level1) 296 { 297 TS_LOGI("test6-8"); 298 // ut8 299 // slice from app to RS 300 // app -----VSYNCStart------------------End--- 301 // -----------------frameNum-------------- 302 // RS -------------------------VSYNCStart------------------End-----VSYNCStart------------------End----------------- 303 // -----------------------------------gpuStart------------------------------gpuEnd---------gpuStart----gpuEnd------ 304 BytraceLine line = {START_TS, TID1}; 305 line.tgid = PID1; 306 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 307 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line, EXPECTED_START, EXPECTED_END, VSYNC_ID, 308 CALLSTACK_SLICE_ID); 309 const uint64_t ON_DO_COMPOSITION_TS = 2; 310 const uint32_t FRAME_NUM = 1; 311 EXPECT_TRUE(stream_.streamFilters_->frameFilter_->BeginRSTransactionData(itid, FRAME_NUM, itid)); 312 BytraceLine line2 = {RS_START_TS, RS_PID}; 313 line.tgid = RS_TID; 314 auto itid2 = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(RS_TID, RS_PID); 315 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line2, RS_EXPECTED_START, RS_EXPECTED_END, RS_VSYNC_ID, 316 RS_CALLSTACK_SLICE_ID); 317 stream_.streamFilters_->frameFilter_->MarkRSOnDoCompositionEvent(RS_TID); 318 const uint64_t GPU_START_TS2 = 7; 319 stream_.streamFilters_->frameFilter_->StartFrameQueue(GPU_START_TS2, RS_TID); 320 const uint64_t END_TS = 10; 321 EXPECT_TRUE(stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid)); 322 323 const uint64_t RS_END_TS = 10; 324 stream_.streamFilters_->frameFilter_->EndVsyncEvent(RS_END_TS, itid2); 325 326 const uint64_t RS_START_TS2 = 11; 327 const uint64_t RS_EXPECTED_START2 = 11; 328 const uint64_t RS_EXPECTED_END2 = 25; 329 const uint32_t RS_VSYNC_ID2 = 3; 330 const uint32_t RS_CALLSTACK_SLICE_ID2 = 3; 331 BytraceLine line3 = {RS_START_TS2, RS_PID, RS_TID}; 332 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(line3, RS_EXPECTED_START2, RS_EXPECTED_END2, RS_VSYNC_ID2, 333 RS_CALLSTACK_SLICE_ID2); 334 stream_.streamFilters_->frameFilter_->MarkRSOnDoCompositionEvent(RS_TID); 335 336 const uint64_t GPU_END_TS = 15; 337 stream_.streamFilters_->frameFilter_->EndFrameQueue(GPU_END_TS, RS_TID); 338 339 const uint64_t GPU_START_TS3 = 16; 340 stream_.streamFilters_->frameFilter_->StartFrameQueue(GPU_START_TS3, RS_TID); 341 const uint64_t END_TS3 = 20; 342 stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS3, RS_TID); 343 344 const uint64_t GPU_END_TS3 = 25; 345 stream_.streamFilters_->frameFilter_->EndFrameQueue(GPU_END_TS3, RS_TID); 346 347 EXPECT_TRUE(stream_.traceDataCache_->GetFrameSliceData()->Durs()[0] == END_TS - START_TS); 348 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[2], GPU_END_TS3 - END_TS3); 349 EXPECT_TRUE(atoi(stream_.traceDataCache_->GetFrameSliceData()->Srcs()[2].c_str()) == 350 stream_.traceDataCache_->GetFrameSliceData()->IdsData()[0]); 351 } 352 353 HWTEST_F(FrameFilterTest, AppUVTraceNoVsyncIdAndFrameNum, TestSize.Level1) 354 { 355 TS_LOGI("test6-9"); 356 // no vsyncId and frameNum 357 // app ---------------H:UVTrace------------------End---uint64_t ts, 358 BytraceLine line = {START_TS, TID1}; 359 line.tgid = PID1; 360 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 361 stream_.streamFilters_->frameFilter_->BeginUVTraceEvent(line, CALLSTACK_SLICE_ID); 362 const uint64_t END_TS = 10; 363 auto res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, itid); 364 EXPECT_FALSE(res); 365 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Flags()[0], INVALID_DATA); // actural frame, no frameNum 366 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->TimeStampData()[0], START_TS); // actural frame 367 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[0], END_TS - START_TS); // actural frame 368 } 369 370 HWTEST_F(FrameFilterTest, AppUVTraceNoFrameNum, TestSize.Level1) 371 { 372 TS_LOGI("test6-10"); 373 // no frameNum 374 // app ---------------H:UVTrace------------------End---uint64_t ts, 375 BytraceLine mainThreadLine = {0, PID1}; 376 mainThreadLine.tgid = PID1; 377 const uint64_t SON_START_TS = 6; 378 BytraceLine line = {SON_START_TS, TID1}; 379 line.tgid = PID1; 380 auto mainThreadId = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(PID1, PID1); 381 auto itid = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 382 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(mainThreadLine, EXPECTED_START, EXPECTED_END, VSYNC_ID, 383 CALLSTACK_SLICE_ID); 384 stream_.streamFilters_->frameFilter_->BeginUVTraceEvent(line, CALLSTACK_SLICE_ID); 385 stream_.streamFilters_->frameFilter_->UpdateVsyncId(line, VSYNC_ID); 386 const uint64_t SON_END_TS = 9; 387 auto res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(SON_END_TS, itid); 388 EXPECT_FALSE(res); 389 const uint64_t END_TS = 10; 390 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, mainThreadId); 391 EXPECT_FALSE(res); 392 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Flags()[SON_THREAD_DATA_INDEX], 393 INVALID_DATA); // actural frame, no frameNum 394 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[SON_THREAD_DATA_INDEX], 395 SON_END_TS - SON_START_TS); // actural frame 396 } 397 398 HWTEST_F(FrameFilterTest, AppUVTraceNormal, TestSize.Level1) 399 { 400 TS_LOGI("test6-11"); 401 // app ---------------H:UVTrace------------------End---uint64_t ts, 402 const uint64_t SON_START_TS = 6; 403 BytraceLine line = {SON_START_TS, TID1}; 404 line.tgid = PID1; 405 auto sonThreadId = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 406 BytraceLine mainThreadLine = {0, PID1}; 407 mainThreadLine.tgid = PID1; 408 auto mainThreadId = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(PID1, PID1); 409 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(mainThreadLine, EXPECTED_START, EXPECTED_END, VSYNC_ID, 410 CALLSTACK_SLICE_ID2); 411 stream_.streamFilters_->frameFilter_->BeginUVTraceEvent(line, CALLSTACK_SLICE_ID2); 412 stream_.streamFilters_->frameFilter_->UpdateVsyncId(line, VSYNC_ID); 413 const uint32_t FRAME_NUM = 1; 414 stream_.streamFilters_->frameFilter_->BeginRSTransactionData(sonThreadId, FRAME_NUM, mainThreadId); 415 const uint64_t SON_END_TS = 8; 416 auto res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(SON_END_TS, sonThreadId); 417 EXPECT_TRUE(res); 418 const uint64_t END_TS = 9; 419 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, mainThreadId); 420 EXPECT_FALSE(res); 421 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Flags()[SON_THREAD_DATA_INDEX], 422 0); // actural frame, no frameNum 423 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[SON_THREAD_DATA_INDEX], 424 SON_END_TS - SON_START_TS); // actural frame 425 } 426 427 HWTEST_F(FrameFilterTest, AppUVTraceTimeout, TestSize.Level1) 428 { 429 TS_LOGI("test6-12"); 430 // app subthread actual frame timeout 431 const uint64_t SON_START_TS = 7; 432 BytraceLine line = {SON_START_TS, TID1}; 433 line.tgid = PID1; 434 const uint64_t START_TS = 6; 435 BytraceLine mainThreadLine = {START_TS, PID1}; 436 mainThreadLine.tgid = PID1; 437 auto sonThreadId = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(TID1, PID1); 438 auto mainThreadId = stream_.streamFilters_->processFilter_->GetOrCreateThreadWithPid(PID1, PID1); 439 stream_.streamFilters_->frameFilter_->BeginVsyncEvent(mainThreadLine, EXPECTED_START, EXPECTED_END, VSYNC_ID, 440 CALLSTACK_SLICE_ID); 441 stream_.streamFilters_->frameFilter_->BeginUVTraceEvent(line, CALLSTACK_SLICE_ID2); 442 stream_.streamFilters_->frameFilter_->UpdateVsyncId(line, VSYNC_ID); 443 const uint32_t FRAME_NUM = 2; 444 stream_.streamFilters_->frameFilter_->BeginRSTransactionData(sonThreadId, FRAME_NUM, mainThreadId); 445 const uint64_t SON_END_TS = 11; 446 auto res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(SON_END_TS, sonThreadId); 447 EXPECT_TRUE(res); 448 const uint64_t END_TS = 9; 449 res = stream_.streamFilters_->frameFilter_->EndVsyncEvent(END_TS, mainThreadId); 450 EXPECT_FALSE(res); 451 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Flags()[SON_THREAD_DATA_INDEX], 452 1); // actural frame, no frameNum 453 EXPECT_EQ(stream_.traceDataCache_->GetFrameSliceData()->Durs()[SON_THREAD_DATA_INDEX], 454 SON_END_TS - SON_START_TS); // actural frame 455 } 456 } // namespace TraceStreamer 457 } // namespace SysTuning 458