blob: 335d15d172648e619a92f299f429e991e30f0aab [file] [log] [blame]
Sandeep Patild22e2c52017-05-02 14:28:31 -07001/*
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 Zhang91456082018-02-08 20:55:27 -080022
Sandeep Patild22e2c52017-05-02 14:28:31 -070023#include <VtsHalHidlTargetTestBase.h>
Zhuoyao Zhang91456082018-02-08 20:55:27 -080024#include <VtsHalHidlTargetTestEnvBase.h>
Sandeep Patild22e2c52017-05-02 14:28:31 -070025
26using HealthConfig = ::android::hardware::health::V1_0::HealthConfig;
27using HealthInfo = ::android::hardware::health::V1_0::HealthInfo;
28using IHealth = ::android::hardware::health::V1_0::IHealth;
29using Result = ::android::hardware::health::V1_0::Result;
30
31using ::android::sp;
32
Zhuoyao Zhang91456082018-02-08 20:55:27 -080033// Test environment for Health HIDL HAL.
34class 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 Patild22e2c52017-05-02 14:28:31 -070047class HealthHidlTest : public ::testing::VtsHalHidlTargetTestBase {
48 public:
49 virtual void SetUp() override {
Zhuoyao Zhang91456082018-02-08 20:55:27 -080050 health = ::testing::VtsHalHidlTargetTestBase::getService<IHealth>(
51 HealthHidlEnvironment::Instance()->getServiceName<IHealth>());
Sandeep Patild22e2c52017-05-02 14:28:31 -070052 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 */
64TEST_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
76int main(int argc, char **argv) {
Zhuoyao Zhang91456082018-02-08 20:55:27 -080077 ::testing::AddGlobalTestEnvironment(HealthHidlEnvironment::Instance());
Sandeep Patild22e2c52017-05-02 14:28:31 -070078 ::testing::InitGoogleTest(&argc, argv);
Zhuoyao Zhang91456082018-02-08 20:55:27 -080079 HealthHidlEnvironment::Instance()->init(&argc, argv);
Sandeep Patild22e2c52017-05-02 14:28:31 -070080 int status = RUN_ALL_TESTS();
81 ALOGI("Test result = %d", status);
82 return status;
83}