Power HAL target-side test
Test: make vts; vts-tradefed run -m HalPowerHidlTargetTest
Bug: 32022775
Change-Id: Id6a14ceb24e6a13e49a236357198686b4348809a
Signed-off-by: Connor O'Brien <connoro@google.com>
diff --git a/power/1.0/vts/functional/Android.bp b/power/1.0/vts/functional/Android.bp
new file mode 100644
index 0000000..81dc316
--- /dev/null
+++ b/power/1.0/vts/functional/Android.bp
@@ -0,0 +1,41 @@
+//
+// Copyright (C) 2016 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: "power_hidl_hal_test",
+ gtest: true,
+ srcs: ["power_hidl_hal_test.cpp"],
+ shared_libs: [
+ "libbase",
+ "liblog",
+ "libcutils",
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "libnativehelper",
+ "libutils",
+ "android.hardware.power@1.0",
+ ],
+ static_libs: ["libgtest"],
+ cflags: [
+ "--coverage",
+ "-O0",
+ "-g",
+ ],
+ ldflags: [
+ "--coverage"
+ ]
+}
diff --git a/power/1.0/vts/functional/power_hidl_hal_test.cpp b/power/1.0/vts/functional/power_hidl_hal_test.cpp
new file mode 100644
index 0000000..ac56f1a
--- /dev/null
+++ b/power/1.0/vts/functional/power_hidl_hal_test.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#define LOG_TAG "power_hidl_hal_test"
+#include <android-base/logging.h>
+
+#include <android/hardware/power/1.0/IPower.h>
+
+#include <gtest/gtest.h>
+
+using ::android::hardware::power::V1_0::IPower;
+using ::android::hardware::power::V1_0::Feature;
+using ::android::hardware::power::V1_0::PowerHint;
+using ::android::hardware::power::V1_0::PowerStatePlatformSleepState;
+using ::android::hardware::power::V1_0::Status;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::sp;
+
+class PowerHidlTest : public ::testing::Test {
+ public:
+ virtual void SetUp() override {
+ power = IPower::getService("power");
+ ASSERT_NE(power, nullptr);
+ }
+
+ virtual void TearDown() override {}
+
+ sp<IPower> power;
+};
+
+// Sanity check Power::setInteractive.
+TEST_F(PowerHidlTest, SetInteractive) {
+ Return<void> ret;
+
+ ret = power->setInteractive(true);
+ ASSERT_TRUE(ret.getStatus().isOk());
+
+ ret = power->setInteractive(false);
+ ASSERT_TRUE(ret.getStatus().isOk());
+}
+
+// Sanity check Power::powerHint on good and bad inputs.
+TEST_F(PowerHidlTest, PowerHint) {
+ PowerHint badHint = static_cast<PowerHint>(0xA);
+ auto hints = {PowerHint::VSYNC, PowerHint::INTERACTION,
+ PowerHint::VIDEO_ENCODE, PowerHint::VIDEO_DECODE,
+ PowerHint::LOW_POWER, PowerHint::SUSTAINED_PERFORMANCE,
+ PowerHint::VR_MODE, PowerHint::LAUNCH,
+ PowerHint::DISABLE_TOUCH, badHint};
+ Return<void> ret;
+ for (auto hint : hints) {
+ ret = power->powerHint(hint, 1);
+ ASSERT_TRUE(ret.getStatus().isOk());
+
+ ret = power->powerHint(hint, 0);
+ ASSERT_TRUE(ret.getStatus().isOk());
+ }
+}
+
+// Sanity check Power::setFeature() on good and bad inputs.
+TEST_F(PowerHidlTest, SetFeature) {
+ Return<void> ret;
+ ret = power->setFeature(Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, true);
+ ASSERT_TRUE(ret.getStatus().isOk());
+ ret = power->setFeature(Feature::POWER_FEATURE_DOUBLE_TAP_TO_WAKE, false);
+ ASSERT_TRUE(ret.getStatus().isOk());
+
+ Feature badFeature = static_cast<Feature>(0x2);
+ ret = power->setFeature(badFeature, true);
+ ASSERT_TRUE(ret.getStatus().isOk());
+ ret = power->setFeature(badFeature, false);
+ ASSERT_TRUE(ret.getStatus().isOk());
+}
+
+// Sanity check Power::getPlatformLowPowerStats().
+TEST_F(PowerHidlTest, GetPlatformLowPowerStats) {
+ hidl_vec<PowerStatePlatformSleepState> vec;
+ Status s;
+ auto cb = [&vec, &s](hidl_vec<PowerStatePlatformSleepState> states,
+ Status status) {
+ vec = states;
+ s = status;
+ };
+ Return<void> ret = power->getPlatformLowPowerStats(cb);
+ ASSERT_TRUE(ret.getStatus().isOk());
+ ASSERT_TRUE(s == Status::SUCCESS || s == Status::FILESYSTEM_ERROR);
+}
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = RUN_ALL_TESTS();
+ ALOGI("Test result = %d", status);
+ return status;
+}
diff --git a/power/1.0/vts/functional/vts/testcases/hal/power/Android.mk b/power/1.0/vts/functional/vts/testcases/hal/power/Android.mk
new file mode 100644
index 0000000..f9e3276
--- /dev/null
+++ b/power/1.0/vts/functional/vts/testcases/hal/power/Android.mk
@@ -0,0 +1,19 @@
+#
+# Copyright (C) 2016 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(call all-subdir-makefiles)
diff --git a/power/1.0/vts/functional/vts/testcases/hal/power/__init__.py b/power/1.0/vts/functional/vts/testcases/hal/power/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/power/1.0/vts/functional/vts/testcases/hal/power/__init__.py
diff --git a/power/1.0/vts/functional/vts/testcases/hal/power/hidl/Android.mk b/power/1.0/vts/functional/vts/testcases/hal/power/hidl/Android.mk
new file mode 100644
index 0000000..f9e3276
--- /dev/null
+++ b/power/1.0/vts/functional/vts/testcases/hal/power/hidl/Android.mk
@@ -0,0 +1,19 @@
+#
+# Copyright (C) 2016 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(call all-subdir-makefiles)
diff --git a/power/1.0/vts/functional/vts/testcases/hal/power/hidl/target/Android.mk b/power/1.0/vts/functional/vts/testcases/hal/power/hidl/target/Android.mk
new file mode 100644
index 0000000..c66b6fb
--- /dev/null
+++ b/power/1.0/vts/functional/vts/testcases/hal/power/hidl/target/Android.mk
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2016 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.
+#
+
+LOCAL_PATH := $(call my-dir)
+
+include $(call all-subdir-makefiles)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := HalPowerHidlTargetTest
+VTS_CONFIG_SRC_DIR := testcases/hal/power/hidl/target
+include test/vts/tools/build/Android.host_config.mk
+
diff --git a/power/1.0/vts/functional/vts/testcases/hal/power/hidl/target/AndroidTest.xml b/power/1.0/vts/functional/vts/testcases/hal/power/hidl/target/AndroidTest.xml
new file mode 100644
index 0000000..bb80de2
--- /dev/null
+++ b/power/1.0/vts/functional/vts/testcases/hal/power/hidl/target/AndroidTest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+<configuration description="Config for VTS Power HIDL HAL's target-side test cases">
+ <target_preparer class="com.android.compatibility.common.tradefed.targetprep.VtsFilePusher">
+ <option name="push-group" value="HidlHalTest.push" />
+ </target_preparer>
+ <target_preparer class="com.android.tradefed.targetprep.VtsPythonVirtualenvPreparer" />
+ <test class="com.android.tradefed.testtype.VtsMultiDeviceTest">
+ <option name="test-module-name" value="HalPowerHidlTargetTest"/>
+ <option name="binary-test-sources" value="
+ _32bit::DATA/nativetest/power_hidl_hal_test/power_hidl_hal_test,
+ _64bit::DATA/nativetest64/power_hidl_hal_test/power_hidl_hal_test,
+ "/>
+ <option name="binary-test-type" value="gtest" />
+ <option name="test-timeout" value="1m" />
+ </test>
+</configuration>