]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
ts/kill/decode: consider arch dependent signum/name association
authorMasatake YAMATO <yamato@redhat.com>
Fri, 10 Oct 2025 20:41:25 +0000 (05:41 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Fri, 10 Oct 2025 21:19:39 +0000 (06:19 +0900)
In the original code, the signal bits passed to the decode test were
sampled on x86_64. As reported in #3774, the association between signal
number and its name is architecture dependent.

With this change, the test case calculates the signal bits from signal
names at runtime instead of hardcoding.

Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Link: https://github.com/util-linux/util-linux/issues/3774
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/expected/kill/decode
tests/ts/kill/decode

index 74783ad8529c4f0f2f861ba53f8af6675280db35..421037772b0469acd6b68e222e729a45bb8f1249 100644 (file)
@@ -1,17 +1,17 @@
-decode "0x00000000000044aa":
+encode-decode round-trip "INT ILL ABRT FPE SEGV TERM":
 INT
 ILL
 ABRT
 FPE
 SEGV
 TERM
-decode "0x0000000000003015":
+encode-decode round-trip "HUP QUIT TRAP PIPE ALRM":
 HUP
 QUIT
 TRAP
 PIPE
 ALRM
-decode "0x0000000000000200":
+encode-decode round-trip "USR1":
 USR1
 Pending (thread): INT ILL 
 Pending (process): USR1 
index 524b4e5e26ee365d8b20298abdf3242efb6f3173..cc3471afa8937eafd6fddac7421fb97d657cd69a 100755 (executable)
@@ -32,16 +32,52 @@ ts_check_test_command "$TS_HELPER_SIGSTATE"
 
 decode()
 {
-    echo decode "\"$1\":"
     "$TS_CMD_KILL" -l "$1"
 }
 
+signame2num()
+{
+    local name=$1
+    local n s
+
+    "$TS_CMD_KILL" -L | while read n s; do
+       if [[ "$s" == "$name" ]]; then
+           echo "$n"
+           return 0
+       fi
+    done
+
+    return 1
+}
+
+encode()
+{
+    local s
+    local n
+    local -i bits=0
+
+    for s in "$@"; do
+       n=$(signame2num "$s")
+       if [[ -z "$n" ]]; then
+           ts_log_both "failed to encode the signal name: $s"
+           # The test may fail.
+           continue
+       fi
+
+       (( bits |= 1 << (n - 1) ))
+    done
+
+    printf "0x%0.16x\n" "$bits"
+}
+
 PID=
 ACK=
 {
-    for d in 0x00000000000044aa \
-                0x0000000000003015 \
-                0x0000000000000200; do
+    for siglist in "INT ILL ABRT FPE SEGV TERM" \
+                      "HUP QUIT TRAP PIPE ALRM" \
+                      "USR1"; do
+       printf 'encode-decode round-trip "%s":\n' "${siglist}"
+       d=$(encode ${siglist})
        decode "$d"
     done