Skip SSIM calculation on Nexus 5 API 21.

There is a problem with the ImageReader formats used by the
SSIM helper that only occurs for Nexus 5 API 21, so as a workaround
we can skip the SSIM calculation on Nexus 5 API 21.

This skips just the SSIM calculation (by setting the value to
1.0 instead and logging). The tests still run when SSIM is skipped
so that we can detect other failures.

PiperOrigin-RevId: 450903183
This commit is contained in:
hschlueter 2022-05-25 12:42:11 +00:00 committed by Marc Baechinger
parent 678b6c0438
commit de1dceedc1
3 changed files with 28 additions and 15 deletions

View File

@ -37,6 +37,8 @@ import org.json.JSONObject;
/** Utilities for instrumentation tests. */
public final class AndroidTestUtil {
private static final String TAG = "AndroidTestUtil";
// TODO(b/228865104): Add device capability based test skipping.
public static final String MP4_ASSET_URI_STRING = "asset:///media/mp4/sample.mp4";
public static final Format MP4_ASSET_FORMAT =
@ -136,7 +138,7 @@ public final class AndroidTestUtil {
*/
public static void recordTestSkipped(Context context, String testId, String reason)
throws JSONException, IOException {
Log.i(testId, reason);
Log.i(TAG, testId + ": " + reason);
JSONObject testJson = new JSONObject();
testJson.put("skipReason", reason);
@ -216,7 +218,7 @@ public final class AndroidTestUtil {
// Log contents as well as writing to file, for easier visibility on individual device testing.
for (String line : Util.split(analysisContents, "\n")) {
Log.i(testId, line);
Log.i(TAG, testId + ": " + line);
}
File analysisFile = createExternalCacheFile(context, /* fileName= */ testId + "-result.txt");

View File

@ -26,6 +26,7 @@ import androidx.media3.common.Format;
import androidx.media3.common.MediaItem;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.SystemClock;
import androidx.media3.common.util.Util;
import androidx.test.platform.app.InstrumentationRegistry;
import java.io.File;
import java.io.IOException;
@ -40,7 +41,7 @@ import org.json.JSONObject;
/** An android instrumentation test runner for {@link Transformer}. */
public class TransformerAndroidTestRunner {
private static final String TAG_PREFIX = "TransformerAndroidTest_";
private static final String TAG = "TransformerAndroidTest";
/** The default transformation timeout value. */
public static final int DEFAULT_TIMEOUT_SECONDS = 120;
@ -299,7 +300,7 @@ public class TransformerAndroidTestRunner {
if (calculateSsim) {
double ssim =
SsimHelper.calculate(
context, /* expectedVideoPath= */ uriString, outputVideoFile.getPath());
context, /* referenceVideoPath= */ uriString, outputVideoFile.getPath());
resultBuilder.setSsim(ssim);
}
} catch (InterruptedException interruptedException) {
@ -308,15 +309,19 @@ public class TransformerAndroidTestRunner {
// TransformationTestResult.
throw interruptedException;
} catch (Throwable analysisFailure) {
// Catch all (checked and unchecked) failures throw by the SsimHelper and process them as
// part of the TransformationTestResult.
Exception analysisException =
analysisFailure instanceof Exception
? (Exception) analysisFailure
: new IllegalStateException(analysisFailure);
if (Util.SDK_INT == 21 && "Nexus 5".equals(Util.MODEL)) { // b/233584640
Log.i(TAG, testId + ": Skipping SSIM calculation due to known device-specific issue");
} else {
// Catch all (checked and unchecked) failures throw by the SsimHelper and process them as
// part of the TransformationTestResult.
Exception analysisException =
analysisFailure instanceof Exception
? (Exception) analysisFailure
: new IllegalStateException(analysisFailure);
resultBuilder.setAnalysisException(analysisException);
Log.e(TAG_PREFIX + testId, "SSIM calculation failed.", analysisException);
resultBuilder.setAnalysisException(analysisException);
Log.e(TAG, testId + ": SSIM calculation failed.", analysisException);
}
}
return resultBuilder.build();
}

View File

@ -60,7 +60,9 @@ public final class TranscodeQualityTest {
.build()
.run(testId, AndroidTestUtil.MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING);
assertThat(result.ssim).isGreaterThan(0.90);
if (result.ssim != TransformationTestResult.SSIM_UNSET) {
assertThat(result.ssim).isGreaterThan(0.90);
}
}
@Test
@ -92,7 +94,9 @@ public final class TranscodeQualityTest {
.build()
.run(testId, AndroidTestUtil.MP4_ASSET_WITH_INCREASING_TIMESTAMPS_URI_STRING);
assertThat(result.ssim).isGreaterThan(0.90);
if (result.ssim != TransformationTestResult.SSIM_UNSET) {
assertThat(result.ssim).isGreaterThan(0.90);
}
}
@Test
@ -119,6 +123,8 @@ public final class TranscodeQualityTest {
testId,
AndroidTestUtil.MP4_ASSET_WITH_INCREASING_TIMESTAMPS_320W_240H_15S_URI_STRING);
assertThat(result.ssim).isGreaterThan(0.90);
if (result.ssim != TransformationTestResult.SSIM_UNSET) {
assertThat(result.ssim).isGreaterThan(0.90);
}
}
}