From 2f1d57241393d53e41e4b92fc526f9c6c0e12fdb Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 30 Dec 2021 23:17:13 +0100 Subject: [PATCH] Add more parallel unit tests for ComputeContext --- .../ComputeSharp.Tests/ComputeContextTests.cs | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/tests/ComputeSharp.Tests/ComputeContextTests.cs b/tests/ComputeSharp.Tests/ComputeContextTests.cs index a4a3e4ff..de3d1a04 100644 --- a/tests/ComputeSharp.Tests/ComputeContextTests.cs +++ b/tests/ComputeSharp.Tests/ComputeContextTests.cs @@ -485,6 +485,13 @@ public partial class ComputeContextTests Validate(); } + [CombinatorialTestMethod] + [AllDevices] + public async Task ForAndForEach_Async_Batched_WithTaskRun(Device device) + { + await Task.Run(() => ForAndForEach_Async_Batched(device)); + } + [CombinatorialTestMethod] [AllDevices] public async Task ForAndForEach_Async_Batched_Parallel(Device device) @@ -500,6 +507,51 @@ public partial class ComputeContextTests await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => TestAsync(device))); } + [CombinatorialTestMethod] + [AllDevices] + public async Task ForAndForEach_Async_Batched_Parallel_WithConfigureAwait(Device device) + { + async Task TestAsync(Device device) + { + for (int i = 0; i < 20; i++) + { + await ForAndForEach_Async_Batched(device).ConfigureAwait(false); + } + } + + await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => TestAsync(device))); + } + + [CombinatorialTestMethod] + [AllDevices] + public async Task ForAndForEach_Async_Batched_Parallel_WithTaskRun(Device device) + { + async Task TestAsync(Device device) + { + for (int i = 0; i < 20; i++) + { + await ForAndForEach_Async_Batched(device); + } + } + + await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => Task.Run(() => TestAsync(device)))); + } + + [CombinatorialTestMethod] + [AllDevices] + public async Task ForAndForEach_Async_Batched_Parallel_WithConfigureAwaitAndTaskRun(Device device) + { + async Task TestAsync(Device device) + { + for (int i = 0; i < 20; i++) + { + await ForAndForEach_Async_Batched(device).ConfigureAwait(false); + } + } + + await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => Task.Run(() => TestAsync(device)))); + } + [CombinatorialTestMethod] [AllDevices] public async Task ForAndForEach_Async_Batched_Parallel_Multiple(Device device) @@ -519,6 +571,63 @@ public partial class ComputeContextTests await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => TestAsync(device))); } + [CombinatorialTestMethod] + [AllDevices] + public async Task ForAndForEach_Async_Batched_Parallel_Multiple_WithConfigureAwait(Device device) + { + async Task TestAsync(Device device) + { + for (int i = 0; i < 10; i++) + { + Task task1 = ForAndForEach_Async_Batched(device); + Task task2 = ForAndForEach_Async_Batched(device); + Task task3 = ForAndForEach_Async_Batched(device); + + await Task.WhenAll(task1, task2, task3).ConfigureAwait(false); + } + } + + await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => TestAsync(device))); + } + + [CombinatorialTestMethod] + [AllDevices] + public async Task ForAndForEach_Async_Batched_Parallel_Multiple_WithTaskRun(Device device) + { + async Task TestAsync(Device device) + { + for (int i = 0; i < 10; i++) + { + Task task1 = ForAndForEach_Async_Batched(device); + Task task2 = ForAndForEach_Async_Batched(device); + Task task3 = ForAndForEach_Async_Batched(device); + + await Task.WhenAll(task1, task2, task3); + } + } + + await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => Task.Run(() => TestAsync(device)))); + } + + [CombinatorialTestMethod] + [AllDevices] + public async Task ForAndForEach_Async_Batched_Parallel_Multiple_WithConfigureAwaitAndTaskRun(Device device) + { + async Task TestAsync(Device device) + { + for (int i = 0; i < 10; i++) + { + Task task1 = ForAndForEach_Async_Batched(device); + Task task2 = ForAndForEach_Async_Batched(device); + Task task3 = ForAndForEach_Async_Batched(device); + + await Task.WhenAll(task1, task2, task3).ConfigureAwait(false); + } + } + + await Task.WhenAll(Enumerable.Range(0, 64).Select(_ => Task.Run(() => TestAsync(device)))); + } + [CombinatorialTestMethod] [AllDevices] [ExpectedException(typeof(InvalidOperationException), AllowDerivedTypes = false)]