blob: bc7b2ee3ce5c047896cd36d49cb8e89f4ff98409 [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>
Dan Shi030bef32019-10-16 14:45:16 -070020#include <gtest/gtest.h>
21#include <hidl/GtestPrinter.h>
22#include <hidl/ServiceManagement.h>
Todd Poynor8d95f2e2017-05-23 20:28:15 -070023
24#include <VtsHalHidlTargetCallbackBase.h>
Todd Poynor8d95f2e2017-05-23 20:28:15 -070025
26using ::android::hardware::thermal::V1_0::Temperature;
27using ::android::hardware::thermal::V1_0::TemperatureType;
28using ::android::hardware::thermal::V1_1::IThermal;
29using ::android::hardware::thermal::V1_1::IThermalCallback;
30using ::android::hardware::Return;
31using ::android::hardware::Void;
32using ::android::sp;
33
34constexpr char kCallbackNameNotifyThrottling[] = "notifyThrottling";
35static const Temperature kThrottleTemp = {
36 .type = TemperatureType::CPU,
37 .name = "test temperature sensor",
38 .currentValue = 98.6,
39 .throttlingThreshold = 58,
40 .shutdownThreshold = 60,
41 .vrThrottlingThreshold = 59,
42};
43
44class ThermalCallbackArgs {
45 public:
46 bool isThrottling;
47 Temperature temperature;
48};
49
50// Callback class for receiving thermal event notifications from main class
51class ThermalCallback
52 : public ::testing::VtsHalHidlTargetCallbackBase<ThermalCallbackArgs>,
53 public IThermalCallback {
54 public:
55 virtual ~ThermalCallback() = default;
56
57 Return<void> notifyThrottling(bool isThrottling,
58 const Temperature& temperature) override {
59 ThermalCallbackArgs args;
60 args.isThrottling = isThrottling;
61 args.temperature = temperature;
62 NotifyFromCallback(kCallbackNameNotifyThrottling, args);
63 return Void();
64 }
65};
66
67// The main test class for THERMAL HIDL HAL 1.1.
Dan Shi030bef32019-10-16 14:45:16 -070068class ThermalHidlTest : public testing::TestWithParam<std::string> {
Todd Poynor8d95f2e2017-05-23 20:28:15 -070069 public:
70 virtual void SetUp() override {
Dan Shi030bef32019-10-16 14:45:16 -070071 mThermal = IThermal::getService(GetParam());
Todd Poynor8d95f2e2017-05-23 20:28:15 -070072 ASSERT_NE(mThermal, nullptr);
73 mThermalCallback = new(std::nothrow) ThermalCallback();
74 ASSERT_NE(mThermalCallback, nullptr);
75 auto ret = mThermal->registerThermalCallback(mThermalCallback);
76 ASSERT_TRUE(ret.isOk());
77 }
78
79 virtual void TearDown() override {
80 auto ret = mThermal->registerThermalCallback(nullptr);
81 ASSERT_TRUE(ret.isOk());
82 }
83
84 protected:
85 sp<IThermal> mThermal;
86 sp<ThermalCallback> mThermalCallback;
87}; // class ThermalHidlTest
88
89// Test ThermalCallback::notifyThrottling().
90// This just calls into and back from our local ThermalCallback impl.
91// Note: a real thermal throttling event from the Thermal HAL could be
92// inadvertently received here.
Dan Shi030bef32019-10-16 14:45:16 -070093TEST_P(ThermalHidlTest, NotifyThrottlingTest) {
Todd Poynor8d95f2e2017-05-23 20:28:15 -070094 auto ret = mThermalCallback->notifyThrottling(true, kThrottleTemp);
95 ASSERT_TRUE(ret.isOk());
96 auto res = mThermalCallback->WaitForCallback(kCallbackNameNotifyThrottling);
97 EXPECT_TRUE(res.no_timeout);
98 ASSERT_TRUE(res.args);
99 EXPECT_EQ(true, res.args->isThrottling);
100 EXPECT_EQ(kThrottleTemp, res.args->temperature);
101}
102
Dan Shi030bef32019-10-16 14:45:16 -0700103INSTANTIATE_TEST_SUITE_P(
104 PerInstance, ThermalHidlTest,
105 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IThermal::descriptor)),
106 android::hardware::PrintInstanceNameToString);