DawnTest: Use last adapter on Metal

This is a temporary workaround to make sure we test the correct adapter
on the macOS builders: on multi-GPU systems the integrated is always
listed first so we would previously only test on Intel.

However we can't change the logic for D3D12 becaue the correct adapter
is the first one.

The proper fix for this is to pass the requested PCI device and vendor
ID to dawn_end2end_tests so it can select the correct adapter, but this
requires PCI IDs to be correct with Metal, which requires rolling the
macOS 10.13 SDK in Chromium.

BUG=dawn:109

Change-Id: Ice33367b0b8850306785b10a2dafc2f68d8b84d7
Reviewed-on: https://dawn-review.googlesource.com/c/5041
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp
index 42bad7e..cc667e4 100644
--- a/src/tests/DawnTest.cpp
+++ b/src/tests/DawnTest.cpp
@@ -249,15 +249,22 @@
     {
         dawn_native::Instance* instance = gTestEnv->GetInstance();
         std::vector<dawn_native::Adapter> adapters = instance->GetAdapters();
-        auto adapterIt = std::find_if(adapters.begin(), adapters.end(),
-                                      [this](const dawn_native::Adapter adapter) -> bool {
-                                          // Chromium's GTest harness has GetParam() as a regular
-                                          // function and not a member function of this.
-                                          DAWN_UNUSED(this);
-                                          return adapter.GetBackendType() == GetParam();
-                                      });
-        ASSERT(adapterIt != adapters.end());
-        backendAdapter = *adapterIt;
+
+        for (const dawn_native::Adapter& adapter : adapters) {
+            if (adapter.GetBackendType() == GetParam()) {
+                backendAdapter = adapter;
+                // On Metal, select the last adapter so that the discrete GPU is tested on
+                // multi-GPU systems.
+                // TODO(cwallez@chromium.org): Replace this with command line arguments requesting
+                // a specific device / vendor ID once the macOS 10.13 SDK is rolled and correct
+                // PCI info collection is implemented on Metal.
+                if (GetParam() != MetalBackend) {
+                    break;
+                }
+            }
+        }
+
+        ASSERT(backendAdapter);
     }
 
     mPCIInfo = backendAdapter.GetPCIInfo();