From 99ed835cd5432e21537c726940b34ae59e3dddca Mon Sep 17 00:00:00 2001 From: Cheng-Yi Chiang Date: Wed, 15 Nov 2017 17:22:28 +0800 Subject: CRAS: rstream_unittest - use a new fd instead of stdout We should not use 1 as fd in the test. In cras_rstream_destroy, it will be closed. Create a socket and close it in the TearDown and/or cras_rstream_destroy. BUG=b:68479798 TEST=run rstream_unittest, check stdout shows test results. Change-Id: Iebe5a9fe6521b384bcd2e80d9849aa3ef14e84bf Reviewed-on: https://chromium-review.googlesource.com/771452 Commit-Ready: Cheng-Yi Chiang Tested-by: Cheng-Yi Chiang Reviewed-by: Dylan Reid --- cras/src/tests/rstream_unittest.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'cras/src/tests/rstream_unittest.cc') diff --git a/cras/src/tests/rstream_unittest.cc b/cras/src/tests/rstream_unittest.cc index 8034bfb6..18073138 100644 --- a/cras/src/tests/rstream_unittest.cc +++ b/cras/src/tests/rstream_unittest.cc @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -20,6 +21,9 @@ namespace { class RstreamTestSuite : public testing::Test { protected: virtual void SetUp() { + int rc; + int sock[2] = {-1, -1}; + fmt_.format = SND_PCM_FORMAT_S16_LE; fmt_.frame_rate = 48000; fmt_.num_channels = 2; @@ -32,10 +36,19 @@ class RstreamTestSuite : public testing::Test { config_.format = &fmt_; config_.buffer_frames = 4096; config_.cb_threshold = 2048; - config_.audio_fd = 1; + + // Create a socket pair because it will be used in rstream. + rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sock); + ASSERT_EQ(0, rc); + config_.audio_fd = sock[1]; + config_.client = NULL; } + virtual void TearDown() { + close(config_.audio_fd); + } + static bool format_equal(cras_audio_format *fmt1, cras_audio_format *fmt2) { return fmt1->format == fmt2->format && fmt1->frame_rate == fmt2->frame_rate && -- cgit v1.2.3