blob: 6c1599bdb2991ff025e58c9076913694859a0032 [file] [log] [blame]
Todd Poynor8d95f2e2017-05-23 20:28:15 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <android/hardware/thermal/1.1/IThermal.h>
18#include <android/hardware/thermal/1.1/IThermalCallback.h>
19#include <android/hardware/thermal/1.0/types.h>
20
21#include <VtsHalHidlTargetCallbackBase.h>
22#include <VtsHalHidlTargetTestBase.h>
23
24using ::android::hardware::thermal::V1_0::Temperature;
25using ::android::hardware::thermal::V1_0::TemperatureType;
26using ::android::hardware::thermal::V1_1::IThermal;
27using ::android::hardware::thermal::V1_1::IThermalCallback;
28using ::android::hardware::Return;
29using ::android::hardware::Void;
30using ::android::sp;
31
32constexpr char kCallbackNameNotifyThrottling[] = "notifyThrottling";
33static const Temperature kThrottleTemp = {
34 .type = TemperatureType::CPU,
35 .name = "test temperature sensor",
36 .currentValue = 98.6,
37 .throttlingThreshold = 58,
38 .shutdownThreshold = 60,
39 .vrThrottlingThreshold = 59,
40};
41
42class ThermalCallbackArgs {
43 public:
44 bool isThrottling;
45 Temperature temperature;
46};
47
48// Callback class for receiving thermal event notifications from main class
49class ThermalCallback
50 : public ::testing::VtsHalHidlTargetCallbackBase<ThermalCallbackArgs>,
51 public IThermalCallback {
52 public:
53 virtual ~ThermalCallback() = default;
54
55 Return<void> notifyThrottling(bool isThrottling,
56 const Temperature& temperature) override {
57 ThermalCallbackArgs args;
58 args.isThrottling = isThrottling;
59 args.temperature = temperature;
60 NotifyFromCallback(kCallbackNameNotifyThrottling, args);
61 return Void();
62 }
63};
64
65// The main test class for THERMAL HIDL HAL 1.1.
66class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
67 public:
68 virtual void SetUp() override {
69 mThermal = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>();
70 ASSERT_NE(mThermal, nullptr);
71 mThermalCallback = new(std::nothrow) ThermalCallback();
72 ASSERT_NE(mThermalCallback, nullptr);
73 auto ret = mThermal->registerThermalCallback(mThermalCallback);
74 ASSERT_TRUE(ret.isOk());
75 }
76
77 virtual void TearDown() override {
78 auto ret = mThermal->registerThermalCallback(nullptr);
79 ASSERT_TRUE(ret.isOk());
80 }
81
82 protected:
83 sp<IThermal> mThermal;
84 sp<ThermalCallback> mThermalCallback;
85}; // class ThermalHidlTest
86
87// Test ThermalCallback::notifyThrottling().
88// This just calls into and back from our local ThermalCallback impl.
89// Note: a real thermal throttling event from the Thermal HAL could be
90// inadvertently received here.
91TEST_F(ThermalHidlTest, NotifyThrottlingTest) {
92 auto ret = mThermalCallback->notifyThrottling(true, kThrottleTemp);
93 ASSERT_TRUE(ret.isOk());
94 auto res = mThermalCallback->WaitForCallback(kCallbackNameNotifyThrottling);
95 EXPECT_TRUE(res.no_timeout);
96 ASSERT_TRUE(res.args);
97 EXPECT_EQ(true, res.args->isThrottling);
98 EXPECT_EQ(kThrottleTemp, res.args->temperature);
99}
100
101int main(int argc, char** argv) {
102 ::testing::InitGoogleTest(&argc, argv);
103 int status = RUN_ALL_TESTS();
104 cout << "Test result = " << status << std::endl;
105 return status;
106}