mirror of
https://github.com/androidx/media.git
synced 2025-05-12 10:09:55 +08:00
Add file logging for skipping instrumentation tests.
PiperOrigin-RevId: 438808231
This commit is contained in:
parent
80ff26b6fa
commit
9fca474027
@ -22,6 +22,7 @@ import android.os.Build;
|
|||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -42,12 +43,22 @@ public final class AndroidTestUtil {
|
|||||||
|
|
||||||
public static final String MP4_REMOTE_4K60_PORTRAIT_URI_STRING =
|
public static final String MP4_REMOTE_4K60_PORTRAIT_URI_STRING =
|
||||||
"https://storage.googleapis.com/exoplayer-test-media-1/mp4/portrait_4k60.mp4";
|
"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);
|
* Log in logcat and in an analysis file that this test was skipped.
|
||||||
checkState(!file.exists() || file.delete(), "Could not delete file: " + file.getAbsolutePath());
|
*
|
||||||
checkState(file.createNewFile(), "Could not create file: " + file.getAbsolutePath());
|
* <p>Analysis file is a JSON summarising the test, saved to the application cache.
|
||||||
return file;
|
*
|
||||||
|
* <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;
|
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() {}
|
private AndroidTestUtil() {}
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,12 @@ import com.google.android.exoplayer2.MediaItem;
|
|||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import com.google.android.exoplayer2.util.SystemClock;
|
import com.google.android.exoplayer2.util.SystemClock;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
import org.checkerframework.checker.nullness.compatqual.NullableType;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
/** An android instrumentation test runner for {@link Transformer}. */
|
/** An android instrumentation test runner for {@link Transformer}. */
|
||||||
@ -174,7 +172,9 @@ public class TransformerAndroidTestRunner {
|
|||||||
*/
|
*/
|
||||||
public TransformationTestResult run(String testId, String uriString) throws Exception {
|
public TransformationTestResult run(String testId, String uriString) throws Exception {
|
||||||
JSONObject resultJson = new JSONObject();
|
JSONObject resultJson = new JSONObject();
|
||||||
resultJson.put("inputValues", JSONObject.wrap(inputValues));
|
if (inputValues != null) {
|
||||||
|
resultJson.put("inputValues", JSONObject.wrap(inputValues));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
TransformationTestResult transformationTestResult = runInternal(testId, uriString);
|
TransformationTestResult transformationTestResult = runInternal(testId, uriString);
|
||||||
resultJson.put("transformationResult", transformationTestResult.asJsonObject());
|
resultJson.put("transformationResult", transformationTestResult.asJsonObject());
|
||||||
@ -186,7 +186,7 @@ public class TransformerAndroidTestRunner {
|
|||||||
resultJson.put("exception", AndroidTestUtil.exceptionAsJsonObject(e));
|
resultJson.put("exception", AndroidTestUtil.exceptionAsJsonObject(e));
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
writeTestSummaryToFile(context, testId, resultJson);
|
AndroidTestUtil.writeTestSummaryToFile(context, testId, resultJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,20 +303,4 @@ public class TransformerAndroidTestRunner {
|
|||||||
|
|
||||||
return resultBuilder.build();
|
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,6 +19,7 @@ import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSE
|
|||||||
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_URI_STRING;
|
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_URI_STRING;
|
||||||
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING;
|
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING;
|
||||||
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_REMOTE_4K60_PORTRAIT_URI_STRING;
|
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.MP4_REMOTE_4K60_PORTRAIT_URI_STRING;
|
||||||
|
import static com.google.android.exoplayer2.transformer.AndroidTestUtil.recordTestSkipped;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
@ -30,7 +31,6 @@ import com.google.android.exoplayer2.transformer.TransformationRequest;
|
|||||||
import com.google.android.exoplayer2.transformer.Transformer;
|
import com.google.android.exoplayer2.transformer.Transformer;
|
||||||
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
|
import com.google.android.exoplayer2.transformer.TransformerAndroidTestRunner;
|
||||||
import com.google.android.exoplayer2.transformer.VideoEncoderSettings;
|
import com.google.android.exoplayer2.transformer.VideoEncoderSettings;
|
||||||
import com.google.android.exoplayer2.util.Log;
|
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -120,14 +120,17 @@ public class TransformationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void transformSef() throws Exception {
|
public void transformSef() throws Exception {
|
||||||
String testId = TAG + "_transformSef";
|
String testId = TAG + "_transformSef";
|
||||||
|
Context context = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
if (Util.SDK_INT < 25) {
|
if (Util.SDK_INT < 25) {
|
||||||
// TODO(b/210593256): Remove test skipping after removing the MediaMuxer dependency.
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Context context = ApplicationProvider.getApplicationContext();
|
|
||||||
Transformer transformer =
|
Transformer transformer =
|
||||||
new Transformer.Builder(context)
|
new Transformer.Builder(context)
|
||||||
.setTransformationRequest(
|
.setTransformationRequest(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user