1 # $NetBSD: t_config.sh,v 1.8 2016/08/27 12:08:14 christos Exp $
3 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
42 local name="${1}"; shift
45 srcdir="$(atf_get_srcdir)"
46 if [ ! -d "${srcdir}/support" ]; then
47 srcdir="$(dirname "${srcdir}")"
48 if [ ! -d "${srcdir}/support" ]; then
49 atf_fail "bad source directory ${srcdir}"
53 supportdir="${srcdir}/support"
56 eval config_str=\$${name}_config_str
57 if [ -n "$config_str" ]; then
59 printf "$config_str" >"${config}"
61 config="${srcdir}/d_${name}"
67 local name="${1}"; shift
69 run_and_check_prep "${name}"
71 atf_check -o ignore -s eq:0 \
72 config -s "${supportdir}" -b "compile/${name}" "${config}"
77 local name="${1}"; shift
79 run_and_check_prep "${name}"
82 eval stderr=\$${name}_stderr
83 atf_check -o ignore -e "${stderr}" -s eq:0 \
84 config -s "${supportdir}" -b "compile/${name}" "${config}"
89 local name="${1}"; shift
91 run_and_check_prep "${name}"
93 atf_check -o ignore -e ignore -s ne:0 \
94 config -s "${supportdir}" -b "compile/${name}" "${config}"
99 local name="${1}"; shift
102 run_and_check_prep "${name}"
104 config -s "${supportdir}" -b compile/"${name}" "${config}" >/dev/null &&
105 cd compile/"${name}" &&
110 atf_check test $res -eq 0
113 # Defines a test case for config(1).
116 local name="${1}"; shift
117 local type="${1}"; shift
120 atf_test_case "${name}"
121 eval "${name}_head() { \
122 atf_set descr \"${descr}\"; \
123 atf_set require.progs \"config\"; \
125 eval "${name}_body() { \
126 run_and_check_${type} '${name}'; \
130 test_case shadow_instance pass "Checks correct handling of shadowed instances"
131 test_case loop pass "Checks correct handling of loops"
132 test_case loop2 pass "Checks correct handling of devices that can be their" \
134 test_case pseudo_parent pass "Checks correct handling of children of pseudo" \
136 test_case postponed_orphan fail "Checks that config catches adding an" \
137 "instance of a child of a negated instance as error"
138 test_case no_pseudo fail "Checks that config catches ommited 'pseudo-device'" \
139 "as error (PR/34111)"
140 test_case deffs_redef fail "Checks that config doesn't allow a deffs to use" \
141 "the same name as a previous defflag/defparam"
143 # Selecting an undefined option.
144 undefined_opt_config_str="
145 include \"${srcdir}/d_min\"
148 test_case undefined_opt pass \
149 "Checks that config allows a selection for an undefined options"
151 # Negating an undefined option.
152 no_undefined_opt_config_str="
153 include \"${srcdir}/d_min\"
156 no_undefined_opt_stderr='match:UNDEFINED'
157 test_case no_undefined_opt warn \
158 "Checks that config allows a negation for an undefined options"
160 # Attribute selection
161 test_case select pass "Attribute selection"
163 include \"${srcdir}/d_min\"
170 grep -q '^ a\.c ' $f &&
171 grep -q '^ b\.c ' $f &&
172 grep -q '^ c\.c ' $f &&
180 test_case no_select pass "Attribute negation"
181 no_select_config_str="
182 include \"${srcdir}/d_min\"
191 grep -q '^a\.o:' $f >>tmp
192 grep -q '^b\.o:' $f >>tmp
193 grep -q '^c\.o:' $f >>tmp
199 test_output no_select
203 test_case devi pass "Device instance"
205 include \"${srcdir}/d_min\"
212 sed -ne '/^struct cfdriver \* const cfdriver_list_initial\[\]/,/^};/p' $f >tmp.cfdriver
213 sed -ne '/^struct cfdata cfdata\[\]/,/^};/p' $f >tmp.cfdata
215 grep -q '^CFDRIVER_DECL(d, ' $f &&
216 grep -q '&d_cd,' tmp.cfdriver &&
217 grep -q '^extern struct cfattach d_ca;$' $f &&
218 grep -q '^static const struct cfiattrdata \* const d_attrs\[\]' $f &&
219 grep -q '^static const struct cfiattrdata icf_iattrdata' $f &&
220 grep -q '{ "d",' tmp.cfdata &&
227 # Check minimal kernel config(1) output
228 test_case min pass "Minimal config"
232 test -e config_file.h &&
233 test -e config_time.src &&
236 test -e locators.h &&
237 test -e swapregress.c &&
246 grep -q '^%' $f >tmp.template
248 grep -q '^MACHINE=regress$' $f &&
249 (merge_backslash $f | grep -q '^IDENT=[ ]*-DMAXUSERS="4"') &&
250 [ ! -s tmp.template ] &&
256 check_min_makefile &&
263 atf_init_test_cases()
265 atf_add_test_case shadow_instance
266 atf_add_test_case loop
267 atf_add_test_case loop2
268 atf_add_test_case pseudo_parent
269 atf_add_test_case postponed_orphan
270 atf_add_test_case no_pseudo
271 atf_add_test_case deffs_redef
272 atf_add_test_case undefined_opt
273 atf_add_test_case no_undefined_opt
274 atf_add_test_case select
275 atf_add_test_case no_select
276 atf_add_test_case devi
277 atf_add_test_case min