From a1fa0c9f0250db15dd483b42b1369a48f87e9e19 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Sun, 12 Nov 2023 02:39:22 +0900 Subject: [PATCH] lslocks: (test) add a case Signed-off-by: Masatake YAMATO --- tests/commands.sh | 1 + tests/expected/lslocks/lslocks-flock-ex | 4 ++ tests/expected/lslocks/lslocks-flock-sh | 4 ++ tests/expected/lslocks/lslocks-lease-w | 4 ++ tests/expected/lslocks/lslocks-posix--w | 4 ++ tests/expected/lslocks/lslocks-posix-r- | 4 ++ tests/expected/lslocks/lslocks-posix-rw | 6 +++ tests/ts/lslocks/lslocks | 69 +++++++++++++++++++++++++ 8 files changed, 96 insertions(+) create mode 100644 tests/expected/lslocks/lslocks-flock-ex create mode 100644 tests/expected/lslocks/lslocks-flock-sh create mode 100644 tests/expected/lslocks/lslocks-lease-w create mode 100644 tests/expected/lslocks/lslocks-posix--w create mode 100644 tests/expected/lslocks/lslocks-posix-r- create mode 100644 tests/expected/lslocks/lslocks-posix-rw create mode 100755 tests/ts/lslocks/lslocks diff --git a/tests/commands.sh b/tests/commands.sh index 17b1132797..a7714bdf3c 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -91,6 +91,7 @@ TS_CMD_LSBLK=${TS_CMD_LSBLK-"${ts_commandsdir}lsblk"} TS_CMD_LSCLOCKS=${TS_CMD_LSCPU-"${ts_commandsdir}lsclocks"} TS_CMD_LSCPU=${TS_CMD_LSCPU-"${ts_commandsdir}lscpu"} TS_CMD_LSFD=${TS_CMD_LSFD-"${ts_commandsdir}lsfd"} +TS_CMD_LSLOCKS=${TS_CMD_LSLOCKS-"${ts_commandsdir}lslocks"} TS_CMD_LSMEM=${TS_CMD_LSMEM-"${ts_commandsdir}lsmem"} TS_CMD_LSNS=${TS_CMD_LSNS-"${ts_commandsdir}lsns"} TS_CMD_MCOOKIE=${TS_CMD_MCOOKIE-"${ts_commandsdir}mcookie"} diff --git a/tests/expected/lslocks/lslocks-flock-ex b/tests/expected/lslocks/lslocks-flock-ex new file mode 100644 index 0000000000..b7e6ee24eb --- /dev/null +++ b/tests/expected/lslocks/lslocks-flock-ex @@ -0,0 +1,4 @@ +test_mkfds FLOCK WRITE 0 0 +# flock-ex + COMMAND,TYPE,SIZE,MODE,START,END + --raw --noheadings: 0 +util-linux-lslocks-target-file +# flock-ex + PATH + --raw --noheadings: 0 diff --git a/tests/expected/lslocks/lslocks-flock-sh b/tests/expected/lslocks/lslocks-flock-sh new file mode 100644 index 0000000000..6188cc141c --- /dev/null +++ b/tests/expected/lslocks/lslocks-flock-sh @@ -0,0 +1,4 @@ +test_mkfds FLOCK READ 0 0 +# flock-sh + COMMAND,TYPE,SIZE,MODE,START,END + --raw --noheadings: 0 +util-linux-lslocks-target-file +# flock-sh + PATH + --raw --noheadings: 0 diff --git a/tests/expected/lslocks/lslocks-lease-w b/tests/expected/lslocks/lslocks-lease-w new file mode 100644 index 0000000000..78a0a2167b --- /dev/null +++ b/tests/expected/lslocks/lslocks-lease-w @@ -0,0 +1,4 @@ +test_mkfds LEASE WRITE 0 0 +# lease-w + COMMAND,TYPE,SIZE,MODE,START,END + --raw --noheadings: 0 +util-linux-lslocks-target-file +# lease-w + PATH + --raw --noheadings: 0 diff --git a/tests/expected/lslocks/lslocks-posix--w b/tests/expected/lslocks/lslocks-posix--w new file mode 100644 index 0000000000..2668fcd483 --- /dev/null +++ b/tests/expected/lslocks/lslocks-posix--w @@ -0,0 +1,4 @@ +test_mkfds POSIX 1B WRITE 0 0 +# posix--w + COMMAND,TYPE,SIZE,MODE,START,END + --raw --noheadings: 0 +util-linux-lslocks-target-file +# posix--w + PATH + --raw --noheadings: 0 diff --git a/tests/expected/lslocks/lslocks-posix-r- b/tests/expected/lslocks/lslocks-posix-r- new file mode 100644 index 0000000000..5e1113dfa9 --- /dev/null +++ b/tests/expected/lslocks/lslocks-posix-r- @@ -0,0 +1,4 @@ +test_mkfds POSIX 1B READ 0 0 +# posix-r- + COMMAND,TYPE,SIZE,MODE,START,END + --raw --noheadings: 0 +util-linux-lslocks-target-file +# posix-r- + PATH + --raw --noheadings: 0 diff --git a/tests/expected/lslocks/lslocks-posix-rw b/tests/expected/lslocks/lslocks-posix-rw new file mode 100644 index 0000000000..890d96a860 --- /dev/null +++ b/tests/expected/lslocks/lslocks-posix-rw @@ -0,0 +1,6 @@ +test_mkfds POSIX 3B READ 0 0 +test_mkfds POSIX 3B WRITE 2 2 +# posix-rw + COMMAND,TYPE,SIZE,MODE,START,END + --raw --noheadings: 0 +util-linux-lslocks-target-file +util-linux-lslocks-target-file +# posix-rw + PATH + --raw --noheadings: 0 diff --git a/tests/ts/lslocks/lslocks b/tests/ts/lslocks/lslocks new file mode 100755 index 0000000000..fc64c8546c --- /dev/null +++ b/tests/ts/lslocks/lslocks @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Copyright (C) 2023 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="flock" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_LSLOCKS" +ts_check_test_command "$TS_HELPER_MKFDS" +ts_check_prog "sed" + +ts_cd "$TS_OUTDIR" + +FILE0=util-linux-lslocks-target-file +FILE=${FILE0}--$$ +FD=17 +COLS=COMMAND,TYPE,SIZE,MODE,START,END +OPTS="--raw --noheadings" +METHODS=( + flock-sh + flock-ex + posix-r- + posix--w + posix-rw +# ofd-r- +# ofd--w +# ofd-rw + lease-w +) + +run_lslocks() +{ + local m=$1 + + { + rm -f "${FILE}" + coproc MKFDS { "$TS_HELPER_MKFDS" make-regular-file $FD file="$FILE" lock=$m; } + if read -r -u "${MKFDS[0]}" PID; then + "$TS_CMD_LSLOCKS" ${OPTS} --pid "${PID}" -o "${COLS}" + echo "# $m + ${COLS} + ${OPTS}": $? + "$TS_CMD_LSLOCKS" ${OPTS} --pid "${PID}" -o PATH | sed -e 's#.*\('"$FILE0"'\)--[0-9]\+ *$#\1#' + echo "# $m + PATH + ${OPTS}": ${PIPESTATUS[0]} + echo DONE >&"${MKFDS[1]}" + fi + } > "$TS_OUTPUT" 2>&1 + + wait "${MKFDS_PID}" +} + +for m in "${METHODS[@]}"; do + ts_init_subtest "$m" + run_lslocks "$m" + ts_finalize_subtest +done -- 2.47.3