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