1*0a6a1f1dSLionel Sambuc# $NetBSD: t_config.sh,v 1.7 2015/10/04 07:59:47 uebayasi Exp $ 211be35a1SLionel Sambuc# 311be35a1SLionel Sambuc# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. 411be35a1SLionel Sambuc# All rights reserved. 511be35a1SLionel Sambuc# 611be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 711be35a1SLionel Sambuc# modification, are permitted provided that the following conditions 811be35a1SLionel Sambuc# are met: 911be35a1SLionel Sambuc# 1. Redistributions of source code must retain the above copyright 1011be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 1111be35a1SLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright 1211be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 1311be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 1411be35a1SLionel Sambuc# 1511be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 1611be35a1SLionel Sambuc# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1711be35a1SLionel Sambuc# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1811be35a1SLionel Sambuc# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 1911be35a1SLionel Sambuc# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2011be35a1SLionel Sambuc# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2111be35a1SLionel Sambuc# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2211be35a1SLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2311be35a1SLionel Sambuc# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2411be35a1SLionel Sambuc# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2511be35a1SLionel Sambuc# POSSIBILITY OF SUCH DAMAGE. 2611be35a1SLionel Sambuc# 2711be35a1SLionel Sambuc 28*0a6a1f1dSLionel Sambucrun_and_check_prep() 2911be35a1SLionel Sambuc{ 3011be35a1SLionel Sambuc local name="${1}"; shift 3111be35a1SLionel Sambuc 3211be35a1SLionel Sambuc mkdir compile 3311be35a1SLionel Sambuc supportdir="$(atf_get_srcdir)/support" 3411be35a1SLionel Sambuc 35*0a6a1f1dSLionel Sambuc local config_str 36*0a6a1f1dSLionel Sambuc eval config_str=\$${name}_config_str 37*0a6a1f1dSLionel Sambuc if [ -n "$config_str" ]; then 38*0a6a1f1dSLionel Sambuc config="d_${name}" 39*0a6a1f1dSLionel Sambuc printf "$config_str" >"${config}" 40*0a6a1f1dSLionel Sambuc else 41*0a6a1f1dSLionel Sambuc config="$(atf_get_srcdir)/d_${name}" 42*0a6a1f1dSLionel Sambuc fi 43*0a6a1f1dSLionel Sambuc} 44*0a6a1f1dSLionel Sambuc 45*0a6a1f1dSLionel Sambucrun_and_check_pass() 46*0a6a1f1dSLionel Sambuc{ 47*0a6a1f1dSLionel Sambuc local name="${1}"; shift 48*0a6a1f1dSLionel Sambuc 49*0a6a1f1dSLionel Sambuc run_and_check_prep "${name}" 50*0a6a1f1dSLionel Sambuc 51*0a6a1f1dSLionel Sambuc atf_check -o ignore -s eq:0 \ 52*0a6a1f1dSLionel Sambuc config -s "${supportdir}" -b "compile/${name}" "${config}" 53*0a6a1f1dSLionel Sambuc} 54*0a6a1f1dSLionel Sambuc 55*0a6a1f1dSLionel Sambucrun_and_check_warn() 56*0a6a1f1dSLionel Sambuc{ 57*0a6a1f1dSLionel Sambuc local name="${1}"; shift 58*0a6a1f1dSLionel Sambuc 59*0a6a1f1dSLionel Sambuc run_and_check_prep "${name}" 60*0a6a1f1dSLionel Sambuc 61*0a6a1f1dSLionel Sambuc local stderr 62*0a6a1f1dSLionel Sambuc eval stderr=\$${name}_stderr 63*0a6a1f1dSLionel Sambuc atf_check -o ignore -e "${stderr}" -s eq:0 \ 6411be35a1SLionel Sambuc config -s "${supportdir}" -b "compile/${name}" "${config}" 6511be35a1SLionel Sambuc} 6611be35a1SLionel Sambuc 6711be35a1SLionel Sambucrun_and_check_fail() 6811be35a1SLionel Sambuc{ 6911be35a1SLionel Sambuc local name="${1}"; shift 7011be35a1SLionel Sambuc 71*0a6a1f1dSLionel Sambuc run_and_check_prep "${name}" 7211be35a1SLionel Sambuc 7311be35a1SLionel Sambuc atf_check -o ignore -e ignore -s ne:0 \ 7411be35a1SLionel Sambuc config -s "${supportdir}" -b "compile/${name}" "${config}" 7511be35a1SLionel Sambuc} 7611be35a1SLionel Sambuc 77*0a6a1f1dSLionel Sambuctest_output() 78*0a6a1f1dSLionel Sambuc{ 79*0a6a1f1dSLionel Sambuc local name="${1}"; shift 80*0a6a1f1dSLionel Sambuc local res=1 81*0a6a1f1dSLionel Sambuc 82*0a6a1f1dSLionel Sambuc run_and_check_prep "${name}" 83*0a6a1f1dSLionel Sambuc 84*0a6a1f1dSLionel Sambuc config -s "${supportdir}" -b compile/"${name}" "${config}" >/dev/null && 85*0a6a1f1dSLionel Sambuc cd compile/"${name}" && 86*0a6a1f1dSLionel Sambuc check_${name} && 87*0a6a1f1dSLionel Sambuc cd $OLDPWD && 88*0a6a1f1dSLionel Sambuc res=0 89*0a6a1f1dSLionel Sambuc 90*0a6a1f1dSLionel Sambuc atf_check test $res -eq 0 91*0a6a1f1dSLionel Sambuc} 92*0a6a1f1dSLionel Sambuc 9311be35a1SLionel Sambuc# Defines a test case for config(1). 9411be35a1SLionel Sambuctest_case() 9511be35a1SLionel Sambuc{ 9611be35a1SLionel Sambuc local name="${1}"; shift 9711be35a1SLionel Sambuc local type="${1}"; shift 9811be35a1SLionel Sambuc local descr="${*}" 9911be35a1SLionel Sambuc 10011be35a1SLionel Sambuc atf_test_case "${name}" 10111be35a1SLionel Sambuc eval "${name}_head() { \ 10211be35a1SLionel Sambuc atf_set descr \"${descr}\"; \ 10311be35a1SLionel Sambuc atf_set require.progs \"config\"; \ 10411be35a1SLionel Sambuc }" 10511be35a1SLionel Sambuc eval "${name}_body() { \ 10611be35a1SLionel Sambuc run_and_check_${type} '${name}'; \ 10711be35a1SLionel Sambuc }" 10811be35a1SLionel Sambuc} 10911be35a1SLionel Sambuc 11011be35a1SLionel Sambuctest_case shadow_instance pass "Checks correct handling of shadowed instances" 11111be35a1SLionel Sambuctest_case loop pass "Checks correct handling of loops" 11211be35a1SLionel Sambuctest_case loop2 pass "Checks correct handling of devices that can be their" \ 11311be35a1SLionel Sambuc "own parents" 11411be35a1SLionel Sambuctest_case pseudo_parent pass "Checks correct handling of children of pseudo" \ 11511be35a1SLionel Sambuc "devices (PR/32329)" 11611be35a1SLionel Sambuctest_case postponed_orphan fail "Checks that config catches adding an" \ 11711be35a1SLionel Sambuc "instance of a child of a negated instance as error" 11811be35a1SLionel Sambuctest_case no_pseudo fail "Checks that config catches ommited 'pseudo-device'" \ 11911be35a1SLionel Sambuc "as error (PR/34111)" 12011be35a1SLionel Sambuctest_case deffs_redef fail "Checks that config doesn't allow a deffs to use" \ 12111be35a1SLionel Sambuc "the same name as a previous defflag/defparam" 12211be35a1SLionel Sambuc 123*0a6a1f1dSLionel Sambuc# Selecting an undefined option. 124*0a6a1f1dSLionel Sambucundefined_opt_config_str=' 125*0a6a1f1dSLionel Sambucinclude "../d_min" 126*0a6a1f1dSLionel Sambucoptions UNDEFINED 127*0a6a1f1dSLionel Sambuc' 128*0a6a1f1dSLionel Sambuctest_case undefined_opt pass \ 129*0a6a1f1dSLionel Sambuc "Checks that config allows a selection for an undefined options" 130*0a6a1f1dSLionel Sambuc 131*0a6a1f1dSLionel Sambuc# Negating an undefined option. 132*0a6a1f1dSLionel Sambucno_undefined_opt_config_str=' 133*0a6a1f1dSLionel Sambucinclude "../d_min" 134*0a6a1f1dSLionel Sambucno options UNDEFINED 135*0a6a1f1dSLionel Sambuc' 136*0a6a1f1dSLionel Sambucno_undefined_opt_stderr='match:UNDEFINED' 137*0a6a1f1dSLionel Sambuctest_case no_undefined_opt warn \ 138*0a6a1f1dSLionel Sambuc "Checks that config allows a negation for an undefined options" 139*0a6a1f1dSLionel Sambuc 140*0a6a1f1dSLionel Sambuc# Attribute selection 141*0a6a1f1dSLionel Sambuctest_case select pass "Attribute selection" 142*0a6a1f1dSLionel Sambucselect_config_str=' 143*0a6a1f1dSLionel Sambucinclude "../d_min" 144*0a6a1f1dSLionel Sambucselect c 145*0a6a1f1dSLionel Sambuc' 146*0a6a1f1dSLionel Sambuccheck_select() 147*0a6a1f1dSLionel Sambuc{ 148*0a6a1f1dSLionel Sambuc local f=Makefile 149*0a6a1f1dSLionel Sambuc 150*0a6a1f1dSLionel Sambuc grep -q '^ a\.c ' $f && 151*0a6a1f1dSLionel Sambuc grep -q '^ b\.c ' $f && 152*0a6a1f1dSLionel Sambuc grep -q '^ c\.c ' $f && 153*0a6a1f1dSLionel Sambuc : 154*0a6a1f1dSLionel Sambuc} 155*0a6a1f1dSLionel Sambucselect_body() { 156*0a6a1f1dSLionel Sambuc test_output select 157*0a6a1f1dSLionel Sambuc} 158*0a6a1f1dSLionel Sambuc 159*0a6a1f1dSLionel Sambuc# Attribute negation 160*0a6a1f1dSLionel Sambuctest_case no_select pass "Attribute negation" 161*0a6a1f1dSLionel Sambucno_select_config_str=' 162*0a6a1f1dSLionel Sambucinclude "../d_min" 163*0a6a1f1dSLionel Sambucselect c 164*0a6a1f1dSLionel Sambucno select a 165*0a6a1f1dSLionel Sambuc' 166*0a6a1f1dSLionel Sambuccheck_no_select() 167*0a6a1f1dSLionel Sambuc{ 168*0a6a1f1dSLionel Sambuc local f=Makefile 169*0a6a1f1dSLionel Sambuc 170*0a6a1f1dSLionel Sambuc : >tmp 171*0a6a1f1dSLionel Sambuc grep -q '^a\.o:' $f >>tmp 172*0a6a1f1dSLionel Sambuc grep -q '^b\.o:' $f >>tmp 173*0a6a1f1dSLionel Sambuc grep -q '^c\.o:' $f >>tmp 174*0a6a1f1dSLionel Sambuc 175*0a6a1f1dSLionel Sambuc [ ! -s tmp ] && 176*0a6a1f1dSLionel Sambuc : 177*0a6a1f1dSLionel Sambuc} 178*0a6a1f1dSLionel Sambucno_select_body() { 179*0a6a1f1dSLionel Sambuc test_output no_select 180*0a6a1f1dSLionel Sambuc} 181*0a6a1f1dSLionel Sambuc 182*0a6a1f1dSLionel Sambuc# Device instance 183*0a6a1f1dSLionel Sambuctest_case devi pass "Device instance" 184*0a6a1f1dSLionel Sambucdevi_config_str=' 185*0a6a1f1dSLionel Sambucinclude "../d_min" 186*0a6a1f1dSLionel Sambucd0 at root 187*0a6a1f1dSLionel Sambuc' 188*0a6a1f1dSLionel Sambuccheck_devi() 189*0a6a1f1dSLionel Sambuc{ 190*0a6a1f1dSLionel Sambuc local f=ioconf.c 191*0a6a1f1dSLionel Sambuc 192*0a6a1f1dSLionel Sambuc sed -ne '/^struct cfdriver \* const cfdriver_list_initial\[\]/,/^};/p' $f >tmp.cfdriver 193*0a6a1f1dSLionel Sambuc sed -ne '/^struct cfdata cfdata\[\]/,/^};/p' $f >tmp.cfdata 194*0a6a1f1dSLionel Sambuc 195*0a6a1f1dSLionel Sambuc grep -q '^CFDRIVER_DECL(d, ' $f && 196*0a6a1f1dSLionel Sambuc grep -q '&d_cd,' tmp.cfdriver && 197*0a6a1f1dSLionel Sambuc grep -q '^extern struct cfattach d_ca;$' $f && 198*0a6a1f1dSLionel Sambuc grep -q '^static const struct cfiattrdata \* const d_attrs\[\]' $f && 199*0a6a1f1dSLionel Sambuc grep -q '^static const struct cfiattrdata icf_iattrdata' $f && 200*0a6a1f1dSLionel Sambuc grep -q '{ "d",' tmp.cfdata && 201*0a6a1f1dSLionel Sambuc : 202*0a6a1f1dSLionel Sambuc} 203*0a6a1f1dSLionel Sambucdevi_body() { 204*0a6a1f1dSLionel Sambuc test_output devi 205*0a6a1f1dSLionel Sambuc} 206*0a6a1f1dSLionel Sambuc 207*0a6a1f1dSLionel Sambuc# Check minimal kernel config(1) output 208*0a6a1f1dSLionel Sambuctest_case min pass "Minimal config" 209*0a6a1f1dSLionel Sambuccheck_min_files() 210*0a6a1f1dSLionel Sambuc{ 211*0a6a1f1dSLionel Sambuc test -e Makefile && 212*0a6a1f1dSLionel Sambuc test -e config_file.h && 213*0a6a1f1dSLionel Sambuc test -e config_time.src && 214*0a6a1f1dSLionel Sambuc test -e ioconf.c && 215*0a6a1f1dSLionel Sambuc test -e ioconf.h && 216*0a6a1f1dSLionel Sambuc test -e locators.h && 217*0a6a1f1dSLionel Sambuc test -e swapregress.c && 218*0a6a1f1dSLionel Sambuc test -h machine && 219*0a6a1f1dSLionel Sambuc test -h regress && 220*0a6a1f1dSLionel Sambuc : 221*0a6a1f1dSLionel Sambuc} 222*0a6a1f1dSLionel Sambuccheck_min_makefile() 223*0a6a1f1dSLionel Sambuc{ 224*0a6a1f1dSLionel Sambuc local f=Makefile 225*0a6a1f1dSLionel Sambuc 226*0a6a1f1dSLionel Sambuc grep -q '^%' $f >tmp.template 227*0a6a1f1dSLionel Sambuc 228*0a6a1f1dSLionel Sambuc grep -q '^MACHINE=regress$' $f && 229*0a6a1f1dSLionel Sambuc grep -q '^PARAM=-DMAXUSERS=4$' $f && 230*0a6a1f1dSLionel Sambuc grep -q '^all: regress$' $f && 231*0a6a1f1dSLionel Sambuc grep -q '^regress:' $f && 232*0a6a1f1dSLionel Sambuc [ ! -s tmp.template ] && 233*0a6a1f1dSLionel Sambuc : 234*0a6a1f1dSLionel Sambuc} 235*0a6a1f1dSLionel Sambuccheck_min() 236*0a6a1f1dSLionel Sambuc{ 237*0a6a1f1dSLionel Sambuc check_min_files && 238*0a6a1f1dSLionel Sambuc check_min_makefile && 239*0a6a1f1dSLionel Sambuc : 240*0a6a1f1dSLionel Sambuc} 241*0a6a1f1dSLionel Sambucmin_body() { 242*0a6a1f1dSLionel Sambuc test_output min 243*0a6a1f1dSLionel Sambuc} 244*0a6a1f1dSLionel Sambuc 24511be35a1SLionel Sambucatf_init_test_cases() 24611be35a1SLionel Sambuc{ 24711be35a1SLionel Sambuc atf_add_test_case shadow_instance 24811be35a1SLionel Sambuc atf_add_test_case loop 24911be35a1SLionel Sambuc atf_add_test_case loop2 25011be35a1SLionel Sambuc atf_add_test_case pseudo_parent 25111be35a1SLionel Sambuc atf_add_test_case postponed_orphan 25211be35a1SLionel Sambuc atf_add_test_case no_pseudo 25311be35a1SLionel Sambuc atf_add_test_case deffs_redef 254*0a6a1f1dSLionel Sambuc atf_add_test_case undefined_opt 255*0a6a1f1dSLionel Sambuc atf_add_test_case no_undefined_opt 256*0a6a1f1dSLionel Sambuc atf_add_test_case select 257*0a6a1f1dSLionel Sambuc atf_add_test_case no_select 258*0a6a1f1dSLionel Sambuc atf_add_test_case devi 259*0a6a1f1dSLionel Sambuc atf_add_test_case min 26011be35a1SLionel Sambuc} 261