This repository was archived by the owner on Feb 25, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +44
-4
lines changed Expand file tree Collapse file tree 3 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,16 @@ namespace impeller {
1212
1313static std::atomic_int32_t sValidationLogsDisabledCount = 0 ;
1414static std::atomic_int32_t sValidationLogsAreFatal = 0 ;
15+ static ValidationFailureCallback sValidationFailureCallback ;
1516
1617void ImpellerValidationErrorsSetFatal (bool fatal) {
1718 sValidationLogsAreFatal = fatal;
1819}
1920
21+ void ImpellerValidationErrorsSetCallback (ValidationFailureCallback callback) {
22+ sValidationFailureCallback = std::move (callback);
23+ }
24+
2025ScopedValidationDisable::ScopedValidationDisable () {
2126 sValidationLogsDisabledCount ++;
2227}
@@ -47,6 +52,10 @@ std::ostream& ValidationLog::GetStream() {
4752}
4853
4954void ImpellerValidationBreak (const char * message, const char * file, int line) {
55+ if (sValidationFailureCallback &&
56+ sValidationFailureCallback (message, file, line)) {
57+ return ;
58+ }
5059 const auto severity =
5160 ImpellerValidationErrorsAreFatal () ? fml::LOG_FATAL : fml::LOG_ERROR;
5261 auto fml_log = fml::LogMessage{severity, file, line, nullptr };
Original file line number Diff line number Diff line change 55#ifndef FLUTTER_IMPELLER_BASE_VALIDATION_H_
66#define FLUTTER_IMPELLER_BASE_VALIDATION_H_
77
8+ #include < functional>
89#include < sstream>
910
1011namespace impeller {
@@ -37,6 +38,21 @@ void ImpellerValidationErrorsSetFatal(bool fatal);
3738
3839bool ImpellerValidationErrorsAreFatal ();
3940
41+ using ValidationFailureCallback =
42+ std::function<bool (const char * message, const char * file, int line)>;
43+
44+ // ------------------------------------------------------------------------------
45+ // / @brief Sets a callback that callers (usually tests) can set to
46+ // / intercept validation failures.
47+ // /
48+ // / Returning true from the callback indicates that Impeller can
49+ // / continue and avoid any default behavior on tripping validation
50+ // / (which could include process termination).
51+ // /
52+ // / @param[in] callback The callback
53+ // /
54+ void ImpellerValidationErrorsSetCallback (ValidationFailureCallback callback);
55+
4056struct ScopedValidationDisable {
4157 ScopedValidationDisable ();
4258
Original file line number Diff line number Diff line change 1111namespace impeller {
1212
1313PlaygroundTest::PlaygroundTest ()
14- : Playground(PlaygroundSwitches{flutter::testing::GetArgsForProcess ()}) {}
14+ : Playground(PlaygroundSwitches{flutter::testing::GetArgsForProcess ()}) {
15+ ImpellerValidationErrorsSetCallback (
16+ [](const char * message, const char * file, int line) -> bool {
17+ // GTEST_MESSAGE_AT_ can only be used in a function that returns void.
18+ // Hence the goofy lambda. The failure message and location will still
19+ // be correct however.
20+ //
21+ // https://google.github.io/googletest/advanced.html#assertion-placement
22+ [message, file, line]() -> void {
23+ GTEST_MESSAGE_AT_ (file, line, " Impeller Validation Error" ,
24+ ::testing::TestPartResult::kFatalFailure )
25+ << message;
26+ }();
27+ return true ;
28+ });
29+ }
1530
16- PlaygroundTest::~PlaygroundTest () = default ;
31+ PlaygroundTest::~PlaygroundTest () {
32+ ImpellerValidationErrorsSetCallback (nullptr );
33+ }
1734
1835namespace {
1936bool DoesSupportWideGamutTests () {
@@ -36,8 +53,6 @@ void PlaygroundTest::SetUp() {
3653 return ;
3754 }
3855
39- ImpellerValidationErrorsSetFatal (true );
40-
4156 // Test names that end with "WideGamut" will render with wide gamut support.
4257 std::string test_name = flutter::testing::GetCurrentTestName ();
4358 PlaygroundSwitches switches = switches_;
You can’t perform that action at this time.
0 commit comments