Add VTS tests for PowerStats HAL 2.0
Right now these VTS tests only check for successful return status since
this HAL only contains a stub implementation at the moment. These tests
will be updated as this HAL implementation is completed.
Bug: 165345767
Test: atest VtsHalPowerStatsTargetTest
Change-Id: I3a6a4a333ee743fac4eba8ae225d5d1c9ffff32e
diff --git a/powerstats/aidl/vts/Android.bp b/powerstats/aidl/vts/Android.bp
new file mode 100644
index 0000000..c61022e
--- /dev/null
+++ b/powerstats/aidl/vts/Android.bp
@@ -0,0 +1,32 @@
+// Copyright (C) 2020 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+cc_test {
+ name: "VtsHalPowerStatsTargetTest",
+ defaults: [
+ "VtsHalTargetTestDefaults",
+ "use_libaidlvintf_gtest_helper_static",
+ ],
+ srcs: ["VtsHalPowerStatsTargetTest.cpp"],
+ shared_libs: [
+ "libbinder_ndk",
+ ],
+ static_libs: [
+ "android.hardware.powerstats-ndk_platform",
+ ],
+ test_suites: [
+ "general-tests",
+ "vts",
+ ],
+}
diff --git a/powerstats/aidl/vts/VtsHalPowerStatsTargetTest.cpp b/powerstats/aidl/vts/VtsHalPowerStatsTargetTest.cpp
new file mode 100644
index 0000000..fc0e659
--- /dev/null
+++ b/powerstats/aidl/vts/VtsHalPowerStatsTargetTest.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <aidl/Gtest.h>
+#include <aidl/Vintf.h>
+
+#include <aidl/android/hardware/powerstats/IPowerStats.h>
+#include <android-base/properties.h>
+#include <android/binder_manager.h>
+#include <android/binder_process.h>
+
+using aidl::android::hardware::powerstats::EnergyData;
+using aidl::android::hardware::powerstats::IPowerStats;
+using aidl::android::hardware::powerstats::PowerEntityInfo;
+using aidl::android::hardware::powerstats::PowerEntityStateResidencyResult;
+using aidl::android::hardware::powerstats::PowerEntityStateSpace;
+using aidl::android::hardware::powerstats::RailInfo;
+using ndk::SpAIBinder;
+
+class PowerStatsAidl : public testing::TestWithParam<std::string> {
+ public:
+ virtual void SetUp() override {
+ powerstats = IPowerStats::fromBinder(
+ SpAIBinder(AServiceManager_waitForService(GetParam().c_str())));
+ ASSERT_NE(nullptr, powerstats.get());
+ }
+
+ std::shared_ptr<IPowerStats> powerstats;
+};
+
+TEST_P(PowerStatsAidl, TestGetEnergyData) {
+ std::vector<EnergyData> data;
+ ASSERT_TRUE(powerstats->getEnergyData({}, &data).isOk());
+}
+
+TEST_P(PowerStatsAidl, TestGetPowerEntityInfo) {
+ std::vector<PowerEntityInfo> info;
+ ASSERT_TRUE(powerstats->getPowerEntityInfo(&info).isOk());
+}
+
+TEST_P(PowerStatsAidl, TestGetPowerEntityStateInfo) {
+ std::vector<PowerEntityStateSpace> info;
+ ASSERT_TRUE(powerstats->getPowerEntityStateInfo({}, &info).isOk());
+}
+
+TEST_P(PowerStatsAidl, TestGetPowerEntityStateResidencyData) {
+ std::vector<PowerEntityStateResidencyResult> data;
+ ASSERT_TRUE(powerstats->getPowerEntityStateResidencyData({}, &data).isOk());
+}
+
+TEST_P(PowerStatsAidl, TestGetRailInfo) {
+ std::vector<RailInfo> info;
+ ASSERT_TRUE(powerstats->getRailInfo(&info).isOk());
+}
+
+GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(PowerStatsAidl);
+INSTANTIATE_TEST_SUITE_P(
+ PowerStats, PowerStatsAidl,
+ testing::ValuesIn(android::getAidlHalInstanceNames(IPowerStats::descriptor)),
+ android::PrintInstanceNameToString);
+
+int main(int argc, char** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ ABinderProcess_setThreadPoolMaxThreadCount(1);
+ ABinderProcess_startThreadPool();
+ return RUN_ALL_TESTS();
+}