blob: b114944f0c4c0b13c2819a19b08a148426693e9f [file] [log] [blame]
Connor O'Brien7106c882016-11-21 16:50:43 -08001/*
2 * Copyright (C) 2016 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#define LOG_TAG "power_hidl_hal_test"
18#include <android-base/logging.h>
19
Connor O'Brienf04688c2016-12-02 18:32:24 -080020#include <cutils/properties.h>
21
Connor O'Brien7106c882016-11-21 16:50:43 -080022#include <android/hardware/power/1.0/IPower.h>
23
24#include <gtest/gtest.h>
25
26using ::android::hardware::power::V1_0::IPower;
27using ::android::hardware::power::V1_0::Feature;
28using ::android::hardware::power::V1_0::PowerHint;
29using ::android::hardware::power::V1_0::PowerStatePlatformSleepState;
30using ::android::hardware::power::V1_0::Status;
31using ::android::hardware::hidl_vec;
32using ::android::hardware::Return;
33using ::android::sp;
34
35class PowerHidlTest : public ::testing::Test {
36 public:
37 virtual void SetUp() override {
Chris Phoenix487c24c2017-01-23 13:14:56 -080038 power = IPower::getService();
Connor O'Brien7106c882016-11-21 16:50:43 -080039 ASSERT_NE(power, nullptr);
40 }
41
42 virtual void TearDown() override {}
43
44 sp<IPower> power;
45};
46
47// Sanity check Power::setInteractive.
48TEST_F(PowerHidlTest, SetInteractive) {
49 Return<void> ret;
50
51 ret = power->setInteractive(true);
Steven Morelandb6438422017-01-03 17:06:57 -080052 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -080053
54 ret = power->setInteractive(false);
Steven Morelandb6438422017-01-03 17:06:57 -080055 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -080056}
57
58// Sanity check Power::powerHint on good and bad inputs.
59TEST_F(PowerHidlTest, PowerHint) {
60 PowerHint badHint = static_cast<PowerHint>(0xA);
61 auto hints = {PowerHint::VSYNC, PowerHint::INTERACTION,
62 PowerHint::VIDEO_ENCODE, PowerHint::VIDEO_DECODE,
63 PowerHint::LOW_POWER, PowerHint::SUSTAINED_PERFORMANCE,
64 PowerHint::VR_MODE, PowerHint::LAUNCH,
Michael Wrightf54971a2017-01-18 22:36:23 +000065 badHint};
Connor O'Brien7106c882016-11-21 16:50:43 -080066 Return<void> ret;
67 for (auto hint : hints) {
68 ret = power->powerHint(hint, 1);
Steven Morelandb6438422017-01-03 17:06:57 -080069 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -080070
71 ret = power->powerHint(hint, 0);
Steven Morelandb6438422017-01-03 17:06:57 -080072 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -080073 }
74}
75
76// Sanity check Power::setFeature() on good and bad inputs.
77TEST_F(PowerHidlTest, SetFeature) {
78 Return<void> ret;
79 ret = power->setFeature(Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, true);
Steven Morelandb6438422017-01-03 17:06:57 -080080 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -080081 ret = power->setFeature(Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, false);
Steven Morelandb6438422017-01-03 17:06:57 -080082 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -080083
84 Feature badFeature = static_cast<Feature>(0x2);
85 ret = power->setFeature(badFeature, true);
Steven Morelandb6438422017-01-03 17:06:57 -080086 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -080087 ret = power->setFeature(badFeature, false);
Steven Morelandb6438422017-01-03 17:06:57 -080088 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -080089}
90
91// Sanity check Power::getPlatformLowPowerStats().
92TEST_F(PowerHidlTest, GetPlatformLowPowerStats) {
93 hidl_vec<PowerStatePlatformSleepState> vec;
94 Status s;
95 auto cb = [&vec, &s](hidl_vec<PowerStatePlatformSleepState> states,
96 Status status) {
97 vec = states;
98 s = status;
99 };
100 Return<void> ret = power->getPlatformLowPowerStats(cb);
Steven Morelandb6438422017-01-03 17:06:57 -0800101 ASSERT_TRUE(ret.isOk());
Connor O'Brien7106c882016-11-21 16:50:43 -0800102 ASSERT_TRUE(s == Status::SUCCESS || s == Status::FILESYSTEM_ERROR);
103}
104
105int main(int argc, char **argv) {
106 ::testing::InitGoogleTest(&argc, argv);
107 int status = RUN_ALL_TESTS();
Yifan Hongf9d30342016-11-30 13:45:34 -0800108 LOG(INFO) << "Test result = " << status;
Connor O'Brien7106c882016-11-21 16:50:43 -0800109 return status;
110}