From: Masatake YAMATO Date: Fri, 8 Mar 2024 01:57:15 +0000 (+0900) Subject: tests: (lsns) add a case testing -Q, --filter option X-Git-Tag: v2.42-start~457^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0b517b611e42c813f4450442e0421a3d2bd021f6;p=thirdparty%2Futil-linux.git tests: (lsns) add a case testing -Q, --filter option Signed-off-by: Masatake YAMATO --- diff --git a/tests/expected/lsns/filter b/tests/expected/lsns/filter new file mode 100644 index 0000000000..ac79b6b367 --- /dev/null +++ b/tests/expected/lsns/filter @@ -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 index 0000000000..fa8b090aed --- /dev/null +++ b/tests/ts/lsns/filter @@ -0,0 +1,65 @@ +#!/bin/bash +# +# Copyright (C) 2024 Masatake YAMATO +# +# 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