summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jordan Demeulenaere <jdemeulenaere@google.com> 2022-07-05 11:29:40 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2022-07-05 11:29:40 +0000
commitd17c4393dff83548ffdd9ddb479c0a33ebc19a2b (patch)
tree91b74d006b4324cef8bf524df4d9220e361c04b9
parent54866bd7cf6990bc7c9d1c78809fca77d2b231ae (diff)
parentfc528523817f2db4d4d0361a74015c45b0ff5cbf (diff)
Merge changes from topic "cf-pixel-perfect-matching" into tm-qpr-dev am: 692d4e65c9 am: fc52852381
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19148787 Change-Id: I04fedd5a299c94c88df600bf66e35e6cf39768e9 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ScreenshotTestRule.kt21
1 files changed, 19 insertions, 2 deletions
diff --git a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ScreenshotTestRule.kt b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ScreenshotTestRule.kt
index 363ce10fa36c..564901c2a773 100644
--- a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ScreenshotTestRule.kt
+++ b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ScreenshotTestRule.kt
@@ -20,6 +20,7 @@ import android.app.UiModeManager
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
+import android.os.Build
import android.os.UserHandle
import android.view.Display
import android.view.View
@@ -32,6 +33,7 @@ import platform.test.screenshot.GoldenImagePathManager
import platform.test.screenshot.PathConfig
import platform.test.screenshot.PathElementNoContext
import platform.test.screenshot.ScreenshotTestRule
+import platform.test.screenshot.matchers.MSSIMMatcher
import platform.test.screenshot.matchers.PixelPerfectMatcher
/**
@@ -55,7 +57,11 @@ class ScreenshotTestRule(private val testSpec: ScreenshotTestSpec) : TestRule {
currentDisplay?.name ?: error("currentDisplay is null")
},
)
- private val defaultMatcher = PixelPerfectMatcher()
+ private val matcher = if (shouldUsePerfectMatching()) {
+ PixelPerfectMatcher()
+ } else {
+ MSSIMMatcher()
+ }
private val screenshotRule =
ScreenshotTestRule(
@@ -67,6 +73,17 @@ class ScreenshotTestRule(private val testSpec: ScreenshotTestSpec) : TestRule {
)
)
+ private fun shouldUsePerfectMatching(): Boolean {
+ // Different CPU architectures can sometimes end up rendering differently, so we can't do
+ // pixel-perfect matching on different architectures using the same golden. Given that our
+ // presubmits are run on cf_x86_64_phone, our goldens should be perfectly matched on the
+ // x86_64 architecture and use the Structural Similarity Index on others.
+ // TODO(b/237511747): Run our screenshot presubmit tests on arm64 instead so that we can
+ // do pixel perfect matching both at presubmit time and at development time with actual
+ // devices.
+ return Build.CPU_ABI == "x86_64"
+ }
+
override fun apply(base: Statement, description: Description): Statement {
// The statement which call beforeTest() before running the test and afterTest() afterwards.
val statement =
@@ -147,7 +164,7 @@ class ScreenshotTestRule(private val testSpec: ScreenshotTestSpec) : TestRule {
// device to assertBitmapAgainstGolden instead?
currentDisplay = testSpec.display
currentGoldenIdentifier = goldenIdentifier
- screenshotRule.assertBitmapAgainstGolden(bitmap, identifierWithSpec, defaultMatcher)
+ screenshotRule.assertBitmapAgainstGolden(bitmap, identifierWithSpec, matcher)
currentDisplay = null
currentGoldenIdentifier = goldenIdentifier
}