1 /*
2 * Copyright (c) 2024 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 <gtest/gtest.h>
16 #include <iostream>
17
18 #include "thermal_collector.h"
19
20 using namespace testing::ext;
21 using namespace OHOS::HiviewDFX;
22 using namespace OHOS::HiviewDFX::UCollectUtil;
23
24 class ThermalCollectorTest : public testing::Test {
25 public:
SetUp()26 void SetUp() {};
TearDown()27 void TearDown() {};
SetUpTestCase()28 static void SetUpTestCase() {};
TearDownTestCase()29 static void TearDownTestCase() {};
30 };
31
32 #ifdef UNIFIED_COLLECTOR_THERMAL_ENABLE
TestResult(const CollectResult<int32_t> & result)33 void TestResult(const CollectResult<int32_t>& result)
34 {
35 if (result.retCode == UCollect::UcError::SUCCESS) {
36 ASSERT_NE(result.data, 0);
37 } else {
38 ASSERT_EQ(result.retCode, UCollect::UcError::UNSUPPORT);
39 }
40 }
41
42 /**
43 * @tc.name: ThermalCollectorTest001
44 * @tc.desc: used to test ThermalCollector.CollectDevThermal
45 * @tc.type: FUNC
46 */
47 HWTEST_F(ThermalCollectorTest, ThermalCollectorTest001, TestSize.Level1)
48 {
49 std::shared_ptr<ThermalCollector> collector = ThermalCollector::Create();
50 CollectResult<int32_t> result;
51 result = collector->CollectDevThermal(ThermalZone::SHELL_FRONT);
52 TestResult(result);
53 result = collector->CollectDevThermal(ThermalZone::SHELL_FRAME);
54 TestResult(result);
55 result = collector->CollectDevThermal(ThermalZone::SHELL_BACK);
56 TestResult(result);
57 result = collector->CollectDevThermal(ThermalZone::SOC_THERMAL);
58 TestResult(result);
59 result = collector->CollectDevThermal(ThermalZone::SYSTEM);
60 TestResult(result);
61 }
62
63 /**
64 * @tc.name: ThermalCollectorTest002
65 * @tc.desc: used to test ThermalCollector.CollectThermaLevel
66 * @tc.type: FUNC
67 */
68 HWTEST_F(ThermalCollectorTest, ThermalCollectorTest002, TestSize.Level1)
69 {
70 std::shared_ptr<ThermalCollector> collector = ThermalCollector::Create();
71 CollectResult<uint32_t> result = collector->CollectThermaLevel();
72 #ifdef THERMAL_MANAGER_ENABLE
73 ASSERT_EQ(result.retCode, UCollect::UcError::SUCCESS);
74 #else
75 ASSERT_EQ(result.retCode, UCollect::UcError::UNSUPPORT);
76 #endif
77 }
78 #else
79
80 /**
81 * @tc.name: ThermalCollectorTest001
82 * @tc.desc: used to test empty ThermalCollector
83 * @tc.type: FUNC
84 */
85 HWTEST_F(ThermalCollectorTest, ThermalCollectorTest001, TestSize.Level1)
86 {
87 std::shared_ptr<ThermalCollector> collector = ThermalCollector::Create();
88 auto result1 = collector->CollectDevThermal(ThermalZone::SHELL_FRONT);
89 ASSERT_EQ(result1.retCode, UCollect::UcError::FEATURE_CLOSED);
90
91 auto result2 = collector->CollectThermaLevel();
92 ASSERT_EQ(result2.retCode, UCollect::UcError::FEATURE_CLOSED);
93 }
94 #endif
95