summaryrefslogtreecommitdiff
path: root/dumpstate
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2017-10-13 18:17:14 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-10-13 18:17:14 +0000
commita780c9d839e6d24d7882b471550d1669028e6810 (patch)
treef41a6eaedf791b46c39051601d81c261fb7a68e1 /dumpstate
parent1a9a146bda76e8adfb6883c11b0ade8e773513ad (diff)
parent8e1e0c4b38967c2286ac99bb42150ee9559280a1 (diff)
Merge "Use pipes instead of tmp files."
Diffstat (limited to 'dumpstate')
-rw-r--r--dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp35
1 files changed, 14 insertions, 21 deletions
diff --git a/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp b/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp
index 046bf56e4b..9e866e7bde 100644
--- a/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp
+++ b/dumpstate/1.0/vts/functional/VtsHalDumpstateV1_0TargetTest.cpp
@@ -16,6 +16,9 @@
#define LOG_TAG "dumpstate_hidl_hal_test"
+#include <fcntl.h>
+#include <unistd.h>
+
#include <android/hardware/dumpstate/1.0/IDumpstateDevice.h>
#include <cutils/native_handle.h>
#include <log/log.h>
@@ -58,50 +61,40 @@ TEST_F(DumpstateHidlTest, TestHandleWithNoFd) {
// 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);
+ // Index 0 corresponds to the read end of the pipe; 1 to the write end.
+ int fds[2];
+ ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno;
native_handle_t* handle = native_handle_create(1, 0);
ASSERT_NE(handle, nullptr) << "Could not create native_handle";
- handle->data[0] = fileno(file);
+ handle->data[0] = fds[1];
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;
+ ASSERT_EQ(1, read(fds[0], &buff, 1)) << "dumped nothing";
native_handle_close(handle);
- native_handle_delete(handle);
}
// Positive test: make sure dumpstateBoard() doesn't crash with two FDs.
TEST_F(DumpstateHidlTest, TestHandleWithTwoFds) {
- FILE* file1 = tmpfile();
- FILE* file2 = tmpfile();
-
- ASSERT_NE(nullptr, file1) << "Could not create temp file #1: " << strerror(errno);
- ASSERT_NE(nullptr, file2) << "Could not create temp file #2: " << strerror(errno);
+ int fds1[2];
+ int fds2[2];
+ ASSERT_EQ(0, pipe2(fds1, O_NONBLOCK)) << errno;
+ ASSERT_EQ(0, pipe2(fds2, O_NONBLOCK)) << errno;
native_handle_t* handle = native_handle_create(2, 0);
ASSERT_NE(handle, nullptr) << "Could not create native_handle";
- handle->data[0] = fileno(file1);
- handle->data[1] = fileno(file2);
+ handle->data[0] = fds1[1];
+ handle->data[1] = fds2[1];
Return<void> status = dumpstate->dumpstateBoard(handle);
ASSERT_TRUE(status.isOk()) << "Status should be ok: " << status.description();
- EXPECT_EQ(0, fclose(file1)) << errno;
- EXPECT_EQ(0, fclose(file2)) << errno;
-
native_handle_close(handle);
- native_handle_delete(handle);
}
int main(int argc, char** argv) {