From ed4a5763f825b911978d2552554baaf14046cdf2 Mon Sep 17 00:00:00 2001 From: Xavier Lepaul Date: Thu, 24 Mar 2022 16:17:18 +0100 Subject: [PATCH] Migrate parameterized tests to the standard parameterized runner MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only caveat is that a name attribute for the `@Parameters` annotation is required, as otherwise the test infrastructure doesn’t find test results. Bug: webrtc:13662 Change-Id: Ib3e2a6671d1045b0e19746ce78dd434fbee78b87 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/256462 Reviewed-by: Linus Nilsson Auto-Submit: Xavier Lepaul‎ Reviewed-by: Björn Terelius Commit-Queue: Björn Terelius Cr-Commit-Position: refs/heads/main@{#36322} --- ...ndroidVideoDecoderInstrumentationTest.java | 33 +++++++------------ .../org/webrtc/HardwareVideoEncoderTest.java | 29 ++++++---------- .../src/org/webrtc/VideoFrameBufferTest.java | 27 ++++++--------- 3 files changed, 31 insertions(+), 58 deletions(-) diff --git a/sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java b/sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java index 37b9b3a749..8166f5b544 100644 --- a/sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java +++ b/sdk/android/instrumentationtests/src/org/webrtc/AndroidVideoDecoderInstrumentationTest.java @@ -16,40 +16,29 @@ import static org.junit.Assert.assertNotNull; import androidx.annotation.Nullable; import androidx.test.filters.SmallTest; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import org.chromium.base.test.params.BaseJUnit4RunnerDelegate; -import org.chromium.base.test.params.ParameterAnnotations.ClassParameter; -import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate; -import org.chromium.base.test.params.ParameterSet; -import org.chromium.base.test.params.ParameterizedRunner; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; /** Unit tests for {@link AndroidVideoDecoder}. */ -@RunWith(ParameterizedRunner.class) -@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class) +@RunWith(Parameterized.class) public final class AndroidVideoDecoderInstrumentationTest { - @ClassParameter private static List CLASS_PARAMS = new ArrayList<>(); - - static { - CLASS_PARAMS.add(new ParameterSet() - .value(/* codecName= */ "VP8", false /* useEglContext */) - .name("VP8WithoutEglContext")); - CLASS_PARAMS.add(new ParameterSet() - .value(/* codecName= */ "VP8", true /* useEglContext */) - .name("VP8WithEglContext")); - CLASS_PARAMS.add(new ParameterSet() - .value(/* codecName= */ "H264", false /* useEglContext */) - .name("H264WithoutEglContext")); - CLASS_PARAMS.add(new ParameterSet() - .value(/* codecName= */ "H264", true /* useEglContext */) - .name("H264WithEglContext")); + @Parameters(name = "{0};useEglContext={1}") + public static Collection parameters() { + return Arrays.asList(new Object[] {/*codecName=*/"VP8", /*useEglContext=*/false}, + new Object[] {/*codecName=*/"VP8", /*useEglContext=*/true}, + new Object[] {/*codecName=*/"H264", /*useEglContext=*/false}, + new Object[] {/*codecName=*/"H264", /*useEglContext=*/true}); } private final VideoCodecInfo codecType; diff --git a/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java b/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java index fa1e46a9be..092d617270 100644 --- a/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java +++ b/sdk/android/instrumentationtests/src/org/webrtc/HardwareVideoEncoderTest.java @@ -23,35 +23,26 @@ import androidx.annotation.Nullable; import androidx.test.filters.SmallTest; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import org.chromium.base.test.params.BaseJUnit4RunnerDelegate; -import org.chromium.base.test.params.ParameterAnnotations.ClassParameter; -import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate; -import org.chromium.base.test.params.ParameterSet; -import org.chromium.base.test.params.ParameterizedRunner; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; -@RunWith(ParameterizedRunner.class) -@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class) +@RunWith(Parameterized.class) public class HardwareVideoEncoderTest { - @ClassParameter private static List CLASS_PARAMS = new ArrayList<>(); - - static { - CLASS_PARAMS.add(new ParameterSet() - .value(false /* useTextures */, false /* useEglContext */) - .name("I420WithoutEglContext")); - CLASS_PARAMS.add(new ParameterSet() - .value(true /* useTextures */, false /* useEglContext */) - .name("TextureWithoutEglContext")); - CLASS_PARAMS.add(new ParameterSet() - .value(true /* useTextures */, true /* useEglContext */) - .name("TextureWithEglContext")); + @Parameters(name = "textures={0};eglContext={1}") + public static Collection parameters() { + return Arrays.asList(new Object[] {/*textures=*/false, /*eglContext=*/false}, + new Object[] {/*textures=*/true, /*eglContext=*/false}, + new Object[] {/*textures=*/true, /*eglContext=*/true}); } private final boolean useTextures; diff --git a/sdk/android/instrumentationtests/src/org/webrtc/VideoFrameBufferTest.java b/sdk/android/instrumentationtests/src/org/webrtc/VideoFrameBufferTest.java index 1744bd0c9b..3668cd71b1 100644 --- a/sdk/android/instrumentationtests/src/org/webrtc/VideoFrameBufferTest.java +++ b/sdk/android/instrumentationtests/src/org/webrtc/VideoFrameBufferTest.java @@ -22,16 +22,15 @@ import android.os.HandlerThread; import androidx.test.filters.SmallTest; import java.nio.ByteBuffer; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.List; -import org.chromium.base.test.params.BaseJUnit4RunnerDelegate; -import org.chromium.base.test.params.ParameterAnnotations.ClassParameter; -import org.chromium.base.test.params.ParameterAnnotations.UseRunnerDelegate; -import org.chromium.base.test.params.ParameterSet; -import org.chromium.base.test.params.ParameterizedRunner; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import org.webrtc.VideoFrame; /** @@ -40,21 +39,16 @@ import org.webrtc.VideoFrame; * GlRectDrawer and we are testing the full chain I420 -> OES/RGB texture -> I420, with and without * cropping in the middle. Reading textures back to I420 also exercises the YuvConverter code. */ -@RunWith(ParameterizedRunner.class) -@UseRunnerDelegate(BaseJUnit4RunnerDelegate.class) +@RunWith(Parameterized.class) public class VideoFrameBufferTest { /** * These tests are parameterized on this enum which represents the different VideoFrame.Buffers. */ private static enum BufferType { I420_JAVA, I420_NATIVE, RGB_TEXTURE, OES_TEXTURE, NV21, NV12 } - @ClassParameter private static List CLASS_PARAMS = new ArrayList<>(); - - static { - for (BufferType bufferType : BufferType.values()) { - // The parameterization framework can not send Enums, so we pass it as a string instead. - CLASS_PARAMS.add(new ParameterSet().value(bufferType.name()).name(bufferType.name())); - } + @Parameters(name = "{0}") + public static Collection parameters() { + return Arrays.asList(BufferType.values()); } @BeforeClass @@ -65,9 +59,8 @@ public class VideoFrameBufferTest { private final BufferType bufferType; - public VideoFrameBufferTest(String bufferTypeName) { - // Parse the string back to an enum. - bufferType = BufferType.valueOf(bufferTypeName); + public VideoFrameBufferTest(BufferType bufferType) { + this.bufferType = bufferType; } /**