1 /*
2 * Copyright (c) 2025 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 "dfx_msg_manager_unit_test.h"
17
18 using namespace testing::ext;
19
20 namespace OHOS {
21 namespace AudioStandard {
22 static constexpr int32_t DEFAULT_DFX_REPORT_INTERVAL_MIN = 24 * 60;
23 static constexpr int32_t MAX_DFX_MSG_MEMBER_SIZE = 100;
24
SetUpTestCase(void)25 void DfxMsgManagerUnitTest::SetUpTestCase(void) {}
TearDownTestCase(void)26 void DfxMsgManagerUnitTest::TearDownTestCase(void) {}
SetUp(void)27 void DfxMsgManagerUnitTest::SetUp(void) {}
TearDown(void)28 void DfxMsgManagerUnitTest::TearDown(void) {}
29
30 /**
31 * @tc.name : Test DfxMsgManager.
32 * @tc.number: SaveAppInfo_001
33 * @tc.desc : Test DfxMsgManager::SaveAppInfo
34 */
35 HWTEST(DfxMsgManagerUnitTest, SaveAppInfo_001, TestSize.Level1)
36 {
37 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
38 DfxRunningAppInfo info;
39
40 info.appUid = 1;
41 dfxMsgManager.SaveAppInfo(info);
42 EXPECT_NE(dfxMsgManager.appInfo_.count(info.appUid), 0);
43 }
44
45 /**
46 * @tc.name : Test DfxMsgManager.
47 * @tc.number: ProcessCheck_001
48 * @tc.desc : Test DfxMsgManager::ProcessCheck
49 */
50 HWTEST(DfxMsgManagerUnitTest, ProcessCheck_001, TestSize.Level1)
51 {
52 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
53 DfxMessage msg;
54 RenderDfxInfo renderInfo;
55 InterruptDfxInfo interruptInfo;
56 CapturerDfxInfo captureInfo;
57
58 msg.appUid = 1;
59 for (int i = 0; i < 100; i++) {
60 msg.renderInfo.push_back(renderInfo);
61 }
62
63 bool ret = dfxMsgManager.ProcessCheck(msg);
64 EXPECT_EQ(ret, false);
65
66 msg.renderInfo.clear();
67 for (int i = 0; i < 100; i++) {
68 msg.interruptInfo.push_back(interruptInfo);
69 }
70
71 ret = dfxMsgManager.ProcessCheck(msg);
72 EXPECT_EQ(ret, false);
73
74 msg.interruptInfo.clear();
75 for (int i = 0; i < 100; i++) {
76 msg.captureInfo.push_back(captureInfo);
77 }
78
79 ret = dfxMsgManager.ProcessCheck(msg);
80 EXPECT_EQ(ret, false);
81 msg.captureInfo.clear();
82
83 dfxMsgManager.isFull_ = true;
84 ret = dfxMsgManager.ProcessCheck(msg);
85 EXPECT_EQ(ret, false);
86
87 dfxMsgManager.isFull_ = false;
88 for (uint32_t i = 0; i < 20; i++) {
89 msg.appUid = i;
90 dfxMsgManager.reportQueue_.insert(std::make_pair(i, msg));
91 }
92 ret = dfxMsgManager.ProcessCheck(msg);
93 EXPECT_EQ(ret, true);
94 }
95
96 /**
97 * @tc.name : Test DfxMsgManager.
98 * @tc.number: Process_001
99 * @tc.desc : Test DfxMsgManager::Process
100 */
101 HWTEST(DfxMsgManagerUnitTest, Process_001, TestSize.Level1)
102 {
103 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
104 DfxMessage msg;
105
106 msg.appUid = 105;
107 bool ret = dfxMsgManager.Process(msg);
108 EXPECT_EQ(ret, true);
109
110 msg.appUid = 5;
111 for (uint32_t i = 0; i < 10; i++) {
112 msg.appUid = i;
113 dfxMsgManager.reportQueue_.insert(std::make_pair(i, msg));
114 }
115 ret = dfxMsgManager.Process(msg);
116 EXPECT_EQ(ret, false);
117 }
118
119 /**
120 * @tc.name : Test DfxMsgManager.
121 * @tc.number: InsertReportQueue_001
122 * @tc.desc : Test DfxMsgManager::InsertReportQueue
123 */
124 HWTEST(DfxMsgManagerUnitTest, InsertReportQueue_001, TestSize.Level1)
125 {
126 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
127 DfxMessage msg;
128 RenderDfxInfo renderInfo;
129
130 dfxMsgManager.reportQueue_.clear();
131 for (uint32_t i = 0; i < 10; i++) {
132 msg.appUid = i;
133 dfxMsgManager.reportQueue_.insert(std::make_pair(i, msg));
134 }
135 dfxMsgManager.InsertReportQueue(msg);
136 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 10);
137
138 dfxMsgManager.reportQueue_.clear();
139 for (uint32_t i = 0; i < 5; i++) {
140 msg.appUid = i;
141 dfxMsgManager.reportQueue_.insert(std::make_pair(i, msg));
142 }
143 msg.appUid = 100;
144 dfxMsgManager.InsertReportQueue(msg);
145 EXPECT_NE(dfxMsgManager.reportQueue_.size(), 0);
146
147 dfxMsgManager.reportQueue_.clear();
148 for (uint32_t i = 0; i < 5; i++) {
149 msg.appUid = i;
150 msg.renderInfo.push_back(renderInfo);
151 dfxMsgManager.reportQueue_.insert(std::make_pair(i, msg));
152 }
153 msg.appUid = 1;
154 dfxMsgManager.InsertReportQueue(msg);
155 EXPECT_NE(dfxMsgManager.reportQueue_.size(), 0);
156 }
157
158 /**
159 * @tc.name : Test DfxMsgManager.
160 * @tc.number: ProcessInner_001
161 * @tc.desc : Test DfxMsgManager::ProcessInner
162 */
163 HWTEST(DfxMsgManagerUnitTest, ProcessInner_001, TestSize.Level1)
164 {
165 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
166 uint32_t index = 0;
167 std::list<RenderDfxInfo> dfxInfo;
168 std::list<RenderDfxInfo> curDfxInfo;
169 RenderDfxInfo renderInfo;
170
171 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
172 EXPECT_EQ(ret, false);
173
174 for (int i = 0; i < 10; i++) {
175 dfxInfo.push_back(renderInfo);
176 }
177 dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
178 ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
179 EXPECT_EQ(ret, true);
180 }
181
182 /**
183 * @tc.name : Test DfxMsgManager.
184 * @tc.number: ProcessInner_002
185 * @tc.desc : Test DfxMsgManager::ProcessInner
186 */
187 HWTEST(DfxMsgManagerUnitTest, ProcessInner_002, TestSize.Level1)
188 {
189 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
190 uint32_t index = 0;
191 std::list<InterruptDfxInfo> dfxInfo;
192 std::list<InterruptDfxInfo> curDfxInfo;
193 InterruptDfxInfo renderInfo;
194
195 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
196 EXPECT_EQ(ret, false);
197
198 for (int i = 0; i < 10; i++) {
199 dfxInfo.push_back(renderInfo);
200 }
201 dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
202 ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
203 EXPECT_EQ(ret, true);
204 }
205
206 /**
207 * @tc.name : Test DfxMsgManager.
208 * @tc.number: ProcessInner_003
209 * @tc.desc : Test DfxMsgManager::ProcessInner
210 */
211 HWTEST(DfxMsgManagerUnitTest, ProcessInner_003, TestSize.Level1)
212 {
213 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
214 uint32_t index = 0;
215 std::list<CapturerDfxInfo> dfxInfo;
216 std::list<CapturerDfxInfo> curDfxInfo;
217 CapturerDfxInfo renderInfo;
218
219 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
220 EXPECT_EQ(ret, false);
221
222 for (int i = 0; i < 10; i++) {
223 dfxInfo.push_back(renderInfo);
224 }
225 dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
226 ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
227 EXPECT_EQ(ret, true);
228 }
229
230 /**
231 * @tc.name : Test DfxMsgManager.
232 * @tc.number: Enqueue_001
233 * @tc.desc : Test DfxMsgManager::Enqueue
234 */
235 HWTEST(DfxMsgManagerUnitTest, Enqueue_001, TestSize.Level1)
236 {
237 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
238 DfxMessage msg;
239
240 dfxMsgManager.isFull_ = true;
241 bool ret = dfxMsgManager.Enqueue(msg);
242 EXPECT_EQ(ret, false);
243
244 dfxMsgManager.isFull_ = false;
245 ret = dfxMsgManager.Enqueue(msg);
246 EXPECT_EQ(ret, false);
247 }
248
249 /**
250 * @tc.name : Test DfxMsgManager.
251 * @tc.number: HandleToHiSysEvent_001
252 * @tc.desc : Test DfxMsgManager::HandleToHiSysEvent
253 */
254 HWTEST(DfxMsgManagerUnitTest, HandleToHiSysEvent_001, TestSize.Level1)
255 {
256 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
257 DfxMessage msg;
258
259 dfxMsgManager.reportedCnt_ = 100;
260 dfxMsgManager.reportQueue_.clear();
261 dfxMsgManager.HandleToHiSysEvent(msg);
262 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
263
264 dfxMsgManager.reportedCnt_ = 0;
265 dfxMsgManager.reportQueue_.clear();
266 dfxMsgManager.HandleToHiSysEvent(msg);
267 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
268 }
269
270 /**
271 * @tc.name : Test DfxMsgManager.
272 * @tc.number: WriteRenderMsg_001
273 * @tc.desc : Test DfxMsgManager::WriteRenderMsg
274 */
275 HWTEST(DfxMsgManagerUnitTest, WriteRenderMsg_001, TestSize.Level1)
276 {
277 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
278 DfxMessage msg;
279 RenderDfxInfo renderInfo;
280 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
281
282 msg.appUid = 1;
283 dfxMsgManager.reportQueue_.clear();
284 for (int i = 0; i < 10; i++) {
285 msg.renderInfo.push_back(renderInfo);
286 }
287 dfxMsgManager.WriteRenderMsg(msg, bean);
288 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
289 }
290
291 /**
292 * @tc.name : Test DfxMsgManager.
293 * @tc.number: WriteInterruptMsg_001
294 * @tc.desc : Test DfxMsgManager::WriteInterruptMsg
295 */
296 HWTEST(DfxMsgManagerUnitTest, WriteInterruptMsg_001, TestSize.Level1)
297 {
298 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
299 DfxMessage msg;
300 InterruptDfxInfo interruptInfo;
301 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
302
303 msg.appUid = 1;
304 for (int i = 0; i < 10; i++) {
305 msg.interruptInfo.push_back(interruptInfo);
306 }
307 dfxMsgManager.WriteInterruptMsg(msg, bean);
308 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
309 }
310
311 /**
312 * @tc.name : Test DfxMsgManager.
313 * @tc.number: WriteCapturerMsg_001
314 * @tc.desc : Test DfxMsgManager::WriteCapturerMsg
315 */
316 HWTEST(DfxMsgManagerUnitTest, WriteCapturerMsg_001, TestSize.Level1)
317 {
318 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
319 DfxMessage msg;
320 CapturerDfxInfo captureInfo;
321 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
322
323 msg.appUid = 1;
324 captureInfo.capturerAction.fourthByte = CapturerStage::CAPTURER_STAGE_PAUSE_OK;
325 for (int i = 0; i < 10; i++) {
326 msg.captureInfo.push_back(captureInfo);
327 }
328 dfxMsgManager.WriteCapturerMsg(msg, bean);
329 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
330
331 captureInfo.capturerAction.fourthByte = CapturerStage::CAPTURER_STAGE_START_FAIL;
332 msg.captureInfo.push_back(captureInfo);
333 dfxMsgManager.WriteCapturerMsg(msg, bean);
334 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
335 }
336
337 /**
338 * @tc.name : Test DfxMsgManager.
339 * @tc.number: WritePlayAudioStatsEvent_001
340 * @tc.desc : Test DfxMsgManager::WritePlayAudioStatsEvent
341 */
342 HWTEST(DfxMsgManagerUnitTest, WritePlayAudioStatsEvent_001, TestSize.Level1)
343 {
344 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
345 std::unique_ptr<DfxReportResult> result = nullptr;
346
347 dfxMsgManager.WritePlayAudioStatsEvent(result);
348 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
349
350 result = std::make_unique<DfxReportResult>();
351 dfxMsgManager.WritePlayAudioStatsEvent(result);
352 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
353 }
354
355 /**
356 * @tc.name : Test DfxMsgManager.
357 * @tc.number: OnHandle_001
358 * @tc.desc : Test DfxMsgManager::OnHandle
359 */
360 HWTEST(DfxMsgManagerUnitTest, OnHandle_001, TestSize.Level1)
361 {
362 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
363 uint32_t code = 0;
364 int64_t data = 0;
365
366 dfxMsgManager.OnHandle(code, data);
367 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
368
369 code = 100;
370 dfxMsgManager.OnHandle(code, data);
371 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 0);
372 }
373
374 /**
375 * @tc.name : Test DfxMsgManager.
376 * @tc.number: SafeSendCallBackEvent_001
377 * @tc.desc : Test DfxMsgManager::SafeSendCallBackEvent
378 */
379 HWTEST(DfxMsgManagerUnitTest, SafeSendCallBackEvent_001, TestSize.Level1)
380 {
381 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
382 uint32_t eventCode = 0;
383 int64_t data = 0;
384 int64_t delayTime = 0;
385
386 dfxMsgManager.SafeSendCallBackEvent(eventCode, data, delayTime);
387 EXPECT_EQ(dfxMsgManager.callbackHandler_, nullptr);
388
389 dfxMsgManager.Init();
390 dfxMsgManager.SafeSendCallBackEvent(eventCode, data, delayTime);
391 EXPECT_NE(dfxMsgManager.callbackHandler_, nullptr);
392 }
393
394 /**
395 * @tc.name : Test DfxMsgManager.
396 * @tc.number: CheckReportDfxMsg_001
397 * @tc.desc : Test DfxMsgManager::CheckReportDfxMsg
398 */
399 HWTEST(DfxMsgManagerUnitTest, CheckReportDfxMsg_001, TestSize.Level1)
400 {
401 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
402 DfxMessage msg;
403
404 msg.appUid = 1;
405 dfxMsgManager.InsertReportQueue(msg);
406 time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
407 dfxMsgManager.lastReportTime_ = now - DEFAULT_DFX_REPORT_INTERVAL_MIN - 1;
408 dfxMsgManager.CheckReportDfxMsg();
409 EXPECT_EQ(dfxMsgManager.isFull_, false);
410
411 dfxMsgManager.lastReportTime_ = now;
412 dfxMsgManager.InsertReportQueue(msg);
413 dfxMsgManager.reportedCnt_ = 30;
414 dfxMsgManager.CheckReportDfxMsg();
415 EXPECT_EQ(dfxMsgManager.isFull_, true);
416
417 dfxMsgManager.InsertReportQueue(msg);
418 dfxMsgManager.reportedCnt_ = 2;
419 dfxMsgManager.CheckReportDfxMsg();
420 EXPECT_EQ(dfxMsgManager.isFull_, true);
421
422 dfxMsgManager.reportQueue_.clear();
423 dfxMsgManager.reportedCnt_ = 30;
424 dfxMsgManager.CheckReportDfxMsg();
425 EXPECT_EQ(dfxMsgManager.isFull_, true);
426 }
427
428 /**
429 * @tc.name : Test DfxMsgManager.
430 * @tc.number: IsMsgReady_001
431 * @tc.desc : Test DfxMsgManager::IsMsgReady
432 */
433 HWTEST(DfxMsgManagerUnitTest, IsMsgReady_001, TestSize.Level1)
434 {
435 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
436 DfxMessage msg;
437 RenderDfxInfo renderInfo;
438 InterruptDfxInfo interruptInfo;
439 CapturerDfxInfo captureInfo;
440
441 msg.appUid = 1;
442 for (int i = 0; i < MAX_DFX_MSG_MEMBER_SIZE; i++) {
443 msg.interruptInfo.push_back(interruptInfo);
444 }
445
446 for (int i = 0; i < MAX_DFX_MSG_MEMBER_SIZE; i++) {
447 msg.renderInfo.push_back(renderInfo);
448 }
449
450 bool ret = dfxMsgManager.IsMsgReady(msg);
451 EXPECT_EQ(ret, true);
452 }
453
454 /**
455 * @tc.name : Test DfxMsgManager.
456 * @tc.number: HandleThreadExit_001
457 * @tc.desc : Test DfxMsgManager::HandleThreadExit
458 */
459 HWTEST(DfxMsgManagerUnitTest, HandleThreadExit_001, TestSize.Level1)
460 {
461 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
462
463 std::unique_ptr<DfxReportResult> result = std::make_unique<DfxReportResult>();
464 result->appName = "appName";
465 result->appVersion = "1.0";
466 result->summary = 2;
467 dfxMsgManager.LogDfxResult(result);
468 dfxMsgManager.HandleThreadExit();
469 EXPECT_EQ(dfxMsgManager.isFull_, false);
470 }
471
472 /**
473 * @tc.name : Test DfxMsgManager.
474 * @tc.number: WriteRunningAppMsg_001
475 * @tc.desc : Test DfxMsgManager::WriteRunningAppMsg
476 */
477 HWTEST(DfxMsgManagerUnitTest, WriteRunningAppMsg_001, TestSize.Level1)
478 {
479 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
480 DfxMessage msg;
481 std::unique_ptr<DfxReportResult> result = std::make_unique<DfxReportResult>();
482 DfxRunningAppInfo appinfo;
483
484 msg.appUid = 1;
485 appinfo.appUid = 1;
486 appinfo.appName = "appName";
487 appinfo.versionName = "1.0";
488 appinfo.appStateVec.push_back(1);
489 appinfo.appStateTimeStampVec.push_back(1);
490 dfxMsgManager.WriteRunningAppMsg(msg, result);
491 EXPECT_EQ(dfxMsgManager.appInfo_.count(msg.appUid), 0);
492
493 dfxMsgManager.appInfo_[msg.appUid] = appinfo;
494 dfxMsgManager.WriteRunningAppMsg(msg, result);
495 EXPECT_NE(dfxMsgManager.appInfo_.count(msg.appUid), 0);
496 }
497
498 /**
499 * @tc.name : Test DfxMsgManager.
500 * @tc.number: CheckCanAddAppInfo_001
501 * @tc.desc : Test DfxMsgManager::CheckCanAddAppInfo
502 */
503 HWTEST(DfxMsgManagerUnitTest, CheckCanAddAppInfo_001, TestSize.Level1)
504 {
505 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
506 int32_t appUid = 1003;
507
508 EXPECT_EQ(dfxMsgManager.CheckCanAddAppInfo(appUid), false);
509
510 appUid = static_cast<int32_t>(getuid());
511 EXPECT_EQ(dfxMsgManager.CheckCanAddAppInfo(appUid), false);
512 }
513
514 /**
515 * @tc.name : Test DfxMsgManager.
516 * @tc.number: UpdateAppState_001
517 * @tc.desc : Test DfxMsgManager::UpdateAppState
518 */
519 HWTEST(DfxMsgManagerUnitTest, UpdateAppState_001, TestSize.Level1)
520 {
521 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
522 int32_t appUid = 1;
523 DfxAppState appState = DFX_APP_STATE_START;
524 bool forceUpdate = false;
525 DfxRunningAppInfo appinfo;
526
527 appinfo.appUid = 1;
528 appinfo.appName = "appName";
529 appinfo.versionName = "1.0";
530 appinfo.appStateVec.push_back(0);
531 appinfo.appStateTimeStampVec.push_back(1);
532 dfxMsgManager.appInfo_[appUid] = appinfo;
533
534 dfxMsgManager.UpdateAppState(appUid, appState, forceUpdate);
535 EXPECT_NE(dfxMsgManager.appInfo_.count(appUid), 0);
536
537 appState = DFX_APP_STATE_FOREGROUND;
538 appinfo.appStateVec.clear();
539 appinfo.appStateVec.push_back(2);
540 dfxMsgManager.appInfo_.clear();
541 dfxMsgManager.appInfo_[appUid] = appinfo;
542 dfxMsgManager.UpdateAppState(appUid, appState, forceUpdate);
543 EXPECT_NE(dfxMsgManager.appInfo_.count(appUid), 0);
544
545 appState = DFX_APP_STATE_FOREGROUND;
546 appinfo.appStateVec.clear();
547 appinfo.appStateVec.push_back(4);
548 dfxMsgManager.appInfo_.clear();
549 dfxMsgManager.appInfo_[appUid] = appinfo;
550 dfxMsgManager.UpdateAppState(appUid, appState, forceUpdate);
551 EXPECT_NE(dfxMsgManager.appInfo_.count(appUid), 0);
552 }
553
554 /**
555 * @tc.name : Test DfxMsgManager.
556 * @tc.number: UpdateAction_001
557 * @tc.desc : Test DfxMsgManager::UpdateAction
558 */
559 HWTEST(DfxMsgManagerUnitTest, UpdateAction_001, TestSize.Level1)
560 {
561 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
562 int32_t appUid = 1;
563 std::list<RenderDfxInfo> renderInfo;
564 RenderDfxInfo renderdfxInfo;
565
566 renderdfxInfo.rendererAction.fourthByte = RendererStage::RENDERER_STAGE_START_FAIL;
567 renderInfo.push_back(renderdfxInfo);
568 dfxMsgManager.UpdateAction(appUid, renderInfo);
569 EXPECT_NE(dfxMsgManager.appInfo_.count(appUid), 0);
570 }
571
572 /**
573 * @tc.name : Test DfxMsgManager.
574 * @tc.number: UpdateAction_002
575 * @tc.desc : Test DfxMsgManager::UpdateAction
576 */
577 HWTEST(DfxMsgManagerUnitTest, UpdateAction_002, TestSize.Level1)
578 {
579 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
580 int32_t appUid = 1;
581 std::list<CapturerDfxInfo> capturerInfo;
582 CapturerDfxInfo capturerdfxInfo;
583
584 capturerdfxInfo.capturerAction.fourthByte = CapturerStage::CAPTURER_STAGE_START_FAIL;
585 capturerInfo.push_back(capturerdfxInfo);
586 dfxMsgManager.UpdateAction(appUid, capturerInfo);
587 EXPECT_NE(dfxMsgManager.appInfo_.count(appUid), 0);
588 }
589
590 /**
591 * @tc.name : Test DfxMsgManager.
592 * @tc.number: UpdateAction_003
593 * @tc.desc : Test DfxMsgManager::UpdateAction
594 */
595 HWTEST(DfxMsgManagerUnitTest, UpdateAction_003, TestSize.Level1)
596 {
597 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
598 int32_t appUid = 1;
599 std::list<InterruptDfxInfo> interruptInfo;
600 InterruptDfxInfo interruptdfxInfo;
601
602 interruptdfxInfo.interruptAction.fourthByte = InterruptStage::INTERRUPT_STAGE_RESTART;
603 interruptInfo.push_back(interruptdfxInfo);
604 dfxMsgManager.UpdateAction(appUid, interruptInfo);
605 EXPECT_NE(dfxMsgManager.appInfo_.count(appUid), 0);
606 }
607
608 /**
609 * @tc.name : Test DfxMsgManager.
610 * @tc.number: GetDfxIndexByType_001
611 * @tc.desc : Test DfxMsgManager::GetDfxIndexByType
612 */
613 HWTEST(DfxMsgManagerUnitTest, GetDfxIndexByType_001, TestSize.Level1)
614 {
615 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
616 int32_t appUid = 1;
617 DfxMsgIndexType type = DfxMsgIndexType::DFX_MSG_IDX_TYPE_RENDER_INFO;
618
619 uint8_t ret = dfxMsgManager.GetDfxIndexByType(appUid, type);
620 EXPECT_NE(ret, 0);
621
622 type = DfxMsgIndexType::DFX_MSG_IDX_TYPE_CAPTURE_INFO;
623 ret = dfxMsgManager.GetDfxIndexByType(appUid, type);
624 EXPECT_NE(ret, 0);
625
626 type = DfxMsgIndexType::DFX_MSG_IDX_TYPE_INTERRUPT_INFO;
627 ret = dfxMsgManager.GetDfxIndexByType(appUid, type);
628 EXPECT_NE(ret, 0);
629
630 type = DfxMsgIndexType::DFX_MSG_IDX_TYPE_INTERRUPT_EFFECT;
631 ret = dfxMsgManager.GetDfxIndexByType(appUid, type);
632 EXPECT_EQ(ret, 0);
633
634 type = static_cast<DfxMsgIndexType>(-1);
635 ret = dfxMsgManager.GetDfxIndexByType(appUid, type);
636 EXPECT_EQ(ret, 1);
637 }
638
639 /**
640 * @tc.name : Test DfxMsgManager.
641 * @tc.number: CheckIsInterrupted_001
642 * @tc.desc : Test DfxMsgManager::CheckIsInterrupted
643 */
644 HWTEST(DfxMsgManagerUnitTest, CheckIsInterrupted_001, TestSize.Level1)
645 {
646 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
647 InterruptStage stage = INTERRUPT_STAGE_STOPPED;
648
649 bool ret = dfxMsgManager.CheckIsInterrupted(stage);
650 EXPECT_EQ(ret, true);
651
652 stage = INTERRUPT_STAGE_DUCK_BEGIN;
653 ret = dfxMsgManager.CheckIsInterrupted(stage);
654 EXPECT_EQ(ret, true);
655
656 stage = INTERRUPT_STAGE_PAUSED;
657 ret = dfxMsgManager.CheckIsInterrupted(stage);
658 EXPECT_EQ(ret, true);
659
660 stage = INTERRUPT_STAGE_RESUMED;
661 ret = dfxMsgManager.CheckIsInterrupted(stage);
662 EXPECT_EQ(ret, true);
663
664 stage = INTERRUPT_STAGE_DUCK_END;
665 ret = dfxMsgManager.CheckIsInterrupted(stage);
666 EXPECT_EQ(ret, true);
667
668 stage = INTERRUPT_STAGE_TIMEOUT;
669 ret = dfxMsgManager.CheckIsInterrupted(stage);
670 EXPECT_EQ(ret, false);
671 }
672
673 /**
674 * @tc.name : ProcessInner.
675 * @tc.number: CapturerDfxInfo_ProcessInner_001
676 * @tc.desc : Test DfxMsgManager::ProcessInner of parameter is CapturerDfxInfo
677 */
678 HWTEST(DfxMsgManagerUnitTest, CapturerDfxInfo_ProcessInner_001, TestSize.Level1)
679 {
680 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
681 uint32_t index = 0;
682 std::list<CapturerDfxInfo> dfxInfo;
683 std::list<CapturerDfxInfo> curDfxInfo;
684 CapturerDfxInfo renderInfo;
685
686 dfxInfo.push_back(renderInfo);
687 for (int i = 0; i < MAX_DFX_MSG_MEMBER_SIZE; i++) {
688 curDfxInfo.push_back(renderInfo);
689 }
690 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
691 EXPECT_EQ(curDfxInfo.size(), 100);
692 EXPECT_EQ(dfxInfo.size(), 1);
693 }
694
695 /**
696 * @tc.name : ProcessInner.
697 * @tc.number: CapturerDfxInfo_ProcessInner_002
698 * @tc.desc : Test DfxMsgManager::ProcessInner of parameter is CapturerDfxInfo
699 */
700 HWTEST(DfxMsgManagerUnitTest, CapturerDfxInfo_ProcessInner_002, TestSize.Level1)
701 {
702 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
703 uint32_t index = 0;
704 std::list<CapturerDfxInfo> dfxInfo;
705 std::list<CapturerDfxInfo> curDfxInfo;
706 CapturerDfxInfo renderInfo;
707
708 curDfxInfo.push_back(renderInfo);
709 for (int i = 0; i < MAX_DFX_MSG_MEMBER_SIZE; i++) {
710 dfxInfo.push_back(renderInfo);
711 }
712 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
713 EXPECT_EQ(curDfxInfo.size(), 100);
714 EXPECT_EQ(dfxInfo.size(), 100);
715 }
716
717 /**
718 * @tc.name : ProcessInner.
719 * @tc.number: RenderDfxInfo_ProcessInner_001
720 * @tc.desc : Test DfxMsgManager::ProcessInner of parameter is RenderDfxInfo
721 */
722 HWTEST(DfxMsgManagerUnitTest, RenderDfxInfo_ProcessInner_001, TestSize.Level1)
723 {
724 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
725 uint32_t index = 0;
726 std::list<RenderDfxInfo> dfxInfo;
727 std::list<RenderDfxInfo> curDfxInfo;
728 RenderDfxInfo renderInfo;
729
730 dfxInfo.push_back(renderInfo);
731 for (int i = 0; i < MAX_DFX_MSG_MEMBER_SIZE; i++) {
732 curDfxInfo.push_back(renderInfo);
733 }
734 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
735 EXPECT_EQ(curDfxInfo.size(), 100);
736 EXPECT_EQ(dfxInfo.size(), 1);
737 }
738
739 /**
740 * @tc.name : ProcessInner.
741 * @tc.number: RenderDfxInfo_ProcessInner_002
742 * @tc.desc : Test DfxMsgManager::ProcessInner of parameter is RenderDfxInfo
743 */
744 HWTEST(DfxMsgManagerUnitTest, RenderDfxInfo_ProcessInner_002, TestSize.Level1)
745 {
746 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
747 uint32_t index = 0;
748 std::list<RenderDfxInfo> dfxInfo;
749 std::list<RenderDfxInfo> curDfxInfo;
750 RenderDfxInfo renderInfo;
751
752 curDfxInfo.push_back(renderInfo);
753 for (int i = 0; i < MAX_DFX_MSG_MEMBER_SIZE; i++) {
754 dfxInfo.push_back(renderInfo);
755 }
756 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
757 EXPECT_EQ(curDfxInfo.size(), 100);
758 EXPECT_EQ(dfxInfo.size(), 100);
759 }
760
761 /**
762 * @tc.name : ProcessInner.
763 * @tc.number: InterruptDfxInfo_ProcessInner_001
764 * @tc.desc : Test DfxMsgManager::ProcessInner of parameter is InterruptDfxInfo
765 */
766 HWTEST(DfxMsgManagerUnitTest, InterruptDfxInfo_ProcessInner_001, TestSize.Level1)
767 {
768 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
769 uint32_t index = 0;
770 std::list<InterruptDfxInfo> dfxInfo;
771 std::list<InterruptDfxInfo> curDfxInfo;
772 InterruptDfxInfo renderInfo;
773
774 dfxInfo.push_back(renderInfo);
775 for (int i = 0; i < MAX_DFX_MSG_MEMBER_SIZE; i++) {
776 curDfxInfo.push_back(renderInfo);
777 }
778 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
779 EXPECT_EQ(curDfxInfo.size(), 100);
780 EXPECT_EQ(dfxInfo.size(), 1);
781 }
782
783 /**
784 * @tc.name : ProcessInner.
785 * @tc.number: InterruptDfxInfo_ProcessInner_002
786 * @tc.desc : Test DfxMsgManager::ProcessInner of parameter is InterruptDfxInfo
787 */
788 HWTEST(DfxMsgManagerUnitTest, InterruptDfxInfo_ProcessInner_002, TestSize.Level1)
789 {
790 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
791 uint32_t index = 0;
792 std::list<InterruptDfxInfo> dfxInfo;
793 std::list<InterruptDfxInfo> curDfxInfo;
794 InterruptDfxInfo renderInfo;
795
796 curDfxInfo.push_back(renderInfo);
797 for (int i = 0; i < MAX_DFX_MSG_MEMBER_SIZE; i++) {
798 dfxInfo.push_back(renderInfo);
799 }
800 bool ret = dfxMsgManager.ProcessInner(index, dfxInfo, curDfxInfo);
801 EXPECT_EQ(curDfxInfo.size(), 100);
802 EXPECT_EQ(dfxInfo.size(), 100);
803 }
804
805 /**
806 * @tc.name : Test DfxMsgManager.
807 * @tc.number: WriteRenderMsg_002
808 * @tc.desc : Test DfxMsgManager::WriteRenderMsg
809 */
810 HWTEST(DfxMsgManagerUnitTest, WriteRenderMsg_002, TestSize.Level1)
811 {
812 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
813 DfxMessage msg;
814 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
815 RenderDfxInfo renderInfo;
816 renderInfo.rendererAction.fourthByte = static_cast<uint8_t>(RendererStage::RENDERER_STAGE_START_OK);
817 msg.appUid = 1;
818 for (int i = 0; i < 10; i++) {
819 msg.renderInfo.push_back(renderInfo);
820 }
821 dfxMsgManager.WriteRenderMsg(msg, bean);
822 EXPECT_EQ(bean->renderInfo.size(), 10);
823 }
824
825 /**
826 * @tc.name : Test DfxMsgManager.
827 * @tc.number: WriteRenderMsg_003
828 * @tc.desc : Test DfxMsgManager::WriteRenderMsg
829 */
830 HWTEST(DfxMsgManagerUnitTest, WriteRenderMsg_003, TestSize.Level1)
831 {
832 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
833 DfxMessage msg;
834 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
835 RenderDfxInfo renderInfo;
836 renderInfo.rendererAction.fourthByte = static_cast<uint8_t>(RendererStage::RENDERER_STAGE_START_FAIL);
837 msg.appUid = 1;
838 for (int i = 0; i < 10; i++) {
839 msg.renderInfo.push_back(renderInfo);
840 }
841 dfxMsgManager.WriteRenderMsg(msg, bean);
842 EXPECT_EQ(bean->renderInfo.size(), 10);
843 }
844
845 /**
846 * @tc.name : Test DfxMsgManager.
847 * @tc.number: WriteRenderMsg_004
848 * @tc.desc : Test DfxMsgManager::WriteRenderMsg
849 */
850 HWTEST(DfxMsgManagerUnitTest, WriteRenderMsg_004, TestSize.Level1)
851 {
852 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
853 DfxMessage msg;
854 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
855 RenderDfxInfo renderInfo;
856 renderInfo.rendererAction.fourthByte = static_cast<uint8_t>(RendererStage::RENDERER_STAGE_STOP_OK);
857 msg.appUid = 1;
858 for (int i = 0; i < 10; i++) {
859 msg.renderInfo.push_back(renderInfo);
860 }
861 dfxMsgManager.WriteRenderMsg(msg, bean);
862 EXPECT_EQ(bean->renderInfo.size(), 0);
863 }
864
865 /**
866 * @tc.name : Test DfxMsgManager.
867 * @tc.number: UpdateAction_004
868 * @tc.desc : Test DfxMsgManager::UpdateAction
869 */
870 HWTEST(DfxMsgManagerUnitTest, UpdateAction_004, TestSize.Level1)
871 {
872 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
873 int32_t appUid = 1;
874 std::list<RenderDfxInfo> renderInfo;
875 RenderDfxInfo renderdfxInfo;
876
877 renderdfxInfo.rendererAction.fourthByte = static_cast<uint8_t>(RendererStage::RENDERER_STAGE_START_OK);
878 renderdfxInfo.rendererAction.firstByte = 1;
879 renderInfo.push_back(renderdfxInfo);
880 dfxMsgManager.UpdateAction(appUid, renderInfo);
881 EXPECT_EQ(renderInfo.front().rendererAction.firstByte, 22);
882 }
883
884 /**
885 * @tc.name : Test DfxMsgManager.
886 * @tc.number: UpdateAction_005
887 * @tc.desc : Test DfxMsgManager::UpdateAction
888 */
889 HWTEST(DfxMsgManagerUnitTest, UpdateAction_005, TestSize.Level1)
890 {
891 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
892 int32_t appUid = 1;
893 std::list<CapturerDfxInfo> capturerInfo;
894 CapturerDfxInfo capturerdfxInfo;
895
896 capturerdfxInfo.capturerAction.fourthByte = static_cast<uint8_t>(CapturerStage::CAPTURER_STAGE_START_OK);
897 capturerdfxInfo.capturerAction.firstByte = 2;
898 capturerInfo.push_back(capturerdfxInfo);
899 dfxMsgManager.UpdateAction(appUid, capturerInfo);
900 EXPECT_EQ(capturerInfo.front().capturerAction.firstByte, 2);
901 }
902
903 /**
904 * @tc.name : Test DfxMsgManager.
905 * @tc.number: UpdateAction_006
906 * @tc.desc : Test DfxMsgManager::UpdateAction
907 */
908 HWTEST(DfxMsgManagerUnitTest, UpdateAction_006, TestSize.Level1)
909 {
910 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
911 int32_t appUid = 1;
912 std::list<InterruptDfxInfo> interruptInfo;
913 InterruptDfxInfo interruptdfxInfo;
914
915 interruptdfxInfo.interruptAction.fourthByte = static_cast<uint8_t>(InterruptStage::INTERRUPT_STAGE_START);
916 interruptdfxInfo.interruptAction.firstByte = 3;
917 interruptInfo.push_back(interruptdfxInfo);
918 dfxMsgManager.UpdateAction(appUid, interruptInfo);
919 EXPECT_EQ(interruptInfo.front().interruptAction.firstByte, 3);
920 }
921
922 /**
923 * @tc.name : Test DfxMsgManager.
924 * @tc.number: UpdateAction_007
925 * @tc.desc : Test DfxMsgManager::UpdateAction
926 */
927 HWTEST(DfxMsgManagerUnitTest, UpdateAction_007, TestSize.Level1)
928 {
929 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
930 int32_t appUid = 1;
931 std::list<RenderDfxInfo> renderInfo;
932 RenderDfxInfo renderdfxInfo;
933 renderdfxInfo.rendererAction.firstByte = 2;
934 renderdfxInfo.rendererAction.fourthByte = 1;
935 renderInfo.push_back(renderdfxInfo);
936 dfxMsgManager.UpdateAction(appUid, renderInfo);
937 EXPECT_EQ(renderInfo.front().rendererAction.firstByte, 22);
938 }
939
940 /**
941 * @tc.name : Test DfxMsgManager.
942 * @tc.number: UpdateAction_008
943 * @tc.desc : Test DfxMsgManager::UpdateAction
944 */
945 HWTEST(DfxMsgManagerUnitTest, UpdateAction_008, TestSize.Level1)
946 {
947 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
948 int32_t appUid = 1;
949 std::list<CapturerDfxInfo> capturerInfo;
950 CapturerDfxInfo capturerdfxInfo;
951 capturerdfxInfo.capturerAction.firstByte = 2;
952 capturerdfxInfo.capturerAction.fourthByte = 1;
953 capturerInfo.push_back(capturerdfxInfo);
954 dfxMsgManager.UpdateAction(appUid, capturerInfo);
955 EXPECT_EQ(capturerInfo.front().capturerAction.firstByte, 2);
956 }
957
958 /**
959 * @tc.name : Test DfxMsgManager.
960 * @tc.number: UpdateAction_009
961 * @tc.desc : Test DfxMsgManager::UpdateAction
962 */
963 HWTEST(DfxMsgManagerUnitTest, UpdateAction_009, TestSize.Level1)
964 {
965 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
966 int32_t appUid = 1;
967 std::list<InterruptDfxInfo> interruptInfo;
968 InterruptDfxInfo interruptdfxInfo;
969 interruptdfxInfo.interruptAction.firstByte = 2;
970 interruptdfxInfo.interruptAction.secondByte = 1;
971 interruptdfxInfo.interruptAction.fourthByte = 1;
972 interruptInfo.push_back(interruptdfxInfo);
973 dfxMsgManager.UpdateAction(appUid, interruptInfo);
974 EXPECT_EQ(interruptInfo.front().interruptAction.firstByte, 2);
975 }
976
977 /**
978 * @tc.name : Test DfxMsgManager.
979 * @tc.number: WriteInterruptMsg_002
980 * @tc.desc : Test DfxMsgManager::WriteInterruptMsg
981 */
982 HWTEST(DfxMsgManagerUnitTest, WriteInterruptMsg_002, TestSize.Level1)
983 {
984 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
985 DfxMessage msg;
986 InterruptDfxInfo interruptInfo;
987 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
988 interruptInfo.interruptAction.fourthByte = InterruptStage::INTERRUPT_STAGE_START;
989
990 msg.appUid = 1;
991 for (int i = 0; i < 10; i++) {
992 msg.interruptInfo.push_back(interruptInfo);
993 }
994 dfxMsgManager.WriteInterruptMsg(msg, bean);
995 EXPECT_EQ(bean->interruptInfo.size(), 10);
996 }
997
998 /**
999 * @tc.name : Test DfxMsgManager.
1000 * @tc.number: WriteInterruptMsg_003
1001 * @tc.desc : Test DfxMsgManager::WriteInterruptMsg
1002 */
1003 HWTEST(DfxMsgManagerUnitTest, WriteInterruptMsg_003, TestSize.Level1)
1004 {
1005 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
1006 DfxMessage msg;
1007 InterruptDfxInfo interruptInfo;
1008 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
1009 interruptInfo.interruptAction.fourthByte = InterruptStage::INTERRUPT_STAGE_RESTART;
1010
1011 msg.appUid = 1;
1012 for (int i = 0; i < 10; i++) {
1013 msg.interruptInfo.push_back(interruptInfo);
1014 }
1015 dfxMsgManager.WriteInterruptMsg(msg, bean);
1016 EXPECT_EQ(bean->interruptInfo.size(), 10);
1017 }
1018
1019 /**
1020 * @tc.name : Test DfxMsgManager.
1021 * @tc.number: WriteCapturerMsg_002
1022 * @tc.desc : Test DfxMsgManager::WriteCapturerMsg
1023 */
1024 HWTEST(DfxMsgManagerUnitTest, WriteCapturerMsg_002, TestSize.Level1)
1025 {
1026 DfxMsgManager &dfxMsgManager = DfxMsgManager::GetInstance();
1027 DfxMessage msg;
1028 CapturerDfxInfo captureInfo;
1029 std::unique_ptr<DfxReportResult> bean = std::make_unique<DfxReportResult>();
1030
1031 msg.appUid = 1;
1032 captureInfo.capturerAction.fourthByte = CapturerStage::CAPTURER_STAGE_STOP_OK;
1033 for (int i = 0; i < 10; i++) {
1034 msg.captureInfo.push_back(captureInfo);
1035 }
1036 dfxMsgManager.WriteCapturerMsg(msg, bean);
1037 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 1);
1038
1039 captureInfo.capturerAction.fourthByte = CapturerStage::CAPTURER_STAGE_START_OK;
1040 msg.captureInfo.push_back(captureInfo);
1041 dfxMsgManager.WriteCapturerMsg(msg, bean);
1042 EXPECT_EQ(dfxMsgManager.reportQueue_.size(), 1);
1043 }
1044 } // AudioStandard
1045 } // OHOS
1046