blob: 91c8b6ec76cf4fb7c2252f1124e069d919df77b0 [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>
Zhuoyao Zhange01b1872018-02-08 21:10:21 -080023#include <VtsHalHidlTargetTestEnvBase.h>
Todd Poynor8d95f2e2017-05-23 20:28:15 -070024
25using ::android::hardware::thermal::V1_0::Temperature;
26using ::android::hardware::thermal::V1_0::TemperatureType;
27using ::android::hardware::thermal::V1_1::IThermal;
28using ::android::hardware::thermal::V1_1::IThermalCallback;
29using ::android::hardware::Return;
30using ::android::hardware::Void;
31using ::android::sp;
32
33constexpr char kCallbackNameNotifyThrottling[] = "notifyThrottling";
34static const Temperature kThrottleTemp = {
35 .type = TemperatureType::CPU,
36 .name = "test temperature sensor",
37 .currentValue = 98.6,
38 .throttlingThreshold = 58,
39 .shutdownThreshold = 60,
40 .vrThrottlingThreshold = 59,
41};
42
43class ThermalCallbackArgs {
44 public:
45 bool isThrottling;
46 Temperature temperature;
47};
48
49// Callback class for receiving thermal event notifications from main class
50class ThermalCallback
51 : public ::testing::VtsHalHidlTargetCallbackBase<ThermalCallbackArgs>,
52 public IThermalCallback {
53 public:
54 virtual ~ThermalCallback() = default;
55
56 Return<void> notifyThrottling(bool isThrottling,
57 const Temperature& temperature) override {
58 ThermalCallbackArgs args;
59 args.isThrottling = isThrottling;
60 args.temperature = temperature;
61 NotifyFromCallback(kCallbackNameNotifyThrottling, args);
62 return Void();
63 }
64};
65
Zhuoyao Zhange01b1872018-02-08 21:10:21 -080066// Test environment for Thermal HIDL HAL.
67class ThermalHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase {
68 public:
69 // get the test environment singleton
70 static ThermalHidlEnvironment* Instance() {
71 static ThermalHidlEnvironment* instance = new ThermalHidlEnvironment;
72 return instance;
73 }
74
75 virtual void registerTestServices() override { registerTestService<IThermal>(); }
76 private:
77 ThermalHidlEnvironment() {}
78};
79
Todd Poynor8d95f2e2017-05-23 20:28:15 -070080// The main test class for THERMAL HIDL HAL 1.1.
81class ThermalHidlTest : public ::testing::VtsHalHidlTargetTestBase {
82 public:
83 virtual void SetUp() override {
Zhuoyao Zhange01b1872018-02-08 21:10:21 -080084 mThermal = ::testing::VtsHalHidlTargetTestBase::getService<IThermal>(
85 ThermalHidlEnvironment::Instance()->getServiceName<IThermal>());
Todd Poynor8d95f2e2017-05-23 20:28:15 -070086 ASSERT_NE(mThermal, nullptr);
87 mThermalCallback = new(std::nothrow) ThermalCallback();
88 ASSERT_NE(mThermalCallback, nullptr);
89 auto ret = mThermal->registerThermalCallback(mThermalCallback);
90 ASSERT_TRUE(ret.isOk());
91 }
92
93 virtual void TearDown() override {
94 auto ret = mThermal->registerThermalCallback(nullptr);
95 ASSERT_TRUE(ret.isOk());
96 }
97
98 protected:
99 sp<IThermal> mThermal;
100 sp<ThermalCallback> mThermalCallback;
101}; // class ThermalHidlTest
102
103// Test ThermalCallback::notifyThrottling().
104// This just calls into and back from our local ThermalCallback impl.
105// Note: a real thermal throttling event from the Thermal HAL could be
106// inadvertently received here.
107TEST_F(ThermalHidlTest, NotifyThrottlingTest) {
108 auto ret = mThermalCallback->notifyThrottling(true, kThrottleTemp);
109 ASSERT_TRUE(ret.isOk());
110 auto res = mThermalCallback->WaitForCallback(kCallbackNameNotifyThrottling);
111 EXPECT_TRUE(res.no_timeout);
112 ASSERT_TRUE(res.args);
113 EXPECT_EQ(true, res.args->isThrottling);
114 EXPECT_EQ(kThrottleTemp, res.args->temperature);
115}
116
117int main(int argc, char** argv) {
Zhuoyao Zhange01b1872018-02-08 21:10:21 -0800118 ::testing::AddGlobalTestEnvironment(ThermalHidlEnvironment::Instance());
Todd Poynor8d95f2e2017-05-23 20:28:15 -0700119 ::testing::InitGoogleTest(&argc, argv);
Zhuoyao Zhange01b1872018-02-08 21:10:21 -0800120 ThermalHidlEnvironment::Instance()->init(&argc, argv);
Todd Poynor8d95f2e2017-05-23 20:28:15 -0700121 int status = RUN_ALL_TESTS();
122 cout << "Test result = " << status << std::endl;
123 return status;
124}