From 74ed8ebed6c4e15c74380d0ad32f089a4e0b2623 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:05:34 -0700 Subject: [PATCH] [Impeller] started asserting golden test runner has fatal impeller validations (flutter/engine#51357) fixes https://github.com/flutter/flutter/issues/145017 This works by removing the conditional compilation for validation and turning them to be fatal in the test runner's main. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style [testing the engine]: https://github.com/flutter/flutter/wiki/Testing-the-engine [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat --- engine/src/flutter/impeller/base/validation.cc | 11 ++++++++--- engine/src/flutter/impeller/base/validation.h | 8 ++------ engine/src/flutter/impeller/golden_tests/main.cc | 8 ++++++++ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/engine/src/flutter/impeller/base/validation.cc b/engine/src/flutter/impeller/base/validation.cc index d68aa6d888..d95a84c811 100644 --- a/engine/src/flutter/impeller/base/validation.cc +++ b/engine/src/flutter/impeller/base/validation.cc @@ -46,17 +46,22 @@ std::ostream& ValidationLog::GetStream() { } void ImpellerValidationBreak(const char* message) { -// Nothing to do. Exists for the debugger. -#ifdef IMPELLER_ENABLE_VALIDATION std::stringstream stream; +#if FLUTTER_RELEASE + stream << "Impeller validation: " << message; +#else stream << "Break on '" << __FUNCTION__ << "' to inspect point of failure: " << message; +#endif if (sValidationLogsAreFatal > 0) { FML_LOG(FATAL) << stream.str(); } else { FML_LOG(ERROR) << stream.str(); } -#endif // IMPELLER_ENABLE_VALIDATION +} + +bool ImpellerValidationErrorsAreFatal() { + return sValidationLogsAreFatal; } } // namespace impeller diff --git a/engine/src/flutter/impeller/base/validation.h b/engine/src/flutter/impeller/base/validation.h index a015686c06..6d3ca3a52d 100644 --- a/engine/src/flutter/impeller/base/validation.h +++ b/engine/src/flutter/impeller/base/validation.h @@ -5,12 +5,6 @@ #ifndef FLUTTER_IMPELLER_BASE_VALIDATION_H_ #define FLUTTER_IMPELLER_BASE_VALIDATION_H_ -#ifndef IMPELLER_ENABLE_VALIDATION -#ifdef IMPELLER_DEBUG -#define IMPELLER_ENABLE_VALIDATION 1 -#endif -#endif - #include namespace impeller { @@ -39,6 +33,8 @@ void ImpellerValidationBreak(const char* message); void ImpellerValidationErrorsSetFatal(bool fatal); +bool ImpellerValidationErrorsAreFatal(); + struct ScopedValidationDisable { ScopedValidationDisable(); diff --git a/engine/src/flutter/impeller/golden_tests/main.cc b/engine/src/flutter/impeller/golden_tests/main.cc index e1ed2a8c4e..4791f3818a 100644 --- a/engine/src/flutter/impeller/golden_tests/main.cc +++ b/engine/src/flutter/impeller/golden_tests/main.cc @@ -8,6 +8,7 @@ #include "flutter/fml/build_config.h" #include "flutter/fml/command_line.h" #include "flutter/fml/logging.h" +#include "flutter/impeller/base/validation.h" #include "flutter/impeller/golden_tests/golden_digest.h" #include "flutter/impeller/golden_tests/working_directory.h" #include "gtest/gtest.h" @@ -24,7 +25,14 @@ void print_usage() { } } // namespace +namespace impeller { +TEST(ValidationTest, IsFatal) { + EXPECT_TRUE(ImpellerValidationErrorsAreFatal()); +} +} // namespace impeller + int main(int argc, char** argv) { + impeller::ImpellerValidationErrorsSetFatal(true); fml::InstallCrashHandler(); testing::InitGoogleTest(&argc, argv); fml::CommandLine cmd = fml::CommandLineFromPlatformOrArgcArgv(argc, argv);