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>
-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
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