Skip to content

Commit

Permalink
OboeTester: return Stop from rapid cycle test
Browse files Browse the repository at this point in the history
This triggers a race condition and a deadlock.

To trigger #2059
  • Loading branch information
philburk committed Jul 8, 2024
1 parent 9f3e628 commit 2611bdc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
21 changes: 13 additions & 8 deletions apps/OboeTester/app/src/main/cpp/TestRapidCycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

using namespace oboe;

// open start start an Oboe stream
// start a thread to cycle through stream tests
int32_t TestRapidCycle::start(bool useOpenSL) {
mThreadEnabled = true;
mCycleCount = 0;
Expand Down Expand Up @@ -69,10 +69,10 @@ int32_t TestRapidCycle::oneCycle(bool useOpenSL) {
int32_t durationMicros = (int32_t)(drand48() * kMaxSleepMicros);
LOGD("TestRapidCycle::oneCycle() - Sleep for %d micros", durationMicros);
usleep(durationMicros);
LOGD("TestRapidCycle::oneCycle() - Woke up, stop stream");
oboe::Result result1 = mStream->requestStop();
oboe::Result result2 = mStream->close();
return (int32_t)((result1 != oboe::Result::OK) ? result1 : result2);
LOGD("TestRapidCycle::oneCycle() - Woke up, close stream");
mDataCallback->returnStop = true;
result = mStream->close();
return (int32_t) result;
}

// Callback that sleeps then touches the audio buffer.
Expand All @@ -85,8 +85,13 @@ DataCallbackResult TestRapidCycle::MyDataCallback::onAudioReady(

// Fill buffer with white noise.
for (int i = 0; i < numSamples; i++) {
floatData[i] = ((float)drand48() - 0.5f) * 2 * 0.1f;
floatData[i] = ((float) drand48() - 0.5f) * 2 * 0.1f;
}
usleep(500); // half a millisecond
if (returnStop) {
usleep(20 * 1000);
return DataCallbackResult::Stop;
} else {
return DataCallbackResult::Continue;
}

return oboe::DataCallbackResult::Continue;
}
2 changes: 2 additions & 0 deletions apps/OboeTester/app/src/main/cpp/TestRapidCycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class TestRapidCycle {
oboe::AudioStream *audioStream,
void *audioData,
int32_t numFrames) override;

bool returnStop = false;
};

std::shared_ptr<oboe::AudioStream> mStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ protected class MyStreamSniffer extends Thread {

@Override
public void run() {
int lastCycleCount = -1;
boolean useOpenSL = mApiOpenSLButton.isChecked();
startRapidCycleTest(useOpenSL);
try {
while (enabled) {
statusBuffer = new StringBuffer();
sleep(100);
log("#" + getCycleCount() + " open/close cycles\n");
int cycleCount = getCycleCount();
if (cycleCount > lastCycleCount) { // reduce spam
log("#" + cycleCount + " open/close cycles\n");
lastCycleCount = cycleCount;
}
}
} catch (InterruptedException e) {
} finally {
Expand Down
5 changes: 2 additions & 3 deletions apps/OboeTester/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,8 @@
</string>

<string name="rapid_cycle_intro">
Maybe cause a crash by rapidly\n
opening, starting, stopping and\n
closing streams.
Maybe cause a crash or hang by rapidly\n
opening, starting, and closing streams.\n
</string>

<string-array name="conversion_qualities">
Expand Down

0 comments on commit 2611bdc

Please sign in to comment.