summaryrefslogtreecommitdiff
path: root/cras/src/tests/audio_thread_unittest.cc
diff options
context:
space:
mode:
authorHsin-Yu Chao <hychao@chromium.org>2014-08-14 15:33:47 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-15 17:59:20 +0000
commitc3722294fb9d1775839d753e53c563512847d512 (patch)
tree3c13eb9f6d41494997468784f04e9921f31b7672 /cras/src/tests/audio_thread_unittest.cc
parent560bf3c78df2db90ab3f4685ad4aee1ef7625e53 (diff)
downloadadhd-c3722294fb9d1775839d753e53c563512847d512.tar.gz
CRAS: unittest - write two streams one empty one full
Add test case to cover that when writing two streams, if one stream becomes empty for some reason, it should be skipped and proceed write the streams which have samples. BUG=None TEST=make check Change-Id: If4960b63245cd79940e5e832d94220d9f3deb9a9 Reviewed-on: https://chromium-review.googlesource.com/212289 Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org> Commit-Queue: Hsinyu Chao <hychao@chromium.org> Tested-by: Hsinyu Chao <hychao@chromium.org>
Diffstat (limited to 'cras/src/tests/audio_thread_unittest.cc')
-rw-r--r--cras/src/tests/audio_thread_unittest.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/cras/src/tests/audio_thread_unittest.cc b/cras/src/tests/audio_thread_unittest.cc
index 774f4f85..ddfa4541 100644
--- a/cras/src/tests/audio_thread_unittest.cc
+++ b/cras/src/tests/audio_thread_unittest.cc
@@ -37,6 +37,7 @@ static uint32_t select_write_value;
static unsigned int cras_iodev_set_format_called;
static unsigned int cras_iodev_set_playback_timestamp_called;
static unsigned int cras_system_get_volume_return;
+static unsigned int cras_mix_add_stream_called;
static int cras_dsp_get_pipeline_called;
static int cras_dsp_get_pipeline_ret;
@@ -662,6 +663,7 @@ class WriteStreamSuite : public testing::Test {
cras_metrics_log_event_called = 0;
cras_rstream_request_audio_called = 0;
cras_rstream_destroy_called = 0;
+ cras_mix_add_stream_called = 0;
cras_dsp_get_pipeline_called = 0;
is_open_ = 0;
close_dev_called_ = 0;
@@ -1055,6 +1057,7 @@ TEST_F(WriteStreamSuite, PossiblyFillGetFromTwoStreamsFull) {
is_open_ = 1;
rc = unified_io(thread_, &ts);
EXPECT_EQ(0, rc);
+ EXPECT_EQ(2, cras_mix_add_stream_called);
EXPECT_EQ(0, ts.tv_sec);
EXPECT_GE(ts.tv_nsec, nsec_expected - 1000);
EXPECT_LE(ts.tv_nsec, nsec_expected + 1000);
@@ -1064,6 +1067,36 @@ TEST_F(WriteStreamSuite, PossiblyFillGetFromTwoStreamsFull) {
EXPECT_EQ(-1, select_max_fd);
}
+TEST_F(WriteStreamSuite, PossiblyFillGetFromTwoOneEmpty) {
+ struct timespec ts;
+ int rc;
+
+ // Have cb_threshold samples left.
+ frames_queued_ = cb_threshold_;
+ audio_buffer_size_ = buffer_frames_ - frames_queued_;
+
+ // First stream empty while the second stream full.
+ shm_->area->write_offset[0] = 0;
+ shm2_->area->write_offset[0] = cras_shm_used_size(shm2_);
+
+ thread_add_stream(thread_, rstream2_);
+
+ FD_ZERO(&select_out_fds);
+ FD_SET(rstream_->fd, &select_out_fds);
+ select_return_value = 1;
+
+ is_open_ = 1;
+ rc = unified_io(thread_, &ts);
+
+ // Assert that the empty stream is skipped, only one stream mixed.
+ EXPECT_EQ(0, rc);
+ EXPECT_EQ(1, cras_mix_add_stream_called);
+ EXPECT_EQ(buffer_frames_ - cb_threshold_, cras_mix_add_stream_count);
+ EXPECT_EQ(1, cras_rstream_request_audio_called);
+ EXPECT_NE(-1, select_max_fd);
+ EXPECT_EQ(0, memcmp(&select_out_fds, &select_in_fds, sizeof(select_in_fds)));
+}
+
TEST_F(WriteStreamSuite, PossiblyFillGetFromTwoStreamsFullOneMixes) {
struct timespec ts;
int rc;
@@ -2128,6 +2161,8 @@ size_t cras_mix_add_stream(struct cras_audio_shm *shm,
size_t num_samples;
size_t frames = 0;
+ cras_mix_add_stream_called++;
+
if (cras_mix_add_stream_dont_fill_next) {
cras_mix_add_stream_dont_fill_next = 0;
return 0;