From eb06b44b11acc8260cbe9cbbff390b51eb6053b9 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sat, 11 Oct 2025 05:41:25 +0900 Subject: [PATCH] ts/kill/decode: consider arch dependent signum/name association 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 Link: https://github.com/util-linux/util-linux/issues/3774 Signed-off-by: Masatake YAMATO --- tests/expected/kill/decode | 6 +++--- tests/ts/kill/decode | 44 ++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/tests/expected/kill/decode b/tests/expected/kill/decode index 74783ad85..421037772 100644 --- a/tests/expected/kill/decode +++ b/tests/expected/kill/decode @@ -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 diff --git a/tests/ts/kill/decode b/tests/ts/kill/decode index 524b4e5e2..cc3471afa 100755 --- a/tests/ts/kill/decode +++ b/tests/ts/kill/decode @@ -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 -- 2.47.3