blob: fc0e659ec77352d2367c11933280ad8b9fd8376b [file] [log] [blame]
Benjamin Schwartz40492c22020-08-31 11:55:55 -07001/*
2 * Copyright (C) 2020 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#include <aidl/Gtest.h>
17#include <aidl/Vintf.h>
18
19#include <aidl/android/hardware/powerstats/IPowerStats.h>
20#include <android-base/properties.h>
21#include <android/binder_manager.h>
22#include <android/binder_process.h>
23
24using aidl::android::hardware::powerstats::EnergyData;
25using aidl::android::hardware::powerstats::IPowerStats;
26using aidl::android::hardware::powerstats::PowerEntityInfo;
27using aidl::android::hardware::powerstats::PowerEntityStateResidencyResult;
28using aidl::android::hardware::powerstats::PowerEntityStateSpace;
29using aidl::android::hardware::powerstats::RailInfo;
30using ndk::SpAIBinder;
31
32class PowerStatsAidl : public testing::TestWithParam<std::string> {
33 public:
34 virtual void SetUp() override {
35 powerstats = IPowerStats::fromBinder(
36 SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
37 ASSERT_NE(nullptr, powerstats.get());
38 }
39
40 std::shared_ptr<IPowerStats> powerstats;
41};
42
43TEST_P(PowerStatsAidl, TestGetEnergyData) {
44 std::vector<EnergyData> data;
45 ASSERT_TRUE(powerstats->getEnergyData({}, &data).isOk());
46}
47
48TEST_P(PowerStatsAidl, TestGetPowerEntityInfo) {
49 std::vector<PowerEntityInfo> info;
50 ASSERT_TRUE(powerstats->getPowerEntityInfo(&info).isOk());
51}
52
53TEST_P(PowerStatsAidl, TestGetPowerEntityStateInfo) {
54 std::vector<PowerEntityStateSpace> info;
55 ASSERT_TRUE(powerstats->getPowerEntityStateInfo({}, &info).isOk());
56}
57
58TEST_P(PowerStatsAidl, TestGetPowerEntityStateResidencyData) {
59 std::vector<PowerEntityStateResidencyResult> data;
60 ASSERT_TRUE(powerstats->getPowerEntityStateResidencyData({}, &data).isOk());
61}
62
63TEST_P(PowerStatsAidl, TestGetRailInfo) {
64 std::vector<RailInfo> info;
65 ASSERT_TRUE(powerstats->getRailInfo(&info).isOk());
66}
67
68GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PowerStatsAidl);
69INSTANTIATE_TEST_SUITE_P(
70 PowerStats, PowerStatsAidl,
71 testing::ValuesIn(android::getAidlHalInstanceNames(IPowerStats::descriptor)),
72 android::PrintInstanceNameToString);
73
74int main(int argc, char** argv) {
75 ::testing::InitGoogleTest(&argc, argv);
76 ABinderProcess_setThreadPoolMaxThreadCount(1);
77 ABinderProcess_startThreadPool();
78 return RUN_ALL_TESTS();
79}