From 90f74bd4027d523b30eb6c2f809d7b142810bccf Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 4 Jul 2022 10:45:01 +0200 Subject: [PATCH] Improve error handling in DeviceExtensions --- .../ComputeSharp.Tests/Extensions/DeviceExtensions.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/ComputeSharp.Tests/Extensions/DeviceExtensions.cs b/tests/ComputeSharp.Tests/Extensions/DeviceExtensions.cs index 3996fa5e..983083bb 100644 --- a/tests/ComputeSharp.Tests/Extensions/DeviceExtensions.cs +++ b/tests/ComputeSharp.Tests/Extensions/DeviceExtensions.cs @@ -20,13 +20,20 @@ public static class DeviceExtensions GraphicsDevice? device = type switch { Device.Discrete => GraphicsDevice.QueryDevices(info => info.IsHardwareAccelerated).FirstOrDefault(), - Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).First(), + Device.Warp => GraphicsDevice.QueryDevices(info => !info.IsHardwareAccelerated).FirstOrDefault(), _ => ThrowHelper.ThrowArgumentException("Invalid device.") }; if (device is null) { - Assert.Inconclusive(); + // If the device is null, fail only if the device was WARP (as it should always be available). + // If a dedicated device was requested instead, just report the test as inconclusive (no GPU). + switch (type) + { + case Device.Discrete: Assert.Inconclusive(); break; + case Device.Warp: Assert.Fail(); break; + } + } return device!;