From 4260e227dc9b638c896dab9ae3852f29f218136c Mon Sep 17 00:00:00 2001 From: Chris Yang Date: Tue, 19 Sep 2023 12:54:00 -0700 Subject: [PATCH] [ios]Adjust golden test threshold for TwoPlatformViewsWithOtherBackDropFilterTests based on current macOS version (flutter/engine#45891) TwoPlatformViewsWithOtherBackDropFilterTests is failing on macOS 13 with the same simulator version used in macOS 12. The image diff looks identical and slightly above the threshold. This PR adjusts the threshold for this test temporarily so our CI can run on both macOS 13 and 12. This change can be reverted when we move all our CI to macOS 13 Fixes https://github.com/flutter/flutter/issues/134740 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../ios/Scenarios/ScenariosUITests/BogusFontTextTest.m | 2 +- .../ios/Scenarios/ScenariosUITests/GoldenImage.h | 2 +- .../ios/Scenarios/ScenariosUITests/GoldenImage.m | 8 +++----- .../Scenarios/ScenariosUITests/GoldenPlatformViewTests.h | 1 + .../Scenarios/ScenariosUITests/GoldenPlatformViewTests.m | 3 ++- .../ios/Scenarios/ScenariosUITests/GoldenTestManager.h | 3 ++- .../ios/Scenarios/ScenariosUITests/GoldenTestManager.m | 5 +++-- .../ios/Scenarios/ScenariosUITests/PlatformViewUITests.m | 5 +++++ .../ios/Scenarios/ScenariosUITests/SpawnEngineTest.m | 2 +- 9 files changed, 19 insertions(+), 12 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/BogusFontTextTest.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/BogusFontTextTest.m index 14c9e0bb93..dc554ae2e5 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/BogusFontTextTest.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/BogusFontTextTest.m @@ -25,7 +25,7 @@ FLUTTER_ASSERT_ARC XCTAssertTrue([addTextField waitForExistenceWithTimeout:30]); GoldenTestManager* manager = [[GoldenTestManager alloc] initWithLaunchArg:@"--bogus-font-text"]; - [manager checkGoldenForTest:self]; + [manager checkGoldenForTest:self rmesThreshold:kDefaultRmseThreshold]; } @end diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.h b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.h index dead0c530e..4c0b9306fe 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.h +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.h @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN // Compare this GoldenImage to `image`. // // Return YES if the `image` of this GoldenImage have the same pixels of provided `image`. -- (BOOL)compareGoldenToImage:(UIImage*)image; +- (BOOL)compareGoldenToImage:(UIImage*)image rmesThreshold:(double)rmesThreshold; @end diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.m index 698207aa68..37ae7b70fb 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.m @@ -8,8 +8,6 @@ #import #include -static const double kRmseThreshold = 0.5; - @interface GoldenImage () @end @@ -28,7 +26,7 @@ static const double kRmseThreshold = 0.5; return self; } -- (BOOL)compareGoldenToImage:(UIImage*)image { +- (BOOL)compareGoldenToImage:(UIImage*)image rmesThreshold:(double)rmesThreshold { if (!self.image || !image) { os_log_error(OS_LOG_DEFAULT, "GOLDEN DIFF FAILED: image does not exists."); return NO; @@ -91,11 +89,11 @@ static const double kRmseThreshold = 0.5; } } double rmse = sqrt(sum / size); - if (rmse > kRmseThreshold) { + if (rmse > rmesThreshold) { os_log_error( OS_LOG_DEFAULT, "GOLDEN DIFF FAILED: image diff greater than threshold. Current diff: %@, threshold: %@", - @(rmse), @(kRmseThreshold)); + @(rmse), @(rmesThreshold)); return NO; } return YES; diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.h b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.h index fd1b05ef0b..625fbf8b31 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.h +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.h @@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GoldenPlatformViewTests : XCTestCase @property(nonatomic, strong) XCUIApplication* application; +@property(nonatomic, assign) double rmseThreadhold; // Initialize with a `GoldenTestManager`. - (instancetype)initWithManager:(GoldenTestManager*)manager invocation:(NSInvocation*)invocation; diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.m index 7e4bb368fc..7199fa2600 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.m @@ -22,6 +22,7 @@ static const NSInteger kSecondsToWaitForPlatformView = 30; - (instancetype)initWithManager:(GoldenTestManager*)manager invocation:(NSInvocation*)invocation { self = [super initWithInvocation:invocation]; _manager = manager; + _rmseThreadhold = kDefaultRmseThreshold; return self; } @@ -45,6 +46,6 @@ static const NSInteger kSecondsToWaitForPlatformView = 30; @(kSecondsToWaitForPlatformView)); } - [self.manager checkGoldenForTest:self]; + [self.manager checkGoldenForTest:self rmesThreshold:self.rmseThreadhold]; } @end diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.h b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.h index 4bb0b275a7..7026672af7 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.h +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.h @@ -9,6 +9,7 @@ NS_ASSUME_NONNULL_BEGIN extern NSDictionary* launchArgsMap; +const extern double kDefaultRmseThreshold; // Manages a `GoldenPlatformViewTests`. // @@ -27,7 +28,7 @@ extern NSDictionary* launchArgsMap; // Take a sceenshot of the test app and check it has the same pixels with // goldenImage inside the `GoldenTestManager`. -- (void)checkGoldenForTest:(XCTestCase*)test; +- (void)checkGoldenForTest:(XCTestCase*)test rmesThreshold:(double)rmesThreshold; @end diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m index 76c95a0650..a8d966379a 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenTestManager.m @@ -14,6 +14,7 @@ @implementation GoldenTestManager NSDictionary* launchArgsMap; +const double kDefaultRmseThreshold = 0.5; - (instancetype)initWithLaunchArg:(NSString*)launchArg { self = [super init]; @@ -73,7 +74,7 @@ NSDictionary* launchArgsMap; return self; } -- (void)checkGoldenForTest:(XCTestCase*)test { +- (void)checkGoldenForTest:(XCTestCase*)test rmesThreshold:(double)rmesThreshold { XCUIScreenshot* screenshot = [[XCUIScreen mainScreen] screenshot]; if (!_goldenImage.image) { XCTAttachment* attachment = [XCTAttachment attachmentWithScreenshot:screenshot]; @@ -88,7 +89,7 @@ NSDictionary* launchArgsMap; _goldenImage.goldenName); } - if (![_goldenImage compareGoldenToImage:screenshot.image]) { + if (![_goldenImage compareGoldenToImage:screenshot.image rmesThreshold:rmesThreshold]) { XCTAttachment* screenshotAttachment = [XCTAttachment attachmentWithImage:screenshot.image]; screenshotAttachment.name = [_goldenImage.goldenName stringByAppendingString:@"_actual.png"]; screenshotAttachment.lifetime = XCTAttachmentLifetimeKeepAlways; diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m index 03984f27fd..7415a51717 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/PlatformViewUITests.m @@ -375,6 +375,11 @@ static const NSInteger kSecondsToWaitForPlatformView = 30; } - (void)testPlatformView { + // (TODO)cyanglaz: remove the threshold adjustment after all the ci migrates to macOS13. + // https://github.com/flutter/flutter/issues/133207 + if ([NSProcessInfo processInfo].operatingSystemVersion.majorVersion >= 13) { + self.rmseThreadhold = 0.7; + } [self checkPlatformViewGolden]; } diff --git a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/SpawnEngineTest.m b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/SpawnEngineTest.m index f00a8c988b..cc5810eeac 100644 --- a/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/SpawnEngineTest.m +++ b/engine/src/flutter/testing/scenario_app/ios/Scenarios/ScenariosUITests/SpawnEngineTest.m @@ -21,7 +21,7 @@ GoldenTestManager* manager = [[GoldenTestManager alloc] initWithLaunchArg:@"--spawn-engine-works"]; - [manager checkGoldenForTest:self]; + [manager checkGoldenForTest:self rmesThreshold:kDefaultRmseThreshold]; } @end