dawn/test: Display an error message if toggles aren't recognised

Instead of cryptically crashing in release builds.

Change-Id: I22d222c6d6550010c3484e1f18397cef22602b92
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122384
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2023-03-03 11:21:52 +00:00 committed by Dawn LUCI CQ
parent ea1fc1daeb
commit b902e56ae7
2 changed files with 25 additions and 0 deletions

View File

@ -133,6 +133,10 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
std::unique_ptr<dawn::native::Instance> instance = CreateInstanceAndDiscoverAdapters(); std::unique_ptr<dawn::native::Instance> instance = CreateInstanceAndDiscoverAdapters();
ASSERT(instance); ASSERT(instance);
if (!ValidateToggles(instance.get())) {
return;
}
SelectPreferredAdapterProperties(instance.get()); SelectPreferredAdapterProperties(instance.get());
PrintTestConfigurationAndAdapterInfo(instance.get()); PrintTestConfigurationAndAdapterInfo(instance.get());
} }
@ -415,6 +419,23 @@ std::vector<AdapterTestParam> DawnTestEnvironment::GetAvailableAdapterTestParams
return testParams; return testParams;
} }
bool DawnTestEnvironment::ValidateToggles(dawn::native::Instance* instance) const {
dawn::LogMessage err = dawn::ErrorLog();
for (const std::string& toggle : GetEnabledToggles()) {
if (!instance->GetToggleInfo(toggle.c_str())) {
err << "unrecognized toggle: '" << toggle << "'\n";
return false;
}
}
for (const std::string& toggle : GetDisabledToggles()) {
if (!instance->GetToggleInfo(toggle.c_str())) {
err << "unrecognized toggle: '" << toggle << "'\n";
return false;
}
}
return true;
}
void DawnTestEnvironment::PrintTestConfigurationAndAdapterInfo( void DawnTestEnvironment::PrintTestConfigurationAndAdapterInfo(
dawn::native::Instance* instance) const { dawn::native::Instance* instance) const {
dawn::LogMessage log = dawn::InfoLog(); dawn::LogMessage log = dawn::InfoLog();

View File

@ -187,6 +187,10 @@ class DawnTestEnvironment : public testing::Environment {
void SelectPreferredAdapterProperties(const dawn::native::Instance* instance); void SelectPreferredAdapterProperties(const dawn::native::Instance* instance);
void PrintTestConfigurationAndAdapterInfo(dawn::native::Instance* instance) const; void PrintTestConfigurationAndAdapterInfo(dawn::native::Instance* instance) const;
/// @returns true if all the toggles are recognised, otherwise prints an error and returns
/// false.
bool ValidateToggles(dawn::native::Instance* instance) const;
bool mUseWire = false; bool mUseWire = false;
dawn::native::BackendValidationLevel mBackendValidationLevel = dawn::native::BackendValidationLevel mBackendValidationLevel =
dawn::native::BackendValidationLevel::Disabled; dawn::native::BackendValidationLevel::Disabled;