t_config.sh revision 1.3 1 # $NetBSD: t_config.sh,v 1.3 2014/10/31 04:54:17 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 # Defines a test case for config(1).
66 test_case()
67 {
68 local name="${1}"; shift
69 local type="${1}"; shift
70 local descr="${*}"
71
72 atf_test_case "${name}"
73 eval "${name}_head() { \
74 atf_set descr \"${descr}\"; \
75 atf_set require.progs \"config\"; \
76 }"
77 eval "${name}_body() { \
78 run_and_check_${type} '${name}'; \
79 }"
80 }
81
82 test_case shadow_instance pass "Checks correct handling of shadowed instances"
83 test_case loop pass "Checks correct handling of loops"
84 test_case loop2 pass "Checks correct handling of devices that can be their" \
85 "own parents"
86 test_case pseudo_parent pass "Checks correct handling of children of pseudo" \
87 "devices (PR/32329)"
88 test_case postponed_orphan fail "Checks that config catches adding an" \
89 "instance of a child of a negated instance as error"
90 test_case no_pseudo fail "Checks that config catches ommited 'pseudo-device'" \
91 "as error (PR/34111)"
92 test_case deffs_redef fail "Checks that config doesn't allow a deffs to use" \
93 "the same name as a previous defflag/defparam"
94
95 # Selecting an undefined option.
96 undefined_opt_config_str='
97 include "../d_min"
98 options UNDEFINED
99 '
100 test_case undefined_opt pass \
101 "Checks that config allows a selection for an undefined options"
102
103 # Negating an undefined option.
104 no_undefined_opt_config_str='
105 include "../d_min"
106 no options UNDEFINED
107 '
108 test_case no_undefined_opt pass \
109 "Checks that config allows a negation for an undefined options"
110
111 # Check minimal kernel config(1) output
112 check_min_files()
113 {
114 test -e Makefile &&
115 test -e config_file.h &&
116 test -e config_time.src &&
117 test -e ioconf.c &&
118 test -e ioconf.h &&
119 test -e locators.h &&
120 test -e swapregress.c &&
121 test -h machine &&
122 test -h regress &&
123 :
124 }
125
126 check_min_makefile()
127 {
128 local f=Makefile
129
130 grep -q '^%' $f >tmp.template
131
132 grep -q '^MACHINE=regress$' $f &&
133 grep -q '^PARAM=-DMAXUSERS=4$' $f &&
134 grep -q '^all: regress$' $f &&
135 grep -q '^regress:' $f &&
136 [ ! -s tmp.template ] &&
137 :
138 }
139
140 test_min()
141 {
142 local res=1
143
144 run_and_check_prep min
145
146 config -s "${supportdir}" -b compile/min "${config}" >/dev/null &&
147 cd compile/min &&
148 check_min_files &&
149 check_min_makefile &&
150 cd $OLDPWD &&
151 res=0
152
153 atf_check test $res -eq 0
154 }
155
156 test_case min pass "Minimal config"
157 min_body() {
158 test_min
159 }
160
161 atf_init_test_cases()
162 {
163 atf_add_test_case shadow_instance
164 atf_add_test_case loop
165 atf_add_test_case loop2
166 atf_add_test_case pseudo_parent
167 atf_add_test_case postponed_orphan
168 atf_add_test_case no_pseudo
169 atf_add_test_case deffs_redef
170 atf_add_test_case undefined_opt
171 atf_add_test_case no_undefined_opt
172 atf_add_test_case min
173 }
174