From 5aa2002a38c5189b19fdfad85d76d599f990a561 Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Tue, 22 Oct 2019 10:05:15 -0700 Subject: [PATCH] Audio VTS: Wait after stream close Due to asynchronous nature of the destruction of server-side objects it is required to flush IPC messages to the server and wait to avoid flakiness due to an attempt to open the stream while it's still not closed on the server side. Test: atest VtsHalAudioV5_0TargetTest Bug: 118655804 Change-Id: Ibd6bb2e20ffe95b83228982c2f2e9232d280e5ff --- .../4.0/AudioPrimaryHidlHalTest.cpp | 2 +- .../vts/functional/AudioPrimaryHidlHalTest.h | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp index 2703b2bf4b..15be3bf470 100644 --- a/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp +++ b/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalTest.cpp @@ -24,7 +24,7 @@ static void waitForDeviceDestruction() { // flushCommand makes sure all local command are sent, thus should reduce // the latency between local and remote destruction. IPCThreadState::self()->flushCommands(); - usleep(100); + usleep(100 * 1000); } TEST_F(AudioHidlTest, OpenPrimaryDeviceUsingGetDevice) { diff --git a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h index fb963233aa..0778720bb0 100644 --- a/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h +++ b/audio/core/all-versions/vts/functional/AudioPrimaryHidlHalTest.h @@ -699,13 +699,27 @@ class OpenStreamTest : public AudioConfigPrimaryTest, Return closeStream() { open = false; - return stream->close(); + auto res = stream->close(); + stream.clear(); + waitForStreamDestruction(); + return res; + } + + void waitForStreamDestruction() { + // FIXME: there is no way to know when the remote IStream is being destroyed + // Binder does not support testing if an object is alive, thus + // wait for 100ms to let the binder destruction propagates and + // the remote device has the time to be destroyed. + // flushCommand makes sure all local command are sent, thus should reduce + // the latency between local and remote destruction. + IPCThreadState::self()->flushCommands(); + usleep(100 * 1000); } private: void TearDown() override { if (open) { - ASSERT_OK(stream->close()); + ASSERT_OK(closeStream()); } AudioConfigPrimaryTest::TearDown(); } @@ -1003,8 +1017,14 @@ TEST_IO_STREAM(getMmapPositionNoMmap, "Get a stream Mmap position before mapping ASSERT_RESULT(invalidStateOrNotSupported, stream->stop())) TEST_IO_STREAM(close, "Make sure a stream can be closed", ASSERT_OK(closeStream())) -TEST_IO_STREAM(closeTwice, "Make sure a stream can not be closed twice", ASSERT_OK(closeStream()); - ASSERT_RESULT(Result::INVALID_STATE, closeStream())) +// clang-format off +TEST_IO_STREAM(closeTwice, "Make sure a stream can not be closed twice", + auto streamCopy = stream; + ASSERT_OK(closeStream()); + ASSERT_RESULT(Result::INVALID_STATE, streamCopy->close()); + streamCopy.clear(); + waitForStreamDestruction()) +// clang-format on static void testCreateTooBigMmapBuffer(IStream* stream) { MmapBufferInfo info;