Kumar Anand | fc72a8d | 2017-01-26 12:23:09 -0800 | [diff] [blame] | 1 | /* |
| 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 | #define LOG_TAG "power_hidl_hal_test" |
| 18 | #include <android-base/logging.h> |
| 19 | #include <android/hardware/power/1.1/IPower.h> |
| 20 | |
| 21 | #include <VtsHalHidlTargetTestBase.h> |
| 22 | |
| 23 | using ::android::hardware::power::V1_1::IPower; |
| 24 | using ::android::hardware::power::V1_1::PowerStateSubsystem; |
| 25 | using ::android::hardware::power::V1_0::Status; |
Philip Cuadra | 48750dc | 2017-07-11 15:26:53 -0700 | [diff] [blame] | 26 | using ::android::hardware::power::V1_0::PowerHint; |
Kumar Anand | fc72a8d | 2017-01-26 12:23:09 -0800 | [diff] [blame] | 27 | using ::android::hardware::hidl_vec; |
| 28 | using ::android::hardware::Return; |
| 29 | using ::android::sp; |
| 30 | |
| 31 | class PowerHidlTest : public ::testing::VtsHalHidlTargetTestBase { |
| 32 | public: |
| 33 | virtual void SetUp() override { |
| 34 | power = ::testing::VtsHalHidlTargetTestBase::getService<IPower>(); |
| 35 | ASSERT_NE(power, nullptr); |
| 36 | } |
| 37 | |
| 38 | virtual void TearDown() override {} |
| 39 | |
| 40 | sp<IPower> power; |
| 41 | }; |
| 42 | |
| 43 | // Sanity check Power::getSubsystemLowPowerStats(). |
| 44 | TEST_F(PowerHidlTest, GetSubsystemLowPowerStats) { |
| 45 | hidl_vec<PowerStateSubsystem> vec; |
| 46 | Status s; |
| 47 | auto cb = [&vec, &s](hidl_vec<PowerStateSubsystem> subsystems, |
| 48 | Status status) { |
| 49 | vec = subsystems; |
| 50 | s = status; |
| 51 | }; |
| 52 | |
| 53 | Return<void> ret = power->getSubsystemLowPowerStats(cb); |
| 54 | ASSERT_TRUE(ret.isOk()); |
| 55 | ASSERT_TRUE(s == Status::SUCCESS || s == Status::FILESYSTEM_ERROR); |
| 56 | } |
| 57 | |
Philip Cuadra | 48750dc | 2017-07-11 15:26:53 -0700 | [diff] [blame] | 58 | // Sanity check Power::powerHintAsync on good and bad inputs. |
| 59 | TEST_F(PowerHidlTest, PowerHintAsync) { |
| 60 | PowerHint badHint = static_cast<PowerHint>(0xA); |
| 61 | auto hints = {PowerHint::VSYNC, PowerHint::INTERACTION, PowerHint::VIDEO_ENCODE, |
| 62 | PowerHint::VIDEO_DECODE, PowerHint::LOW_POWER, PowerHint::SUSTAINED_PERFORMANCE, |
| 63 | PowerHint::VR_MODE, PowerHint::LAUNCH, badHint}; |
| 64 | Return<void> ret; |
| 65 | for (auto hint : hints) { |
| 66 | ret = power->powerHintAsync(hint, 30000); |
| 67 | ASSERT_TRUE(ret.isOk()); |
| 68 | |
| 69 | ret = power->powerHintAsync(hint, 0); |
| 70 | ASSERT_TRUE(ret.isOk()); |
| 71 | } |
| 72 | |
| 73 | // Turning these hints on in different orders triggers different code paths, |
| 74 | // so iterate over possible orderings. |
| 75 | std::vector<PowerHint> hints2 = {PowerHint::LAUNCH, PowerHint::VR_MODE, |
| 76 | PowerHint::SUSTAINED_PERFORMANCE, PowerHint::INTERACTION}; |
| 77 | auto compareHints = [](PowerHint l, PowerHint r) { |
| 78 | return static_cast<uint32_t>(l) < static_cast<uint32_t>(r); |
| 79 | }; |
| 80 | std::sort(hints2.begin(), hints2.end(), compareHints); |
| 81 | do { |
| 82 | for (auto iter = hints2.begin(); iter != hints2.end(); iter++) { |
| 83 | ret = power->powerHintAsync(*iter, 0); |
| 84 | ASSERT_TRUE(ret.isOk()); |
| 85 | } |
| 86 | for (auto iter = hints2.begin(); iter != hints2.end(); iter++) { |
| 87 | ret = power->powerHintAsync(*iter, 30000); |
| 88 | ASSERT_TRUE(ret.isOk()); |
| 89 | } |
| 90 | } while (std::next_permutation(hints2.begin(), hints2.end(), compareHints)); |
| 91 | } |
| 92 | |
Kumar Anand | fc72a8d | 2017-01-26 12:23:09 -0800 | [diff] [blame] | 93 | int main(int argc, char **argv) { |
| 94 | ::testing::InitGoogleTest(&argc, argv); |
| 95 | int status = RUN_ALL_TESTS(); |
| 96 | LOG(INFO) << "Test result = " << status; |
| 97 | return status; |
| 98 | } |