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 <gtest/gtest.h>
22 #include <hidl/GtestPrinter.h>
23 #include <hidl/ServiceManagement.h>
24 #include <log/log.h>
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
33 class HealthHidlTest : public ::testing::TestWithParam<std::string> {
34 public:
SetUp()35 virtual void SetUp() override {
36 health = IHealth::getService(GetParam());
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 */
TEST_P(HealthHidlTest,TestEnergyCounter)49 TEST_P(HealthHidlTest, TestEnergyCounter) {
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
61 INSTANTIATE_TEST_SUITE_P(
62 PerInstance, HealthHidlTest,
63 testing::ValuesIn(android::hardware::getAllHalInstanceNames(IHealth::descriptor)),
64 android::hardware::PrintInstanceNameToString);
65