t_rc_d_cli.sh revision 1.5 1 # $NetBSD: t_rc_d_cli.sh,v 1.5 2022/02/26 16:21:59 gson Exp $
2 #
3 # Copyright (c) 2010 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # This code is derived from software contributed to The NetBSD Foundation
7 # by Julio Merino.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29 #
30
31 atf_test_case no_command
32 no_command_head() {
33 atf_set "descr" "Tests that the lack of a command errors out"
34 }
35 no_command_body() {
36 export h_simple=YES
37 rc_helper=$(atf_get_srcdir)/h_simple
38
39 atf_check -s eq:1 -o empty -e ignore ${rc_helper}
40 }
41
42 atf_test_case default_start_no_args
43 default_start_no_args_head() {
44 atf_set "descr" "Tests that running the default 'start' without" \
45 "arguments does not error out"
46 }
47 default_start_no_args_body() {
48 export h_simple=YES
49 rc_helper=$(atf_get_srcdir)/h_simple
50
51 atf_expect_fail "PR bin/56506"
52 atf_check -s eq:0 -o ignore -e empty ${rc_helper} start
53 ${rc_helper} forcestop
54 atf_fail "random failure did not happen this time"
55 }
56
57 atf_test_case default_start_with_args
58 default_start_with_args_head() {
59 atf_set "descr" "Tests that running the default 'start' with" \
60 "arguments errors out"
61 }
62 default_start_with_args_body() {
63 export h_simple=YES
64 rc_helper=$(atf_get_srcdir)/h_simple
65
66 atf_check -s eq:1 -o ignore -e ignore ${rc_helper} start foo
67 if ${rc_helper} status >/dev/null; then
68 ${rc_helper} forcestop
69 atf_fail 'extra argument to start did not error out'
70 fi
71 }
72
73 atf_test_case default_stop_no_args
74 default_stop_no_args_head() {
75 atf_set "descr" "Tests that running the default 'stop' without" \
76 "arguments does not error out"
77 }
78 default_stop_no_args_body() {
79 export h_simple=YES
80 rc_helper=$(atf_get_srcdir)/h_simple
81
82 atf_expect_fail "PR bin/56506"
83 ${rc_helper} start
84 atf_check -s eq:0 -o ignore -e empty ${rc_helper} stop
85 atf_fail "random failure did not happen this time"
86 }
87
88 atf_test_case default_stop_with_args
89 default_stop_with_args_head() {
90 atf_set "descr" "Tests that running the default 'stop' with" \
91 "arguments errors out"
92 }
93 default_stop_with_args_body() {
94 export h_simple=YES
95 rc_helper=$(atf_get_srcdir)/h_simple
96
97 ${rc_helper} start
98 atf_check -s eq:1 -o ignore -e ignore ${rc_helper} stop foo
99 if ${rc_helper} status >/dev/null; then
100 ${rc_helper} forcestop
101 else
102 atf_fail 'extra argument to stop did not error out'
103 fi
104 }
105
106 atf_test_case default_restart_no_args
107 default_restart_no_args_head() {
108 atf_set "descr" "Tests that running the default 'restart' without" \
109 "arguments does not error out"
110 }
111 default_restart_no_args_body() {
112 export h_simple=YES
113 rc_helper=$(atf_get_srcdir)/h_simple
114
115 atf_expect_fail "PR bin/56506"
116 ${rc_helper} start
117 atf_check -s eq:0 -o ignore -e empty ${rc_helper} restart
118 ${rc_helper} forcestop
119 atf_fail "random failure did not happen this time"
120 }
121
122 atf_test_case default_restart_with_args
123 default_restart_with_args_head() {
124 atf_set "descr" "Tests that running the default 'restart' with" \
125 "arguments errors out"
126 }
127 default_restart_with_args_body() {
128 export h_simple=YES
129 rc_helper=$(atf_get_srcdir)/h_simple
130
131 ${rc_helper} start
132 atf_check -s eq:1 -o ignore -e ignore ${rc_helper} restart foo
133 ${rc_helper} forcestop
134 }
135
136 do_overriden_no_args() {
137 local command="${1}"; shift
138
139 export h_args=YES
140 rc_helper=$(atf_get_srcdir)/h_args
141
142 cat >expout <<EOF
143 pre${command}:.
144 ${command}:.
145 post${command}:.
146 EOF
147 atf_check -s eq:0 -o file:expout -e empty ${rc_helper} ${command}
148 }
149
150 do_overriden_with_args() {
151 local command="${1}"; shift
152
153 export h_args=YES
154 rc_helper=$(atf_get_srcdir)/h_args
155
156 cat >expout <<EOF
157 pre${command}:.
158 ${command}: >arg1< > arg 2 < >arg3< >*<.
159 post${command}:.
160 EOF
161 atf_check -s eq:0 -o file:expout -e empty ${rc_helper} ${command} \
162 'arg1' ' arg 2 ' 'arg3' '*'
163 }
164
165 atf_test_case overriden_start_no_args
166 overriden_start_no_args_head() {
167 atf_set "descr" "Tests that running a custom 'start' without" \
168 "arguments does not pass any parameters to the command"
169 }
170 overriden_start_no_args_body() {
171 do_overriden_no_args start
172 }
173
174 atf_test_case overriden_start_with_args
175 overriden_start_with_args_head() {
176 atf_set "descr" "Tests that running a custom 'start' with" \
177 "arguments passes those arguments as parameters to the command"
178 }
179 overriden_start_with_args_body() {
180 do_overriden_with_args start
181 }
182
183 atf_test_case overriden_stop_no_args
184 overriden_stop_no_args_head() {
185 atf_set "descr" "Tests that running a custom 'stop' without" \
186 "arguments does not pass any parameters to the command"
187 }
188 overriden_stop_no_args_body() {
189 do_overriden_no_args stop
190 }
191
192 atf_test_case overriden_stop_with_args
193 overriden_stop_with_args_head() {
194 atf_set "descr" "Tests that running a custom 'stop' with" \
195 "arguments passes those arguments as parameters to the command"
196 }
197 overriden_stop_with_args_body() {
198 do_overriden_with_args stop
199 }
200
201 atf_test_case overriden_restart_no_args
202 overriden_restart_no_args_head() {
203 atf_set "descr" "Tests that running a custom 'restart' without" \
204 "arguments does not pass any parameters to the command"
205 }
206 overriden_restart_no_args_body() {
207 do_overriden_no_args restart
208 }
209
210 atf_test_case overriden_restart_with_args
211 overriden_restart_with_args_head() {
212 atf_set "descr" "Tests that running a custom 'restart' with" \
213 "arguments passes those arguments as parameters to the command"
214 }
215 overriden_restart_with_args_body() {
216 do_overriden_with_args restart
217 }
218
219 atf_test_case overriden_custom_no_args
220 overriden_custom_no_args_head() {
221 atf_set "descr" "Tests that running a custom command without" \
222 "arguments does not pass any parameters to the command"
223 }
224 overriden_custom_no_args_body() {
225 do_overriden_no_args custom
226 }
227
228 atf_test_case overriden_custom_with_args
229 overriden_custom_with_args_head() {
230 atf_set "descr" "Tests that running a custom command with" \
231 "arguments passes those arguments as parameters to the command"
232 }
233 overriden_custom_with_args_body() {
234 do_overriden_with_args custom
235 }
236
237 atf_init_test_cases()
238 {
239 atf_add_test_case no_command
240
241 atf_add_test_case default_start_no_args
242 atf_add_test_case default_start_with_args
243 atf_add_test_case default_stop_no_args
244 atf_add_test_case default_stop_with_args
245 atf_add_test_case default_restart_no_args
246 atf_add_test_case default_restart_with_args
247
248 atf_add_test_case overriden_start_no_args
249 atf_add_test_case overriden_start_with_args
250 atf_add_test_case overriden_stop_no_args
251 atf_add_test_case overriden_stop_with_args
252 atf_add_test_case overriden_restart_no_args
253 atf_add_test_case overriden_restart_with_args
254 atf_add_test_case overriden_custom_no_args
255 atf_add_test_case overriden_custom_with_args
256 }
257