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 b96d962a05..3fdc29bcd8 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/AndroidTestUtil.java @@ -22,6 +22,7 @@ import android.os.Build; import androidx.media3.common.Format; import androidx.media3.common.util.Log; import java.io.File; +import java.io.FileWriter; import java.io.IOException; import java.util.List; import org.json.JSONException; @@ -42,12 +43,22 @@ public final class AndroidTestUtil { public static final String MP4_REMOTE_4K60_PORTRAIT_URI_STRING = "https://storage.googleapis.com/exoplayer-test-media-1/mp4/portrait_4k60.mp4"; - /* package */ static File createExternalCacheFile(Context context, String fileName) - throws IOException { - File file = new File(context.getExternalCacheDir(), fileName); - checkState(!file.exists() || file.delete(), "Could not delete file: " + file.getAbsolutePath()); - checkState(file.createNewFile(), "Could not create file: " + file.getAbsolutePath()); - return file; + + /** + * Log in logcat and in an analysis file that this test was skipped. + * + *

Analysis file is a JSON summarising the test, saved to the application cache. + * + *

The analysis json will contain a {@code skipReason} key, with the reason for skipping the + * test case. + */ + public static void recordTestSkipped(Context context, String testId, String reason) + throws JSONException, IOException { + Log.i(testId, reason); + JSONObject testJson = new JSONObject(); + testJson.put("skipReason", reason); + + writeTestSummaryToFile(context, testId, testJson); } /** @@ -106,5 +117,42 @@ public final class AndroidTestUtil { return exceptionJson; } + /** + * Writes the summary of a test run to the application cache file. + * + *

The cache filename follows the pattern {@code -result.txt}. + * + * @param context The {@link Context}. + * @param testId A unique identifier for the transformer test run. + * @param testJson A {@link JSONObject} containing a summary of the test run. + */ + /* package */ static void writeTestSummaryToFile( + Context context, String testId, JSONObject testJson) throws IOException, JSONException { + testJson.put("testId", testId).put("device", getDeviceDetailsAsJsonObject()); + + String analysisContents = testJson.toString(/* indentSpaces= */ 2); + + // Log contents as well as writing to file, for easier visibility on individual device testing. + Log.i(testId, analysisContents); + + File analysisFile = createExternalCacheFile(context, /* fileName= */ testId + "-result.txt"); + try (FileWriter fileWriter = new FileWriter(analysisFile)) { + fileWriter.write(analysisContents); + } + } + + /** + * Creates a {@link File} of the {@code fileName} in the application cache directory. + * + *

If a file of that name already exists, it is overwritten. + */ + /* package */ static File createExternalCacheFile(Context context, String fileName) + throws IOException { + File file = new File(context.getExternalCacheDir(), fileName); + checkState(!file.exists() || file.delete(), "Could not delete file: " + file.getAbsolutePath()); + checkState(file.createNewFile(), "Could not create file: " + file.getAbsolutePath()); + return file; + } + private AndroidTestUtil() {} } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerAndroidTestRunner.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerAndroidTestRunner.java index 043eaa2b84..8fd685129e 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerAndroidTestRunner.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/TransformerAndroidTestRunner.java @@ -26,14 +26,12 @@ import androidx.media3.common.util.Log; import androidx.media3.common.util.SystemClock; import androidx.test.platform.app.InstrumentationRegistry; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; import org.checkerframework.checker.nullness.compatqual.NullableType; -import org.json.JSONException; import org.json.JSONObject; /** An android instrumentation test runner for {@link Transformer}. */ @@ -174,7 +172,9 @@ public class TransformerAndroidTestRunner { */ public TransformationTestResult run(String testId, String uriString) throws Exception { JSONObject resultJson = new JSONObject(); - resultJson.put("inputValues", JSONObject.wrap(inputValues)); + if (inputValues != null) { + resultJson.put("inputValues", JSONObject.wrap(inputValues)); + } try { TransformationTestResult transformationTestResult = runInternal(testId, uriString); resultJson.put("transformationResult", transformationTestResult.asJsonObject()); @@ -186,7 +186,7 @@ public class TransformerAndroidTestRunner { resultJson.put("exception", AndroidTestUtil.exceptionAsJsonObject(e)); throw e; } finally { - writeTestSummaryToFile(context, testId, resultJson); + AndroidTestUtil.writeTestSummaryToFile(context, testId, resultJson); } } @@ -303,20 +303,4 @@ public class TransformerAndroidTestRunner { return resultBuilder.build(); } - - private static void writeTestSummaryToFile(Context context, String testId, JSONObject resultJson) - throws IOException, JSONException { - resultJson.put("testId", testId).put("device", AndroidTestUtil.getDeviceDetailsAsJsonObject()); - - String analysisContents = resultJson.toString(/* indentSpaces= */ 2); - - // Log contents as well as writing to file, for easier visibility on individual device testing. - Log.i(TAG_PREFIX + testId, analysisContents); - - File analysisFile = - AndroidTestUtil.createExternalCacheFile(context, /* fileName= */ testId + "-result.txt"); - try (FileWriter fileWriter = new FileWriter(analysisFile)) { - fileWriter.write(analysisContents); - } - } } diff --git a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/TransformationTest.java b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/TransformationTest.java index f5ca5f962a..1457584391 100644 --- a/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/TransformationTest.java +++ b/libraries/transformer/src/androidTest/java/androidx/media3/transformer/mh/TransformationTest.java @@ -19,9 +19,9 @@ import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_SEF_URI_STRI import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_URI_STRING; import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING; import static androidx.media3.transformer.AndroidTestUtil.MP4_REMOTE_4K60_PORTRAIT_URI_STRING; +import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped; import android.content.Context; -import androidx.media3.common.util.Log; import androidx.media3.common.util.Util; import androidx.media3.transformer.AndroidTestUtil; import androidx.media3.transformer.DefaultEncoderFactory; @@ -120,14 +120,17 @@ public class TransformationTest { @Test public void transformSef() throws Exception { String testId = TAG + "_transformSef"; + Context context = ApplicationProvider.getApplicationContext(); if (Util.SDK_INT < 25) { // TODO(b/210593256): Remove test skipping after removing the MediaMuxer dependency. - Log.i(testId, "Skipping on this API version due to lack of muxing support"); + recordTestSkipped( + context, + testId, + /* reason= */ "Skipping on this API version due to lack of muxing support"); return; } - Context context = ApplicationProvider.getApplicationContext(); Transformer transformer = new Transformer.Builder(context) .setTransformationRequest(