Skip to content

Return failure code when SafeHandle tests fail. #48083

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
3 commits merged into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,29 @@ public class InvalidSafeHandleMarshallingTests
{
public static void RunTest()
{
Assert.Throws<InvalidOperationException>(() => SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle()));
if (TestLibrary.Utilities.IsWindows)
{
// The interface marshaller is only available when COM interop is
// enabled. The interface marshaller is what initiates the COM
// interop system which is what subsequently defines defined exception
// type to throw - matches .NET Framework behavior. At present support
// is limited to Windows so we branch on that.
Assert.Throws<InvalidOperationException>(() => MarshalSafeHandleAsInterface());
}
else
{
// When the interface marshaller is not available we fallback to
// the marshalling system which will throw a different exception.
Assert.Throws<MarshalDirectiveException>(() => MarshalSafeHandleAsInterface());
}

Assert.Throws<MarshalDirectiveException>(() => SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle[1]));
Assert.Throws<TypeLoadException>(() => SafeHandleNative.SafeHandle_Invalid(new SafeHandleNative.StructWithSafeHandleArray()));
}

static void MarshalSafeHandleAsInterface()
{
SafeHandleNative.SafeHandle_Invalid(new TestSafeHandle());
}
}
}
2 changes: 2 additions & 0 deletions src/tests/Interop/PInvoke/SafeHandles/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public static int Main(string[] args)
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return 101;
}

return 100;
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/tests/issues.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,9 @@
<ExcludeList Include="$(XunitTestBinBase)/Interop/PInvoke/Generics/GenericsTest/GenericsTest/**">
<Issue>needs triage</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/Interop/PInvoke/SafeHandles/**">
<Issue>https://github.com/dotnet/runtime/issues/48084</Issue>
</ExcludeList>
<ExcludeList Include="$(XunitTestBinBase)/Interop/PInvoke/SizeParamIndex/PInvoke/Invalid/InvalidParamIndex/**">
<Issue>needs triage</Issue>
</ExcludeList>
Expand Down