Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [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 "health_hidl_hal_test" |
| 18 | |
| 19 | #include <android/hardware/health/1.0/IHealth.h> |
| 20 | #include <android/hardware/health/1.0/types.h> |
nelsonli | cb460b6 | 2019-10-25 17:24:18 +0800 | [diff] [blame] | 21 | #include <gtest/gtest.h> |
| 22 | #include <hidl/GtestPrinter.h> |
| 23 | #include <hidl/ServiceManagement.h> |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 24 | #include <log/log.h> |
Zhuoyao Zhang | 9145608 | 2018-02-08 20:55:27 -0800 | [diff] [blame] | 25 | |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 26 | using HealthConfig = ::android::hardware::health::V1_0::HealthConfig; |
| 27 | using HealthInfo = ::android::hardware::health::V1_0::HealthInfo; |
| 28 | using IHealth = ::android::hardware::health::V1_0::IHealth; |
| 29 | using Result = ::android::hardware::health::V1_0::Result; |
| 30 | |
| 31 | using ::android::sp; |
| 32 | |
nelsonli | cb460b6 | 2019-10-25 17:24:18 +0800 | [diff] [blame] | 33 | class HealthHidlTest : public ::testing::TestWithParam<std::string> { |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 34 | public: |
| 35 | virtual void SetUp() override { |
nelsonli | cb460b6 | 2019-10-25 17:24:18 +0800 | [diff] [blame] | 36 | health = IHealth::getService(GetParam()); |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 37 | ASSERT_NE(health, nullptr); |
| 38 | health->init(config, |
| 39 | [&](const auto& halConfigOut) { config = halConfigOut; }); |
| 40 | } |
| 41 | |
| 42 | sp<IHealth> health; |
| 43 | HealthConfig config; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * Ensure EnergyCounter call returns positive energy counter or NOT_SUPPORTED |
| 48 | */ |
nelsonli | cb460b6 | 2019-10-25 17:24:18 +0800 | [diff] [blame] | 49 | TEST_P(HealthHidlTest, TestEnergyCounter) { |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 50 | Result result; |
| 51 | int64_t energy = 0; |
| 52 | health->energyCounter([&](Result ret, int64_t energyOut) { |
| 53 | result = ret; |
| 54 | energy = energyOut; |
| 55 | }); |
| 56 | |
| 57 | ASSERT_TRUE(result == Result::SUCCESS || result == Result::NOT_SUPPORTED); |
| 58 | ASSERT_TRUE(result != Result::SUCCESS || energy > 0); |
| 59 | } |
| 60 | |
nelsonli | cb460b6 | 2019-10-25 17:24:18 +0800 | [diff] [blame] | 61 | INSTANTIATE_TEST_SUITE_P( |
| 62 | PerInstance, HealthHidlTest, |
| 63 | testing::ValuesIn(android::hardware::getAllHalInstanceNames(IHealth::descriptor)), |
| 64 | android::hardware::PrintInstanceNameToString); |