]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: (lsns) add a case testing -Q, --filter option
authorMasatake YAMATO <yamato@redhat.com>
Fri, 8 Mar 2024 01:57:15 +0000 (10:57 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Wed, 27 Mar 2024 01:45:08 +0000 (10:45 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
tests/expected/lsns/filter [new file with mode: 0644]
tests/ts/lsns/filter [new file with mode: 0755]

diff --git a/tests/expected/lsns/filter b/tests/expected/lsns/filter
new file mode 100644 (file)
index 0000000..ac79b6b
--- /dev/null
@@ -0,0 +1,2 @@
+-Q: pid == PID
+--filter: pid == PID
diff --git a/tests/ts/lsns/filter b/tests/ts/lsns/filter
new file mode 100755 (executable)
index 0000000..fa8b090
--- /dev/null
@@ -0,0 +1,65 @@
+#!/bin/bash
+#
+# Copyright (C) 2024 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="-Q, --filter option"
+
+. "$TS_TOPDIR"/functions.sh
+# for $EPERM
+. "$TS_TOPDIR"/ts/lsfd/lsfd-functions.bash
+
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSNS"
+ts_check_test_command "$TS_CMD_LSFD"
+
+ts_check_test_command "$TS_HELPER_MKFDS"
+
+# unshare(2) used in userns factory of test_mkfds reports "Invalid argument".
+ts_skip_qemu_user
+
+ts_cd "$TS_OUTDIR"
+PID=
+FD=4
+EXPR=
+
+{
+    coproc MKFDS { "$TS_HELPER_MKFDS" --comm ABC userns $FD; }
+    if read -u ${MKFDS[0]} PID; then
+       expr="PID == \"${PID}\" and ASSOC == \"user\""
+       inode=$(${TS_CMD_LSFD} -n --raw -o INODE -Q "${expr}")
+       for opt in -Q --filter; do
+           pid=$(${TS_CMD_LSNS} -n --raw -o PID "$opt" "NS == $inode && NPROCS == 1")
+           if [[ "$pid" = "$PID" ]]; then
+               echo  "$opt: pid == PID"
+           else
+               echo "$opt: pid != PID"
+               echo expr: "${expr}"
+               ${TS_CMD_LSFD} -n --raw -o INODE -Q "${expr}"
+               echo inode: "${inode}"
+               ${TS_CMD_LSNS} -n --raw -o PID -Q "NS == $inode && NPROCS == 1"
+               echo pid: "${pid}"
+               echo PID: "${PID}"
+           fi
+       done
+       echo DONE >&"${MKFDS[1]}"
+    fi
+    wait "${MKFDS_PID}"
+} > $TS_OUTPUT 2>&1
+if [ "$?" == "$EPERM" ]; then
+    ts_skip "unshare(2) is not permitted on this platform"
+fi
+ts_finalize