Skip to content

Commit

Permalink
Fixed failing unit tests when run in DEBUG configuration. (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoFtZ authored Mar 2, 2023
1 parent 24f0b0a commit ed4c169
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions Src/ILGPU.Tests/KernelEntryPoints.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ---------------------------------------------------------------------------------------
// ILGPU
// Copyright (c) 2021 ILGPU Project
// Copyright (c) 2021-2023 ILGPU Project
// www.ilgpu.net
//
// File: KernelEntryPoints.cs
Expand Down Expand Up @@ -510,6 +510,27 @@ public void LocalCapturingLambdaIndex3EntryPoint(int length)
Execute(kernel.Method, extent, buffer.View, extent));
}

private static void VerifyStaticFieldCapturingLambdaException(
InternalCompilerException e)
{
// We would normally expect that a lambda that captures a static field would
// throw a NotSupportedException. However, in DEBUG build configuration, the
// the Method Builder is never marked as completed, and when running in
// VisualStudio, a second exception is thrown from a failed Debug.Assert.
// Deal with both expectations, so that unit tests pass in DEBUG mode when
// running in VisualStudio.
#if DEBUG
if (e.InnerException is not NotSupportedException)
{
Assert.Equal(
"Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException",
e.InnerException?.GetType().FullName);
return;
}
#endif
Assert.IsType<NotSupportedException>(e.InnerException);
}

[Theory]
[InlineData(33)]
[InlineData(1025)]
Expand All @@ -524,7 +545,7 @@ public void StaticFieldCapturingLambdaIndex1EntryPoint(int length)
using var buffer = Accelerator.Allocate1D<int>(length);
var e = Assert.Throws<InternalCompilerException>(() =>
Execute(kernel.Method, new Index1D((int)buffer.Length), buffer.View));
Assert.IsType<NotSupportedException>(e.InnerException);
VerifyStaticFieldCapturingLambdaException(e);
}

[Theory]
Expand All @@ -543,7 +564,7 @@ public void StaticFieldCapturingLambdaIndex2EntryPoint(int length)
using var buffer = Accelerator.Allocate1D<int>(extent.Size);
var e = Assert.Throws<InternalCompilerException>(() =>
Execute(kernel.Method, extent, buffer.View, extent));
Assert.IsType<NotSupportedException>(e.InnerException);
VerifyStaticFieldCapturingLambdaException(e);
}

[Theory]
Expand All @@ -562,7 +583,7 @@ public void StaticFieldCapturingLambdaIndex3EntryPoint(int length)
using var buffer = Accelerator.Allocate1D<int>(extent.Size);
var e = Assert.Throws<InternalCompilerException>(() =>
Execute(kernel.Method, extent, buffer.View, extent));
Assert.IsType<NotSupportedException>(e.InnerException);
VerifyStaticFieldCapturingLambdaException(e);
}

[KernelName("My @ CustomKernel.Name12345 [1211]")]
Expand Down

0 comments on commit ed4c169

Please sign in to comment.