Skip to content

Commit 302a563

Browse files
janvorliCopilot
andauthored
Fix unhandled exception test for interpreter (#121397)
The test was accepting only 0xc0000005 as an exit code for NullReferenceException. But in the interpreter case, the exception is thrown using COMPlusThrow(kNullReferenceException) and gets the error code of regular managed exception, the 0xE0434352. This change updates the test to accept that one too and adds verification that the exception message contains the System.NullReferenceException to make sure the tested app didn't exit due to some other exception. --------- Co-authored-by: Copilot <[email protected]>
1 parent 177eff3 commit 302a563

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

src/tests/baseservices/exceptions/unhandled/unhandledTester.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,47 @@ static void RunExternalProcess(string unhandledType, string assembly)
4040
Console.WriteLine($"Test process {assembly} with argument {unhandledType} exited");
4141
testProcess.CancelErrorRead();
4242

43-
int expectedExitCode;
43+
int[] expectedExitCodes;
4444
if (TestLibrary.Utilities.IsMonoRuntime)
4545
{
46-
expectedExitCode = 1;
46+
expectedExitCodes = new[] { 1 };
4747
}
4848
else if (!OperatingSystem.IsWindows())
4949
{
50-
expectedExitCode = 128 + 6; // SIGABRT
50+
expectedExitCodes = new[] { 128 + 6 }; // SIGABRT
5151
}
5252
else if (TestLibrary.Utilities.IsNativeAot)
5353
{
54-
expectedExitCode = unchecked((int)0xC0000409);
54+
expectedExitCodes = new[] { unchecked((int)0xC0000409) };
5555
}
5656
else
5757
{
5858
if (unhandledType.EndsWith("hardware"))
5959
{
6060
// Null reference exception code
61-
expectedExitCode = unchecked((int)0xC0000005);
61+
expectedExitCodes = new[] { unchecked((int)0xC0000005), unchecked((int)0xE0434352) };
6262
}
6363
else if (unhandledType == "collecteddelegate")
6464
{
6565
// Fail fast exit code
66-
expectedExitCode = unchecked((int)0x80131623);
66+
expectedExitCodes = new[] { unchecked((int)0x80131623) };
6767
}
6868
else
6969
{
70-
expectedExitCode = unchecked((int)0xE0434352);
70+
expectedExitCodes = new[] { unchecked((int)0xE0434352) };
7171
}
7272
}
7373

74-
if (expectedExitCode != testProcess.ExitCode)
74+
if (!Array.Exists(expectedExitCodes, code => testProcess.ExitCode == code))
7575
{
76-
throw new Exception($"Wrong exit code 0x{testProcess.ExitCode:X8}, expected 0x{expectedExitCode:X8}");
76+
string separator = string.Empty;
77+
StringBuilder expectedListBuilder = new StringBuilder();
78+
Array.ForEach(expectedExitCodes, code =>
79+
{
80+
expectedListBuilder.Append($"{separator}0x{code:X8}");
81+
separator = " or ";
82+
});
83+
throw new Exception($"Wrong exit code: 0x{testProcess.ExitCode:X8}, expected {expectedListBuilder}");
7784
}
7885

7986
int exceptionStackFrameLine = 1;
@@ -97,6 +104,13 @@ static void RunExternalProcess(string unhandledType, string assembly)
97104
throw new Exception("Missing exception type and message");
98105
}
99106
}
107+
else if (unhandledType.EndsWith("hardware"))
108+
{
109+
if (!lines[1].StartsWith("System.NullReferenceException: Object reference not set to an instance of an object"))
110+
{
111+
throw new Exception("Missing exception type and message");
112+
}
113+
}
100114

101115
exceptionStackFrameLine = 2;
102116
}

0 commit comments

Comments
 (0)