Do not record test skipped for tests skipped on emulator

AndroiTestUtil.recordTestSkipped is useful for MH tests

PiperOrigin-RevId: 726397349
This commit is contained in:
kimvde 2025-02-13 02:58:06 -08:00 committed by Copybara-Service
parent 56bd32da96
commit cea67e8826
3 changed files with 66 additions and 120 deletions

View File

@ -23,10 +23,10 @@ import static androidx.media3.common.util.Util.isRunningOnEmulator;
import static androidx.media3.common.util.Util.usToMs;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.PNG_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static com.google.common.truth.Truth.assertThat;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.Assume.assumeFalse;
import android.content.Context;
import androidx.media3.common.Effect;
@ -43,19 +43,13 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.junit.After;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
/** Playback tests for {@link CompositionPlayer} */
@RunWith(AndroidJUnit4.class)
public class CompositionPlaybackTest {
@Rule public final TestName testName = new TestName();
private static final long TEST_TIMEOUT_MS = isRunningOnEmulator() ? 20_000 : 10_000;
private static final MediaItem VIDEO_MEDIA_ITEM = MediaItem.fromUri(MP4_ASSET.uri);
private static final long VIDEO_DURATION_US = MP4_ASSET.videoDurationUs;
@ -73,14 +67,8 @@ public class CompositionPlaybackTest {
private final Context context = getInstrumentation().getContext().getApplicationContext();
private final PlayerTestListener playerTestListener = new PlayerTestListener(TEST_TIMEOUT_MS);
private String testId;
private @MonotonicNonNull CompositionPlayer player;
@Before
public void setUp() {
testId = testName.getMethodName();
}
@After
public void tearDown() {
getInstrumentation()
@ -222,12 +210,9 @@ public class CompositionPlaybackTest {
@Test
public void playback_sequenceOfImageAndVideo_effectsReceiveCorrectTimestamps() throws Exception {
if (isRunningOnEmulator()) {
// The MediaCodec decoder's output surface is sometimes dropping frames on emulator despite
// using MediaFormat.KEY_ALLOW_FRAME_DROP.
recordTestSkipped(context, testId, /* reason= */ "Skipped due to surface dropping frames");
throw new AssumptionViolatedException("Skipped due to surface dropping frames");
}
// The MediaCodec decoder's output surface is sometimes dropping frames on emulator despite
// using MediaFormat.KEY_ALLOW_FRAME_DROP.
assumeFalse("Skipped on emulator due to surface dropping frames", isRunningOnEmulator());
InputTimestampRecordingShaderProgram inputTimestampRecordingShaderProgram =
new InputTimestampRecordingShaderProgram();
Effect videoEffect = (GlEffect) (context, useHdr) -> inputTimestampRecordingShaderProgram;

View File

@ -20,7 +20,6 @@ import static androidx.media3.common.util.Util.isRunningOnEmulator;
import static androidx.media3.common.util.Util.usToMs;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.PNG_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static com.google.common.collect.Iterables.getLast;
import static com.google.common.collect.Iterables.skip;
@ -28,6 +27,7 @@ import static com.google.common.collect.Iterables.transform;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.junit.Assume.assumeFalse;
import android.content.Context;
import android.view.SurfaceView;
@ -59,11 +59,9 @@ import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.After;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
/**
@ -92,8 +90,6 @@ public class CompositionPlayerSeekTest {
ImmutableList.of(0L, 33_333L, 66_667L, 100_000L, 133_333L, 166_667L);
private static final long VIDEO_GRAPH_END_TIMEOUT_MS = 1_000;
@Rule public final TestName testName = new TestName();
@Rule
public ActivityScenarioRule<SurfaceTestActivity> rule =
new ActivityScenarioRule<>(SurfaceTestActivity.class);
@ -102,13 +98,11 @@ public class CompositionPlayerSeekTest {
getInstrumentation().getContext().getApplicationContext();
private final PlayerTestListener playerTestListener = new PlayerTestListener(TEST_TIMEOUT_MS);
private String testId;
private CompositionPlayer compositionPlayer;
private SurfaceView surfaceView;
@Before
public void setUp() {
testId = testName.getMethodName();
rule.getScenario().onActivity(activity -> surfaceView = activity.getSurfaceView());
}
@ -126,10 +120,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToZero_afterPlayingSingleSequenceOfTwoVideos() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<Long> sequenceTimestampsUs =
new ImmutableList.Builder<Long>()
// Plays the first video
@ -153,10 +146,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToFirstVideo_afterPlayingSingleSequenceOfTwoVideos() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
// Skips the first three video frames
long seekTimeMs = 100;
ImmutableList<Long> sequenceTimestampsUs =
@ -180,10 +172,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToStartOfSecondVideo_afterPlayingSingleSequenceOfTwoVideos() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
// Seeks to the end of the first video
long seekTimeMs = usToMs(VIDEO_DURATION_US);
ImmutableList<Long> sequenceTimestampsUs =
@ -206,10 +197,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToSecondVideo_afterPlayingSingleSequenceOfTwoVideos() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
// Skips the first three image frames of the second image.
long seekTimeMs = usToMs(VIDEO_DURATION_US) + 100;
ImmutableList<Long> sequenceTimestampsUs =
@ -234,10 +224,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToEndOfSecondVideo_afterPlayingSingleSequenceOfTwoVideos() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
// Seeks to the end of the second video
long seekTimeMs = usToMs(2 * VIDEO_DURATION_US);
ImmutableList<Long> sequenceTimestampsUs =
@ -259,10 +248,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToAfterEndOfSecondVideo_afterPlayingSingleSequenceOfTwoVideos() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
long seekTimeMs = usToMs(3 * VIDEO_DURATION_US);
ImmutableList<Long> sequenceTimestampsUs =
new ImmutableList.Builder<Long>()
@ -416,10 +404,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToZero_afterPlayingSingleSequenceOfVideoAndImage() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<Long> sequenceTimestampsUs =
new ImmutableList.Builder<Long>()
// Plays the video
@ -443,10 +430,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToVideo_afterPlayingSingleSequenceOfVideoAndImage() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
// Skips three video frames
long seekTimeMs = 100;
ImmutableList<Long> sequenceTimestampsUs =
@ -471,10 +457,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToImage_afterPlayingSingleSequenceOfVideoAndImage() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
// Skips video frames and three image frames
long seekTimeMs = usToMs(VIDEO_DURATION_US) + 100;
ImmutableList<Long> sequenceTimestampsUs =
@ -499,11 +484,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToZero_afterPlayingSingleSequenceOfImageAndVideo() throws Exception {
if (isRunningOnEmulator()) {
// The MediaCodec decoder's output surface is sometimes dropping frames on emulator despite
// using MediaFormat.KEY_ALLOW_FRAME_DROP.
skipTest("Skipped due to surface dropping frames");
}
// The MediaCodec decoder's output surface is sometimes dropping frames on emulator despite
// using MediaFormat.KEY_ALLOW_FRAME_DROP.
assumeFalse("Skipped on emulator due to surface dropping frames", isRunningOnEmulator());
ImmutableList<Long> sequenceTimestampsUs =
new ImmutableList.Builder<Long>()
// Plays the image
@ -527,11 +510,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToImage_afterPlayingSingleSequenceOfImageAndVideo() throws Exception {
if (isRunningOnEmulator()) {
// The MediaCodec decoder's output surface is sometimes dropping frames on emulator despite
// using MediaFormat.KEY_ALLOW_FRAME_DROP.
skipTest("Skipped due to surface dropping frames");
}
// The MediaCodec decoder's output surface is sometimes dropping frames on emulator despite
// using MediaFormat.KEY_ALLOW_FRAME_DROP.
assumeFalse("Skipped on emulator due to surface dropping frames", isRunningOnEmulator());
// Skips three image frames
long seekTimeMs = 100;
ImmutableList<Long> sequenceTimestampsUs =
@ -555,10 +536,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToVideo_afterPlayingSingleSequenceOfImageAndVideo() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
// Skips to the first video frame.
long seekTimeMs = usToMs(IMAGE_DURATION_US);
ImmutableList<Long> sequenceTimestampsUs =
@ -581,10 +561,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToZero_duringPlayingFirstVideoInSingleSequenceOfTwoVideos() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<MediaItemConfig> mediaItems =
ImmutableList.of(VIDEO_MEDIA_ITEM, VIDEO_MEDIA_ITEM);
int numberOfFramesBeforeSeeking = 15;
@ -610,10 +589,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToSecondVideo_duringPlayingFirstVideoInSingleSequenceOfTwoVideos()
throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<MediaItemConfig> mediaItems =
ImmutableList.of(VIDEO_MEDIA_ITEM, VIDEO_MEDIA_ITEM);
int numberOfFramesBeforeSeeking = 15;
@ -640,10 +618,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToFirstVideo_duringPlayingSecondVideoInSingleSequenceOfTwoVideos()
throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<MediaItemConfig> mediaItems =
ImmutableList.of(VIDEO_MEDIA_ITEM, VIDEO_MEDIA_ITEM);
int numberOfFramesBeforeSeeking = 45;
@ -674,10 +651,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToEndOfFirstVideo_duringPlayingFirstVideoInSingleSequenceOfTwoVideos()
throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<MediaItemConfig> mediaItems =
ImmutableList.of(VIDEO_MEDIA_ITEM, VIDEO_MEDIA_ITEM);
int numberOfFramesBeforeSeeking = 15;
@ -702,10 +678,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToEndOfSecondVideo_duringPlayingFirstVideoInSingleSequenceOfTwoVideos()
throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<MediaItemConfig> mediaItems =
ImmutableList.of(VIDEO_MEDIA_ITEM, VIDEO_MEDIA_ITEM);
int numberOfFramesBeforeSeeking = 15;
@ -728,10 +703,6 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToFirstImage_duringPlayingFirstImageInSequenceOfTwoImages() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
ImmutableList<MediaItemConfig> mediaItems = ImmutableList.of(IMAGE_MEDIA_ITEM);
int numberOfFramesBeforeSeeking = 2;
// Should skip the first 3 frames.
@ -778,10 +749,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToImage_duringPlayingFirstImageInSequenceOfVideoAndImage() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<MediaItemConfig> mediaItems =
ImmutableList.of(VIDEO_MEDIA_ITEM, IMAGE_MEDIA_ITEM);
int numberOfFramesBeforeSeeking = 15;
@ -807,10 +777,9 @@ public class CompositionPlayerSeekTest {
@Test
public void seekToVideo_duringPlayingFirstImageInSequenceOfImageAndVideo() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The audio decoder is failing on API 31 emulator.
skipTest("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing audio decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
ImmutableList<MediaItemConfig> mediaItems =
ImmutableList.of(IMAGE_MEDIA_ITEM, VIDEO_MEDIA_ITEM);
int numberOfFramesBeforeSeeking = 3;
@ -834,11 +803,6 @@ public class CompositionPlayerSeekTest {
assertThat(actualTimestampsUs).isEqualTo(expectedTimestampsUs);
}
private void skipTest(String reason) throws Exception {
recordTestSkipped(applicationContext, testId, reason);
throw new AssumptionViolatedException(reason);
}
/**
* Plays the first {@code numberOfFramesBeforeSeeking} frames of the provided sequence, seeks to
* {@code seekTimeMs}, resumes playback until it ends, and returns the timestamps of the processed

View File

@ -26,9 +26,9 @@ import static androidx.media3.transformer.AndroidTestUtil.JPG_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.MP4_ASSET;
import static androidx.media3.transformer.AndroidTestUtil.assumeFormatsSupported;
import static androidx.media3.transformer.AndroidTestUtil.extractBitmapsFromVideo;
import static androidx.media3.transformer.AndroidTestUtil.recordTestSkipped;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import static org.junit.Assume.assumeFalse;
import android.content.Context;
import android.graphics.Bitmap;
@ -51,7 +51,6 @@ import com.google.common.collect.ImmutableList;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.junit.AssumptionViolatedException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -235,11 +234,9 @@ public final class TransformerMultiSequenceCompositionTest {
@Test
public void export_completesWithConsistentFrameCount() throws Exception {
if (isRunningOnEmulator() && Util.SDK_INT == 31) {
// The decoder is failing on API 31 emulator.
recordTestSkipped(context, testId, /* reason= */ "Skipped due to failing decoder");
throw new AssumptionViolatedException("Skipped due to failing decoder");
}
assumeFalse(
"Skipped due to failing video decoder on API 31 emulator",
isRunningOnEmulator() && Util.SDK_INT == 31);
assumeFormatsSupported(
context,
testId,