@@ -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,9 +438,12 @@ void testPerformancePaths() throws InterruptedException {
434438 requestedOutConfig .setMMap (false );
435439 }
436440
441+ File getRecordingDir () {
442+ return getExternalFilesDir (Environment .DIRECTORY_MUSIC );
443+ }
444+
437445 private void saveRecordingAsWave () {
438- File recordingDir = getExternalFilesDir (Environment .DIRECTORY_MUSIC );
439- File waveFile = new File (recordingDir , String .format ("glitch_%03d.wav" , getTestCount ()));
446+ File waveFile = new File (getRecordingDir (), String .format ("glitch_%03d.wav" , getTestCount ()));
440447 int saveResult = saveWaveFile (waveFile .getAbsolutePath ());
441448 if (saveResult > 0 ) {
442449 appendFailedSummary ("Saved in " + waveFile .getAbsolutePath () + "\n " );
@@ -445,6 +452,26 @@ private void saveRecordingAsWave() {
445452 }
446453 }
447454
455+ /**
456+ * Delete all the previously saved WAV files so the user does not
457+ * debug obsolete data.
458+ */
459+ private void deleteOldWaveFiles () {
460+ File recordingDir = getRecordingDir ();
461+ if (recordingDir .exists ()) {
462+ File [] files = recordingDir .listFiles ();
463+ if (files != null ) {
464+ for (File file : files ) {
465+ if (file .isFile ()) {
466+ if (!file .delete ()) {
467+ appendFailedSummary ("Failed to delete file: " + file .getAbsolutePath ());
468+ }
469+ }
470+ }
471+ }
472+ }
473+ }
474+
448475 protected int getTestCount () {
449476 return mAutomatedTestRunner .getTestCount ();
450477 }
0 commit comments