]> git.ipfire.org Git - thirdparty/util-linux.git/blame - tests/ts/lslocks/lslocks
lslocks: don't abort gathering per-process information even if opening a /proc/[0...
[thirdparty/util-linux.git] / tests / ts / lslocks / lslocks
CommitLineData
a1fa0c9f
MY
1#!/bin/bash
2#
3# Copyright (C) 2023 Masatake YAMATO <yamato@redhat.com>
4#
5# This file is part of util-linux.
6#
7# This file is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2 of the License, or
10# (at your option) any later version.
11#
12# This file is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17TS_TOPDIR="${0%/*}/../.."
18TS_DESC="flock"
19
20. "$TS_TOPDIR"/functions.sh
21ts_init "$*"
22
23ts_check_test_command "$TS_CMD_LSLOCKS"
24ts_check_test_command "$TS_HELPER_MKFDS"
25ts_check_prog "sed"
26
27ts_cd "$TS_OUTDIR"
28
29FILE0=util-linux-lslocks-target-file
30FILE=${FILE0}--$$
31FD=17
503b1faa 32DFD=18
a1fa0c9f
MY
33COLS=COMMAND,TYPE,SIZE,MODE,START,END
34OPTS="--raw --noheadings"
35METHODS=(
36 flock-sh
59342d89 37 flock-ex
a1fa0c9f
MY
38 posix-r-
39 posix--w
40 posix-rw
8a387323
MY
41 ofd-r-
42 ofd--w
43 ofd-rw
a1fa0c9f
MY
44 lease-w
45)
46
503b1faa
MY
47OFD_METHODS=(
48 flock-sh
49 flock-ex
50 ofd-r-
51 ofd--w
52 ofd-rw
53 lease-w
54)
55
56DFD=18
57COLS_WITH_HOLDERS=COMMAND,TYPE,SIZE,MODE,START,END,HOLDERS
a1fa0c9f
MY
58run_lslocks()
59{
60 local m=$1
61
62 {
63 rm -f "${FILE}"
64 coproc MKFDS { "$TS_HELPER_MKFDS" make-regular-file $FD file="$FILE" lock=$m; }
65 if read -r -u "${MKFDS[0]}" PID; then
66 "$TS_CMD_LSLOCKS" ${OPTS} --pid "${PID}" -o "${COLS}"
67 echo "# $m + ${COLS} + ${OPTS}": $?
68 "$TS_CMD_LSLOCKS" ${OPTS} --pid "${PID}" -o PATH | sed -e 's#.*\('"$FILE0"'\)--[0-9]\+ *$#\1#'
69 echo "# $m + PATH + ${OPTS}": ${PIPESTATUS[0]}
70 echo DONE >&"${MKFDS[1]}"
71 fi
72 } > "$TS_OUTPUT" 2>&1
73
74 wait "${MKFDS_PID}"
75}
76
503b1faa
MY
77run_lslocks_with_co_holders()
78{
79 local m=$1
80
81 {
82 rm -f "${FILE}"
83 coproc MKFDS { "$TS_HELPER_MKFDS" make-regular-file $FD file="$FILE" lock=$m dupfd=$DFD; }
84 if read -r -u "${MKFDS[0]}" PID; then
85 "$TS_CMD_LSLOCKS" ${OPTS} --pid "${PID}" -o "${COLS_WITH_HOLDERS}" | sed -e "s/${PID},/1,/g"
86 echo "# $m + ${COLS_WITH_HOLDERS} + ${OPTS}": ${PIPESTATUS[0]}
87 echo DONE >&"${MKFDS[1]}"
88 fi
89 } > "$TS_OUTPUT" 2>&1
90
91 wait "${MKFDS_PID}"
92}
93
a1fa0c9f
MY
94for m in "${METHODS[@]}"; do
95 ts_init_subtest "$m"
503b1faa
MY
96 run_lslocks "$m"
97 ts_finalize_subtest
98done
99
100for m in "${OFD_METHODS[@]}"; do
101 ts_init_subtest "$m+HOLDERS"
102 run_lslocks_with_co_holders "$m"
a1fa0c9f
MY
103 ts_finalize_subtest
104done
ccd7d3dd
MY
105
106ts_finalize