Home | History | Annotate | Line # | Download | only in config
t_config.sh revision 1.8.14.1
      1  1.8.14.1    martin # $NetBSD: t_config.sh,v 1.8.14.1 2020/04/08 14:09:13 martin 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.8  christos srcdir=..
     29       1.8  christos merge_backslash()
     30       1.8  christos {
     31       1.8  christos 	sed '
     32       1.8  christos : again
     33       1.8  christos /\\$/ {
     34       1.8  christos     N
     35       1.8  christos     s/\\\n//
     36       1.8  christos     t again
     37       1.8  christos }
     38       1.8  christos ' "$1"
     39       1.8  christos }
     40       1.2  uebayasi run_and_check_prep()
     41       1.1    jruoho {
     42       1.1    jruoho 	local name="${1}"; shift
     43       1.1    jruoho 
     44       1.8  christos 	mkdir -p compile
     45       1.8  christos 	srcdir="$(atf_get_srcdir)"
     46       1.8  christos 	if [ ! -d "${srcdir}/support" ]; then
     47       1.8  christos 		srcdir="$(dirname "${srcdir}")"
     48       1.8  christos 		if [ ! -d "${srcdir}/support" ]; then
     49       1.8  christos 			atf_fail "bad source directory ${srcdir}"
     50       1.8  christos 			exit 1
     51       1.8  christos 		fi
     52       1.8  christos 	fi
     53       1.8  christos 	supportdir="${srcdir}/support"
     54       1.3  uebayasi 
     55       1.3  uebayasi 	local config_str
     56       1.3  uebayasi 	eval config_str=\$${name}_config_str
     57       1.3  uebayasi 	if [ -n "$config_str" ]; then
     58       1.3  uebayasi 		config="d_${name}"
     59       1.3  uebayasi 		printf "$config_str" >"${config}"
     60       1.3  uebayasi 	else
     61       1.8  christos 		config="${srcdir}/d_${name}"
     62       1.3  uebayasi 	fi
     63       1.2  uebayasi }
     64       1.2  uebayasi 
     65       1.2  uebayasi run_and_check_pass()
     66       1.2  uebayasi {
     67       1.2  uebayasi 	local name="${1}"; shift
     68       1.2  uebayasi 
     69       1.2  uebayasi 	run_and_check_prep "${name}"
     70       1.1    jruoho 
     71       1.6  uebayasi 	atf_check -o ignore -s eq:0 \
     72       1.6  uebayasi 	    config -s "${supportdir}" -b "compile/${name}" "${config}"
     73       1.6  uebayasi }
     74       1.6  uebayasi 
     75       1.6  uebayasi run_and_check_warn()
     76       1.6  uebayasi {
     77       1.6  uebayasi 	local name="${1}"; shift
     78       1.6  uebayasi 
     79       1.6  uebayasi 	run_and_check_prep "${name}"
     80       1.6  uebayasi 
     81       1.6  uebayasi 	local stderr
     82       1.6  uebayasi 	eval stderr=\$${name}_stderr
     83       1.6  uebayasi 	atf_check -o ignore -e "${stderr}" -s eq:0 \
     84       1.1    jruoho 	    config -s "${supportdir}" -b "compile/${name}" "${config}"
     85       1.1    jruoho }
     86       1.1    jruoho 
     87       1.1    jruoho run_and_check_fail()
     88       1.1    jruoho {
     89       1.1    jruoho 	local name="${1}"; shift
     90       1.1    jruoho 
     91       1.2  uebayasi 	run_and_check_prep "${name}"
     92       1.1    jruoho 
     93       1.1    jruoho 	atf_check -o ignore -e ignore -s ne:0 \
     94       1.1    jruoho 	    config -s "${supportdir}" -b "compile/${name}" "${config}"
     95       1.1    jruoho }
     96       1.1    jruoho 
     97       1.4  uebayasi test_output()
     98       1.4  uebayasi {
     99       1.4  uebayasi 	local name="${1}"; shift
    100       1.4  uebayasi 	local res=1
    101       1.4  uebayasi 
    102       1.4  uebayasi 	run_and_check_prep "${name}"
    103       1.4  uebayasi 
    104       1.4  uebayasi 	config -s "${supportdir}" -b compile/"${name}" "${config}" >/dev/null &&
    105       1.4  uebayasi 	cd compile/"${name}" &&
    106       1.4  uebayasi 	check_${name} &&
    107       1.4  uebayasi 	cd $OLDPWD &&
    108       1.4  uebayasi 	res=0
    109       1.4  uebayasi 
    110       1.4  uebayasi 	atf_check test $res -eq 0
    111       1.4  uebayasi }
    112       1.4  uebayasi 
    113       1.1    jruoho # Defines a test case for config(1).
    114       1.1    jruoho test_case()
    115       1.1    jruoho {
    116       1.1    jruoho 	local name="${1}"; shift
    117       1.1    jruoho 	local type="${1}"; shift
    118       1.1    jruoho 	local descr="${*}"
    119       1.1    jruoho 
    120       1.1    jruoho 	atf_test_case "${name}"
    121       1.1    jruoho 	eval "${name}_head() { \
    122       1.1    jruoho 		atf_set descr \"${descr}\"; \
    123       1.1    jruoho 		atf_set require.progs \"config\"; \
    124       1.1    jruoho 	}"
    125       1.1    jruoho 	eval "${name}_body() { \
    126       1.1    jruoho 		run_and_check_${type} '${name}'; \
    127       1.1    jruoho 	}"
    128       1.1    jruoho }
    129       1.1    jruoho 
    130       1.1    jruoho test_case shadow_instance pass "Checks correct handling of shadowed instances"
    131       1.1    jruoho test_case loop pass "Checks correct handling of loops"
    132       1.1    jruoho test_case loop2 pass "Checks correct handling of devices that can be their" \
    133       1.1    jruoho     "own parents"
    134       1.1    jruoho test_case pseudo_parent pass "Checks correct handling of children of pseudo" \
    135       1.1    jruoho     "devices (PR/32329)"
    136       1.1    jruoho test_case postponed_orphan fail "Checks that config catches adding an" \
    137       1.1    jruoho     "instance of a child of a negated instance as error"
    138       1.1    jruoho test_case no_pseudo fail "Checks that config catches ommited 'pseudo-device'" \
    139       1.1    jruoho     "as error (PR/34111)"
    140       1.1    jruoho test_case deffs_redef fail "Checks that config doesn't allow a deffs to use" \
    141       1.1    jruoho     "the same name as a previous defflag/defparam"
    142       1.1    jruoho 
    143       1.3  uebayasi # Selecting an undefined option.
    144       1.8  christos undefined_opt_config_str="
    145       1.8  christos include \"${srcdir}/d_min\"
    146       1.3  uebayasi options UNDEFINED
    147       1.8  christos "
    148       1.3  uebayasi test_case undefined_opt pass \
    149       1.3  uebayasi     "Checks that config allows a selection for an undefined options"
    150       1.3  uebayasi 
    151       1.3  uebayasi # Negating an undefined option.
    152       1.8  christos no_undefined_opt_config_str="
    153       1.8  christos include \"${srcdir}/d_min\"
    154       1.3  uebayasi no options UNDEFINED
    155       1.8  christos "
    156       1.6  uebayasi no_undefined_opt_stderr='match:UNDEFINED'
    157       1.6  uebayasi test_case no_undefined_opt warn \
    158       1.3  uebayasi     "Checks that config allows a negation for an undefined options"
    159       1.3  uebayasi 
    160       1.4  uebayasi # Attribute selection
    161       1.4  uebayasi test_case select pass "Attribute selection"
    162       1.8  christos select_config_str="
    163       1.8  christos include \"${srcdir}/d_min\"
    164       1.4  uebayasi select c
    165       1.8  christos "
    166       1.4  uebayasi check_select()
    167       1.4  uebayasi {
    168       1.4  uebayasi 	local f=Makefile
    169       1.4  uebayasi 
    170       1.7  uebayasi 	grep -q '^	a\.c ' $f &&
    171       1.7  uebayasi 	grep -q '^	b\.c ' $f &&
    172       1.7  uebayasi 	grep -q '^	c\.c ' $f &&
    173       1.4  uebayasi 	:
    174       1.4  uebayasi }
    175       1.4  uebayasi select_body() {
    176       1.4  uebayasi 	test_output select
    177       1.4  uebayasi }
    178       1.4  uebayasi 
    179       1.4  uebayasi # Attribute negation
    180       1.4  uebayasi test_case no_select pass "Attribute negation"
    181       1.8  christos no_select_config_str="
    182       1.8  christos include \"${srcdir}/d_min\"
    183       1.4  uebayasi select c
    184       1.4  uebayasi no select a
    185       1.8  christos "
    186       1.4  uebayasi check_no_select()
    187       1.4  uebayasi {
    188       1.4  uebayasi 	local f=Makefile
    189       1.4  uebayasi 
    190       1.4  uebayasi 	: >tmp
    191       1.4  uebayasi 	grep -q '^a\.o:' $f >>tmp
    192       1.4  uebayasi 	grep -q '^b\.o:' $f >>tmp
    193       1.4  uebayasi 	grep -q '^c\.o:' $f >>tmp
    194       1.4  uebayasi 
    195       1.4  uebayasi 	[ ! -s tmp ] &&
    196       1.4  uebayasi 	:
    197       1.4  uebayasi }
    198       1.4  uebayasi no_select_body() {
    199       1.4  uebayasi 	test_output no_select
    200       1.4  uebayasi }
    201       1.4  uebayasi 
    202       1.5  uebayasi # Device instance
    203       1.5  uebayasi test_case devi pass "Device instance"
    204       1.8  christos devi_config_str="
    205       1.8  christos include \"${srcdir}/d_min\"
    206       1.5  uebayasi d0 at root
    207       1.8  christos "
    208       1.5  uebayasi check_devi()
    209       1.5  uebayasi {
    210       1.5  uebayasi 	local f=ioconf.c
    211       1.5  uebayasi 
    212       1.5  uebayasi 	sed -ne '/^struct cfdriver \* const cfdriver_list_initial\[\]/,/^};/p' $f >tmp.cfdriver
    213       1.5  uebayasi 	sed -ne '/^struct cfdata cfdata\[\]/,/^};/p' $f >tmp.cfdata
    214       1.5  uebayasi 
    215       1.5  uebayasi 	grep -q '^CFDRIVER_DECL(d, ' $f &&
    216       1.5  uebayasi 	grep -q '&d_cd,' tmp.cfdriver &&
    217       1.5  uebayasi 	grep -q '^extern struct cfattach d_ca;$' $f &&
    218       1.5  uebayasi 	grep -q '^static const struct cfiattrdata \* const d_attrs\[\]' $f &&
    219       1.5  uebayasi 	grep -q '^static const struct cfiattrdata icf_iattrdata' $f &&
    220       1.5  uebayasi 	grep -q '{ "d",' tmp.cfdata &&
    221       1.5  uebayasi 	:
    222       1.5  uebayasi }
    223       1.5  uebayasi devi_body() {
    224       1.5  uebayasi 	test_output devi
    225       1.5  uebayasi }
    226       1.5  uebayasi 
    227       1.2  uebayasi # Check minimal kernel config(1) output
    228       1.4  uebayasi test_case min pass "Minimal config"
    229       1.2  uebayasi check_min_files()
    230       1.2  uebayasi {
    231       1.2  uebayasi 	test -e Makefile &&
    232       1.2  uebayasi 	test -e config_file.h &&
    233       1.2  uebayasi 	test -e config_time.src &&
    234       1.2  uebayasi 	test -e ioconf.c &&
    235       1.2  uebayasi 	test -e ioconf.h &&
    236       1.2  uebayasi 	test -e locators.h &&
    237       1.2  uebayasi 	test -e swapregress.c &&
    238       1.2  uebayasi 	test -h machine &&
    239       1.2  uebayasi 	test -h regress &&
    240       1.2  uebayasi 	:
    241       1.2  uebayasi }
    242       1.2  uebayasi check_min_makefile()
    243       1.2  uebayasi {
    244       1.3  uebayasi 	local f=Makefile
    245       1.3  uebayasi 
    246       1.3  uebayasi 	grep -q '^%' $f >tmp.template
    247       1.2  uebayasi 
    248       1.3  uebayasi 	grep -q '^MACHINE=regress$' $f &&
    249       1.8  christos 	(merge_backslash $f | grep -q '^IDENT=[ 	]*-DMAXUSERS="4"') &&
    250       1.2  uebayasi 	[ ! -s tmp.template ] &&
    251       1.2  uebayasi 	:
    252       1.2  uebayasi }
    253       1.4  uebayasi check_min()
    254       1.2  uebayasi {
    255       1.2  uebayasi 	check_min_files &&
    256       1.2  uebayasi 	check_min_makefile &&
    257       1.4  uebayasi 	:
    258       1.2  uebayasi }
    259       1.2  uebayasi min_body() {
    260       1.4  uebayasi 	test_output min
    261       1.2  uebayasi }
    262       1.2  uebayasi 
    263  1.8.14.1    martin # Check ifdef supper
    264  1.8.14.1    martin test_case ifdef pass "ifdef config"
    265  1.8.14.1    martin check_ifdef_files()
    266  1.8.14.1    martin {
    267  1.8.14.1    martin 	test -e Makefile &&
    268  1.8.14.1    martin 	test -e config_file.h &&
    269  1.8.14.1    martin 	test -e config_time.src &&
    270  1.8.14.1    martin 	test -e ioconf.c &&
    271  1.8.14.1    martin 	test -e ioconf.h &&
    272  1.8.14.1    martin 	test -e locators.h &&
    273  1.8.14.1    martin 	test -e swapregress.c &&
    274  1.8.14.1    martin 	test -h machine &&
    275  1.8.14.1    martin 	test -h regress &&
    276  1.8.14.1    martin 	:
    277  1.8.14.1    martin }
    278  1.8.14.1    martin 
    279  1.8.14.1    martin check_ifdef_makefile()
    280  1.8.14.1    martin {
    281  1.8.14.1    martin 	local f=Makefile
    282  1.8.14.1    martin 	local e='-DOK1_1  -DOK2_1  -DOK2_2  -DOK3_1  -DOK3_2  -DOK3_3  -DOK3_4  -DOK3_5  -DOK4_1  -DMAXUSERS="4"'
    283  1.8.14.1    martin 	local r
    284  1.8.14.1    martin 	r=$(make -f Makefile -V IDENT)
    285  1.8.14.1    martin 	if [ "$r" != "$e" ]; then
    286  1.8.14.1    martin 		echo "Expected: '$e'"
    287  1.8.14.1    martin 		echo "Result: '$r'"
    288  1.8.14.1    martin 		return 1
    289  1.8.14.1    martin 	fi
    290  1.8.14.1    martin }
    291  1.8.14.1    martin 
    292  1.8.14.1    martin check_ifdef()
    293  1.8.14.1    martin {
    294  1.8.14.1    martin 	check_ifdef_files &&
    295  1.8.14.1    martin 	check_ifdef_makefile &&
    296  1.8.14.1    martin 	:
    297  1.8.14.1    martin }
    298  1.8.14.1    martin ifdef_body() {
    299  1.8.14.1    martin 	test_output ifdef
    300  1.8.14.1    martin }
    301  1.8.14.1    martin 
    302       1.1    jruoho atf_init_test_cases()
    303       1.1    jruoho {
    304       1.1    jruoho 	atf_add_test_case shadow_instance
    305       1.1    jruoho 	atf_add_test_case loop
    306       1.1    jruoho 	atf_add_test_case loop2
    307       1.1    jruoho 	atf_add_test_case pseudo_parent
    308       1.1    jruoho 	atf_add_test_case postponed_orphan
    309       1.1    jruoho 	atf_add_test_case no_pseudo
    310       1.1    jruoho 	atf_add_test_case deffs_redef
    311       1.3  uebayasi 	atf_add_test_case undefined_opt
    312       1.3  uebayasi 	atf_add_test_case no_undefined_opt
    313       1.4  uebayasi 	atf_add_test_case select
    314       1.4  uebayasi 	atf_add_test_case no_select
    315       1.5  uebayasi 	atf_add_test_case devi
    316       1.2  uebayasi 	atf_add_test_case min
    317  1.8.14.1    martin 	atf_add_test_case ifdef
    318       1.1    jruoho }
    319