Home | History | Annotate | Line # | Download | only in config
t_config.sh revision 1.6
      1  1.2  uebayasi # $NetBSD: t_config.sh,v 1.6 2014/11/20 09:02:00 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.6  uebayasi 	atf_check -o ignore -s eq:0 \
     52  1.6  uebayasi 	    config -s "${supportdir}" -b "compile/${name}" "${config}"
     53  1.6  uebayasi }
     54  1.6  uebayasi 
     55  1.6  uebayasi run_and_check_warn()
     56  1.6  uebayasi {
     57  1.6  uebayasi 	local name="${1}"; shift
     58  1.6  uebayasi 
     59  1.6  uebayasi 	run_and_check_prep "${name}"
     60  1.6  uebayasi 
     61  1.6  uebayasi 	local stderr
     62  1.6  uebayasi 	eval stderr=\$${name}_stderr
     63  1.6  uebayasi 	atf_check -o ignore -e "${stderr}" -s eq:0 \
     64  1.1    jruoho 	    config -s "${supportdir}" -b "compile/${name}" "${config}"
     65  1.1    jruoho }
     66  1.1    jruoho 
     67  1.1    jruoho run_and_check_fail()
     68  1.1    jruoho {
     69  1.1    jruoho 	local name="${1}"; shift
     70  1.1    jruoho 
     71  1.2  uebayasi 	run_and_check_prep "${name}"
     72  1.1    jruoho 
     73  1.1    jruoho 	atf_check -o ignore -e ignore -s ne:0 \
     74  1.1    jruoho 	    config -s "${supportdir}" -b "compile/${name}" "${config}"
     75  1.1    jruoho }
     76  1.1    jruoho 
     77  1.4  uebayasi test_output()
     78  1.4  uebayasi {
     79  1.4  uebayasi 	local name="${1}"; shift
     80  1.4  uebayasi 	local res=1
     81  1.4  uebayasi 
     82  1.4  uebayasi 	run_and_check_prep "${name}"
     83  1.4  uebayasi 
     84  1.4  uebayasi 	config -s "${supportdir}" -b compile/"${name}" "${config}" >/dev/null &&
     85  1.4  uebayasi 	cd compile/"${name}" &&
     86  1.4  uebayasi 	check_${name} &&
     87  1.4  uebayasi 	cd $OLDPWD &&
     88  1.4  uebayasi 	res=0
     89  1.4  uebayasi 
     90  1.4  uebayasi 	atf_check test $res -eq 0
     91  1.4  uebayasi }
     92  1.4  uebayasi 
     93  1.1    jruoho # Defines a test case for config(1).
     94  1.1    jruoho test_case()
     95  1.1    jruoho {
     96  1.1    jruoho 	local name="${1}"; shift
     97  1.1    jruoho 	local type="${1}"; shift
     98  1.1    jruoho 	local descr="${*}"
     99  1.1    jruoho 
    100  1.1    jruoho 	atf_test_case "${name}"
    101  1.1    jruoho 	eval "${name}_head() { \
    102  1.1    jruoho 		atf_set descr \"${descr}\"; \
    103  1.1    jruoho 		atf_set require.progs \"config\"; \
    104  1.1    jruoho 	}"
    105  1.1    jruoho 	eval "${name}_body() { \
    106  1.1    jruoho 		run_and_check_${type} '${name}'; \
    107  1.1    jruoho 	}"
    108  1.1    jruoho }
    109  1.1    jruoho 
    110  1.1    jruoho test_case shadow_instance pass "Checks correct handling of shadowed instances"
    111  1.1    jruoho test_case loop pass "Checks correct handling of loops"
    112  1.1    jruoho test_case loop2 pass "Checks correct handling of devices that can be their" \
    113  1.1    jruoho     "own parents"
    114  1.1    jruoho test_case pseudo_parent pass "Checks correct handling of children of pseudo" \
    115  1.1    jruoho     "devices (PR/32329)"
    116  1.1    jruoho test_case postponed_orphan fail "Checks that config catches adding an" \
    117  1.1    jruoho     "instance of a child of a negated instance as error"
    118  1.1    jruoho test_case no_pseudo fail "Checks that config catches ommited 'pseudo-device'" \
    119  1.1    jruoho     "as error (PR/34111)"
    120  1.1    jruoho test_case deffs_redef fail "Checks that config doesn't allow a deffs to use" \
    121  1.1    jruoho     "the same name as a previous defflag/defparam"
    122  1.1    jruoho 
    123  1.3  uebayasi # Selecting an undefined option.
    124  1.3  uebayasi undefined_opt_config_str='
    125  1.3  uebayasi include "../d_min"
    126  1.3  uebayasi options UNDEFINED
    127  1.3  uebayasi '
    128  1.3  uebayasi test_case undefined_opt pass \
    129  1.3  uebayasi     "Checks that config allows a selection for an undefined options"
    130  1.3  uebayasi 
    131  1.3  uebayasi # Negating an undefined option.
    132  1.3  uebayasi no_undefined_opt_config_str='
    133  1.3  uebayasi include "../d_min"
    134  1.3  uebayasi no options UNDEFINED
    135  1.3  uebayasi '
    136  1.6  uebayasi no_undefined_opt_stderr='match:UNDEFINED'
    137  1.6  uebayasi test_case no_undefined_opt warn \
    138  1.3  uebayasi     "Checks that config allows a negation for an undefined options"
    139  1.3  uebayasi 
    140  1.4  uebayasi # Attribute selection
    141  1.4  uebayasi test_case select pass "Attribute selection"
    142  1.4  uebayasi select_config_str='
    143  1.4  uebayasi include "../d_min"
    144  1.4  uebayasi select c
    145  1.4  uebayasi '
    146  1.4  uebayasi check_select()
    147  1.4  uebayasi {
    148  1.4  uebayasi 	local f=Makefile
    149  1.4  uebayasi 
    150  1.4  uebayasi 	grep -q '^a\.o:' $f &&
    151  1.4  uebayasi 	grep -q '^b\.o:' $f &&
    152  1.4  uebayasi 	grep -q '^c\.o:' $f &&
    153  1.4  uebayasi 	:
    154  1.4  uebayasi }
    155  1.4  uebayasi select_body() {
    156  1.4  uebayasi 	test_output select
    157  1.4  uebayasi }
    158  1.4  uebayasi 
    159  1.4  uebayasi # Attribute negation
    160  1.4  uebayasi test_case no_select pass "Attribute negation"
    161  1.4  uebayasi no_select_config_str='
    162  1.4  uebayasi include "../d_min"
    163  1.4  uebayasi select c
    164  1.4  uebayasi no select a
    165  1.4  uebayasi '
    166  1.4  uebayasi check_no_select()
    167  1.4  uebayasi {
    168  1.4  uebayasi 	local f=Makefile
    169  1.4  uebayasi 
    170  1.4  uebayasi 	: >tmp
    171  1.4  uebayasi 	grep -q '^a\.o:' $f >>tmp
    172  1.4  uebayasi 	grep -q '^b\.o:' $f >>tmp
    173  1.4  uebayasi 	grep -q '^c\.o:' $f >>tmp
    174  1.4  uebayasi 
    175  1.4  uebayasi 	[ ! -s tmp ] &&
    176  1.4  uebayasi 	:
    177  1.4  uebayasi }
    178  1.4  uebayasi no_select_body() {
    179  1.4  uebayasi 	test_output no_select
    180  1.4  uebayasi }
    181  1.4  uebayasi 
    182  1.5  uebayasi # Device instance
    183  1.5  uebayasi test_case devi pass "Device instance"
    184  1.5  uebayasi devi_config_str='
    185  1.5  uebayasi include "../d_min"
    186  1.5  uebayasi d0 at root
    187  1.5  uebayasi '
    188  1.5  uebayasi check_devi()
    189  1.5  uebayasi {
    190  1.5  uebayasi 	local f=ioconf.c
    191  1.5  uebayasi 
    192  1.5  uebayasi 	sed -ne '/^struct cfdriver \* const cfdriver_list_initial\[\]/,/^};/p' $f >tmp.cfdriver
    193  1.5  uebayasi 	sed -ne '/^struct cfdata cfdata\[\]/,/^};/p' $f >tmp.cfdata
    194  1.5  uebayasi 
    195  1.5  uebayasi 	grep -q '^CFDRIVER_DECL(d, ' $f &&
    196  1.5  uebayasi 	grep -q '&d_cd,' tmp.cfdriver &&
    197  1.5  uebayasi 	grep -q '^extern struct cfattach d_ca;$' $f &&
    198  1.5  uebayasi 	grep -q '^static const struct cfiattrdata \* const d_attrs\[\]' $f &&
    199  1.5  uebayasi 	grep -q '^static const struct cfiattrdata icf_iattrdata' $f &&
    200  1.5  uebayasi 	grep -q '{ "d",' tmp.cfdata &&
    201  1.5  uebayasi 	:
    202  1.5  uebayasi }
    203  1.5  uebayasi devi_body() {
    204  1.5  uebayasi 	test_output devi
    205  1.5  uebayasi }
    206  1.5  uebayasi 
    207  1.2  uebayasi # Check minimal kernel config(1) output
    208  1.4  uebayasi test_case min pass "Minimal config"
    209  1.2  uebayasi check_min_files()
    210  1.2  uebayasi {
    211  1.2  uebayasi 	test -e Makefile &&
    212  1.2  uebayasi 	test -e config_file.h &&
    213  1.2  uebayasi 	test -e config_time.src &&
    214  1.2  uebayasi 	test -e ioconf.c &&
    215  1.2  uebayasi 	test -e ioconf.h &&
    216  1.2  uebayasi 	test -e locators.h &&
    217  1.2  uebayasi 	test -e swapregress.c &&
    218  1.2  uebayasi 	test -h machine &&
    219  1.2  uebayasi 	test -h regress &&
    220  1.2  uebayasi 	:
    221  1.2  uebayasi }
    222  1.2  uebayasi check_min_makefile()
    223  1.2  uebayasi {
    224  1.3  uebayasi 	local f=Makefile
    225  1.3  uebayasi 
    226  1.3  uebayasi 	grep -q '^%' $f >tmp.template
    227  1.2  uebayasi 
    228  1.3  uebayasi 	grep -q '^MACHINE=regress$' $f &&
    229  1.3  uebayasi 	grep -q '^PARAM=-DMAXUSERS=4$' $f &&
    230  1.3  uebayasi 	grep -q '^all: regress$' $f &&
    231  1.3  uebayasi 	grep -q '^regress:' $f &&
    232  1.2  uebayasi 	[ ! -s tmp.template ] &&
    233  1.2  uebayasi 	:
    234  1.2  uebayasi }
    235  1.4  uebayasi check_min()
    236  1.2  uebayasi {
    237  1.2  uebayasi 	check_min_files &&
    238  1.2  uebayasi 	check_min_makefile &&
    239  1.4  uebayasi 	:
    240  1.2  uebayasi }
    241  1.2  uebayasi min_body() {
    242  1.4  uebayasi 	test_output min
    243  1.2  uebayasi }
    244  1.2  uebayasi 
    245  1.1    jruoho atf_init_test_cases()
    246  1.1    jruoho {
    247  1.1    jruoho 	atf_add_test_case shadow_instance
    248  1.1    jruoho 	atf_add_test_case loop
    249  1.1    jruoho 	atf_add_test_case loop2
    250  1.1    jruoho 	atf_add_test_case pseudo_parent
    251  1.1    jruoho 	atf_add_test_case postponed_orphan
    252  1.1    jruoho 	atf_add_test_case no_pseudo
    253  1.1    jruoho 	atf_add_test_case deffs_redef
    254  1.3  uebayasi 	atf_add_test_case undefined_opt
    255  1.3  uebayasi 	atf_add_test_case no_undefined_opt
    256  1.4  uebayasi 	atf_add_test_case select
    257  1.4  uebayasi 	atf_add_test_case no_select
    258  1.5  uebayasi 	atf_add_test_case devi
    259  1.2  uebayasi 	atf_add_test_case min
    260  1.1    jruoho }
    261