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