• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "trace_data_cache.h"
21 #include "trace_streamer_filters.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 IPID = 1;
29 const uint32_t ITID = 1;
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 uint64_t RS_START_TS = 5;
35 const uint32_t RS_IPID = 2;
36 const uint32_t RS_ITID = 2;
37 const uint64_t RS_EXPECTED_START = 6;
38 const uint64_t RS_EXPECTED_END = 11;
39 const uint32_t RS_VSYNC_ID = 2;
40 const uint32_t RS_CALLSTACK_SLICE_ID = 2;
41 
42 class FrameFilterTest : public ::testing::Test {
43 public:
SetUp()44     void SetUp()
45     {
46         streamFilters_.frameFilter_ = std::make_unique<FrameFilter>(&traceDataCache_, &streamFilters_);
47     }
48 
TearDown()49     void TearDown() {}
50 
51 public:
52     TraceStreamerFilters streamFilters_;
53     TraceDataCache traceDataCache_;
54 };
55 
56 /**
57  * @tc.name: AppVsyncNoFrameNum
58  * @tc.desc: app's vsync event no frameNum
59  * @tc.type: FUNC
60  */
61 HWTEST_F(FrameFilterTest, AppVsyncNoFrameNum, TestSize.Level1)
62 {
63     TS_LOGI("test6-1");
64     // ut 1 no frameNum
65     // app ---------------VSYNCStart------------------End---uint64_t ts,
66     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS, IPID, ITID, EXPECTED_START, EXPECTED_END, VSYNC_ID,
67                                                  CALLSTACK_SLICE_ID);
68     const uint64_t END_TS = 10;
69     auto res = streamFilters_.frameFilter_->EndVsyncEvent(END_TS, ITID);
70     EXPECT_FALSE(res);
71     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->Flags()[0], 2);                      // actural frame, no frameNum
72     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->Flags()[1], 2);                      // expect frame, no frameNum
73     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->TimeStampData()[0], START_TS);       // actural frame
74     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->TimeStampData()[1], EXPECTED_START); // expect frame
75     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->Durs()[0], END_TS - START_TS);       // actural frame
76     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->Durs()[1], EXPECTED_END - EXPECTED_START); // expect frame
77 }
78 
79 /**
80  * @tc.name: AppVsyncHasFrameNum
81  * @tc.desc: app's vsync event has frameNum
82  * @tc.type: FUNC
83  */
84 HWTEST_F(FrameFilterTest, AppVsyncHasFrameNum, TestSize.Level1)
85 {
86     TS_LOGI("test6-2");
87     // ut 2 has frameNum
88     // app -----VSYNCStart------------------End---
89     //     -----------------frameNum--------------
90     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS, IPID, ITID, EXPECTED_START, EXPECTED_END, VSYNC_ID,
91                                                  CALLSTACK_SLICE_ID);
92     const uint64_t FRAME_TS = 5;
93     const uint32_t FRAME_NUM = 1;
94     bool res = streamFilters_.frameFilter_->BeginRSTransactionData(FRAME_TS, ITID, FRAME_NUM);
95     EXPECT_TRUE(res);
96     const uint64_t END_TS = 10;
97     res = streamFilters_.frameFilter_->EndVsyncEvent(END_TS, ITID);
98     EXPECT_TRUE(res);
99     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->Flags()[0], 0);                      // actural frame, no frameNum
100     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->Flags()[1], 255);                    // expect frame, no frameNum
101     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->TimeStampData()[0], START_TS);       // actural frame
102     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->TimeStampData()[1], EXPECTED_START); // expect frame
103     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->Durs()[0], END_TS - START_TS);       // actural frame
104     EXPECT_EQ(traceDataCache_.GetFrameSliceData()->Durs()[1], EXPECTED_END - EXPECTED_START); // expect frame
105     EXPECT_EQ(streamFilters_.frameFilter_->dstRenderSlice_[ITID][FRAME_NUM].get()->startTs_, START_TS);
106 }
107 /**
108  * @tc.name: RSVsyncHasFrameNum
109  * @tc.desc: RS's vsync event has no frameNum
110  * @tc.type: FUNC
111  */
112 HWTEST_F(FrameFilterTest, RSVsyncHasNoFrameNum, TestSize.Level1)
113 {
114     TS_LOGI("test6-3");
115     // ut3 RS no frame
116     // RS ---------------VSYNCStart------------------End---
117     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS, IPID, ITID, EXPECTED_START, EXPECTED_END, VSYNC_ID,
118                                                  CALLSTACK_SLICE_ID);
119     const uint64_t ON_DO_COMPOSITION_TS = 2;
120     auto res = streamFilters_.frameFilter_->MarkRSOnDoCompositionEvent(ON_DO_COMPOSITION_TS, ITID);
121     EXPECT_TRUE(res);
122     const uint64_t END_TS = 10;
123     res = streamFilters_.frameFilter_->EndVsyncEvent(END_TS, ITID);
124     EXPECT_TRUE(res);
125     EXPECT_TRUE(streamFilters_.frameFilter_->vsyncRenderSlice_[ITID].begin()->get()->isRsMainThread_ == true);
126 }
127 
128 /**
129  * @tc.name: RSVsyncHasFrameNumNotMatched
130  * @tc.desc: RS's vsync event has frameNum,but not matched
131  * @tc.type: FUNC
132  */
133 HWTEST_F(FrameFilterTest, RSVsyncHasFrameNumNotMatched, TestSize.Level1)
134 {
135     TS_LOGI("test6-4");
136     // ut4 RS has frame, bu not matched
137     // RS -----VSYNCStart------------------End---
138     //     -----------frameNum-------------------
139     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS, IPID, ITID, EXPECTED_START, EXPECTED_END, VSYNC_ID,
140                                                  CALLSTACK_SLICE_ID);
141     const uint64_t ON_DO_COMPOSITION_TS = 2;
142     auto res = streamFilters_.frameFilter_->MarkRSOnDoCompositionEvent(ON_DO_COMPOSITION_TS, ITID);
143     EXPECT_TRUE(res);
144 
145     const uint32_t SOURCE_ITID1 = 2;
146     const uint32_t SOURCE_FRAME_NUM = 1;
147     const uint64_t UNI_TS = 3;
148     std::vector<FrameFilter::FrameMap> frames;
149     frames.push_back({SOURCE_ITID1, SOURCE_FRAME_NUM});
150     streamFilters_.frameFilter_->BeginProcessCommandUni(UNI_TS, ITID, frames, 0);
151     const uint64_t END_TS = 10;
152     res = streamFilters_.frameFilter_->EndVsyncEvent(END_TS, ITID);
153     EXPECT_TRUE(res);
154     EXPECT_TRUE(streamFilters_.frameFilter_->vsyncRenderSlice_[ITID].begin()->get()->isRsMainThread_ == true);
155     EXPECT_TRUE(traceDataCache_.GetFrameSliceData()->Srcs()[0].empty() == true);
156 }
157 
158 /**
159  * @tc.name: RSVsyncHasGpu
160  * @tc.desc: RS's vsync event has gpu
161  * @tc.type: FUNC
162  */
163 HWTEST_F(FrameFilterTest, RSVsyncHasGpu, TestSize.Level1)
164 {
165     TS_LOGI("test6-5");
166     // ut5 RS has gpu inner
167     // RS -----VSYNCStart------------------End---
168     // --------------gpuStart----gpuEnd----------
169     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS, IPID, ITID, EXPECTED_START, EXPECTED_END, VSYNC_ID,
170                                                  CALLSTACK_SLICE_ID);
171     const uint64_t ON_DO_COMPOSITION_TS = 2;
172     auto res = streamFilters_.frameFilter_->MarkRSOnDoCompositionEvent(ON_DO_COMPOSITION_TS, ITID);
173     EXPECT_TRUE(res);
174 
175     const uint32_t SOURCE_ITID1 = 2;
176     const uint32_t SOURCE_FRAME_NUM = 1;
177     const uint64_t UNI_TS = 3;
178     std::vector<FrameFilter::FrameMap> frames;
179     frames.push_back({SOURCE_ITID1, SOURCE_FRAME_NUM});
180     streamFilters_.frameFilter_->BeginProcessCommandUni(UNI_TS, ITID, frames, 0);
181     const uint64_t END_TS = 10;
182     res = streamFilters_.frameFilter_->EndVsyncEvent(END_TS, ITID);
183     EXPECT_TRUE(res);
184     EXPECT_TRUE((streamFilters_.frameFilter_->vsyncRenderSlice_[ITID].begin()->get()->isRsMainThread_ == true));
185     EXPECT_TRUE(traceDataCache_.GetFrameSliceData()->Srcs()[0].empty() == true);
186 }
187 
188 /**
189  * @tc.name: RSVsyncHasGpuCross
190  * @tc.desc: RS's vsync event has gpu
191  * @tc.type: FUNC
192  */
193 HWTEST_F(FrameFilterTest, RSVsyncHasGpuCross, TestSize.Level1)
194 {
195     TS_LOGI("test6-6");
196     // ut6 RS has gpu later
197     // RS -----VSYNCStart------------------End------------
198     // ------------------------------gpuStart----gpuEnd---
199     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS, IPID, ITID, EXPECTED_START, EXPECTED_END, VSYNC_ID,
200                                                  CALLSTACK_SLICE_ID);
201     const uint64_t ON_DO_COMPOSITION_TS = 2;
202     auto res = streamFilters_.frameFilter_->MarkRSOnDoCompositionEvent(ON_DO_COMPOSITION_TS, ITID);
203     EXPECT_TRUE(res);
204     const uint64_t GPU_START_TS = 3;
205     streamFilters_.frameFilter_->StartFrameQueue(GPU_START_TS, ITID);
206     const uint64_t END_TS = 10;
207     res = streamFilters_.frameFilter_->EndVsyncEvent(END_TS, ITID);
208     EXPECT_TRUE(res);
209 
210     const uint64_t GPU_END_TS = 15;
211     res = streamFilters_.frameFilter_->EndFrameQueue(GPU_END_TS, ITID);
212 
213     EXPECT_TRUE(res);
214     EXPECT_TRUE((streamFilters_.frameFilter_->vsyncRenderSlice_[ITID].begin()->get()->isRsMainThread_ == true));
215     EXPECT_TRUE(traceDataCache_.GetFrameSliceData()->Durs()[0] == GPU_END_TS - START_TS);
216 }
217 
218 /**
219  * @tc.name: RSVsyncHasGpu2Slices
220  * @tc.desc: RS's vsync event has gpu, two slice across
221  * @tc.type: FUNC
222  */
223 HWTEST_F(FrameFilterTest, RSVsyncHasGpu2Slices, TestSize.Level1)
224 {
225     TS_LOGI("test6-7");
226     // ut7 RS two slice across
227     // RS -----VSYNCStart------------------End-----VSYNCStart------------------End--------
228     // --------------gpuStart------------------------------gpuEnd---------gpuStart----gpuEnd------
229     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS, IPID, ITID, EXPECTED_START, EXPECTED_END, VSYNC_ID,
230                                                  CALLSTACK_SLICE_ID);
231     const uint64_t ON_DO_COMPOSITION_TS = 2;
232     auto res = streamFilters_.frameFilter_->MarkRSOnDoCompositionEvent(ON_DO_COMPOSITION_TS, ITID);
233     EXPECT_TRUE(res);
234     const uint64_t GPU_START_TS = 3;
235     streamFilters_.frameFilter_->StartFrameQueue(GPU_START_TS, ITID);
236     const uint64_t END_TS = 10;
237     res = streamFilters_.frameFilter_->EndVsyncEvent(END_TS, ITID);
238     EXPECT_TRUE(res);
239 
240     const uint64_t START_TS2 = 4;
241     const uint64_t EXPECTED_START2 = 6;
242     const uint64_t EXPECTED_END2 = 11;
243     const uint32_t VSYNC_ID2 = 2;
244     const uint32_t CALLSTACK_SLICE_ID2 = 2;
245 
246     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS2, IPID, ITID, EXPECTED_START2, EXPECTED_END2, VSYNC_ID2,
247                                                  CALLSTACK_SLICE_ID2);
248     const uint64_t ON_DO_COMPOSITION_TS2 = 5;
249     res = streamFilters_.frameFilter_->MarkRSOnDoCompositionEvent(ON_DO_COMPOSITION_TS2, ITID);
250     EXPECT_TRUE(res);
251 
252     const uint64_t GPU_END_TS = 15;
253     res = streamFilters_.frameFilter_->EndFrameQueue(GPU_END_TS, ITID);
254 
255     const uint64_t GPU_START_TS2 = 16;
256     streamFilters_.frameFilter_->StartFrameQueue(GPU_START_TS2, ITID);
257     const uint64_t END_TS2 = 18;
258     res = streamFilters_.frameFilter_->EndVsyncEvent(END_TS2, ITID);
259 
260     const uint64_t GPU_END_TS2 = 20;
261     res = streamFilters_.frameFilter_->EndFrameQueue(GPU_END_TS2, ITID);
262 
263     EXPECT_TRUE(res);
264     EXPECT_TRUE((streamFilters_.frameFilter_->vsyncRenderSlice_[ITID].begin()->get()->isRsMainThread_ == true));
265     EXPECT_TRUE(traceDataCache_.GetFrameSliceData()->Durs()[0] == GPU_END_TS - START_TS);
266     EXPECT_TRUE(traceDataCache_.GetFrameSliceData()->Durs()[2] == GPU_END_TS2 - START_TS2);
267     EXPECT_TRUE(streamFilters_.frameFilter_->vsyncRenderSlice_.size() == 1);
268 }
269 
270 /**
271  * @tc.name: RSVsyncHasGpu2Slices
272  * @tc.desc: RS's vsync event has gpu, two slice across
273  * @tc.type: FUNC
274  */
275 HWTEST_F(FrameFilterTest, SliceFromAppToRS, TestSize.Level1)
276 {
277     TS_LOGI("test6-8");
278     // ut8
279     // slice from app to RS
280     // app -----VSYNCStart------------------End---
281     //     -----------------frameNum--------------
282     // RS -------------------------VSYNCStart------------------End-----VSYNCStart------------------End-----------------
283     // -----------------------------------gpuStart------------------------------gpuEnd---------gpuStart----gpuEnd------
284     streamFilters_.frameFilter_->BeginVsyncEvent(START_TS, IPID, ITID, EXPECTED_START, EXPECTED_END, VSYNC_ID,
285                                                  CALLSTACK_SLICE_ID);
286     const uint64_t ON_DO_COMPOSITION_TS = 2;
287     const uint32_t FRAME_NUM = 1;
288     EXPECT_TRUE(streamFilters_.frameFilter_->BeginRSTransactionData(ON_DO_COMPOSITION_TS, ITID, FRAME_NUM));
289     streamFilters_.frameFilter_->BeginVsyncEvent(RS_START_TS, RS_IPID, RS_ITID, RS_EXPECTED_START, RS_EXPECTED_END,
290                                                  RS_VSYNC_ID, RS_CALLSTACK_SLICE_ID);
291     const uint64_t ON_DO_COMPOSITION_TS2 = 7;
292     streamFilters_.frameFilter_->MarkRSOnDoCompositionEvent(ON_DO_COMPOSITION_TS2, RS_ITID);
293     const uint64_t GPU_START_TS2 = 7;
294     streamFilters_.frameFilter_->StartFrameQueue(GPU_START_TS2, RS_ITID);
295     const uint64_t END_TS = 10;
296     EXPECT_TRUE(streamFilters_.frameFilter_->EndVsyncEvent(END_TS, ITID));
297 
298     const uint64_t RS_END_TS = 10;
299     streamFilters_.frameFilter_->EndVsyncEvent(RS_END_TS, RS_ITID);
300 
301     const uint64_t RS_START_TS2 = 11;
302     const uint64_t RS_EXPECTED_START2 = 11;
303     const uint64_t RS_EXPECTED_END2 = 25;
304     const uint32_t RS_VSYNC_ID2 = 3;
305     const uint32_t RS_CALLSTACK_SLICE_ID2 = 3;
306     streamFilters_.frameFilter_->BeginVsyncEvent(RS_START_TS2, RS_IPID, RS_ITID, RS_EXPECTED_START2, RS_EXPECTED_END2,
307                                                  RS_VSYNC_ID2, RS_CALLSTACK_SLICE_ID2);
308     const uint64_t ON_DO_COMPOSITION_TS3 = 12;
309     streamFilters_.frameFilter_->MarkRSOnDoCompositionEvent(ON_DO_COMPOSITION_TS3, RS_ITID);
310 
311     const uint64_t GPU_END_TS = 15;
312     streamFilters_.frameFilter_->EndFrameQueue(GPU_END_TS, RS_ITID);
313 
314     const uint64_t GPU_START_TS3 = 16;
315     streamFilters_.frameFilter_->StartFrameQueue(GPU_START_TS3, RS_ITID);
316     const uint64_t END_TS3 = 20;
317     streamFilters_.frameFilter_->EndVsyncEvent(END_TS3, RS_ITID);
318 
319     const uint64_t GPU_END_TS3 = 25;
320     streamFilters_.frameFilter_->EndFrameQueue(GPU_END_TS3, RS_ITID);
321 
322     EXPECT_TRUE(traceDataCache_.GetFrameSliceData()->Durs()[0] == END_TS - START_TS);
323     EXPECT_TRUE(traceDataCache_.GetFrameSliceData()->Durs()[2] == GPU_END_TS - RS_START_TS);
324     EXPECT_TRUE(atoi(traceDataCache_.GetFrameSliceData()->Srcs()[2].c_str()) ==
325                 traceDataCache_.GetFrameSliceData()->IdsData()[0]);
326 }
327 } // namespace TraceStreamer
328 } // namespace SysTuning
329