From: Masatake YAMATO Date: Sat, 15 Apr 2023 03:07:58 +0000 (+0900) Subject: tests: (lsfd) adjust the output for unix stream sockets X-Git-Tag: v2.39-rc3~21^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3a24c299d1deeeb890965465015587d1024d18b1;p=thirdparty%2Futil-linux.git tests: (lsfd) adjust the output for unix stream sockets lsfd changes the output of NAME column for a unix stream socket whether the kernel reports it is a "UNIX-STREAM" socket or a "UNIX" socket. Rather older version of kernels report the socket "UNIX" For "UNIX", lsfd appends "type=stream" to the NAME column. This caused a failure in test cases. To avoid the failure, this change strips "type=stream" from the output before comparing the output strings and expected strings. See also the commit log of a60ac11fe0087584f37329b4733edfade3452c64. Signed-off-by: Masatake YAMATO --- diff --git a/tests/ts/lsfd/lsfd-functions.bash b/tests/ts/lsfd/lsfd-functions.bash index 014145e3ca..1ebc327592 100644 --- a/tests/ts/lsfd/lsfd-functions.bash +++ b/tests/ts/lsfd/lsfd-functions.bash @@ -57,3 +57,12 @@ function lsfd_compare_dev { echo 'STAT_DEVNUM:' "${STAT_DEVNUM}" fi } + +lsfd_strip_type_stream() +{ + # lsfd changes the output of NAME column for a unix stream socket + # whether the kernel reports it is a "UNIX-STREAM" socket or a + # "UNIX" socket. For "UNIX", lsfd appends "type=stream" to the + # NAME column. Let's delete the appended string before comparing. + sed -e 's/ type=stream//' +} diff --git a/tests/ts/lsfd/mkfds-unix-in-netns b/tests/ts/lsfd/mkfds-unix-in-netns index 4e46f577fa..cfca087b15 100755 --- a/tests/ts/lsfd/mkfds-unix-in-netns +++ b/tests/ts/lsfd/mkfds-unix-in-netns @@ -55,6 +55,15 @@ compare_net_namespaces() fi } +strip_type_stream() +{ + if [ "$1" = stream ]; then + lsfd_strip_type_stream + else + cat + fi +} + for t in stream dgram seqpacket; do ts_init_subtest "$t" { @@ -64,8 +73,8 @@ for t in stream dgram seqpacket; do if read -r -u "${MKFDS[0]}" PID; then ${TS_CMD_LSFD} -n \ -o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ - -p "${PID}" -Q "${EXPR}" - echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': $? + -p "${PID}" -Q "${EXPR}" | strip_type_stream $t + echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} compare_net_namespaces "$t" "${PID}" @@ -80,8 +89,8 @@ for t in stream dgram seqpacket; do if read -r -u "${MKFDS[0]}" PID; then ${TS_CMD_LSFD} -n \ -o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ - -p "${PID}" -Q "${EXPR}" - echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': $? + -p "${PID}" -Q "${EXPR}" | strip_type_stream $t + echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} compare_net_namespaces "abstract $t" "${PID}" diff --git a/tests/ts/lsfd/mkfds-unix-stream b/tests/ts/lsfd/mkfds-unix-stream index 2d0dd67fb8..fe08e72035 100755 --- a/tests/ts/lsfd/mkfds-unix-stream +++ b/tests/ts/lsfd/mkfds-unix-stream @@ -20,6 +20,8 @@ TS_DESC="UNIX stream sockets" . "$TS_TOPDIR"/functions.sh ts_init "$*" +. "$TS_SELF/lsfd-functions.bash" + ts_check_test_command "$TS_CMD_LSFD" ts_check_test_command "$TS_HELPER_MKFDS" @@ -41,8 +43,8 @@ EXPR='(((TYPE == "UNIX-STREAM") or (TYPE == "UNIX")) and (FD >= 3) and (FD <= 5) if read -r -u "${MKFDS[0]}" PID; then ${TS_CMD_LSFD} -n \ -o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ - -p "${PID}" -Q "${EXPR}" - echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': $? + -p "${PID}" -Q "${EXPR}" | lsfd_strip_type_stream + echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} kill -CONT "${PID}" fi @@ -54,8 +56,8 @@ EXPR='(((TYPE == "UNIX-STREAM") or (TYPE == "UNIX")) and (FD >= 3) and (FD <= 5) if read -r -u "${MKFDS[0]}" PID; then ${TS_CMD_LSFD} -n \ -o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ - -p "${PID}" -Q "${EXPR}" - echo '(abs) ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': $? + -p "${PID}" -Q "${EXPR}" | lsfd_strip_type_stream + echo '(abs) ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} kill -CONT "${PID}" fi @@ -69,8 +71,8 @@ EXPR='(((TYPE == "UNIX-STREAM") or (TYPE == "UNIX")) and (FD >= 3) and (FD <= 5) if read -r -u "${MKFDS[0]}" PID; then ${TS_CMD_LSFD} -n \ -o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ - -p "${PID}" -Q "${EXPR}" - echo '(shutdown) ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': $? + -p "${PID}" -Q "${EXPR}" | lsfd_strip_type_stream + echo '(shutdown) ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} # Surprisingly, the socket status doesn't change at all. kill -CONT "${PID}" @@ -83,8 +85,8 @@ EXPR='(((TYPE == "UNIX-STREAM") or (TYPE == "UNIX")) and (FD >= 3) and (FD <= 5) if read -r -u "${MKFDS[0]}" PID; then ${TS_CMD_LSFD} -n \ -o ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH \ - -p "${PID}" -Q "${EXPR}" - echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': $? + -p "${PID}" -Q "${EXPR}" | lsfd_strip_type_stream + echo 'ASSOC,STTYPE,NAME,SOCK.STATE,SOCK.TYPE,SOCK.LISTENING,UNIX.PATH': ${PIPESTATUS[0]} kill -CONT "${PID}" fi