1272343Sngie# $NetBSD: t_config.sh,v 1.1 2012/03/17 16:33:12 jruoho Exp $
2272343Sngie#
3272343Sngie# Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
4272343Sngie# All rights reserved.
5272343Sngie#
6272343Sngie# Redistribution and use in source and binary forms, with or without
7272343Sngie# modification, are permitted provided that the following conditions
8272343Sngie# are met:
9272343Sngie# 1. Redistributions of source code must retain the above copyright
10272343Sngie#    notice, this list of conditions and the following disclaimer.
11272343Sngie# 2. Redistributions in binary form must reproduce the above copyright
12272343Sngie#    notice, this list of conditions and the following disclaimer in the
13272343Sngie#    documentation and/or other materials provided with the distribution.
14272343Sngie#
15272343Sngie# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16272343Sngie# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17272343Sngie# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18272343Sngie# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19272343Sngie# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20272343Sngie# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21272343Sngie# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22272343Sngie# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23272343Sngie# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24272343Sngie# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25272343Sngie# POSSIBILITY OF SUCH DAMAGE.
26272343Sngie#
27272343Sngie
28272343Sngierun_and_check_pass()
29272343Sngie{
30272343Sngie	local name="${1}"; shift
31272343Sngie
32272343Sngie	mkdir compile
33272343Sngie	supportdir="$(atf_get_srcdir)/support"
34272343Sngie	config="$(atf_get_srcdir)/d_${name}"
35272343Sngie
36272343Sngie	atf_check -o ignore \
37272343Sngie	    config -s "${supportdir}" -b "compile/${name}" "${config}"
38272343Sngie}
39272343Sngie
40272343Sngierun_and_check_fail()
41272343Sngie{
42272343Sngie	local name="${1}"; shift
43272343Sngie
44272343Sngie	mkdir compile
45272343Sngie	supportdir="$(atf_get_srcdir)/support"
46272343Sngie	config="$(atf_get_srcdir)/d_${name}"
47272343Sngie
48272343Sngie	atf_check -o ignore -e ignore -s ne:0 \
49272343Sngie	    config -s "${supportdir}" -b "compile/${name}" "${config}"
50272343Sngie}
51272343Sngie
52272343Sngie# Defines a test case for config(1).
53272343Sngietest_case()
54272343Sngie{
55272343Sngie	local name="${1}"; shift
56272343Sngie	local type="${1}"; shift
57272343Sngie	local descr="${*}"
58272343Sngie
59272343Sngie	atf_test_case "${name}"
60272343Sngie	eval "${name}_head() { \
61272343Sngie		atf_set descr \"${descr}\"; \
62272343Sngie		atf_set require.progs \"config\"; \
63272343Sngie	}"
64272343Sngie	eval "${name}_body() { \
65272343Sngie		run_and_check_${type} '${name}'; \
66272343Sngie	}"
67272343Sngie}
68272343Sngie
69272343Sngietest_case shadow_instance pass "Checks correct handling of shadowed instances"
70272343Sngietest_case loop pass "Checks correct handling of loops"
71272343Sngietest_case loop2 pass "Checks correct handling of devices that can be their" \
72272343Sngie    "own parents"
73272343Sngietest_case pseudo_parent pass "Checks correct handling of children of pseudo" \
74272343Sngie    "devices (PR/32329)"
75272343Sngietest_case postponed_orphan fail "Checks that config catches adding an" \
76272343Sngie    "instance of a child of a negated instance as error"
77272343Sngietest_case no_pseudo fail "Checks that config catches ommited 'pseudo-device'" \
78272343Sngie    "as error (PR/34111)"
79272343Sngietest_case deffs_redef fail "Checks that config doesn't allow a deffs to use" \
80272343Sngie    "the same name as a previous defflag/defparam"
81272343Sngie
82272343Sngieatf_init_test_cases()
83272343Sngie{
84272343Sngie	atf_add_test_case shadow_instance
85272343Sngie	atf_add_test_case loop
86272343Sngie	atf_add_test_case loop2
87272343Sngie	atf_add_test_case pseudo_parent
88272343Sngie	atf_add_test_case postponed_orphan
89272343Sngie	atf_add_test_case no_pseudo
90272343Sngie	atf_add_test_case deffs_redef
91272343Sngie}
92