]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (lsfd) add a case for PING and PINGv6 sockets
authorMasatake YAMATO <yamato@redhat.com>
Fri, 24 Feb 2023 17:24:51 +0000 (02:24 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Sun, 26 Feb 2023 08:26:40 +0000 (17:26 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/expected/lsfd/mkfds-ping-ping [new file with mode: 0644]
tests/expected/lsfd/mkfds-ping-ping6 [new file with mode: 0644]
tests/ts/lsfd/mkfds-ping [new file with mode: 0755]

diff --git a/tests/expected/lsfd/mkfds-ping-ping b/tests/expected/lsfd/mkfds-ping-ping
new file mode 100644 (file)
index 0000000..cad42b1
--- /dev/null
@@ -0,0 +1,4 @@
+    3 PING state=established id=9999 laddr=127.0.0.1 raddr=127.0.0.1 established     dgram  127.0.0.1  127.0.0.1    9999
+ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,INET.LADDR,INET.RADDR,PING.ID: 0
+    3 PING state=close id=9999 laddr=127.0.0.1      close     dgram  127.0.0.1    0.0.0.0    9999
+ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,INET.LADDR,INET.RADDR,PING.ID: 0
diff --git a/tests/expected/lsfd/mkfds-ping-ping6 b/tests/expected/lsfd/mkfds-ping-ping6
new file mode 100644 (file)
index 0000000..3ef9730
--- /dev/null
@@ -0,0 +1,4 @@
+    3 PINGv6 state=established id=9999 laddr=::1 raddr=::1 established     dgram         ::1         ::1    9999
+ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,INET6.LADDR,INET6.RADDR,PING.ID: 0
+    3 PINGv6 state=close id=9999 laddr=::1      close     dgram         ::1          ::    9999
+ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,INET6.LADDR,INET6.RADDR,PING.ID: 0
diff --git a/tests/ts/lsfd/mkfds-ping b/tests/ts/lsfd/mkfds-ping
new file mode 100755 (executable)
index 0000000..610901c
--- /dev/null
@@ -0,0 +1,83 @@
+#!/bin/bash
+#
+# Copyright (C) 2023 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="PING and PINGv6 sockets"
+
+. "$TS_TOPDIR"/functions.sh
+ts_init "$*"
+
+ts_skip_nonroot
+
+ts_check_test_command "$TS_CMD_LSFD"
+ts_check_test_command "$TS_HELPER_MKFDS"
+ts_check_native_byteorder
+
+ts_cd "$TS_OUTDIR"
+
+PID=
+FD=3
+EXPR=(
+    '(TYPE == "PING") and (FD == 3)'
+    '(TYPE == "PINGv6") and (FD == 3)'
+)
+FACTORY=(
+    ping
+    ping6
+)
+TYPE=(
+    'PING'
+    'PINGv6'
+)
+COLNS=(
+    INET
+    INET6
+)
+ID=9999
+
+for i in 0 1; do
+    if ! "$TS_HELPER_MKFDS"  -c -q "${FACTORY[$i]}" 3 id=$ID; then
+       ts_skip "making ${TYPE[$i]} socket with specifying id is failed (blocked by SELinux?)"
+    fi
+done
+
+for i in 0 1; do
+    ts_init_subtest "${FACTORY[$i]}"
+    {
+       coproc MKFDS { "$TS_HELPER_MKFDS" "${FACTORY[$i]}" $FD id=$ID; }
+       if read -r -u "${MKFDS[0]}" PID; then
+           ${TS_CMD_LSFD} -n \
+                          -o ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,${COLNS[$i]}.LADDR,${COLNS[$i]}.RADDR,PING.ID \
+                          -p "${PID}" -Q "${EXPR[$i]}"
+           echo "ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,${COLNS[$i]}.LADDR,${COLNS[$i]}.RADDR,PING.ID": $?
+           kill -CONT "${PID}"
+       fi
+       wait "${MKFDS_PID}"
+
+       coproc MKFDS { "$TS_HELPER_MKFDS" "${FACTORY[$i]}" $FD id=$ID connect=0; }
+       if read -r -u "${MKFDS[0]}" PID; then
+           ${TS_CMD_LSFD} -n \
+                          -o ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,${COLNS[$i]}.LADDR,${COLNS[$i]}.RADDR,PING.ID \
+                          -p "${PID}" -Q "${EXPR[$i]}"
+           echo "ASSOC,TYPE,NAME,SOCK.STATE,SOCK.TYPE,${COLNS[$i]}.LADDR,${COLNS[$i]}.RADDR,PING.ID": $?
+           kill -CONT "${PID}"
+       fi
+    } > "$TS_OUTPUT" 2>&1
+    wait "${MKFDS_PID}"
+    ts_finalize_subtest
+done
+
+ts_finalize