Skip to content

Commit 168d109

Browse files
Return failure code when SafeHandle tests fail. (#48083)
* Return failure code when SafeHandle tests fail. * Disable SafeHandle tests on mono. * Handle platform specific exception type.
1 parent ed32f68 commit 168d109

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/tests/Interop/PInvoke/SafeHandles/InvalidSafeHandleMarshallingTests.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,29 @@ public class InvalidSafeHandleMarshallingTests
1212
{
1313
public static void RunTest()
1414
{
15-
Assert.Throws<InvalidOperationException>(() => SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle()));
15+
if (TestLibrary.Utilities.IsWindows)
16+
{
17+
// The interface marshaller is only available when COM interop is
18+
// enabled. The interface marshaller is what initiates the COM
19+
// interop system which is what subsequently defines defined exception
20+
// type to throw - matches .NET Framework behavior. At present support
21+
// is limited to Windows so we branch on that.
22+
Assert.Throws<InvalidOperationException>(() => MarshalSafeHandleAsInterface());
23+
}
24+
else
25+
{
26+
// When the interface marshaller is not available we fallback to
27+
// the marshalling system which will throw a different exception.
28+
Assert.Throws<MarshalDirectiveException>(() => MarshalSafeHandleAsInterface());
29+
}
30+
1631
Assert.Throws<MarshalDirectiveException>(() => SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle[1]));
1732
Assert.Throws<TypeLoadException>(() => SafeHandleNative.SafeHandle_Invalid(new SafeHandleNative.StructWithSafeHandleArray()));
1833
}
34+
35+
static void MarshalSafeHandleAsInterface()
36+
{
37+
SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle());
38+
}
1939
}
2040
}

src/tests/Interop/PInvoke/SafeHandles/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public static int Main(string[] args)
2626
catch (Exception ex)
2727
{
2828
Console.WriteLine(ex.ToString());
29+
return 101;
2930
}
31+
3032
return 100;
3133
}
3234
}

src/tests/issues.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,9 @@
12061206
<ExcludeList Include="$(XunitTestBinBase)/Interop/PInvoke/Generics/GenericsTest/GenericsTest/**">
12071207
<Issue>needs triage</Issue>
12081208
</ExcludeList>
1209+
<ExcludeList Include="$(XunitTestBinBase)/Interop/PInvoke/SafeHandles/**">
1210+
<Issue>https://github.com/dotnet/runtime/issues/48084</Issue>
1211+
</ExcludeList>
12091212
<ExcludeList Include="$(XunitTestBinBase)/Interop/PInvoke/SizeParamIndex/PInvoke/Invalid/InvalidParamIndex/**">
12101213
<Issue>needs triage</Issue>
12111214
</ExcludeList>

0 commit comments

Comments
 (0)