1 # $NetBSD: t_config.sh,v 1.7 2015/10/04 07:59:47 uebayasi 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.
30 local name
="${1}"; shift
33 supportdir
="$(atf_get_srcdir)/support"
36 eval config_str
=\$
${name}_config_str
37 if [ -n "$config_str" ]; then
39 printf "$config_str" >"${config}"
41 config
="$(atf_get_srcdir)/d_${name}"
47 local name
="${1}"; shift
49 run_and_check_prep
"${name}"
51 atf_check
-o ignore
-s eq
:0 \
52 config
-s "${supportdir}" -b "compile/${name}" "${config}"
57 local name
="${1}"; shift
59 run_and_check_prep
"${name}"
62 eval stderr
=\$
${name}_stderr
63 atf_check
-o ignore
-e "${stderr}" -s eq
:0 \
64 config
-s "${supportdir}" -b "compile/${name}" "${config}"
69 local name
="${1}"; shift
71 run_and_check_prep
"${name}"
73 atf_check
-o ignore
-e ignore
-s ne
:0 \
74 config
-s "${supportdir}" -b "compile/${name}" "${config}"
79 local name
="${1}"; shift
82 run_and_check_prep
"${name}"
84 config
-s "${supportdir}" -b compile/"${name}" "${config}" >/dev
/null
&&
85 cd compile
/"${name}" &&
90 atf_check
test $res -eq 0
93 # Defines a test case for config(1).
96 local name
="${1}"; shift
97 local type="${1}"; shift
100 atf_test_case
"${name}"
101 eval "${name}_head() { \
102 atf_set descr \"${descr}\"; \
103 atf_set require.progs \"config\"; \
105 eval "${name}_body() { \
106 run_and_check_${type} '${name}'; \
110 test_case shadow_instance pass
"Checks correct handling of shadowed instances"
111 test_case loop pass
"Checks correct handling of loops"
112 test_case loop2 pass
"Checks correct handling of devices that can be their" \
114 test_case pseudo_parent pass
"Checks correct handling of children of pseudo" \
116 test_case postponed_orphan fail
"Checks that config catches adding an" \
117 "instance of a child of a negated instance as error"
118 test_case no_pseudo fail
"Checks that config catches ommited 'pseudo-device'" \
119 "as error (PR/34111)"
120 test_case deffs_redef fail
"Checks that config doesn't allow a deffs to use" \
121 "the same name as a previous defflag/defparam"
123 # Selecting an undefined option.
124 undefined_opt_config_str
='
128 test_case undefined_opt pass \
129 "Checks that config allows a selection for an undefined options"
131 # Negating an undefined option.
132 no_undefined_opt_config_str
='
136 no_undefined_opt_stderr
='match:UNDEFINED'
137 test_case no_undefined_opt warn \
138 "Checks that config allows a negation for an undefined options"
140 # Attribute selection
141 test_case
select pass
"Attribute selection"
150 grep -q '^ a\.c ' $f &&
151 grep -q '^ b\.c ' $f &&
152 grep -q '^ c\.c ' $f &&
160 test_case no_select pass
"Attribute negation"
161 no_select_config_str
='
171 grep -q '^a\.o:' $f >>tmp
172 grep -q '^b\.o:' $f >>tmp
173 grep -q '^c\.o:' $f >>tmp
179 test_output no_select
183 test_case devi pass
"Device instance"
192 sed -ne '/^struct cfdriver \* const cfdriver_list_initial\[\]/,/^};/p' $f >tmp.cfdriver
193 sed -ne '/^struct cfdata cfdata\[\]/,/^};/p' $f >tmp.cfdata
195 grep -q '^CFDRIVER_DECL(d, ' $f &&
196 grep -q '&d_cd,' tmp.cfdriver
&&
197 grep -q '^extern struct cfattach d_ca;$' $f &&
198 grep -q '^static const struct cfiattrdata \* const d_attrs\[\]' $f &&
199 grep -q '^static const struct cfiattrdata icf_iattrdata' $f &&
200 grep -q '{ "d",' tmp.cfdata
&&
207 # Check minimal kernel config(1) output
208 test_case min pass
"Minimal config"
212 test -e config_file.h
&&
213 test -e config_time.src
&&
216 test -e locators.h
&&
217 test -e swapregress.c
&&
226 grep -q '^%' $f >tmp.template
228 grep -q '^MACHINE=regress$' $f &&
229 grep -q '^PARAM=-DMAXUSERS=4$' $f &&
230 grep -q '^all: regress$' $f &&
231 grep -q '^regress:' $f &&
232 [ ! -s tmp.template
] &&
238 check_min_makefile
&&
245 atf_init_test_cases
()
247 atf_add_test_case shadow_instance
248 atf_add_test_case loop
249 atf_add_test_case loop2
250 atf_add_test_case pseudo_parent
251 atf_add_test_case postponed_orphan
252 atf_add_test_case no_pseudo
253 atf_add_test_case deffs_redef
254 atf_add_test_case undefined_opt
255 atf_add_test_case no_undefined_opt
256 atf_add_test_case
select
257 atf_add_test_case no_select
258 atf_add_test_case devi
259 atf_add_test_case min