Commit 8d5b3689 by samrobinson Committed by kim-vde

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
parent 0fbd4959
...@@ -50,6 +50,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -50,6 +50,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
* Transforms the {@code uriString} with the {@link Transformer}. * Transforms the {@code uriString} with the {@link Transformer}.
* *
* @param context The {@link Context}. * @param context The {@link Context}.
* @param testId An identifier for the test.
* @param transformer The {@link Transformer} that performs the transformation. * @param transformer The {@link Transformer} that performs the transformation.
* @param uriString The uri (as a {@link String}) that will be transformed. * @param uriString The uri (as a {@link String}) that will be transformed.
* @param timeoutSeconds The transformer timeout. An assertion confirms this is not exceeded. * @param timeoutSeconds The transformer timeout. An assertion confirms this is not exceeded.
...@@ -57,7 +58,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -57,7 +58,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
* @throws Exception The cause of the transformation not completing. * @throws Exception The cause of the transformation not completing.
*/ */
public static TransformationResult runTransformer( public static TransformationResult runTransformer(
Context context, Transformer transformer, String uriString, int timeoutSeconds) Context context, String testId, Transformer transformer, String uriString, int timeoutSeconds)
throws Exception { throws Exception {
AtomicReference<@NullableType Exception> exceptionReference = new AtomicReference<>(); AtomicReference<@NullableType Exception> exceptionReference = new AtomicReference<>();
CountDownLatch countDownLatch = new CountDownLatch(1); CountDownLatch countDownLatch = new CountDownLatch(1);
...@@ -81,7 +82,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -81,7 +82,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
.build(); .build();
Uri uri = Uri.parse(uriString); Uri uri = Uri.parse(uriString);
File externalCacheFile = createExternalCacheFile(uri, context); File externalCacheFile = createExternalCacheFile(context, /* filePrefix= */ testId);
try { try {
InstrumentationRegistry.getInstrumentation() InstrumentationRegistry.getInstrumentation()
.runOnMainSync( .runOnMainSync(
...@@ -108,11 +109,12 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -108,11 +109,12 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
} }
} }
private static File createExternalCacheFile(Uri uri, Context context) throws IOException { private static File createExternalCacheFile(Context context, String filePrefix)
File file = new File(context.getExternalCacheDir(), "transformer-" + uri.hashCode()); throws IOException {
File file = new File(context.getExternalCacheDir(), filePrefix + "-output.mp4");
Assertions.checkState( Assertions.checkState(
!file.exists() || file.delete(), "Could not delete the previous 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"); Assertions.checkState(file.createNewFile(), "Could not create the transformer output file.");
return file; return file;
} }
......
...@@ -31,6 +31,11 @@ public class RemoveAudioTransformationTest { ...@@ -31,6 +31,11 @@ public class RemoveAudioTransformationTest {
public void removeAudioTransform() throws Exception { public void removeAudioTransform() throws Exception {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).setRemoveAudio(true).build(); 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);
} }
} }
...@@ -31,6 +31,11 @@ public class RemoveVideoTransformationTest { ...@@ -31,6 +31,11 @@ public class RemoveVideoTransformationTest {
public void removeVideoTransform() throws Exception { public void removeVideoTransform() throws Exception {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).setRemoveVideo(true).build(); 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);
} }
} }
...@@ -32,7 +32,6 @@ import org.junit.runner.RunWith; ...@@ -32,7 +32,6 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@Ignore("Internal - b/206917996") @Ignore("Internal - b/206917996")
public final class RepeatedTranscodeTransformationTest { public final class RepeatedTranscodeTransformationTest {
private static final int TRANSCODE_COUNT = 10; private static final int TRANSCODE_COUNT = 10;
@Test @Test
...@@ -50,6 +49,7 @@ public final class RepeatedTranscodeTransformationTest { ...@@ -50,6 +49,7 @@ public final class RepeatedTranscodeTransformationTest {
differentOutputSizesBytes.add( differentOutputSizesBytes.add(
runTransformer( runTransformer(
context, context,
/* testId= */ "repeatedTranscode_givesConsistentLengthOutput",
transformer, transformer,
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
/* timeoutSeconds= */ 120) /* timeoutSeconds= */ 120)
...@@ -77,6 +77,7 @@ public final class RepeatedTranscodeTransformationTest { ...@@ -77,6 +77,7 @@ public final class RepeatedTranscodeTransformationTest {
differentOutputSizesBytes.add( differentOutputSizesBytes.add(
runTransformer( runTransformer(
context, context,
/* testId= */ "repeatedTranscodeNoAudio_givesConsistentLengthOutput",
transformer, transformer,
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
/* timeoutSeconds= */ 120) /* timeoutSeconds= */ 120)
...@@ -104,6 +105,7 @@ public final class RepeatedTranscodeTransformationTest { ...@@ -104,6 +105,7 @@ public final class RepeatedTranscodeTransformationTest {
differentOutputSizesBytes.add( differentOutputSizesBytes.add(
runTransformer( runTransformer(
context, context,
/* testId= */ "repeatedTranscodeNoVideo_givesConsistentLengthOutput",
transcodingTransformer, transcodingTransformer,
AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING, AndroidTestUtil.REMOTE_MP4_10_SECONDS_URI_STRING,
/* timeoutSeconds= */ 120) /* timeoutSeconds= */ 120)
......
...@@ -32,6 +32,11 @@ public class SefTransformationTest { ...@@ -32,6 +32,11 @@ public class SefTransformationTest {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = Transformer transformer =
new Transformer.Builder(context).setFlattenForSlowMotion(true).build(); 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);
} }
} }
...@@ -31,6 +31,11 @@ public class TransformationTest { ...@@ -31,6 +31,11 @@ public class TransformationTest {
public void transform() throws Exception { public void transform() throws Exception {
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
Transformer transformer = new Transformer.Builder(context).build(); 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);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment