From 6c00ac31bbdd5ff85b0446bd89805f50dac4b78f Mon Sep 17 00:00:00 2001 From: Tri Vo Date: Thu, 12 Oct 2017 15:47:32 -0700 Subject: [PATCH] Use a pipe instead of tmp for debugDump tests. Audio hal does not have selinux permissions to files under /data/locat/tmp. We pass an fd to a pipe to the HAL instead. Bug: 67665722 Test: VtsHalAudioV2_0Target Change-Id: I695917be1816ba007f48afab5e978ab31024ffba --- .../functional/AudioPrimaryHidlHalTest.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp index 90fec018ef..c88c6344b4 100644 --- a/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp +++ b/audio/2.0/vts/functional/AudioPrimaryHidlHalTest.cpp @@ -26,6 +26,9 @@ #include #include +#include +#include + #include #include @@ -527,19 +530,19 @@ TEST_F(AudioPrimaryHidlTest, getParameters) { template static void testDebugDump(DebugDump debugDump) { - // Dump in a temporary file - // Note that SELinux must be deactivate for this test to work - FILE* file = tmpfile(); - ASSERT_NE(nullptr, file) << errno; + // File descriptors to our pipe. fds[0] corresponds to the read end and + // fds[1] to the write end. + int fds[2]; + ASSERT_EQ(0, pipe2(fds, O_NONBLOCK)) << errno; // Wrap the temporary file file descriptor in a native handle auto* nativeHandle = native_handle_create(1, 0); ASSERT_NE(nullptr, nativeHandle); - nativeHandle->data[0] = fileno(file); + nativeHandle->data[0] = fds[1]; // Wrap this native handle in a hidl handle hidl_handle handle; - handle.setTo(nativeHandle, true /*take ownership*/); + handle.setTo(nativeHandle, false /*take ownership*/); ASSERT_OK(debugDump(handle)); @@ -547,12 +550,12 @@ static void testDebugDump(DebugDump debugDump) { // TODO: debugDump does not return a Result. // This mean that the hal can not report that it not implementing the // function. - rewind(file); // can not fail char buff; - if (fread(&buff, sizeof(buff), 1, file) != 1) { + if (read(fds[0], &buff, 1) != 1) { doc::note("debugDump does not seem implemented"); } - EXPECT_EQ(0, fclose(file)) << errno; + EXPECT_EQ(0, close(fds[0])) << errno; + EXPECT_EQ(0, close(fds[1])) << errno; } TEST_F(AudioPrimaryHidlTest, DebugDump) {