Skip to content

Commit 8bfd302

Browse files
committed
tests: test waitForStateChange() timeout
Seems broken on OpenSL ES. Tests for #1061
1 parent 120b61d commit 8bfd302

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

tests/testStreamWaitState.cpp

+41-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ class TestStreamWaitState : public ::testing::Test {
6464
EXPECT_EQ(Result::ErrorTimeout, result);
6565
}
6666

67+
void checkWaitNonZeroTimeout() {
68+
StreamState next = StreamState::Unknown;
69+
int64_t timeout = 200 * kNanosPerMillisecond; // wait for a state change that will never come
70+
Result result = mStream->waitForStateChange(mStream->getState(), &next, timeout);
71+
EXPECT_EQ(Result::ErrorTimeout, result);
72+
}
73+
6774
void checkStopWhileWaiting() {
6875
StreamState next = StreamState::Unknown;
6976
auto r = mStream->requestStart();
@@ -120,6 +127,7 @@ class TestStreamWaitState : public ::testing::Test {
120127

121128
};
122129

130+
// Test return of error timeout when zero passed as the timeoutNanos.
123131
TEST_F(TestStreamWaitState, OutputLowWaitZero) {
124132
ASSERT_TRUE(openStream(Direction::Output, PerformanceMode::LowLatency));
125133
checkWaitZeroTimeout();
@@ -150,6 +158,38 @@ TEST_F(TestStreamWaitState, OutputNoneWaitZeroSLES) {
150158
ASSERT_TRUE(closeStream());
151159
}
152160

161+
// Test actual timeout.
162+
TEST_F(TestStreamWaitState, OutputLowWaitNonZero) {
163+
ASSERT_TRUE(openStream(Direction::Output, PerformanceMode::LowLatency));
164+
checkWaitNonZeroTimeout();
165+
ASSERT_TRUE(closeStream());
166+
}
167+
168+
TEST_F(TestStreamWaitState, OutputNoneWaitNonZero) {
169+
ASSERT_TRUE(openStream(Direction::Output, PerformanceMode::None));
170+
checkWaitNonZeroTimeout();
171+
ASSERT_TRUE(closeStream());
172+
}
173+
174+
TEST_F(TestStreamWaitState, OutputLowWaitNonZeroSLES) {
175+
AudioStreamBuilder builder;
176+
builder.setPerformanceMode(PerformanceMode::LowLatency);
177+
builder.setAudioApi(AudioApi::OpenSLES);
178+
ASSERT_TRUE(openStream(builder));
179+
checkWaitNonZeroTimeout();
180+
ASSERT_TRUE(closeStream());
181+
}
182+
183+
TEST_F(TestStreamWaitState, OutputNoneWaitNonZeroSLES) {
184+
AudioStreamBuilder builder;
185+
builder.setPerformanceMode(PerformanceMode::None);
186+
builder.setAudioApi(AudioApi::OpenSLES);
187+
ASSERT_TRUE(openStream(builder));
188+
checkWaitNonZeroTimeout();
189+
ASSERT_TRUE(closeStream());
190+
}
191+
192+
153193

154194
TEST_F(TestStreamWaitState, OutputLowStopWhileWaiting) {
155195
ASSERT_TRUE(openStream(Direction::Output, PerformanceMode::LowLatency));
@@ -215,4 +255,4 @@ TEST_F(TestStreamWaitState, OutputLowCloseWhileWaitingSLES) {
215255
ASSERT_TRUE(openStream(builder));
216256
checkCloseWhileWaiting();
217257
ASSERT_TRUE(closeStream());
218-
}
258+
}

0 commit comments

Comments
 (0)