icmp: improve INVARIANTS check
[freebsd/src.git] / bin / pwait / tests / pwait_test.sh
bloba726c467f57ec2f19fb35646004de26f026e0f90
2 atf_test_case basic
3 basic_head()
5 atf_set "descr" "Basic tests on pwait(1) utility"
8 basic_body()
10 sleep 1 &
11 p1=$!
13 sleep 5 &
14 p5=$!
16 sleep 10 &
17 p10=$!
19 atf_check \
20 -o empty \
21 -e empty \
22 -s exit:0 \
23 timeout --preserve-status 15 pwait $p1 $p5 $p10
25 atf_check \
26 -o empty \
27 -e inline:"kill: $p1: No such process\n" \
28 -s exit:1 \
29 kill -0 $p1
31 atf_check \
32 -o empty \
33 -e inline:"kill: $p5: No such process\n" \
34 -s exit:1 \
35 kill -0 $p5
37 atf_check \
38 -o empty \
39 -e inline:"kill: $p10: No such process\n" \
40 -s exit:1 \
41 kill -0 $p10
45 basic_cleanup()
47 kill $p1 $p5 $p10 >/dev/null 2>&1
48 wait $p1 $p5 $p10 >/dev/null 2>&1
51 atf_test_case time_unit
52 time_unit_head()
54 atf_set "descr" "Test parsing the timeout unit and value"
57 time_unit_body()
59 init=1
61 atf_check \
62 -o empty \
63 -e inline:"pwait: timeout unit\n" \
64 -s exit:65 \
65 timeout --preserve-status 2 pwait -t 1d $init
67 atf_check \
68 -o empty \
69 -e inline:"pwait: timeout unit\n" \
70 -s exit:65 \
71 timeout --preserve-status 2 pwait -t 1d $init
73 atf_check \
74 -o empty \
75 -e inline:"pwait: timeout value\n" \
76 -s exit:65 \
77 timeout --preserve-status 2 pwait -t -1 $init
79 atf_check \
80 -o empty \
81 -e inline:"pwait: timeout value\n" \
82 -s exit:65 \
83 timeout --preserve-status 2 pwait -t 100000001 $init
85 # These long duration cases are expected to timeout from the
86 # timeout utility rather than pwait -t.
87 atf_check \
88 -o empty \
89 -e empty \
90 -s exit:143 \
91 timeout --preserve-status 2 pwait -t 100000000 $init
93 atf_check \
94 -o empty \
95 -e empty \
96 -s exit:143 \
97 timeout --preserve-status 2 pwait -t 1h $init
99 atf_check \
100 -o empty \
101 -e empty \
102 -s exit:143 \
103 timeout --preserve-status 2 pwait -t 1.5h $init
105 atf_check \
106 -o empty \
107 -e empty \
108 -s exit:143 \
109 timeout --preserve-status 2 pwait -t 1m $init
111 atf_check \
112 -o empty \
113 -e empty \
114 -s exit:143 \
115 timeout --preserve-status 2 pwait -t 1.5m $init
117 atf_check \
118 -o empty \
119 -e empty \
120 -s exit:143 \
121 timeout --preserve-status 2 pwait -t 0 $init
123 # The rest are fast enough that pwait -t is expected to trigger
124 # the timeout.
125 atf_check \
126 -o empty \
127 -e empty \
128 -s exit:124 \
129 timeout --preserve-status 2 pwait -t 1s $init
131 atf_check \
132 -o empty \
133 -e empty \
134 -s exit:124 \
135 timeout --preserve-status 2 pwait -t 1.5s $init
137 atf_check \
138 -o empty \
139 -e empty \
140 -s exit:124 \
141 timeout --preserve-status 2 pwait -t 1 $init
143 atf_check \
144 -o empty \
145 -e empty \
146 -s exit:124 \
147 timeout --preserve-status 2 pwait -t 1.5 $init
149 atf_check \
150 -o empty \
151 -e empty \
152 -s exit:124 \
153 timeout --preserve-status 2 pwait -t 0.5 $init
156 atf_test_case timeout_trigger_timeout
157 timeout_trigger_timeout_head()
159 atf_set "descr" "Test that exceeding the timeout is detected"
162 timeout_trigger_timeout_body()
164 sleep 10 &
165 p10=$!
167 atf_check \
168 -o empty \
169 -e empty \
170 -s exit:124 \
171 timeout --preserve-status 6.5 pwait -t 5 $p10
174 timeout_trigger_timeout_cleanup()
176 kill $p10 >/dev/null 2>&1
177 wait $p10 >/dev/null 2>&1
180 atf_test_case timeout_no_timeout
181 timeout_no_timeout_head()
183 atf_set "descr" "Test that not exceeding the timeout continues to wait"
186 timeout_no_timeout_body()
188 sleep 10 &
189 p10=$!
191 atf_check \
192 -o empty \
193 -e empty \
194 -s exit:0 \
195 timeout --preserve-status 11.5 pwait -t 12 $p10
198 timeout_no_timeout_cleanup()
200 kill $p10 >/dev/null 2>&1
201 wait $p10 >/dev/null 2>&1
204 atf_test_case timeout_many
205 timeout_many_head()
207 atf_set "descr" "Test timeout on many processes"
210 timeout_many_body()
212 sleep 1 &
213 p1=$!
215 sleep 5 &
216 p5=$!
218 sleep 10 &
219 p10=$!
221 atf_check \
222 -o empty \
223 -e empty \
224 -s exit:124 \
225 timeout --preserve-status 7.5 pwait -t 6 $p1 $p5 $p10
228 timeout_many_cleanup()
230 kill $p1 $p5 $p10 >/dev/null 2>&1
231 wait $p1 $p5 $p10 >/dev/null 2>&1
234 atf_test_case or_flag
235 or_flag_head()
237 atf_set "descr" "Test OR flag"
240 or_flag_body()
242 sleep 2 &
243 p2=$!
245 sleep 4 &
246 p4=$!
248 sleep 6 &
249 p6=$!
251 atf_check \
252 -o inline:"$p2: exited with status 0.\n" \
253 -e empty \
254 -s exit:0 \
255 timeout --preserve-status 15 pwait -o -v $p2 $p4 $p6
257 atf_check \
258 -o empty \
259 -e inline:"pwait: $p2: No such process\n" \
260 -s exit:0 \
261 timeout --preserve-status 15 pwait -o $p2 $p4 $p6
263 atf_check \
264 -o empty \
265 -e empty \
266 -s exit:0 \
267 timeout --preserve-status 15 pwait -o $p4 $p6
269 atf_check \
270 -o empty \
271 -e inline:"pwait: $p4: No such process\n" \
272 -s exit:0 \
273 timeout --preserve-status 15 pwait -o $p4 $p6
275 atf_check \
276 -o inline:"$p6: exited with status 0.\n" \
277 -e empty \
278 -s exit:0 \
279 timeout --preserve-status 15 pwait -o -v $p6
281 atf_check \
282 -o empty \
283 -e inline:"pwait: $p6: No such process\n" \
284 -s exit:0 \
285 timeout --preserve-status 15 pwait -o $p6
287 atf_check \
288 -o empty \
289 -e inline:"kill: $p2: No such process\n" \
290 -s exit:1 \
291 kill -0 $p2
293 atf_check \
294 -o empty \
295 -e inline:"kill: $p4: No such process\n" \
296 -s exit:1 \
297 kill -0 $p4
299 atf_check \
300 -o empty \
301 -e inline:"kill: $p6: No such process\n" \
302 -s exit:1 \
303 kill -0 $p6
307 or_flag_cleanup()
309 kill $p2 $p4 $p6 >/dev/null 2>&1
310 wait $p2 $p4 $p6 >/dev/null 2>&1
313 atf_init_test_cases()
315 atf_add_test_case basic
316 atf_add_test_case time_unit
317 atf_add_test_case timeout_trigger_timeout
318 atf_add_test_case timeout_no_timeout
319 atf_add_test_case timeout_many
320 atf_add_test_case or_flag