From e45140871ef0dedb4f9702e126489eb7285f5f1d Mon Sep 17 00:00:00 2001 From: samrobinson Date: Wed, 24 Nov 2021 18:48:02 +0000 Subject: [PATCH] Derive test output video name from the TAG. We need the filename of the output videos to be predictable, because MobileHarness requires the exact filename to pull the file. PiperOrigin-RevId: 412092347 --- .../media3/transformer/AndroidTestUtil.java | 14 ++++++++------ .../transformer/RemoveAudioTransformationTest.java | 7 ++++++- .../transformer/RemoveVideoTransformationTest.java | 7 ++++++- .../RepeatedTranscodeTransformationTest.java | 4 +++- .../media3/transformer/SefTransformationTest.java | 7 ++++++- .../media3/transformer/TransformationTest.java | 7 ++++++- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java index 5497e878d0..a54e693d5c 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java @@ -50,6 +50,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; * Transforms the {@code uriString} with the {@link Transformer}. * * @param context The {@link Context}. + * @param testId An identifier for the test. * @param transformer The {@link Transformer} that performs the transformation. * @param uriString The uri (as a {@link String}) that will be transformed. * @param timeoutSeconds The transformer timeout. An assertion confirms this is not exceeded. @@ -57,7 +58,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; * @throws Exception The cause of the transformation not completing. */ public static TransformationResult runTransformer( - Context context, Transformer transformer, String uriString, int timeoutSeconds) + Context context, String testId, Transformer transformer, String uriString, int timeoutSeconds) throws Exception { AtomicReference<@NullableType Exception> exceptionReference = new AtomicReference<>(); CountDownLatch countDownLatch = new CountDownLatch(1); @@ -81,7 +82,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; .build(); Uri uri = Uri.parse(uriString); - File externalCacheFile = createExternalCacheFile(uri, context); + File externalCacheFile = createExternalCacheFile(context, /* filePrefix= */ testId); try { InstrumentationRegistry.getInstrumentation() .runOnMainSync( @@ -108,11 +109,12 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; } } - private static File createExternalCacheFile(Uri uri, Context context) throws IOException { - File file = new File(context.getExternalCacheDir(), "transformer-" + uri.hashCode()); + private static File createExternalCacheFile(Context context, String filePrefix) + throws IOException { + File file = new File(context.getExternalCacheDir(), filePrefix + "-output.mp4"); Assertions.checkState( - !file.exists() || file.delete(), "Could not delete the previous transformer output file"); - Assertions.checkState(file.createNewFile(), "Could not create the transformer output file"); + !file.exists() || file.delete(), "Could not delete the previous transformer output file."); + Assertions.checkState(file.createNewFile(), "Could not create the transformer output file."); return file; } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RemoveAudioTransformationTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RemoveAudioTransformationTest.java index d9b15076d8..fcc0546b19 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RemoveAudioTransformationTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RemoveAudioTransformationTest.java @@ -31,6 +31,11 @@ public class RemoveAudioTransformationTest { public void removeAudioTransform() throws Exception { Context context = ApplicationProvider.getApplicationContext(); Transformer transformer = new Transformer.Builder(context).setRemoveAudio(true).build(); - runTransformer(context, transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */ 120); + runTransformer( + context, + /* testId= */ "removeAudioTransform", + transformer, + MP4_ASSET_URI_STRING, + /* timeoutSeconds= */ 120); } } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RemoveVideoTransformationTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RemoveVideoTransformationTest.java index 0a82a55965..bd096b5b59 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RemoveVideoTransformationTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RemoveVideoTransformationTest.java @@ -31,6 +31,11 @@ public class RemoveVideoTransformationTest { public void removeVideoTransform() throws Exception { Context context = ApplicationProvider.getApplicationContext(); Transformer transformer = new Transformer.Builder(context).setRemoveVideo(true).build(); - runTransformer(context, transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */ 120); + runTransformer( + context, + /* testId= */ "removeVideoTransform", + transformer, + MP4_ASSET_URI_STRING, + /* timeoutSeconds= */ 120); } } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RepeatedTranscodeTransformationTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RepeatedTranscodeTransformationTest.java index d8ff6c6689..bac7fc6841 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RepeatedTranscodeTransformationTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/RepeatedTranscodeTransformationTest.java @@ -32,7 +32,6 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) @Ignore("Internal - b/206917996") public final class RepeatedTranscodeTransformationTest { - private static final int TRANSCODE_COUNT = 10; @Test @@ -50,6 +49,7 @@ public final class RepeatedTranscodeTransformationTest { differentOutputSizesBytes.add( runTransformer( context, + /* testId= */ "repeatedTranscode_givesConsistentLengthOutput", transformer, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, /* timeoutSeconds= */ 120) @@ -77,6 +77,7 @@ public final class RepeatedTranscodeTransformationTest { differentOutputSizesBytes.add( runTransformer( context, + /* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput", transformer, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, /* timeoutSeconds= */ 120) @@ -104,6 +105,7 @@ public final class RepeatedTranscodeTransformationTest { differentOutputSizesBytes.add( runTransformer( context, + /* testId= */ "repeatedTranscodeNoVideo_givesConsistentLengthOutput", transcodingTransformer, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, /* timeoutSeconds= */ 120) diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/SefTransformationTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/SefTransformationTest.java index 7019b6de28..dc515e0017 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/SefTransformationTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/SefTransformationTest.java @@ -32,6 +32,11 @@ public class SefTransformationTest { Context context = ApplicationProvider.getApplicationContext(); Transformer transformer = new Transformer.Builder(context).setFlattenForSlowMotion(true).build(); - runTransformer(context, transformer, SEF_ASSET_URI_STRING, /* timeoutSeconds= */ 120); + runTransformer( + context, + /* testId = */ "sefTransform", + transformer, + SEF_ASSET_URI_STRING, + /* timeoutSeconds= */ 120); } } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformationTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformationTest.java index e40f0e8ae6..81519f3e75 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformationTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformationTest.java @@ -31,6 +31,11 @@ public class TransformationTest { public void transform() throws Exception { Context context = ApplicationProvider.getApplicationContext(); Transformer transformer = new Transformer.Builder(context).build(); - runTransformer(context, transformer, MP4_ASSET_URI_STRING, /* timeoutSeconds= */ 120); + runTransformer( + context, + /* testId= */ "transform", + transformer, + MP4_ASSET_URI_STRING, + /* timeoutSeconds= */ 120); } }