IR HAL Target-side test
Test: make vts; vts-tradefed run -m HalIrHidlTargetTest
Change-Id: I6b750f66a0bc207056abcb493693baebc8af81a5
Signed-off-by: Connor O'Brien <connoro@google.com>
diff --git a/ir/1.0/vts/functional/Android.bp b/ir/1.0/vts/functional/Android.bp
new file mode 100644
index 0000000..c5265de
--- /dev/null
+++ b/ir/1.0/vts/functional/Android.bp
@@ -0,0 +1,40 @@
+//
+// 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: "ir_hidl_hal_test",
+ gtest: true,
+ srcs: ["ir_hidl_hal_test.cpp"],
+ shared_libs: [
+ "libbase",
+ "liblog",
+ "libcutils",
+ "libhidlbase",
+ "libhidltransport",
+ "libhwbinder",
+ "libutils",
+ "android.hardware.ir@1.0",
+ ],
+ static_libs: ["libgtest"],
+ cflags: [
+ "--coverage",
+ "-O0",
+ "-g",
+ ],
+ ldflags: [
+ "--coverage"
+ ]
+}
diff --git a/ir/1.0/vts/functional/ir_hidl_hal_test.cpp b/ir/1.0/vts/functional/ir_hidl_hal_test.cpp
new file mode 100644
index 0000000..57d0b73
--- /dev/null
+++ b/ir/1.0/vts/functional/ir_hidl_hal_test.cpp
@@ -0,0 +1,86 @@
+/*
+ * 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 "ir_hidl_hal_test"
+
+#include <android-base/logging.h>
+
+#include <android/hardware/ir/1.0/IConsumerIr.h>
+#include <android/hardware/ir/1.0/types.h>
+
+#include <gtest/gtest.h>
+#include <algorithm>
+
+using ::android::hardware::ir::V1_0::IConsumerIr;
+using ::android::hardware::ir::V1_0::ConsumerIrFreqRange;
+using ::android::hardware::hidl_vec;
+using ::android::hardware::Return;
+using ::android::sp;
+
+// The main test class for IR HIDL HAL.
+class ConsumerIrHidlTest : public ::testing::Test {
+ public:
+ virtual void SetUp() override {
+ ir = IConsumerIr::getService(false);
+ ASSERT_NE(ir, nullptr);
+ }
+
+ virtual void TearDown() override {}
+
+ sp<IConsumerIr> ir;
+};
+
+// Test transmit() for the min and max frequency of every available range
+TEST_F(ConsumerIrHidlTest, TransmitTest) {
+ int32_t freqs;
+ bool success;
+ hidl_vec<ConsumerIrFreqRange> ranges;
+ auto cb = [&](bool s, hidl_vec<ConsumerIrFreqRange> v) {
+ ranges = v;
+ success = s;
+ };
+ Return<void> ret = ir->getCarrierFreqs(cb);
+ ASSERT_TRUE(ret.isOk());
+ ASSERT_TRUE(success);
+
+ if (ranges.size() > 0) {
+ uint32_t len = 16;
+ hidl_vec<int32_t> vec;
+ vec.resize(len);
+ std::fill(vec.begin(), vec.end(), 1);
+ for (auto range = ranges.begin(); range != ranges.end(); range++) {
+ EXPECT_TRUE(ir->transmit(range->min, vec));
+ EXPECT_TRUE(ir->transmit(range->max, vec));
+ }
+ }
+}
+
+// Test transmit() when called with invalid frequencies
+TEST_F(ConsumerIrHidlTest, BadFreqTest) {
+ uint32_t len = 16;
+ hidl_vec<int32_t> vec;
+ vec.resize(len);
+ std::fill(vec.begin(), vec.end(), 1);
+ EXPECT_FALSE(ir->transmit(-1, vec));
+ EXPECT_FALSE(ir->transmit(0, vec));
+}
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ int status = RUN_ALL_TESTS();
+ LOG(INFO) << "Test result = " << status;
+ return status;
+}
diff --git a/ir/1.0/vts/functional/vts/testcases/hal/ir/hidl/target/Android.mk b/ir/1.0/vts/functional/vts/testcases/hal/ir/hidl/target/Android.mk
new file mode 100644
index 0000000..a69fd08
--- /dev/null
+++ b/ir/1.0/vts/functional/vts/testcases/hal/ir/hidl/target/Android.mk
@@ -0,0 +1,23 @@
+#
+# 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 $(CLEAR_VARS)
+
+LOCAL_MODULE := HalIrHidlTargetTest
+VTS_CONFIG_SRC_DIR := testcases/hal/ir/hidl/target
+include test/vts/tools/build/Android.host_config.mk
diff --git a/ir/1.0/vts/functional/vts/testcases/hal/ir/hidl/target/AndroidTest.xml b/ir/1.0/vts/functional/vts/testcases/hal/ir/hidl/target/AndroidTest.xml
new file mode 100644
index 0000000..3ad7e45
--- /dev/null
+++ b/ir/1.0/vts/functional/vts/testcases/hal/ir/hidl/target/AndroidTest.xml
@@ -0,0 +1,31 @@
+<?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 IR 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="HalIrHidlTargetTest"/>
+ <option name="binary-test-sources" value="
+ _32bit::DATA/nativetest/ir_hidl_hal_test/ir_hidl_hal_test,
+ _64bit::DATA/nativetest64/ir_hidl_hal_test/ir_hidl_hal_test,
+ "/>
+ <option name="binary-test-type" value="hal_hidl_gtest" />
+ <option name="hwbinder-service" value="android.hardware.ir" />
+ <option name="test-timeout" value="1m" />
+ </test>
+</configuration>