From b902e56ae7de006f7e865e95240a515e74449b9d Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Fri, 3 Mar 2023 11:21:52 +0000 Subject: [PATCH] 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 Commit-Queue: Ben Clayton Reviewed-by: Austin Eng Kokoro: Kokoro --- src/dawn/tests/DawnTest.cpp | 21 +++++++++++++++++++++ src/dawn/tests/DawnTest.h | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp index 7b118e83b2..18f12f57db 100644 --- a/src/dawn/tests/DawnTest.cpp +++ b/src/dawn/tests/DawnTest.cpp @@ -133,6 +133,10 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) { std::unique_ptr instance = CreateInstanceAndDiscoverAdapters(); ASSERT(instance); + if (!ValidateToggles(instance.get())) { + return; + } + SelectPreferredAdapterProperties(instance.get()); PrintTestConfigurationAndAdapterInfo(instance.get()); } @@ -415,6 +419,23 @@ std::vector DawnTestEnvironment::GetAvailableAdapterTestParams 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( dawn::native::Instance* instance) const { dawn::LogMessage log = dawn::InfoLog(); diff --git a/src/dawn/tests/DawnTest.h b/src/dawn/tests/DawnTest.h index a254710252..f8a8afc04a 100644 --- a/src/dawn/tests/DawnTest.h +++ b/src/dawn/tests/DawnTest.h @@ -187,6 +187,10 @@ class DawnTestEnvironment : public testing::Environment { void SelectPreferredAdapterProperties(const dawn::native::Instance* instance); 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; dawn::native::BackendValidationLevel mBackendValidationLevel = dawn::native::BackendValidationLevel::Disabled;