[release/6.0] The signal enum in the native library should match the managed code...
authorgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Wed, 8 Sep 2021 01:40:01 +0000 (19:40 -0600)
committerGitHub <noreply@github.com>
Wed, 8 Sep 2021 01:40:01 +0000 (19:40 -0600)
* The signal enum in the native library should match the managed code.

* PosixSignalRegistrationTests.Unix: validate signal pal mapping (#58711)

* PosixSignalRegistrationTests.Unix: validate signal pal mapping

* Use InvariantCulture for pid ToString

* Invoke kill through shell.

* Remove InvariantCulture

Co-authored-by: James Truher <jimtru@microsoft.com>
Co-authored-by: Tom Deseyn <tom.deseyn@gmail.com>
src/libraries/Native/Unix/System.Native/pal_signal.h
src/libraries/System.Runtime.InteropServices/tests/System/Runtime/InteropServices/PosixSignalRegistrationTests.Unix.cs

index 146fdab..c3c2100 100644 (file)
@@ -40,8 +40,8 @@ typedef enum
     PosixSignalSIGQUIT = -3,
     PosixSignalSIGTERM = -4,
     PosixSignalSIGCHLD = -5,
-    PosixSignalSIGWINCH = -6,
-    PosixSignalSIGCONT = -7,
+    PosixSignalSIGCONT = -6,
+    PosixSignalSIGWINCH = -7,
     PosixSignalSIGTTIN = -8,
     PosixSignalSIGTTOU = -9,
     PosixSignalSIGTSTP = -10
index 4b0c9fc..f844b4d 100644 (file)
@@ -2,6 +2,8 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using Xunit;
+using System.Diagnostics;
+using System.Globalization;
 using System.Threading;
 using System.Runtime.InteropServices;
 using System.Runtime.CompilerServices;
@@ -57,7 +59,16 @@ namespace System.Tests
                     semaphore.Release();
                 });
 
-                kill(signal);
+                // Use 'kill' command with signal name to validate the signal pal mapping.
+                string sigArg = signalStr.StartsWith("SIG") ? signalStr.Substring(3) : signalStr;
+                using var process = Process.Start(new ProcessStartInfo
+                    {
+                        FileName = "/bin/sh", // Use a shell because not all platforms include a 'kill' executable.
+                        ArgumentList = { "-c", $"kill -s {sigArg} {Environment.ProcessId.ToString()}" }
+                    });
+                process.WaitForExit();
+                Assert.Equal(0, process.ExitCode);
+
                 bool entered = semaphore.Wait(SuccessTimeout);
                 Assert.True(entered);
             }, s.ToString()).Dispose();