Add file logging for skipping instrumentation tests.
PiperOrigin-RevId: 438808231
This commit is contained in:
parent
ad387378b2
commit
0c6882867b
@ -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.
|
||||
*
|
||||
* <p>Analysis file is a JSON summarising the test, saved to the application cache.
|
||||
*
|
||||
* <p>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.
|
||||
*
|
||||
* <p>The cache filename follows the pattern {@code <testId>-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.
|
||||
*
|
||||
* <p>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() {}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user