• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #include <climits>
16 #include <gtest/gtest.h>
17 #include <iostream>
18 #include <unistd.h>
19 
20 #include "file_util.h"
21 #include "parameter_ex.h"
22 #include "trace_collector.h"
23 #include "trace_flow_controller.h"
24 #include "trace_utils.h"
25 
26 using namespace testing::ext;
27 using namespace OHOS::HiviewDFX;
28 using namespace OHOS::HiviewDFX::UCollectUtil;
29 using namespace OHOS::HiviewDFX::UCollect;
30 
31 class TraceCollectorTest : public testing::Test {
32 public:
SetUp()33     void SetUp() override {};
TearDown()34     void TearDown() override {};
SetUpTestCase()35     static void SetUpTestCase() {}
TearDownTestCase()36     static void TearDownTestCase() {}
37 };
38 
39 /**
40  * @tc.name: TraceCollectorTest001
41  * @tc.desc: used to test TraceCollector for xpower dump
42  * @tc.type: FUNC
43 */
44 HWTEST_F(TraceCollectorTest, TraceCollectorTest001, TestSize.Level1) {
45     std::shared_ptr<TraceCollector> collector = TraceCollector::Create();
46     auto result1 = collector->FilterTraceOn(TeleModule::XPOWER);
47     ASSERT_EQ(result1.retCode, UCollect::UcError::PERMISSION_CHECK_FAILED);
48     auto result2 = collector->FilterTraceOn(TeleModule::XPOWER, 1000);
49     ASSERT_EQ(result2.retCode, UCollect::UcError::PERMISSION_CHECK_FAILED);
50     auto result3 = collector->FilterTraceOff(TeleModule::XPOWER);
51     ASSERT_EQ(result3.retCode, UCollect::UcError::PERMISSION_CHECK_FAILED);
52 }
53 
54 /**
55  * @tc.name: TraceCollectorTest002
56  * @tc.desc: used to test TraceCollector for xpower dump
57  * @tc.type: FUNC
58 */
59 HWTEST_F(TraceCollectorTest, TraceCollectorTest002, TestSize.Level1)
60 {
61     std::shared_ptr<TraceCollector> collector = TraceCollector::Create();
62     CollectResult<std::vector<std::string>> result = collector->DumpTraceWithDuration(XPOWER, 0, 0);
63     ASSERT_EQ(result.retCode, UCollect::UcError::PERMISSION_CHECK_FAILED);
64 }
65 
66 /**
67  * @tc.name: TraceCollectorTest003
68  * @tc.desc: used to test TraceCollector for screen dump
69  * @tc.type: FUNC
70 */
71 HWTEST_F(TraceCollectorTest, TraceCollectorTest003, TestSize.Level1)
72 {
73     std::shared_ptr<TraceCollector> collector = TraceCollector::Create();
74     CollectResult<std::vector<std::string>> result = collector->DumpTrace(SCREEN);
75     ASSERT_EQ(result.retCode, UCollect::UcError::PERMISSION_CHECK_FAILED);
76 }
77 
78 /**
79  * @tc.name: TraceCollectorTest004
80  * @tc.desc: used to test TraceCollector for DumpTraceWithFilter
81  * @tc.type: FUNC
82 */
83 HWTEST_F(TraceCollectorTest, TraceCollectorTest004, TestSize.Level1)
84 {
85     std::shared_ptr<TraceCollector> collector = TraceCollector::Create();
86     CollectResult<std::vector<std::string>> result = collector->DumpTraceWithFilter(TeleModule::XPOWER, 0,
87         0);
88     ASSERT_EQ(result.retCode, UCollect::UcError::PERMISSION_CHECK_FAILED);
89 }
90 
91 /**
92  * @tc.name: TraceCollectorTest005
93  * @tc.desc: used to test TraceCollector for RecoverTmpTrace
94  * @tc.type: FUNC
95 */
96 HWTEST_F(TraceCollectorTest, TraceCollectorTest005, TestSize.Level1)
97 {
98     std::shared_ptr<TraceCollector> collector = TraceCollector::Create();
99     bool result = collector->RecoverTmpTrace();
100     ASSERT_FALSE(result);
101 }
102