atf-run_test.sh revision 1.2.6.2 1 1.2.6.2 tls #! __ATF_SH__
2 1.2.6.2 tls # Copyright 2012 Google Inc.
3 1.2.6.2 tls # All rights reserved.
4 1.2.6.2 tls #
5 1.2.6.2 tls # Redistribution and use in source and binary forms, with or without
6 1.2.6.2 tls # modification, are permitted provided that the following conditions are
7 1.2.6.2 tls # met:
8 1.2.6.2 tls #
9 1.2.6.2 tls # * Redistributions of source code must retain the above copyright
10 1.2.6.2 tls # notice, this list of conditions and the following disclaimer.
11 1.2.6.2 tls # * Redistributions in binary form must reproduce the above copyright
12 1.2.6.2 tls # notice, this list of conditions and the following disclaimer in the
13 1.2.6.2 tls # documentation and/or other materials provided with the distribution.
14 1.2.6.2 tls # * Neither the name of Google Inc. nor the names of its contributors
15 1.2.6.2 tls # may be used to endorse or promote products derived from this software
16 1.2.6.2 tls # without specific prior written permission.
17 1.2.6.2 tls #
18 1.2.6.2 tls # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 1.2.6.2 tls # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 1.2.6.2 tls # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 1.2.6.2 tls # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 1.2.6.2 tls # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 1.2.6.2 tls # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 1.2.6.2 tls # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.2.6.2 tls # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.2.6.2 tls # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.2.6.2 tls # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 1.2.6.2 tls # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.2.6.2 tls
30 1.2.6.2 tls
31 1.2.6.2 tls . "${KYUA_ATF_COMPAT_PKGDATADIR:-__PKGDATADIR__}/tests_lib.subr"
32 1.2.6.2 tls
33 1.2.6.2 tls
34 1.2.6.2 tls atf_test_case all_pass
35 1.2.6.2 tls all_pass_body() {
36 1.2.6.2 tls create_test_program program1 pass skip
37 1.2.6.2 tls create_atffile Atffile 'prop: test-suite = "suite"' \
38 1.2.6.2 tls 'tp: program1' 'tp: subdir'
39 1.2.6.2 tls
40 1.2.6.2 tls mkdir subdir
41 1.2.6.2 tls create_test_program subdir/program2 skip
42 1.2.6.2 tls create_atffile subdir/Atffile 'prop: test-suite = "suite"' \
43 1.2.6.2 tls 'tp: program2'
44 1.2.6.2 tls
45 1.2.6.2 tls atf_check -s exit:0 -e ignore \
46 1.2.6.2 tls -o match:'program1:pass -> passed' \
47 1.2.6.2 tls -o match:'program1:skip -> skipped' \
48 1.2.6.2 tls -o match:'subdir/program2:skip -> skipped' \
49 1.2.6.2 tls -o match:'Committed action 1' \
50 1.2.6.2 tls atf-run
51 1.2.6.2 tls }
52 1.2.6.2 tls
53 1.2.6.2 tls
54 1.2.6.2 tls atf_test_case some_fail
55 1.2.6.2 tls some_fail_body() {
56 1.2.6.2 tls create_test_program program1 pass skip
57 1.2.6.2 tls create_atffile Atffile 'prop: test-suite = "suite"' \
58 1.2.6.2 tls 'tp: program1' 'tp: subdir'
59 1.2.6.2 tls
60 1.2.6.2 tls mkdir subdir
61 1.2.6.2 tls create_atffile subdir/Atffile 'tp-glob: *'
62 1.2.6.2 tls
63 1.2.6.2 tls mkdir subdir/nested
64 1.2.6.2 tls create_test_program subdir/nested/program2 skip fail
65 1.2.6.2 tls create_atffile subdir/nested/Atffile 'prop: test-suite = "suite"' \
66 1.2.6.2 tls 'tp-glob: program2*'
67 1.2.6.2 tls
68 1.2.6.2 tls atf_check -s exit:1 -e ignore \
69 1.2.6.2 tls -o match:'program1:pass -> passed' \
70 1.2.6.2 tls -o match:'program1:skip -> skipped' \
71 1.2.6.2 tls -o match:'subdir/nested/program2:fail -> failed' \
72 1.2.6.2 tls -o match:'subdir/nested/program2:skip -> skipped' \
73 1.2.6.2 tls -o match:'Committed action 1' \
74 1.2.6.2 tls atf-run
75 1.2.6.2 tls }
76 1.2.6.2 tls
77 1.2.6.2 tls atf_test_case prefer_kyuafiles
78 1.2.6.2 tls prefer_kyuafiles_body() {
79 1.2.6.2 tls create_test_program program1 pass skip
80 1.2.6.2 tls cat >Kyuafile <<EOF
81 1.2.6.2 tls syntax('kyuafile', 1)
82 1.2.6.2 tls test_suite('foo')
83 1.2.6.2 tls atf_test_program{name='program1'}
84 1.2.6.2 tls EOF
85 1.2.6.2 tls echo "This file is invalid" >Atffile
86 1.2.6.2 tls
87 1.2.6.2 tls atf_check -s exit:0 -e ignore \
88 1.2.6.2 tls -o match:'program1:pass -> passed' \
89 1.2.6.2 tls -o match:'program1:skip -> skipped' \
90 1.2.6.2 tls atf-run
91 1.2.6.2 tls }
92 1.2.6.2 tls
93 1.2.6.2 tls
94 1.2.6.2 tls atf_test_case selectors
95 1.2.6.2 tls selectors_body() {
96 1.2.6.2 tls create_test_program program1 pass skip
97 1.2.6.2 tls create_atffile Atffile 'prop: test-suite = "suite"' \
98 1.2.6.2 tls 'tp: program1' 'tp: subdir'
99 1.2.6.2 tls
100 1.2.6.2 tls mkdir subdir
101 1.2.6.2 tls create_atffile subdir/Atffile 'tp-glob: *'
102 1.2.6.2 tls
103 1.2.6.2 tls mkdir subdir/nested
104 1.2.6.2 tls create_test_program subdir/nested/program2 skip fail
105 1.2.6.2 tls create_atffile subdir/nested/Atffile 'prop: test-suite = "suite"' \
106 1.2.6.2 tls 'tp-glob: program2*'
107 1.2.6.2 tls
108 1.2.6.2 tls atf_check -s exit:1 -e ignore \
109 1.2.6.2 tls -o match:'program1:pass -> passed' \
110 1.2.6.2 tls -o match:'program1:skip -> skipped' \
111 1.2.6.2 tls -o match:'subdir/nested/program2:fail -> failed' \
112 1.2.6.2 tls -o match:'subdir/nested/program2:skip -> skipped' \
113 1.2.6.2 tls -o match:'Committed action 1' \
114 1.2.6.2 tls atf-run
115 1.2.6.2 tls
116 1.2.6.2 tls atf_check -s exit:0 -e ignore \
117 1.2.6.2 tls -o match:'program1:pass -> passed' \
118 1.2.6.2 tls -o not-match:'program1:skip -> skipped' \
119 1.2.6.2 tls -o not-match:'subdir/nested/program2:fail -> failed' \
120 1.2.6.2 tls -o match:'subdir/nested/program2:skip -> skipped' \
121 1.2.6.2 tls -o match:'Committed action 2' \
122 1.2.6.2 tls atf-run program1:pass subdir/nested/program2:skip
123 1.2.6.2 tls
124 1.2.6.2 tls atf_check -s exit:1 -e ignore \
125 1.2.6.2 tls -o not-match:'program1:pass -> passed' \
126 1.2.6.2 tls -o not-match:'program1:skip -> skipped' \
127 1.2.6.2 tls -o match:'subdir/nested/program2:fail -> failed' \
128 1.2.6.2 tls -o match:'subdir/nested/program2:skip -> skipped' \
129 1.2.6.2 tls -o match:'Committed action 3' \
130 1.2.6.2 tls atf-run subdir/nested/program2
131 1.2.6.2 tls }
132 1.2.6.2 tls
133 1.2.6.2 tls
134 1.2.6.2 tls atf_test_case config__priorities
135 1.2.6.2 tls config__priorities_body()
136 1.2.6.2 tls {
137 1.2.6.2 tls mkdir system
138 1.2.6.2 tls export ATF_CONFDIR="$(pwd)/system"
139 1.2.6.2 tls mkdir user
140 1.2.6.2 tls mkdir user/.atf
141 1.2.6.2 tls export HOME="$(pwd)/user"
142 1.2.6.2 tls
143 1.2.6.2 tls create_test_program helper config
144 1.2.6.2 tls create_atffile Atffile 'prop: test-suite = "irrelevant"' 'tp: helper'
145 1.2.6.2 tls
146 1.2.6.2 tls echo "Checking system-wide configuration only"
147 1.2.6.2 tls create_config system/common.conf ' unprivileged-user = "nobody"'
148 1.2.6.2 tls atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run
149 1.2.6.2 tls atf_check -s exit:0 -o 'inline:unprivileged-user = nobody\n' \
150 1.2.6.2 tls cat config.out
151 1.2.6.2 tls
152 1.2.6.2 tls echo "Checking user-specific overrides"
153 1.2.6.2 tls create_config user/.atf/common.conf ' unprivileged-user = "root"'
154 1.2.6.2 tls atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run
155 1.2.6.2 tls atf_check -s exit:0 -o 'inline:unprivileged-user = root\n' \
156 1.2.6.2 tls cat config.out
157 1.2.6.2 tls
158 1.2.6.2 tls echo "Checking command-line overrides"
159 1.2.6.2 tls atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run \
160 1.2.6.2 tls -v"unprivileged-user=$(id -u -n)"
161 1.2.6.2 tls atf_check -s exit:0 -o "inline:unprivileged-user = $(id -u -n)\n" \
162 1.2.6.2 tls cat config.out
163 1.2.6.2 tls }
164 1.2.6.2 tls
165 1.2.6.2 tls
166 1.2.6.2 tls atf_test_case config__test_suites__files
167 1.2.6.2 tls config__test_suites__files_body()
168 1.2.6.2 tls {
169 1.2.6.2 tls mkdir system
170 1.2.6.2 tls export ATF_CONFDIR="$(pwd)/system"
171 1.2.6.2 tls
172 1.2.6.2 tls create_config system/suite1.conf 'var1 = "var1-for-suite1"' \
173 1.2.6.2 tls 'var2 = "var2-for-suite1"'
174 1.2.6.2 tls create_config system/suite2.conf 'var1 = "var1-for-suite2"' \
175 1.2.6.2 tls 'var2 = "var2-for-suite2"'
176 1.2.6.2 tls
177 1.2.6.2 tls create_test_program helper1 config
178 1.2.6.2 tls create_atffile Atffile 'prop: test-suite = "suite1"' 'tp: helper1' \
179 1.2.6.2 tls 'tp: subdir'
180 1.2.6.2 tls mkdir subdir
181 1.2.6.2 tls create_test_program subdir/helper2 config
182 1.2.6.2 tls create_atffile subdir/Atffile 'prop: test-suite = "suite2"' 'tp: helper2'
183 1.2.6.2 tls
184 1.2.6.2 tls atf_check -s exit:0 -o ignore -e ignore atf-run helper1
185 1.2.6.2 tls atf_check -s exit:0 -o 'match:var1 = var1-for-suite1' \
186 1.2.6.2 tls -o 'match:var2 = var2-for-suite1' -o 'not-match:suite2' \
187 1.2.6.2 tls cat config.out
188 1.2.6.2 tls
189 1.2.6.2 tls atf_check -s exit:0 -o ignore -e ignore atf-run subdir/helper2
190 1.2.6.2 tls atf_check -s exit:0 -o 'match:var1 = var1-for-suite2' \
191 1.2.6.2 tls -o 'match:var2 = var2-for-suite2' -o 'not-match:suite1' \
192 1.2.6.2 tls cat config.out
193 1.2.6.2 tls }
194 1.2.6.2 tls
195 1.2.6.2 tls
196 1.2.6.2 tls atf_test_case config__test_suites__vflags
197 1.2.6.2 tls config__test_suites__vflags_body()
198 1.2.6.2 tls {
199 1.2.6.2 tls create_test_program helper1 config
200 1.2.6.2 tls create_atffile Atffile 'prop: test-suite = "suite1"' 'tp: helper1' \
201 1.2.6.2 tls 'tp: subdir'
202 1.2.6.2 tls mkdir subdir
203 1.2.6.2 tls create_test_program subdir/helper2 config
204 1.2.6.2 tls create_atffile subdir/Atffile 'prop: test-suite = "suite2"' 'tp: helper2'
205 1.2.6.2 tls
206 1.2.6.2 tls atf_check -s exit:0 -o ignore -e ignore atf-run -v var1=foo helper1
207 1.2.6.2 tls atf_check -s exit:0 -o 'match:var1 = foo' cat config.out
208 1.2.6.2 tls
209 1.2.6.2 tls atf_check -s exit:0 -o ignore -e ignore atf-run -v var1=bar helper1
210 1.2.6.2 tls atf_check -s exit:0 -o 'match:var1 = bar' cat config.out
211 1.2.6.2 tls }
212 1.2.6.2 tls
213 1.2.6.2 tls
214 1.2.6.2 tls atf_test_case unknown_option
215 1.2.6.2 tls unknown_option_body() {
216 1.2.6.2 tls atf_check -s exit:1 -o empty -e match:'E: Unknown option -Z' \
217 1.2.6.2 tls atf-run -Z -A
218 1.2.6.2 tls }
219 1.2.6.2 tls
220 1.2.6.2 tls
221 1.2.6.2 tls atf_init_test_cases() {
222 1.2.6.2 tls atf_add_test_case all_pass
223 1.2.6.2 tls atf_add_test_case some_fail
224 1.2.6.2 tls atf_add_test_case selectors
225 1.2.6.2 tls
226 1.2.6.2 tls atf_add_test_case prefer_kyuafiles
227 1.2.6.2 tls
228 1.2.6.2 tls atf_add_test_case config__priorities
229 1.2.6.2 tls atf_add_test_case config__test_suites__files
230 1.2.6.2 tls atf_add_test_case config__test_suites__vflags
231 1.2.6.2 tls
232 1.2.6.2 tls atf_add_test_case unknown_option
233 1.2.6.2 tls }
234