Debian Codegraph @

tests/ts/lslocks/filter

raw
1 #!/bin/bash
2 #
3 # Copyright (C) 2025 Masatake YAMATO <[email protected]>
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 #
17 TS_TOPDIR="${0%/*}/../.."
18 TS_DESC="filter"
19
20 . "$TS_TOPDIR"/functions.sh
21 ts_init "$*"
22
23 ts_check_test_command "$TS_CMD_LSLOCKS"
24 ts_check_test_command "$TS_CMD_FLOCK"
25 ts_check_test_command "$TS_HELPER_MKFDS"
26 ts_check_prog "dd"
27
28 ts_cd "$TS_OUTDIR"
29
30 readonly FILE0=util-linux-lslocks-target-file
31 readonly FILE=${FILE0}--$$
32 readonly SIZE=4096
33 readonly HSIZE=4K
34 readonly START=1024
35 readonly LENGTH=1000
36 readonly END=$(( START + LENGTH - 1 ))
37 readonly COLS=COMMAND,TYPE,MODE,SIZE,M,START,END
38
39 cleanup()
40 {
41 rm -f "$FILE"
42 }
43
44 cleanup
45 trap "cleanup" EXIT
46
47
48 if ! dd if=/dev/zero of="$FILE" bs=$SIZE count=1 status=none; then
49 ts_skip "failed to create a temporary file"
50 fi
51
52 do_lslocks_flock_crash()
53 {
54 local pid=$1
55
56 echo "#### crash when printing PID column ####"
57 [[ "$pid" == $("$TS_CMD_LSLOCKS" \
58 --raw --noheadings --pid "$PID" \
59 --filter 'PATH =~ '"'.*/$FILE'"" and TYPE == 'FLOCK'" \
60 --output PID) ]]
61 echo "PID: $?"
62 }
63
64 do_lslocks_common()
65 {
66 local pid=$1
67 local type=$2
68 local bopt=$3
69
70 echo "#### $type $bopt (common) ####"
71
72 echo '# -Q PID == ...'
73 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid" -o $COLS
74
75 echo '# -Q PATH =~ .*/...'
76 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PATH =~ '.*/$FILE'" -o $COLS
77 echo '# -Q PATH =~ .*/...x'
78 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PATH =~ '.*/${FILE}x'" -o $COLS
79
80 echo '# -Q PID == ... SIZE == '"$SIZE"
81 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and SIZE == $SIZE" -o $COLS
82 echo '# -Q PID == ... SIZE < '"$SIZE"
83 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and SIZE < $SIZE" -o $COLS
84 echo '# -Q PID == ... SIZE > '"$SIZE"
85 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and SIZE > $SIZE" -o $COLS
86
87
88 echo '# -Q PID == ... SIZE == '"$HSIZE"
89 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and SIZE == $HSIZE" -o $COLS
90 echo '# -Q PID == ... SIZE < '"$HSIZE"
91 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and SIZE < $HSIZE" -o $COLS
92 echo '# -Q PID == ... SIZE > '"$HSIZE"
93 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and SIZE > $HSIZE" -o $COLS
94
95 echo '# -Q PID == ... TYPE == FLOCK'
96 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and TYPE == 'FLOCK'" -o $COLS
97 echo '# -Q PID == ... TYPE != FLOCK'
98 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and TYPE != 'FLOCK'" -o $COLS
99 echo '# -Q PID == ... TYPE == POSIX'
100 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and TYPE == 'POSIX'" -o $COLS
101 echo '# -Q PID == ... TYPE != POSIX'
102 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and TYPE != 'POSIX'" -o $COLS
103 echo '# -Q PID == ... TYPE == OFDLCK'
104 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and TYPE == 'OFDLCK'" -o $COLS
105 echo '# -Q PID == ... TYPE != OFDLCK'
106 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and TYPE != 'OFDLCK'" -o $COLS
107
108 echo '# -Q PID == ... MODE == READ'
109 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and MODE == 'READ'" -o $COLS
110 echo '# -Q PID == ... MODE != READ'
111 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and MODE != 'READ'" -o $COLS
112 echo '# -Q PID == ... MODE == WRITE'
113 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and MODE == 'WRITE'" -o $COLS
114 echo '# -Q PID == ... MODE != WRITE'
115 "$TS_CMD_LSLOCKS" $bopt -r -n -Q "PID == $pid and MODE != 'WRITE'" -o $COLS
116 echo
117 }
118
119 do_lslocks_fcntl()
120 {
121 local type=fcntl
122 local pid=$1
123
124 echo "#### $type (fcntl specific) ####"
125
126 echo '# -Q PID == ... START == $START'
127 "$TS_CMD_LSLOCKS" -r -n -Q "PID == $pid and START == $START" -o $COLS
128 echo '# -Q PID == ... START < $START'
129 "$TS_CMD_LSLOCKS" -r -n -Q "PID == $pid and START < $START" -o $COLS
130 echo '# -Q PID == ... START > $START'
131 "$TS_CMD_LSLOCKS" -r -n -Q "PID == $pid and START > $START" -o $COLS
132
133 echo '# -Q PID == ... END == $END'
134 "$TS_CMD_LSLOCKS" -r -n -Q "PID == $pid and END == $END" -o $COLS
135 echo '# -Q PID == ... END < $END'
136 "$TS_CMD_LSLOCKS" -r -n -Q "PID == $pid and END < $END" -o $COLS
137 echo '# -Q PID == ... END > $END'
138 "$TS_CMD_LSLOCKS" -r -n -Q "PID == $pid and END > $END" -o $COLS
139 }
140
141 {
142 coproc MKFDS { "$TS_CMD_FLOCK" \
143 --no-fork \
144 "$FILE" \
145 "$TS_HELPER_MKFDS" nop; }
146 if read -r -u "${MKFDS[0]}" PID; then
147 do_lslocks_flock_crash $PID
148 do_lslocks_common $PID flock
149 echo DONE >&"${MKFDS[1]}"
150 fi
151 wait "${MKFDS_PID}"
152
153 coproc MKFDS { "$TS_CMD_FLOCK" \
154 --no-fork \
155 --fcntl --start "$START" --length "$LENGTH" --shared \
156 "$FILE" \
157 "$TS_HELPER_MKFDS" nop; }
158 if read -r -u "${MKFDS[0]}" PID; then
159 do_lslocks_common $PID fcntl --bytes
160 do_lslocks_fcntl $PID
161 echo DONE >&"${MKFDS[1]}"
162 fi
163 wait "${MKFDS_PID}"
164
165 } > "$TS_OUTPUT" 2>&1
166
167 ts_finalize