From 131bc5fdce71507ec5434eea49c75a5e4c685165 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 13 Aug 2019 13:21:14 +0200 Subject: [PATCH] Added test for multi GPU --- .../InitializationTests.cs | 42 +++++++++++++++++++ tests/ComputeSharp.NetCore.Tests/MiscTests.cs | 17 -------- 2 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 tests/ComputeSharp.NetCore.Tests/InitializationTests.cs delete mode 100644 tests/ComputeSharp.NetCore.Tests/MiscTests.cs diff --git a/tests/ComputeSharp.NetCore.Tests/InitializationTests.cs b/tests/ComputeSharp.NetCore.Tests/InitializationTests.cs new file mode 100644 index 00000000..4e3b4c0f --- /dev/null +++ b/tests/ComputeSharp.NetCore.Tests/InitializationTests.cs @@ -0,0 +1,42 @@ +using System; +using System.Linq; +using ComputeSharp.Graphics; +using ComputeSharp.Graphics.Buffers; +using ComputeSharp.NetCore.Tests.Extensions; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace ComputeSharp.NetCore.Tests +{ + [TestClass] + [TestCategory("Initialization")] + public class InitializationTests + { + [TestMethod] + public void CheckIsSupportedAndGetDefaultDevice() + { + if (Gpu.IsSupported) Assert.IsNotNull(Gpu.Default); + else Assert.ThrowsException(() => Gpu.Default); + } + + [TestMethod] + public void RunShaderOnAllDevices() + { + foreach (GraphicsDevice gpu in Gpu.EnumerateDevices()) + { + using (ReadWriteBuffer buffer = gpu.AllocateReadWriteBuffer(100)) + { + Action action = id => buffer[id.X] = id.X; + + gpu.For(100, action); + + float[] array = buffer.GetData(); + float[] expected = Enumerable.Range(0, 100).Select(i => (float)i).ToArray(); + + Assert.IsTrue(array.AsSpan().ContentEquals(expected)); + } + + gpu.Dispose(); + } + } + } +} diff --git a/tests/ComputeSharp.NetCore.Tests/MiscTests.cs b/tests/ComputeSharp.NetCore.Tests/MiscTests.cs deleted file mode 100644 index 76ba23c8..00000000 --- a/tests/ComputeSharp.NetCore.Tests/MiscTests.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace ComputeSharp.NetCore.Tests -{ - [TestClass] - [TestCategory("Misc")] - public class MiscTests - { - [TestMethod] - public void CheckIsSupportedAndGetDefaultDevice() - { - if (Gpu.IsSupported) Assert.IsNotNull(Gpu.Default); - else Assert.ThrowsException(() => Gpu.Default); - } - } -}