summaryrefslogtreecommitdiffstats
path: root/dumpstate
diff options
context:
space:
mode:
authorFelipe Leme <felipeal@google.com>2017-05-26 14:55:14 -0700
committerFelipe Leme <felipeal@google.com>2017-06-05 09:05:03 -0700
commit4b89d221e0dbaac180bc306a2e276646bbb7dfb1 (patch)
treecd2c176ef0cc58cc6d5b0ef1776fa1b9707033ba /dumpstate
parent4833a88bd761fd7231d2b9d582bca20d1286b4eb (diff)
downloadplatform_hardware_interfaces-4b89d221e0dbaac180bc306a2e276646bbb7dfb1.tar.gz
platform_hardware_interfaces-4b89d221e0dbaac180bc306a2e276646bbb7dfb1.tar.bz2
platform_hardware_interfaces-4b89d221e0dbaac180bc306a2e276646bbb7dfb1.zip
Implemented VTS for Dumpstate HIDL.
Test: adb shell /data/nativetest64/VtsHalDumpstateV1_0TargetTest/VtsHalDumpstateV1_0TargetTest Test: adb shell /data/nativetest/VtsHalDumpstateV1_0TargetTest/VtsHalDumpstateV1_0TargetTest Fixes: 35915971 Change-Id: I2508699da9a36612961899a100c273f3a5d62cc6
Diffstat (limited to 'dumpstate')
-rw-r--r--dumpstate/1.0/vts/functional/Android.bp32
-rw-r--r--dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp88
-rw-r--r--dumpstate/Android.bp1
3 files changed, 121 insertions, 0 deletions
diff --git a/dumpstate/1.0/vts/functional/Android.bp b/dumpstate/1.0/vts/functional/Android.bp
new file mode 100644
index 0000000000..a1c735b1e4
--- /dev/null
+++ b/dumpstate/1.0/vts/functional/Android.bp
@@ -0,0 +1,32 @@
+//
+// Copyright (C) 2017 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: "VtsHalDumpstateV1_0TargetTest",
+ defaults: ["hidl_defaults"],
+ srcs: ["VtsHalDumpstateV1_0TargetTest.cpp"],
+ shared_libs: [
+ "android.hardware.dumpstate@1.0",
+ "libcutils",
+ "libhidlbase",
+ "liblog",
+ "libutils",
+ ],
+ static_libs: ["VtsHalHidlTargetTestBase"],
+ cflags: [
+ "-O0",
+ "-g",
+ ]
+}
diff --git a/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp b/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp
new file mode 100644
index 0000000000..7ab4812ba6
--- /dev/null
+++ b/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2017 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 "dumpstate_hidl_hal_test"
+
+#include <android/hardware/dumpstate/1.0/IDumpstateDevice.h>
+#include <cutils/native_handle.h>
+#include <log/log.h>
+
+#include <VtsHalHidlTargetTestBase.h>
+
+using ::android::hardware::dumpstate::V1_0::IDumpstateDevice;
+using ::android::hardware::Return;
+using ::android::sp;
+
+class DumpstateHidlTest : public ::testing::VtsHalHidlTargetTestBase {
+ public:
+ virtual void SetUp() override {
+ dumpstate = ::testing::VtsHalHidlTargetTestBase::getService<IDumpstateDevice>();
+ ASSERT_NE(dumpstate, nullptr) << "Could not get HIDL instance";
+ }
+
+ sp<IDumpstateDevice> dumpstate;
+};
+
+// Negative test: make sure dumpstateBoard() doesn't crash when passed a null pointer.
+TEST_F(DumpstateHidlTest, TestNullHandle) {
+ Return<void> status = dumpstate->dumpstateBoard(nullptr);
+
+ ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description();
+}
+
+// Negative test: make sure dumpstateBoard() ignores a handle with no FD.
+TEST_F(DumpstateHidlTest, TestHandleWithNoFd) {
+ native_handle_t* handle = native_handle_create(0, 0);
+ ASSERT_NE(handle, nullptr) << "Could not create native_handle";
+
+ Return<void> status = dumpstate->dumpstateBoard(handle);
+
+ ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description();
+
+ native_handle_close(handle);
+ native_handle_delete(handle);
+}
+
+// Positive test: make sure dumpstateBoard() writes something to the FD.
+TEST_F(DumpstateHidlTest, TestOk) {
+ FILE* file = tmpfile();
+ ASSERT_NE(nullptr, file) << "Could not create temp file: " << strerror(errno);
+
+ native_handle_t* handle = native_handle_create(1, 0);
+ ASSERT_NE(handle, nullptr) << "Could not create native_handle";
+ handle->data[0] = fileno(file);
+
+ Return<void> status = dumpstate->dumpstateBoard(handle);
+ ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description();
+
+ // Check that at least one byte was written
+ rewind(file); // can not fail
+ char buff;
+ int read = fread(&buff, sizeof(buff), 1, file);
+ ASSERT_EQ(1, read) << "dumped nothing";
+
+ EXPECT_EQ(0, fclose(file)) << errno;
+
+ native_handle_close(handle);
+ native_handle_delete(handle);
+}
+
+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/dumpstate/Android.bp b/dumpstate/Android.bp
index bbb3e4bac0..33f70ebae2 100644
--- a/dumpstate/Android.bp
+++ b/dumpstate/Android.bp
@@ -1,4 +1,5 @@
// This is an autogenerated file, do not edit.
subdirs = [
"1.0",
+ "1.0/vts/functional",
]