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> |
| 21 | #include <log/log.h> |
Zhuoyao Zhang | 9145608 | 2018-02-08 20:55:27 -0800 | [diff] [blame^] | 22 | |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 23 | #include <VtsHalHidlTargetTestBase.h> |
Zhuoyao Zhang | 9145608 | 2018-02-08 20:55:27 -0800 | [diff] [blame^] | 24 | #include <VtsHalHidlTargetTestEnvBase.h> |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 25 | |
| 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 | |
Zhuoyao Zhang | 9145608 | 2018-02-08 20:55:27 -0800 | [diff] [blame^] | 33 | // Test environment for Health HIDL HAL. |
| 34 | class HealthHidlEnvironment : public ::testing::VtsHalHidlTargetTestEnvBase { |
| 35 | public: |
| 36 | // get the test environment singleton |
| 37 | static HealthHidlEnvironment* Instance() { |
| 38 | static HealthHidlEnvironment* instance = new HealthHidlEnvironment; |
| 39 | return instance; |
| 40 | } |
| 41 | |
| 42 | virtual void registerTestServices() override { registerTestService<IHealth>(); } |
| 43 | private: |
| 44 | HealthHidlEnvironment() {} |
| 45 | }; |
| 46 | |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 47 | class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase { |
| 48 | public: |
| 49 | virtual void SetUp() override { |
Zhuoyao Zhang | 9145608 | 2018-02-08 20:55:27 -0800 | [diff] [blame^] | 50 | health = ::testing::VtsHalHidlTargetTestBase::getService<IHealth>( |
| 51 | HealthHidlEnvironment::Instance()->getServiceName<IHealth>()); |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 52 | ASSERT_NE(health, nullptr); |
| 53 | health->init(config, |
| 54 | [&](const auto& halConfigOut) { config = halConfigOut; }); |
| 55 | } |
| 56 | |
| 57 | sp<IHealth> health; |
| 58 | HealthConfig config; |
| 59 | }; |
| 60 | |
| 61 | /** |
| 62 | * Ensure EnergyCounter call returns positive energy counter or NOT_SUPPORTED |
| 63 | */ |
| 64 | TEST_F(HealthHidlTest, TestEnergyCounter) { |
| 65 | Result result; |
| 66 | int64_t energy = 0; |
| 67 | health->energyCounter([&](Result ret, int64_t energyOut) { |
| 68 | result = ret; |
| 69 | energy = energyOut; |
| 70 | }); |
| 71 | |
| 72 | ASSERT_TRUE(result == Result::SUCCESS || result == Result::NOT_SUPPORTED); |
| 73 | ASSERT_TRUE(result != Result::SUCCESS || energy > 0); |
| 74 | } |
| 75 | |
| 76 | int main(int argc, char **argv) { |
Zhuoyao Zhang | 9145608 | 2018-02-08 20:55:27 -0800 | [diff] [blame^] | 77 | ::testing::AddGlobalTestEnvironment(HealthHidlEnvironment::Instance()); |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 78 | ::testing::InitGoogleTest(&argc, argv); |
Zhuoyao Zhang | 9145608 | 2018-02-08 20:55:27 -0800 | [diff] [blame^] | 79 | HealthHidlEnvironment::Instance()->init(&argc, argv); |
Sandeep Patil | d22e2c5 | 2017-05-02 14:28:31 -0700 | [diff] [blame] | 80 | int status = RUN_ALL_TESTS(); |
| 81 | ALOGI("Test result = %d", status); |
| 82 | return status; |
| 83 | } |