Skip to content

Commit 0d8b1c1

Browse files
tmdsstephentoub
authored andcommitted
PosixSignalRegistrationTests.Unix: validate signal pal mapping (#58711)
* PosixSignalRegistrationTests.Unix: validate signal pal mapping * Use InvariantCulture for pid ToString * Invoke kill through shell. * Remove InvariantCulture
1 parent 7cbc169 commit 0d8b1c1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Xunit;
5+
using System.Diagnostics;
6+
using System.Globalization;
57
using System.Threading;
68
using System.Runtime.InteropServices;
79
using System.Runtime.CompilerServices;
@@ -57,7 +59,16 @@ public void SignalHandlerCalledForKnownSignals(PosixSignal s)
5759
semaphore.Release();
5860
});
5961

60-
kill(signal);
62+
// Use 'kill' command with signal name to validate the signal pal mapping.
63+
string sigArg = signalStr.StartsWith("SIG") ? signalStr.Substring(3) : signalStr;
64+
using var process = Process.Start(new ProcessStartInfo
65+
{
66+
FileName = "/bin/sh", // Use a shell because not all platforms include a 'kill' executable.
67+
ArgumentList = { "-c", $"kill -s {sigArg} {Environment.ProcessId.ToString()}" }
68+
});
69+
process.WaitForExit();
70+
Assert.Equal(0, process.ExitCode);
71+
6172
bool entered = semaphore.Wait(SuccessTimeout);
6273
Assert.True(entered);
6374
}, s.ToString()).Dispose();

0 commit comments

Comments
 (0)