mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[Impeller] Validation errors in tests cause GTest failures. (flutter/engine#53786)
Earlier, this used to take down the entire process. Now, the entire set of failures will be listed instead.
This commit is contained in:
parent
8d233c3b90
commit
e4f189806b
@ -12,11 +12,16 @@ namespace impeller {
|
||||
|
||||
static std::atomic_int32_t sValidationLogsDisabledCount = 0;
|
||||
static std::atomic_int32_t sValidationLogsAreFatal = 0;
|
||||
static ValidationFailureCallback sValidationFailureCallback;
|
||||
|
||||
void ImpellerValidationErrorsSetFatal(bool fatal) {
|
||||
sValidationLogsAreFatal = fatal;
|
||||
}
|
||||
|
||||
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback) {
|
||||
sValidationFailureCallback = std::move(callback);
|
||||
}
|
||||
|
||||
ScopedValidationDisable::ScopedValidationDisable() {
|
||||
sValidationLogsDisabledCount++;
|
||||
}
|
||||
@ -47,6 +52,10 @@ std::ostream& ValidationLog::GetStream() {
|
||||
}
|
||||
|
||||
void ImpellerValidationBreak(const char* message, const char* file, int line) {
|
||||
if (sValidationFailureCallback &&
|
||||
sValidationFailureCallback(message, file, line)) {
|
||||
return;
|
||||
}
|
||||
const auto severity =
|
||||
ImpellerValidationErrorsAreFatal() ? fml::LOG_FATAL : fml::LOG_ERROR;
|
||||
auto fml_log = fml::LogMessage{severity, file, line, nullptr};
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#ifndef FLUTTER_IMPELLER_BASE_VALIDATION_H_
|
||||
#define FLUTTER_IMPELLER_BASE_VALIDATION_H_
|
||||
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
|
||||
namespace impeller {
|
||||
@ -37,6 +38,21 @@ void ImpellerValidationErrorsSetFatal(bool fatal);
|
||||
|
||||
bool ImpellerValidationErrorsAreFatal();
|
||||
|
||||
using ValidationFailureCallback =
|
||||
std::function<bool(const char* message, const char* file, int line)>;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
/// @brief Sets a callback that callers (usually tests) can set to
|
||||
/// intercept validation failures.
|
||||
///
|
||||
/// Returning true from the callback indicates that Impeller can
|
||||
/// continue and avoid any default behavior on tripping validation
|
||||
/// (which could include process termination).
|
||||
///
|
||||
/// @param[in] callback The callback
|
||||
///
|
||||
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback);
|
||||
|
||||
struct ScopedValidationDisable {
|
||||
ScopedValidationDisable();
|
||||
|
||||
|
||||
@ -11,9 +11,26 @@
|
||||
namespace impeller {
|
||||
|
||||
PlaygroundTest::PlaygroundTest()
|
||||
: Playground(PlaygroundSwitches{flutter::testing::GetArgsForProcess()}) {}
|
||||
: Playground(PlaygroundSwitches{flutter::testing::GetArgsForProcess()}) {
|
||||
ImpellerValidationErrorsSetCallback(
|
||||
[](const char* message, const char* file, int line) -> bool {
|
||||
// GTEST_MESSAGE_AT_ can only be used in a function that returns void.
|
||||
// Hence the goofy lambda. The failure message and location will still
|
||||
// be correct however.
|
||||
//
|
||||
// https://google.github.io/googletest/advanced.html#assertion-placement
|
||||
[message, file, line]() -> void {
|
||||
GTEST_MESSAGE_AT_(file, line, "Impeller Validation Error",
|
||||
::testing::TestPartResult::kFatalFailure)
|
||||
<< message;
|
||||
}();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
PlaygroundTest::~PlaygroundTest() = default;
|
||||
PlaygroundTest::~PlaygroundTest() {
|
||||
ImpellerValidationErrorsSetCallback(nullptr);
|
||||
}
|
||||
|
||||
namespace {
|
||||
bool DoesSupportWideGamutTests() {
|
||||
@ -36,8 +53,6 @@ void PlaygroundTest::SetUp() {
|
||||
return;
|
||||
}
|
||||
|
||||
ImpellerValidationErrorsSetFatal(true);
|
||||
|
||||
// Test names that end with "WideGamut" will render with wide gamut support.
|
||||
std::string test_name = flutter::testing::GetCurrentTestName();
|
||||
PlaygroundSwitches switches = switches_;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user