@@ -273,6 +273,10 @@ protected TestResult testCurrentConfigurations() throws InterruptedException {
273273 }
274274
275275 log ("========================== #" + getTestCount ());
276+ if (getTestCount () == 1 ) {
277+ deleteOldWaveFiles ();
278+ }
279+
276280 int result = 0 ;
277281 StreamConfiguration requestedInConfig = mAudioInputTester .requestedConfiguration ;
278282 StreamConfiguration requestedOutConfig = mAudioOutTester .requestedConfiguration ;
@@ -385,13 +389,13 @@ protected TestResult testCurrentConfigurations() throws InterruptedException {
385389 appendFailedSummary (" " + getConfigText (actualInConfig ) + "\n " );
386390 appendFailedSummary (" " + getConfigText (actualOutConfig ) + "\n " );
387391 appendFailedSummary (" " + resultText + "\n " );
388- saveRecordingAsWave ();
389392 mAutomatedTestRunner .incrementFailCount ();
390393 result = TEST_RESULT_FAILED ;
391394 } else {
392395 mAutomatedTestRunner .incrementPassCount ();
393396 result = TEST_RESULT_PASSED ;
394397 }
398+ saveRecordingAsWave (); // Save recording for both pass and fail results.
395399 }
396400 mAutomatedTestRunner .flushLog ();
397401
@@ -434,14 +438,45 @@ void testPerformancePaths() throws InterruptedException {
434438 requestedOutConfig .setMMap (false );
435439 }
436440
441+ File getRecordingDir () {
442+ return getExternalFilesDir (Environment .DIRECTORY_MUSIC );
443+ }
444+
445+ void reportSavedWaveFiles () {
446+ logAnalysis ("\n --------\n "
447+ + "Audio for each test saved in:\n "
448+ + getRecordingDir ().getAbsolutePath ()
449+ + "/glitch_{###}.wav\n " );
450+ }
451+
437452 private void saveRecordingAsWave () {
438- File recordingDir = getExternalFilesDir ( Environment . DIRECTORY_MUSIC );
439- File waveFile = new File ( recordingDir , String .format ("glitch_%03d.wav" , getTestCount ()));
453+ File waveFile = new File ( getRecordingDir (),
454+ String .format ("glitch_%03d.wav" , getTestCount ()));
440455 int saveResult = saveWaveFile (waveFile .getAbsolutePath ());
441- if (saveResult > 0 ) {
442- appendFailedSummary ("Saved in " + waveFile .getAbsolutePath () + "\n " );
443- } else {
444- appendFailedSummary ("saveWaveFile() returned " + saveResult + "\n " );
456+ if (saveResult <= 0 ) {
457+ appendSummary ("ERROR: saving "
458+ + waveFile .getAbsolutePath ()
459+ + " returned " + saveResult + "\n " );
460+ }
461+ }
462+
463+ /**
464+ * Delete all the previously saved WAV files so the user does not
465+ * debug obsolete data.
466+ */
467+ private void deleteOldWaveFiles () {
468+ File recordingDir = getRecordingDir ();
469+ if (recordingDir .exists ()) {
470+ File [] files = recordingDir .listFiles ();
471+ if (files != null ) {
472+ for (File file : files ) {
473+ if (file .isFile ()) {
474+ if (!file .delete ()) {
475+ appendFailedSummary ("Failed to delete file: " + file .getAbsolutePath ());
476+ }
477+ }
478+ }
479+ }
445480 }
446481 }
447482
0 commit comments