t_config.sh revision 1.5 1 # $NetBSD: t_config.sh,v 1.5 2014/10/31 09:11:42 uebayasi Exp $
2 #
3 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 run_and_check_prep()
29 {
30 local name="${1}"; shift
31
32 mkdir compile
33 supportdir="$(atf_get_srcdir)/support"
34
35 local config_str
36 eval config_str=\$${name}_config_str
37 if [ -n "$config_str" ]; then
38 config="d_${name}"
39 printf "$config_str" >"${config}"
40 else
41 config="$(atf_get_srcdir)/d_${name}"
42 fi
43 }
44
45 run_and_check_pass()
46 {
47 local name="${1}"; shift
48
49 run_and_check_prep "${name}"
50
51 atf_check -o ignore \
52 config -s "${supportdir}" -b "compile/${name}" "${config}"
53 }
54
55 run_and_check_fail()
56 {
57 local name="${1}"; shift
58
59 run_and_check_prep "${name}"
60
61 atf_check -o ignore -e ignore -s ne:0 \
62 config -s "${supportdir}" -b "compile/${name}" "${config}"
63 }
64
65 test_output()
66 {
67 local name="${1}"; shift
68 local res=1
69
70 run_and_check_prep "${name}"
71
72 config -s "${supportdir}" -b compile/"${name}" "${config}" >/dev/null &&
73 cd compile/"${name}" &&
74 check_${name} &&
75 cd $OLDPWD &&
76 res=0
77
78 atf_check test $res -eq 0
79 }
80
81 # Defines a test case for config(1).
82 test_case()
83 {
84 local name="${1}"; shift
85 local type="${1}"; shift
86 local descr="${*}"
87
88 atf_test_case "${name}"
89 eval "${name}_head() { \
90 atf_set descr \"${descr}\"; \
91 atf_set require.progs \"config\"; \
92 }"
93 eval "${name}_body() { \
94 run_and_check_${type} '${name}'; \
95 }"
96 }
97
98 test_case shadow_instance pass "Checks correct handling of shadowed instances"
99 test_case loop pass "Checks correct handling of loops"
100 test_case loop2 pass "Checks correct handling of devices that can be their" \
101 "own parents"
102 test_case pseudo_parent pass "Checks correct handling of children of pseudo" \
103 "devices (PR/32329)"
104 test_case postponed_orphan fail "Checks that config catches adding an" \
105 "instance of a child of a negated instance as error"
106 test_case no_pseudo fail "Checks that config catches ommited 'pseudo-device'" \
107 "as error (PR/34111)"
108 test_case deffs_redef fail "Checks that config doesn't allow a deffs to use" \
109 "the same name as a previous defflag/defparam"
110
111 # Selecting an undefined option.
112 undefined_opt_config_str='
113 include "../d_min"
114 options UNDEFINED
115 '
116 test_case undefined_opt pass \
117 "Checks that config allows a selection for an undefined options"
118
119 # Negating an undefined option.
120 no_undefined_opt_config_str='
121 include "../d_min"
122 no options UNDEFINED
123 '
124 test_case no_undefined_opt pass \
125 "Checks that config allows a negation for an undefined options"
126
127 # Attribute selection
128 test_case select pass "Attribute selection"
129 select_config_str='
130 include "../d_min"
131 select c
132 '
133 check_select()
134 {
135 local f=Makefile
136
137 grep -q '^a\.o:' $f &&
138 grep -q '^b\.o:' $f &&
139 grep -q '^c\.o:' $f &&
140 :
141 }
142 select_body() {
143 test_output select
144 }
145
146 # Attribute negation
147 test_case no_select pass "Attribute negation"
148 no_select_config_str='
149 include "../d_min"
150 select c
151 no select a
152 '
153 check_no_select()
154 {
155 local f=Makefile
156
157 : >tmp
158 grep -q '^a\.o:' $f >>tmp
159 grep -q '^b\.o:' $f >>tmp
160 grep -q '^c\.o:' $f >>tmp
161
162 [ ! -s tmp ] &&
163 :
164 }
165 no_select_body() {
166 test_output no_select
167 }
168
169 # Device instance
170 test_case devi pass "Device instance"
171 devi_config_str='
172 include "../d_min"
173 d0 at root
174 '
175 check_devi()
176 {
177 local f=ioconf.c
178
179 sed -ne '/^struct cfdriver \* const cfdriver_list_initial\[\]/,/^};/p' $f >tmp.cfdriver
180 sed -ne '/^struct cfdata cfdata\[\]/,/^};/p' $f >tmp.cfdata
181
182 grep -q '^CFDRIVER_DECL(d, ' $f &&
183 grep -q '&d_cd,' tmp.cfdriver &&
184 grep -q '^extern struct cfattach d_ca;$' $f &&
185 grep -q '^static const struct cfiattrdata \* const d_attrs\[\]' $f &&
186 grep -q '^static const struct cfiattrdata icf_iattrdata' $f &&
187 grep -q '{ "d",' tmp.cfdata &&
188 :
189 }
190 devi_body() {
191 test_output devi
192 }
193
194 # Check minimal kernel config(1) output
195 test_case min pass "Minimal config"
196 check_min_files()
197 {
198 test -e Makefile &&
199 test -e config_file.h &&
200 test -e config_time.src &&
201 test -e ioconf.c &&
202 test -e ioconf.h &&
203 test -e locators.h &&
204 test -e swapregress.c &&
205 test -h machine &&
206 test -h regress &&
207 :
208 }
209 check_min_makefile()
210 {
211 local f=Makefile
212
213 grep -q '^%' $f >tmp.template
214
215 grep -q '^MACHINE=regress$' $f &&
216 grep -q '^PARAM=-DMAXUSERS=4$' $f &&
217 grep -q '^all: regress$' $f &&
218 grep -q '^regress:' $f &&
219 [ ! -s tmp.template ] &&
220 :
221 }
222 check_min()
223 {
224 check_min_files &&
225 check_min_makefile &&
226 :
227 }
228 min_body() {
229 test_output min
230 }
231
232 atf_init_test_cases()
233 {
234 atf_add_test_case shadow_instance
235 atf_add_test_case loop
236 atf_add_test_case loop2
237 atf_add_test_case pseudo_parent
238 atf_add_test_case postponed_orphan
239 atf_add_test_case no_pseudo
240 atf_add_test_case deffs_redef
241 atf_add_test_case undefined_opt
242 atf_add_test_case no_undefined_opt
243 atf_add_test_case select
244 atf_add_test_case no_select
245 atf_add_test_case devi
246 atf_add_test_case min
247 }
248