[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:
@@ -12,11 +12,16 @@ namespace impeller {
|
|||||||
|
|
||||||
static std::atomic_int32_t sValidationLogsDisabledCount = 0;
|
static std::atomic_int32_t sValidationLogsDisabledCount = 0;
|
||||||
static std::atomic_int32_t sValidationLogsAreFatal = 0;
|
static std::atomic_int32_t sValidationLogsAreFatal = 0;
|
||||||
|
static ValidationFailureCallback sValidationFailureCallback;
|
||||||
|
|
||||||
void ImpellerValidationErrorsSetFatal(bool fatal) {
|
void ImpellerValidationErrorsSetFatal(bool fatal) {
|
||||||
sValidationLogsAreFatal = fatal;
|
sValidationLogsAreFatal = fatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImpellerValidationErrorsSetCallback(ValidationFailureCallback callback) {
|
||||||
|
sValidationFailureCallback = std::move(callback);
|
||||||
|
}
|
||||||
|
|
||||||
ScopedValidationDisable::ScopedValidationDisable() {
|
ScopedValidationDisable::ScopedValidationDisable() {
|
||||||
sValidationLogsDisabledCount++;
|
sValidationLogsDisabledCount++;
|
||||||
}
|
}
|
||||||
@@ -47,6 +52,10 @@ std::ostream& ValidationLog::GetStream() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ImpellerValidationBreak(const char* message, const char* file, int line) {
|
void ImpellerValidationBreak(const char* message, const char* file, int line) {
|
||||||
|
if (sValidationFailureCallback &&
|
||||||
|
sValidationFailureCallback(message, file, line)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const auto severity =
|
const auto severity =
|
||||||
ImpellerValidationErrorsAreFatal() ? fml::LOG_FATAL : fml::LOG_ERROR;
|
ImpellerValidationErrorsAreFatal() ? fml::LOG_FATAL : fml::LOG_ERROR;
|
||||||
auto fml_log = fml::LogMessage{severity, file, line, nullptr};
|
auto fml_log = fml::LogMessage{severity, file, line, nullptr};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#ifndef FLUTTER_IMPELLER_BASE_VALIDATION_H_
|
#ifndef FLUTTER_IMPELLER_BASE_VALIDATION_H_
|
||||||
#define FLUTTER_IMPELLER_BASE_VALIDATION_H_
|
#define FLUTTER_IMPELLER_BASE_VALIDATION_H_
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
namespace impeller {
|
namespace impeller {
|
||||||
@@ -37,6 +38,21 @@ void ImpellerValidationErrorsSetFatal(bool fatal);
|
|||||||
|
|
||||||
bool ImpellerValidationErrorsAreFatal();
|
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 {
|
struct ScopedValidationDisable {
|
||||||
ScopedValidationDisable();
|
ScopedValidationDisable();
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,26 @@
|
|||||||
namespace impeller {
|
namespace impeller {
|
||||||
|
|
||||||
PlaygroundTest::PlaygroundTest()
|
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 {
|
namespace {
|
||||||
bool DoesSupportWideGamutTests() {
|
bool DoesSupportWideGamutTests() {
|
||||||
@@ -36,8 +53,6 @@ void PlaygroundTest::SetUp() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImpellerValidationErrorsSetFatal(true);
|
|
||||||
|
|
||||||
// Test names that end with "WideGamut" will render with wide gamut support.
|
// Test names that end with "WideGamut" will render with wide gamut support.
|
||||||
std::string test_name = flutter::testing::GetCurrentTestName();
|
std::string test_name = flutter::testing::GetCurrentTestName();
|
||||||
PlaygroundSwitches switches = switches_;
|
PlaygroundSwitches switches = switches_;
|
||||||
|
|||||||
Reference in New Issue
Block a user