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>
diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp
index 7b118e8..18f12f5 100644
--- a/src/dawn/tests/DawnTest.cpp
+++ b/src/dawn/tests/DawnTest.cpp
@@ -133,6 +133,10 @@
     std::unique_ptr<dawn::native::Instance> instance = CreateInstanceAndDiscoverAdapters();
     ASSERT(instance);
 
+    if (!ValidateToggles(instance.get())) {
+        return;
+    }
+
     SelectPreferredAdapterProperties(instance.get());
     PrintTestConfigurationAndAdapterInfo(instance.get());
 }
@@ -415,6 +419,23 @@
     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 a254710..f8a8afc0 100644
--- a/src/dawn/tests/DawnTest.h
+++ b/src/dawn/tests/DawnTest.h
@@ -187,6 +187,10 @@
     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;