From: Masatake YAMATO Date: Tue, 24 Feb 2026 17:58:02 +0000 (+0900) Subject: tests: (lsfd::*) revise the way to use "$?" X-Git-Tag: v2.43-devel~46^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96ede0703b3585470fe512a5ed8f292e04832028;p=thirdparty%2Futil-linux.git tests: (lsfd::*) revise the way to use "$?" * Don't use $? for printing the result of if-conditions; use literals instead (0 or 1). * Don' use $? for referring to the result of wait built-in; store the result to $RC just after the wait built-in invocation. * Use ${PIPESTATUS[]} instead of $?. Signed-off-by: Masatake YAMATO --- diff --git a/tests/ts/lsfd/column-ainodeclass b/tests/ts/lsfd/column-ainodeclass index ab2abebd6..01b5d6891 100755 --- a/tests/ts/lsfd/column-ainodeclass +++ b/tests/ts/lsfd/column-ainodeclass @@ -29,8 +29,10 @@ ts_cd "$TS_OUTDIR" PID= FD=3 EXPR="(FD == 3)" +RC= for C in pidfd inotify; do + RC= ts_init_subtest $C { coproc MKFDS { "$TS_HELPER_MKFDS" $C $FD ; } @@ -41,9 +43,10 @@ for C in pidfd inotify; do echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 - if [ "$C-$?" == "pidfd-$TS_EXIT_NOTSUPP" ]; then + if [ "$C-$RC" == "pidfd-$TS_EXIT_NOTSUPP" ]; then ts_skip_subtest "pidfd_open(2) is not available" continue fi diff --git a/tests/ts/lsfd/column-name b/tests/ts/lsfd/column-name index 9c67de889..00b47c6bb 100755 --- a/tests/ts/lsfd/column-name +++ b/tests/ts/lsfd/column-name @@ -30,6 +30,7 @@ ts_cd "$TS_OUTDIR" PID= FD=3 EXPR="(FD == 3)" +RC= make_state_connected() { @@ -41,6 +42,7 @@ make_state_connected() } for C in ro-regular-file pidfd socketpair; do + RC= ts_init_subtest $C { coproc MKFDS { @@ -64,8 +66,9 @@ for C in ro-regular-file pidfd socketpair; do fi } > "$TS_OUTPUT" 2>&1 wait "${MKFDS_PID}" + RC=$? - if [ "$C-$?" == "pidfd-$TS_EXIT_NOTSUPP" ]; then + if [ "$C-$RC" == "pidfd-$TS_EXIT_NOTSUPP" ]; then ts_skip_subtest "pidfd_open(2) is not available" continue fi diff --git a/tests/ts/lsfd/column-type b/tests/ts/lsfd/column-type index 1b8aa8c6f..73dab873a 100755 --- a/tests/ts/lsfd/column-type +++ b/tests/ts/lsfd/column-type @@ -29,8 +29,10 @@ ts_cd "$TS_OUTDIR" PID= FD=3 EXPR="(FD == 3)" +RC= for C in ro-regular-file pidfd inotify socketpair; do + RC= ts_init_subtest $C { coproc MKFDS { @@ -49,9 +51,10 @@ for C in ro-regular-file pidfd inotify socketpair; do echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 - if [ "$C-$?" == "pidfd-$TS_EXIT_NOTSUPP" ]; then + if [ "$C-$RC" == "pidfd-$TS_EXIT_NOTSUPP" ]; then ts_skip_subtest "pidfd_open(2) is not available" continue fi diff --git a/tests/ts/lsfd/column-xmode b/tests/ts/lsfd/column-xmode index 1e719a4a5..048be3b5d 100755 --- a/tests/ts/lsfd/column-xmode +++ b/tests/ts/lsfd/column-xmode @@ -131,6 +131,7 @@ ts_init_subtest "XMODE-D-bit" wait "${MKFDS_PID}" ts_finalize_subtest +RC= for m in flock-sh posix-r- ofd-r-; do ts_init_subtest "XMODE-l-bit-$m" { @@ -143,7 +144,8 @@ for m in flock-sh posix-r- ofd-r-; do fi } > "$TS_OUTPUT" 2>&1 wait "${MKFDS_PID}" - if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then + RC=$? + if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then ts_skip_subtest "$m lock is not available" continue fi @@ -165,6 +167,7 @@ wait "${MKFDS_PID}" rm -f "$f" ts_finalize_subtest +RC= for m in flock-ex posix--w posix-rw ofd--w ofd-rw lease-w; do ts_init_subtest "XMODE-L-bit-$m" { @@ -177,7 +180,8 @@ for m in flock-ex posix--w posix-rw ofd--w ofd-rw lease-w; do fi } > "$TS_OUTPUT" 2>&1 wait "${MKFDS_PID}" - if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then + RC=$? + if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then ts_skip_subtest "$m lock is not available" continue fi diff --git a/tests/ts/lsfd/filter-floating-point-nums b/tests/ts/lsfd/filter-floating-point-nums index 7f66dd51d..f7d137592 100755 --- a/tests/ts/lsfd/filter-floating-point-nums +++ b/tests/ts/lsfd/filter-floating-point-nums @@ -39,9 +39,9 @@ EXPR= echo "pid in a range:" $? if [[ "${PID_0}" == "${PID}" ]]; then - echo "coparing pids": $? + echo "coparing pids": 0 else - echo "coparing pids": $? "PID_0:${PID_0} == PID:${PID}" + echo "coparing pids": 1 "PID_0:${PID_0} == PID:${PID}" fi EXPR='(TIMERFD.INTERVAL < 10.000051) and (TIMERFD.INTERVAL > 10)' diff --git a/tests/ts/lsfd/mkfds-bpf-map b/tests/ts/lsfd/mkfds-bpf-map index 7821fe506..d4fb8e7af 100755 --- a/tests/ts/lsfd/mkfds-bpf-map +++ b/tests/ts/lsfd/mkfds-bpf-map @@ -31,6 +31,8 @@ ts_cd "$TS_OUTDIR" PID= FD=3 NAME=mkfds_map +RC= + { coproc MKFDS { "$TS_HELPER_MKFDS" bpf-map "$FD" map-type-id=2 name="$NAME"; } if read -r -u "${MKFDS[0]}" PID; then @@ -40,9 +42,10 @@ NAME=mkfds_map echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 -if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then +if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then ts_skip "bpf(2) is not available" fi diff --git a/tests/ts/lsfd/mkfds-bpf-prog b/tests/ts/lsfd/mkfds-bpf-prog index 1ec4cbf8f..c7ef895e4 100755 --- a/tests/ts/lsfd/mkfds-bpf-prog +++ b/tests/ts/lsfd/mkfds-bpf-prog @@ -33,6 +33,8 @@ ID= TAG= FD=3 NAME=mkdfs_prog +RC= + { coproc MKFDS { "$TS_HELPER_MKFDS" bpf-prog "$FD" prog-type-id=2 name="$NAME"; } if read -r -u "${MKFDS[0]}" PID ID TAG; then @@ -56,9 +58,10 @@ NAME=mkdfs_prog echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 -if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then +if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then ts_skip "bpf(2) is not available" fi diff --git a/tests/ts/lsfd/mkfds-cdev-tun b/tests/ts/lsfd/mkfds-cdev-tun index 5848f18bd..f69874010 100755 --- a/tests/ts/lsfd/mkfds-cdev-tun +++ b/tests/ts/lsfd/mkfds-cdev-tun @@ -68,12 +68,12 @@ cdev_tun_test() output=$(${TS_CMD_LSFD} -p "${PID}" -n --raw -o NAME -Q "${EXPR}") if [[ "$output" =~ "iface=$IFNAME"(\\x20devnetns=$netns)? ]]; then - echo 'NAME': $? + echo 'NAME': 0 if [[ -n "${BASH_REMATCH[1]}" ]]; then devnetns_available=yes fi else - echo 'NAME': $? + echo 'NAME': 1 echo "expected NAME: iface=$IFNAME" echo "output NAME: $output" echo "netns: $netns" @@ -81,9 +81,9 @@ cdev_tun_test() output=$(${TS_CMD_LSFD} -p "${PID}" -n --raw -o TUN.IFACE -Q "${EXPR}") if [[ "$output" == "$IFNAME" ]]; then - echo 'TUN.IFACE': $? + echo 'TUN.IFACE': 0 else - echo 'TUN.IFACE': $? + echo 'TUN.IFACE': 1 echo "expected TUN.IFACE: $IFNAME" echo "output TUN.IFACE: $output" fi @@ -98,9 +98,9 @@ cdev_tun_test() { output=$(${TS_CMD_LSFD} -p "${PID}" -n --raw -o TUN.DEVNETNS -Q "${EXPR}") if [[ "$output" == "$netns" ]]; then - echo 'TUN.DEVNETNS': $? + echo 'TUN.DEVNETNS': 0 else - echo 'TUN.DEVNETNS': $? + echo 'TUN.DEVNETNS': 1 echo "expected TUN.DEVNETNS: $netns" echo "output TUN.DEVNETNS: $output" fi diff --git a/tests/ts/lsfd/mkfds-directory b/tests/ts/lsfd/mkfds-directory index 272bdb387..2e0ac24c0 100755 --- a/tests/ts/lsfd/mkfds-directory +++ b/tests/ts/lsfd/mkfds-directory @@ -71,7 +71,7 @@ esac cat fi } - echo 'ASSOC,MODE,TYPE,FLAGS,NAME': $? + echo 'ASSOC,MODE,TYPE,FLAGS,NAME': ${PIPESTATUS[0]} LSFD_PID=$(${TS_CMD_LSFD} --raw -n -o PID -Q "${EXPR}") echo 'PID[RUN]:' $? diff --git a/tests/ts/lsfd/mkfds-eventfd b/tests/ts/lsfd/mkfds-eventfd index 02c86a604..d21b11252 100755 --- a/tests/ts/lsfd/mkfds-eventfd +++ b/tests/ts/lsfd/mkfds-eventfd @@ -60,25 +60,25 @@ ENDPOINTS= echo 'child: ID': $? if [ "${NAME0}" == "${NAME1}" ]; then - echo 'NAME[STR]:' $? + echo 'NAME[STR]:' 0 else - echo 'NAME[STR]:' $? + echo 'NAME[STR]:' 1 echo NAME0: "${NAME0}" echo NAME1: "${NAME1}" fi if [ "${ID0}" == "${ID1}" ]; then - echo 'ID[STR]:' $? + echo 'ID[STR]:' 0 else - echo 'ID[STR]:' $? + echo 'ID[STR]:' 1 echo ID0: "${ID0}" echo ID0: "${ID1}" fi if [ "${NAME0}" == "id=${ID1}" ]; then - echo 'NAMExID[STR]:' $? + echo 'NAMExID[STR]:' 0 else - echo 'NAMExID[STR]:' $? + echo 'NAMExID[STR]:' 1 echo NAME0: "${NAME0}" echo ID0: "${ID0}" fi @@ -89,9 +89,9 @@ ENDPOINTS= "$PID0" "$FD0" "$PID1" "$FD1" \ "$PID1" "$FD1" "$PID0" "$FD0") if [ "$ENDPOINTS" == "$tmp" ]; then - echo 'ENDPOINTS[STR]:' $? + echo 'ENDPOINTS[STR]:' 0 else - echo 'ENDPOINTS[STR]:' $? + echo 'ENDPOINTS[STR]:' 1 echo 'ENDPOINTS:' "$ENDPOINTS" echo 'lsfd:' "$tmp" fi diff --git a/tests/ts/lsfd/mkfds-foreign-sockets b/tests/ts/lsfd/mkfds-foreign-sockets index 76138a7a6..2fabdb4e5 100755 --- a/tests/ts/lsfd/mkfds-foreign-sockets +++ b/tests/ts/lsfd/mkfds-foreign-sockets @@ -41,6 +41,7 @@ PID= NETNS= FD0=3 FD1=4 +RC= { coproc MKFDS { "$TS_HELPER_MKFDS" foreign-sockets $FD0 $FD1 ; } @@ -74,8 +75,9 @@ FD1=4 echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 -if [[ "$?" == "$EPERM" ]]; then +if [[ "$RC" == "$EPERM" ]]; then ts_skip "unshare(2) is not permitted on this platform" fi diff --git a/tests/ts/lsfd/mkfds-netlink-groups b/tests/ts/lsfd/mkfds-netlink-groups index b7646c228..f16e6d1be 100755 --- a/tests/ts/lsfd/mkfds-netlink-groups +++ b/tests/ts/lsfd/mkfds-netlink-groups @@ -33,6 +33,7 @@ EXPR='(TYPE == "NETLINK") and (FD == 3)' NETLINK_PROTOCOL=4 NETLINK_LPORT= NETLINK_GROUPS=5 +RC= { coproc MKFDS { "$TS_HELPER_MKFDS" netlink $FD protocol=$NETLINK_PROTOCOL groups=$NETLINK_GROUPS; } @@ -50,9 +51,10 @@ NETLINK_GROUPS=5 echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 -if [[ $? == "$EPROTONOSUPPORT" ]]; then +if [[ $RC == "$EPROTONOSUPPORT" ]]; then ts_skip "It seems that this platform doesn't support making a netlink socket" fi diff --git a/tests/ts/lsfd/mkfds-netlink-protocol b/tests/ts/lsfd/mkfds-netlink-protocol index abf2eb2ca..9c1496601 100755 --- a/tests/ts/lsfd/mkfds-netlink-protocol +++ b/tests/ts/lsfd/mkfds-netlink-protocol @@ -32,6 +32,7 @@ EXPR='(TYPE == "NETLINK") and (FD == 3)' NETLINK_PROTOCOL=4 NETLINK_LPORT= NETLINK_GROUPS=5 +RC= { coproc MKFDS { "$TS_HELPER_MKFDS" netlink $FD protocol=$NETLINK_PROTOCOL; } @@ -49,9 +50,10 @@ NETLINK_GROUPS=5 echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 -if [[ $? == "$EPROTONOSUPPORT" ]]; then +if [[ $RC == "$EPROTONOSUPPORT" ]]; then ts_skip "It seems that this platform doesn't support making a netlink socket" fi diff --git a/tests/ts/lsfd/mkfds-netns b/tests/ts/lsfd/mkfds-netns index 0fbaec88f..ddd68deb0 100755 --- a/tests/ts/lsfd/mkfds-netns +++ b/tests/ts/lsfd/mkfds-netns @@ -35,6 +35,7 @@ NAME_FD= NAME_NS= INO_FD= INO_NS= +RC= { coproc MKFDS { "$TS_HELPER_MKFDS" netns "$FD"; } if read -r -u "${MKFDS[0]}" PID; then @@ -45,28 +46,29 @@ INO_NS= INO_NS=$( "${TS_CMD_LSFD}" -n -oINODE -p "${PID}" -Q '(ASSOC == "net")') if [[ "$NAME_FD" = "$NAME_NS" ]]; then - echo "NAME_FD" == "NAME_NS": $? + echo "NAME_FD" == "NAME_NS": 0 else - echo "NAME_FD: $NAME_FD" == "NAME_NS: $NAME_NS": $? + echo "NAME_FD: $NAME_FD" == "NAME_NS: $NAME_NS": 1 fi if [[ "$NAME_FD" = "net:[$INO_FD]" ]]; then - echo "NAME_FD" == "net:[INO_FD]": $? + echo "NAME_FD" == "net:[INO_FD]": 0 else - echo "NAME_FD: $NAME_FD" == "net:[INO_FD: $INO_FD]": $? + echo "NAME_FD: $NAME_FD" == "net:[INO_FD: $INO_FD]": 1 fi if [[ "$NAME_FD" = "net:[$INO_NS]" ]]; then - echo "NAME_FD" == "net:[INO_NS]": $? + echo "NAME_FD" == "net:[INO_NS]": 0 else - echo "NAME_FD: $NAME_FD" == "net:[INO_NS: $INO_NS]": $? + echo "NAME_FD: $NAME_FD" == "net:[INO_NS: $INO_NS]": 1 fi echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 -if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then +if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then ts_skip "ioctl(fd, SIOCGSKNS) is not available" fi diff --git a/tests/ts/lsfd/mkfds-pidfd b/tests/ts/lsfd/mkfds-pidfd index 9b0ff33c6..9370d337c 100755 --- a/tests/ts/lsfd/mkfds-pidfd +++ b/tests/ts/lsfd/mkfds-pidfd @@ -33,6 +33,7 @@ PID= FD=3 TARGET=1 EXPR="(PID != ${TARGET}) and (FD == 3) and (PIDFD.PID == ${TARGET})" +RC= { coproc MKFDS { "$TS_HELPER_MKFDS" pidfd $FD target-pid=${TARGET} ; } @@ -43,9 +44,10 @@ EXPR="(PID != ${TARGET}) and (FD == 3) and (PIDFD.PID == ${TARGET})" echo DONE >&"${MKFDS[1]}" fi wait ${MKFDS_PID} + RC=$? } > $TS_OUTPUT 2>&1 -if [ "$?" == "$TS_EXIT_NOTSUPP" ]; then +if [ "$RC" == "$TS_EXIT_NOTSUPP" ]; then ts_skip "pidfd_open(2) is not available" fi diff --git a/tests/ts/lsfd/mkfds-pipe-no-fork b/tests/ts/lsfd/mkfds-pipe-no-fork index f2f950a87..d3ca46c3b 100755 --- a/tests/ts/lsfd/mkfds-pipe-no-fork +++ b/tests/ts/lsfd/mkfds-pipe-no-fork @@ -85,7 +85,7 @@ EXPR= expected=$(printf '%s\n%s' "${line0}" "${line1}") if [ "${LSFD_ENDPOINTS}" == "${expected}" ]; then - echo 'ENDPOINTS[STR]:' $? + echo 'ENDPOINTS[STR]:' 0 else echo "lsfd output:" echo "${LSFD_ENDPOINTS}" diff --git a/tests/ts/lsfd/mkfds-unix-in-netns b/tests/ts/lsfd/mkfds-unix-in-netns index 2df604029..3078adf31 100755 --- a/tests/ts/lsfd/mkfds-unix-in-netns +++ b/tests/ts/lsfd/mkfds-unix-in-netns @@ -35,6 +35,7 @@ FDALTNS=4 FDSOCK=5 EXPR='((TYPE == "UNIX") or (TYPE == "UNIX-STREAM")) and (FD == 5)' +RC= compare_net_namespaces() { @@ -65,6 +66,7 @@ strip_type_stream() } for t in stream dgram seqpacket; do + RC= ts_init_subtest "$t" { coproc MKFDS { "$TS_HELPER_MKFDS" unix-in-netns $FDSELFNS $FDALTNS $FDSOCK \ @@ -97,8 +99,9 @@ for t in stream dgram seqpacket; do echo DONE >&"${MKFDS[1]}" fi wait "${MKFDS_PID}" + RC=$? } > "$TS_OUTPUT" 2>&1 - if [ "$?" == "$EPERM" ]; then + if [ "$RC" == "$EPERM" ]; then ts_skip_subtest "unshare(2) is not permitted on this platform" continue fi