xref: /minix3/external/bsd/atf/dist/tools/atf-run_test.sh (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc#
2*0a6a1f1dSLionel Sambuc# Automated Testing Framework (atf)
3*0a6a1f1dSLionel Sambuc#
4*0a6a1f1dSLionel Sambuc# Copyright (c) 2007 The NetBSD Foundation, Inc.
5*0a6a1f1dSLionel Sambuc# All rights reserved.
6*0a6a1f1dSLionel Sambuc#
7*0a6a1f1dSLionel Sambuc# Redistribution and use in source and binary forms, with or without
8*0a6a1f1dSLionel Sambuc# modification, are permitted provided that the following conditions
9*0a6a1f1dSLionel Sambuc# are met:
10*0a6a1f1dSLionel Sambuc# 1. Redistributions of source code must retain the above copyright
11*0a6a1f1dSLionel Sambuc#    notice, this list of conditions and the following disclaimer.
12*0a6a1f1dSLionel Sambuc# 2. Redistributions in binary form must reproduce the above copyright
13*0a6a1f1dSLionel Sambuc#    notice, this list of conditions and the following disclaimer in the
14*0a6a1f1dSLionel Sambuc#    documentation and/or other materials provided with the distribution.
15*0a6a1f1dSLionel Sambuc#
16*0a6a1f1dSLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*0a6a1f1dSLionel Sambuc# CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*0a6a1f1dSLionel Sambuc# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*0a6a1f1dSLionel Sambuc# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*0a6a1f1dSLionel Sambuc# IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*0a6a1f1dSLionel Sambuc# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*0a6a1f1dSLionel Sambuc# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*0a6a1f1dSLionel Sambuc# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*0a6a1f1dSLionel Sambuc# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*0a6a1f1dSLionel Sambuc# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*0a6a1f1dSLionel Sambuc# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*0a6a1f1dSLionel Sambuc# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*0a6a1f1dSLionel Sambuc#
29*0a6a1f1dSLionel Sambuc
30*0a6a1f1dSLionel Sambuccreate_atffile()
31*0a6a1f1dSLionel Sambuc{
32*0a6a1f1dSLionel Sambuc    ATF_CONFDIR="$(pwd)"; export ATF_CONFDIR
33*0a6a1f1dSLionel Sambuc
34*0a6a1f1dSLionel Sambuc    cat >Atffile <<EOF
35*0a6a1f1dSLionel SambucContent-Type: application/X-atf-atffile; version="1"
36*0a6a1f1dSLionel Sambuc
37*0a6a1f1dSLionel Sambucprop: test-suite = atf
38*0a6a1f1dSLionel Sambuc
39*0a6a1f1dSLionel SambucEOF
40*0a6a1f1dSLionel Sambuc    for f in "${@}"; do
41*0a6a1f1dSLionel Sambuc        echo "tp: ${f}" >>Atffile
42*0a6a1f1dSLionel Sambuc    done
43*0a6a1f1dSLionel Sambuc}
44*0a6a1f1dSLionel Sambuc
45*0a6a1f1dSLionel Sambuccreate_helper()
46*0a6a1f1dSLionel Sambuc{
47*0a6a1f1dSLionel Sambuc    cp $(atf_get_srcdir)/misc_helpers helper
48*0a6a1f1dSLionel Sambuc    create_atffile helper
49*0a6a1f1dSLionel Sambuc    TESTCASE=${1}; export TESTCASE
50*0a6a1f1dSLionel Sambuc}
51*0a6a1f1dSLionel Sambuc
52*0a6a1f1dSLionel Sambuccreate_helper_stdin()
53*0a6a1f1dSLionel Sambuc{
54*0a6a1f1dSLionel Sambuc    # TODO: This really, really, really must use real test programs.
55*0a6a1f1dSLionel Sambuc    cat >${1} <<EOF
56*0a6a1f1dSLionel Sambuc#! $(atf-config -t atf_shell)
57*0a6a1f1dSLionel Sambucwhile [ \${#} -gt 0 ]; do
58*0a6a1f1dSLionel Sambuc    case \${1} in
59*0a6a1f1dSLionel Sambuc        -l)
60*0a6a1f1dSLionel Sambuc            echo 'Content-Type: application/X-atf-tp; version="1"'
61*0a6a1f1dSLionel Sambuc            echo
62*0a6a1f1dSLionel SambucEOF
63*0a6a1f1dSLionel Sambuc    cnt=1
64*0a6a1f1dSLionel Sambuc    while [ ${cnt} -le ${2} ]; do
65*0a6a1f1dSLionel Sambuc        echo "echo 'ident: tc${cnt}'" >>${1}
66*0a6a1f1dSLionel Sambuc        [ ${cnt} -lt ${2} ] && echo "echo" >>${1}
67*0a6a1f1dSLionel Sambuc        cnt=$((${cnt} + 1))
68*0a6a1f1dSLionel Sambuc    done
69*0a6a1f1dSLionel Sambuccat >>${1} <<EOF
70*0a6a1f1dSLionel Sambuc            exit 0
71*0a6a1f1dSLionel Sambuc            ;;
72*0a6a1f1dSLionel Sambuc        -r*)
73*0a6a1f1dSLionel Sambuc            resfile=\$(echo \${1} | cut -d r -f 2-)
74*0a6a1f1dSLionel Sambuc            ;;
75*0a6a1f1dSLionel Sambuc    esac
76*0a6a1f1dSLionel Sambuc    testcase=\$(echo \${1} | cut -d : -f 1)
77*0a6a1f1dSLionel Sambuc    shift
78*0a6a1f1dSLionel Sambucdone
79*0a6a1f1dSLionel SambucEOF
80*0a6a1f1dSLionel Sambuc    cat >>${1}
81*0a6a1f1dSLionel Sambuc}
82*0a6a1f1dSLionel Sambuc
83*0a6a1f1dSLionel Sambuccreate_mount_helper()
84*0a6a1f1dSLionel Sambuc{
85*0a6a1f1dSLionel Sambuc    cat >${1} <<EOF
86*0a6a1f1dSLionel Sambuc#! /usr/bin/env atf-sh
87*0a6a1f1dSLionel Sambuc
88*0a6a1f1dSLionel Sambucdo_mount() {
89*0a6a1f1dSLionel Sambuc    platform=\$(uname)
90*0a6a1f1dSLionel Sambuc    case \${platform} in
91*0a6a1f1dSLionel Sambuc    Linux|NetBSD)
92*0a6a1f1dSLionel Sambuc        mount -t tmpfs tmpfs \${1} || atf_fail "Mount failed"
93*0a6a1f1dSLionel Sambuc        ;;
94*0a6a1f1dSLionel Sambuc    FreeBSD)
95*0a6a1f1dSLionel Sambuc        mdmfs -s 16m md \${1} || atf_fail "Mount failed"
96*0a6a1f1dSLionel Sambuc        ;;
97*0a6a1f1dSLionel Sambuc    SunOS)
98*0a6a1f1dSLionel Sambuc        mount -F tmpfs tmpfs \$(pwd)/\${1} || atf_fail "Mount failed"
99*0a6a1f1dSLionel Sambuc        ;;
100*0a6a1f1dSLionel Sambuc    *)
101*0a6a1f1dSLionel Sambuc        atf_fail "create_mount_helper called for an unsupported platform."
102*0a6a1f1dSLionel Sambuc        ;;
103*0a6a1f1dSLionel Sambuc    esac
104*0a6a1f1dSLionel Sambuc}
105*0a6a1f1dSLionel Sambuc
106*0a6a1f1dSLionel Sambucatf_test_case main
107*0a6a1f1dSLionel Sambucmain_head() {
108*0a6a1f1dSLionel Sambuc    atf_set "require.user" "root"
109*0a6a1f1dSLionel Sambuc}
110*0a6a1f1dSLionel Sambucmain_body() {
111*0a6a1f1dSLionel SambucEOF
112*0a6a1f1dSLionel Sambuc    cat >>${1}
113*0a6a1f1dSLionel Sambuc    cat >>${1} <<EOF
114*0a6a1f1dSLionel Sambuc}
115*0a6a1f1dSLionel Sambuc
116*0a6a1f1dSLionel Sambucatf_init_test_cases()
117*0a6a1f1dSLionel Sambuc{
118*0a6a1f1dSLionel Sambuc    atf_add_test_case main
119*0a6a1f1dSLionel Sambuc}
120*0a6a1f1dSLionel SambucEOF
121*0a6a1f1dSLionel Sambuc}
122*0a6a1f1dSLionel Sambuc
123*0a6a1f1dSLionel Sambucatf_test_case no_warnings
124*0a6a1f1dSLionel Sambucno_warnings_head()
125*0a6a1f1dSLionel Sambuc{
126*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run suppresses warnings about not running" \
127*0a6a1f1dSLionel Sambuc                    "within atf-run"
128*0a6a1f1dSLionel Sambuc}
129*0a6a1f1dSLionel Sambucno_warnings_body()
130*0a6a1f1dSLionel Sambuc{
131*0a6a1f1dSLionel Sambuc    create_helper pass
132*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o ignore -e not-match:'WARNING.*atf-run' atf-run helper
133*0a6a1f1dSLionel Sambuc}
134*0a6a1f1dSLionel Sambuc
135*0a6a1f1dSLionel Sambucatf_test_case config
136*0a6a1f1dSLionel Sambucconfig_head()
137*0a6a1f1dSLionel Sambuc{
138*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that the config files are read in the correct" \
139*0a6a1f1dSLionel Sambuc                    "order"
140*0a6a1f1dSLionel Sambuc}
141*0a6a1f1dSLionel Sambucconfig_body()
142*0a6a1f1dSLionel Sambuc{
143*0a6a1f1dSLionel Sambuc    create_helper config
144*0a6a1f1dSLionel Sambuc
145*0a6a1f1dSLionel Sambuc    mkdir etc
146*0a6a1f1dSLionel Sambuc    mkdir .atf
147*0a6a1f1dSLionel Sambuc
148*0a6a1f1dSLionel Sambuc    echo "First: read system-wide common.conf."
149*0a6a1f1dSLionel Sambuc    cat >etc/common.conf <<EOF
150*0a6a1f1dSLionel SambucContent-Type: application/X-atf-config; version="1"
151*0a6a1f1dSLionel Sambuc
152*0a6a1f1dSLionel Sambuc1st = "sw common"
153*0a6a1f1dSLionel Sambuc2nd = "sw common"
154*0a6a1f1dSLionel Sambuc3rd = "sw common"
155*0a6a1f1dSLionel Sambuc4th = "sw common"
156*0a6a1f1dSLionel SambucEOF
157*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
158*0a6a1f1dSLionel Sambuc        -o match:'1st: sw common' \
159*0a6a1f1dSLionel Sambuc        -o match:'2nd: sw common' \
160*0a6a1f1dSLionel Sambuc        -o match:'3rd: sw common' \
161*0a6a1f1dSLionel Sambuc        -o match:'4th: sw common' \
162*0a6a1f1dSLionel Sambuc        -e ignore -x \
163*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
164*0a6a1f1dSLionel Sambuc
165*0a6a1f1dSLionel Sambuc    echo "Second: read system-wide <test-suite>.conf."
166*0a6a1f1dSLionel Sambuc    cat >etc/atf.conf <<EOF
167*0a6a1f1dSLionel SambucContent-Type: application/X-atf-config; version="1"
168*0a6a1f1dSLionel Sambuc
169*0a6a1f1dSLionel Sambuc1st = "sw atf"
170*0a6a1f1dSLionel SambucEOF
171*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
172*0a6a1f1dSLionel Sambuc        -o match:'1st: sw atf' \
173*0a6a1f1dSLionel Sambuc        -o match:'2nd: sw common' \
174*0a6a1f1dSLionel Sambuc        -o match:'3rd: sw common' \
175*0a6a1f1dSLionel Sambuc        -o match:'4th: sw common' \
176*0a6a1f1dSLionel Sambuc        -e ignore -x \
177*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
178*0a6a1f1dSLionel Sambuc
179*0a6a1f1dSLionel Sambuc    echo "Third: read user-specific common.conf."
180*0a6a1f1dSLionel Sambuc    cat >.atf/common.conf <<EOF
181*0a6a1f1dSLionel SambucContent-Type: application/X-atf-config; version="1"
182*0a6a1f1dSLionel Sambuc
183*0a6a1f1dSLionel Sambuc2nd = "us common"
184*0a6a1f1dSLionel SambucEOF
185*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
186*0a6a1f1dSLionel Sambuc        -o match:'1st: sw atf' \
187*0a6a1f1dSLionel Sambuc        -o match:'2nd: us common' \
188*0a6a1f1dSLionel Sambuc        -o match:'3rd: sw common' \
189*0a6a1f1dSLionel Sambuc        -o match:'4th: sw common' \
190*0a6a1f1dSLionel Sambuc        -e ignore -x \
191*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
192*0a6a1f1dSLionel Sambuc
193*0a6a1f1dSLionel Sambuc    echo "Fourth: read user-specific <test-suite>.conf."
194*0a6a1f1dSLionel Sambuc    cat >.atf/atf.conf <<EOF
195*0a6a1f1dSLionel SambucContent-Type: application/X-atf-config; version="1"
196*0a6a1f1dSLionel Sambuc
197*0a6a1f1dSLionel Sambuc3rd = "us atf"
198*0a6a1f1dSLionel SambucEOF
199*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
200*0a6a1f1dSLionel Sambuc        -o match:'1st: sw atf' \
201*0a6a1f1dSLionel Sambuc        -o match:'2nd: us common' \
202*0a6a1f1dSLionel Sambuc        -o match:'3rd: us atf' \
203*0a6a1f1dSLionel Sambuc        -o match:'4th: sw common' \
204*0a6a1f1dSLionel Sambuc        -e ignore -x \
205*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/etc HOME=$(pwd) atf-run helper"
206*0a6a1f1dSLionel Sambuc}
207*0a6a1f1dSLionel Sambuc
208*0a6a1f1dSLionel Sambucatf_test_case vflag
209*0a6a1f1dSLionel Sambucvflag_head()
210*0a6a1f1dSLionel Sambuc{
211*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that the -v flag works and that it properly" \
212*0a6a1f1dSLionel Sambuc                    "overrides the values in configuration files"
213*0a6a1f1dSLionel Sambuc}
214*0a6a1f1dSLionel Sambucvflag_body()
215*0a6a1f1dSLionel Sambuc{
216*0a6a1f1dSLionel Sambuc    create_helper testvar
217*0a6a1f1dSLionel Sambuc
218*0a6a1f1dSLionel Sambuc    echo "Checking that 'testvar' is not defined."
219*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o ignore -e ignore -x \
220*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/etc atf-run helper"
221*0a6a1f1dSLionel Sambuc
222*0a6a1f1dSLionel Sambuc    echo "Checking that defining 'testvar' trough '-v' works."
223*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'testvar: a value' -e ignore -x \
224*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='a value' helper"
225*0a6a1f1dSLionel Sambuc
226*0a6a1f1dSLionel Sambuc    echo "Checking that defining 'testvar' trough the configuration" \
227*0a6a1f1dSLionel Sambuc         "file works."
228*0a6a1f1dSLionel Sambuc    mkdir etc
229*0a6a1f1dSLionel Sambuc    cat >etc/common.conf <<EOF
230*0a6a1f1dSLionel SambucContent-Type: application/X-atf-config; version="1"
231*0a6a1f1dSLionel Sambuc
232*0a6a1f1dSLionel Sambuctestvar = "value in conf file"
233*0a6a1f1dSLionel SambucEOF
234*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'testvar: value in conf file' -e ignore -x \
235*0a6a1f1dSLionel Sambuc              "ATF_CONFDIR=$(pwd)/etc atf-run helper"
236*0a6a1f1dSLionel Sambuc
237*0a6a1f1dSLionel Sambuc    echo "Checking that defining 'testvar' trough -v overrides the" \
238*0a6a1f1dSLionel Sambuc         "configuration file."
239*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'testvar: a value' -e ignore -x \
240*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='a value' helper"
241*0a6a1f1dSLionel Sambuc}
242*0a6a1f1dSLionel Sambuc
243*0a6a1f1dSLionel Sambucatf_test_case atffile
244*0a6a1f1dSLionel Sambucatffile_head()
245*0a6a1f1dSLionel Sambuc{
246*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that the variables defined by the Atffile" \
247*0a6a1f1dSLionel Sambuc                    "are recognized and that they take the lowest priority"
248*0a6a1f1dSLionel Sambuc}
249*0a6a1f1dSLionel Sambucatffile_body()
250*0a6a1f1dSLionel Sambuc{
251*0a6a1f1dSLionel Sambuc    create_helper testvar
252*0a6a1f1dSLionel Sambuc
253*0a6a1f1dSLionel Sambuc    echo "Checking that 'testvar' is not defined."
254*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o ignore -e ignore -x \
255*0a6a1f1dSLionel Sambuc              "ATF_CONFDIR=$(pwd)/etc atf-run helper"
256*0a6a1f1dSLionel Sambuc
257*0a6a1f1dSLionel Sambuc    echo "Checking that defining 'testvar' trough the Atffile works."
258*0a6a1f1dSLionel Sambuc    echo 'conf: testvar = "a value"' >>Atffile
259*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'testvar: a value' -e ignore -x \
260*0a6a1f1dSLionel Sambuc              "ATF_CONFDIR=$(pwd)/etc atf-run helper"
261*0a6a1f1dSLionel Sambuc
262*0a6a1f1dSLionel Sambuc    echo "Checking that defining 'testvar' trough the configuration" \
263*0a6a1f1dSLionel Sambuc         "file overrides the one in the Atffile."
264*0a6a1f1dSLionel Sambuc    mkdir etc
265*0a6a1f1dSLionel Sambuc    cat >etc/common.conf <<EOF
266*0a6a1f1dSLionel SambucContent-Type: application/X-atf-config; version="1"
267*0a6a1f1dSLionel Sambuc
268*0a6a1f1dSLionel Sambuctestvar = "value in conf file"
269*0a6a1f1dSLionel SambucEOF
270*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'testvar: value in conf file' -e ignore -x \
271*0a6a1f1dSLionel Sambuc              "ATF_CONFDIR=$(pwd)/etc atf-run helper"
272*0a6a1f1dSLionel Sambuc    rm -rf etc
273*0a6a1f1dSLionel Sambuc
274*0a6a1f1dSLionel Sambuc    echo "Checking that defining 'testvar' trough -v overrides the" \
275*0a6a1f1dSLionel Sambuc         "one in the Atffile."
276*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'testvar: new value' -e ignore -x \
277*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/etc atf-run -v testvar='new value' helper"
278*0a6a1f1dSLionel Sambuc}
279*0a6a1f1dSLionel Sambuc
280*0a6a1f1dSLionel Sambucatf_test_case atffile_recursive
281*0a6a1f1dSLionel Sambucatffile_recursive_head()
282*0a6a1f1dSLionel Sambuc{
283*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that variables defined by an Atffile are not" \
284*0a6a1f1dSLionel Sambuc                    "inherited by other Atffiles."
285*0a6a1f1dSLionel Sambuc}
286*0a6a1f1dSLionel Sambucatffile_recursive_body()
287*0a6a1f1dSLionel Sambuc{
288*0a6a1f1dSLionel Sambuc    create_helper testvar
289*0a6a1f1dSLionel Sambuc
290*0a6a1f1dSLionel Sambuc    mkdir dir
291*0a6a1f1dSLionel Sambuc    mv Atffile helper dir
292*0a6a1f1dSLionel Sambuc
293*0a6a1f1dSLionel Sambuc    echo "Checking that 'testvar' is not inherited."
294*0a6a1f1dSLionel Sambuc    create_atffile dir
295*0a6a1f1dSLionel Sambuc    echo 'conf: testvar = "a value"' >> Atffile
296*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o ignore -e ignore -x "ATF_CONFDIR=$(pwd)/etc atf-run"
297*0a6a1f1dSLionel Sambuc
298*0a6a1f1dSLionel Sambuc    echo "Checking that defining 'testvar' in the correct Atffile works."
299*0a6a1f1dSLionel Sambuc    echo 'conf: testvar = "a value"' >>dir/Atffile
300*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'testvar: a value' -e ignore -x \
301*0a6a1f1dSLionel Sambuc              "ATF_CONFDIR=$(pwd)/etc atf-run"
302*0a6a1f1dSLionel Sambuc}
303*0a6a1f1dSLionel Sambuc
304*0a6a1f1dSLionel Sambucatf_test_case fds
305*0a6a1f1dSLionel Sambucfds_head()
306*0a6a1f1dSLionel Sambuc{
307*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that all streams are properly captured"
308*0a6a1f1dSLionel Sambuc}
309*0a6a1f1dSLionel Sambucfds_body()
310*0a6a1f1dSLionel Sambuc{
311*0a6a1f1dSLionel Sambuc    create_helper fds
312*0a6a1f1dSLionel Sambuc
313*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
314*0a6a1f1dSLionel Sambuc        -o match:'^tc-so:msg1 to stdout$' \
315*0a6a1f1dSLionel Sambuc        -o match:'^tc-so:msg2 to stdout$' \
316*0a6a1f1dSLionel Sambuc        -o match:'^tc-se:msg1 to stderr$' \
317*0a6a1f1dSLionel Sambuc        -o match:'^tc-se:msg2 to stderr$' \
318*0a6a1f1dSLionel Sambuc        -e empty atf-run
319*0a6a1f1dSLionel Sambuc}
320*0a6a1f1dSLionel Sambuc
321*0a6a1f1dSLionel Sambucatf_test_case mux_streams
322*0a6a1f1dSLionel Sambucmux_streams_head()
323*0a6a1f1dSLionel Sambuc{
324*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests for a race condition in stream multiplexing"
325*0a6a1f1dSLionel Sambuc}
326*0a6a1f1dSLionel Sambucmux_streams_body()
327*0a6a1f1dSLionel Sambuc{
328*0a6a1f1dSLionel Sambuc    create_helper mux_streams
329*0a6a1f1dSLionel Sambuc
330*0a6a1f1dSLionel Sambuc    for i in 1 2 3 4 5; do
331*0a6a1f1dSLionel Sambuc        echo "Attempt ${i}"
332*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o match:'stdout 9999' -o match:'stderr 9999' atf-run
333*0a6a1f1dSLionel Sambuc    done
334*0a6a1f1dSLionel Sambuc}
335*0a6a1f1dSLionel Sambuc
336*0a6a1f1dSLionel Sambucatf_test_case expect
337*0a6a1f1dSLionel Sambucexpect_head()
338*0a6a1f1dSLionel Sambuc{
339*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests the processing of test case results and the" \
340*0a6a1f1dSLionel Sambuc        "expect features"
341*0a6a1f1dSLionel Sambuc}
342*0a6a1f1dSLionel Sambucexpect_body()
343*0a6a1f1dSLionel Sambuc{
344*0a6a1f1dSLionel Sambuc    ln -s "$(atf_get_srcdir)/expect_helpers" .
345*0a6a1f1dSLionel Sambuc    create_atffile expect_helpers
346*0a6a1f1dSLionel Sambuc
347*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 \
348*0a6a1f1dSLionel Sambuc        -o match:'death_and_exit, expected_death' \
349*0a6a1f1dSLionel Sambuc        -o match:'death_and_signal, expected_death' \
350*0a6a1f1dSLionel Sambuc        -o match:'death_but_pass, failed' \
351*0a6a1f1dSLionel Sambuc        -o match:'exit_any_and_exit, expected_exit' \
352*0a6a1f1dSLionel Sambuc        -o match:'exit_but_pass, failed' \
353*0a6a1f1dSLionel Sambuc        -o match:'exit_code_and_exit, expected_exit' \
354*0a6a1f1dSLionel Sambuc        -o match:'fail_and_fail_check, expected_failure' \
355*0a6a1f1dSLionel Sambuc        -o match:'fail_and_fail_requirement, expected_failure' \
356*0a6a1f1dSLionel Sambuc        -o match:'fail_but_pass, failed' \
357*0a6a1f1dSLionel Sambuc        -o match:'pass_and_pass, passed' \
358*0a6a1f1dSLionel Sambuc        -o match:'pass_but_fail_check, failed' \
359*0a6a1f1dSLionel Sambuc        -o match:'pass_but_fail_requirement, failed' \
360*0a6a1f1dSLionel Sambuc        -o match:'signal_any_and_signal, expected_signal' \
361*0a6a1f1dSLionel Sambuc        -o match:'signal_but_pass, failed' \
362*0a6a1f1dSLionel Sambuc        -o match:'signal_no_and_signal, expected_signal' \
363*0a6a1f1dSLionel Sambuc        -o match:'timeout_and_hang, expected_timeout' \
364*0a6a1f1dSLionel Sambuc        -o match:'timeout_but_pass, failed' \
365*0a6a1f1dSLionel Sambuc        -e empty atf-run
366*0a6a1f1dSLionel Sambuc}
367*0a6a1f1dSLionel Sambuc
368*0a6a1f1dSLionel Sambucatf_test_case missing_results
369*0a6a1f1dSLionel Sambucmissing_results_head()
370*0a6a1f1dSLionel Sambuc{
371*0a6a1f1dSLionel Sambuc    atf_set "descr" "Ensures that atf-run correctly handles test cases that " \
372*0a6a1f1dSLionel Sambuc                    "do not create the results file"
373*0a6a1f1dSLionel Sambuc}
374*0a6a1f1dSLionel Sambucmissing_results_body()
375*0a6a1f1dSLionel Sambuc{
376*0a6a1f1dSLionel Sambuc    create_helper_stdin helper 1 <<EOF
377*0a6a1f1dSLionel Sambuctest -f \${resfile} && echo "resfile found"
378*0a6a1f1dSLionel Sambucexit 0
379*0a6a1f1dSLionel SambucEOF
380*0a6a1f1dSLionel Sambuc    chmod +x helper
381*0a6a1f1dSLionel Sambuc
382*0a6a1f1dSLionel Sambuc    create_atffile helper
383*0a6a1f1dSLionel Sambuc
384*0a6a1f1dSLionel Sambuc    re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
385*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 \
386*0a6a1f1dSLionel Sambuc        -o match:"${re} failed,.*failed to create" \
387*0a6a1f1dSLionel Sambuc        -o not-match:'resfile found' \
388*0a6a1f1dSLionel Sambuc        -e empty atf-run
389*0a6a1f1dSLionel Sambuc}
390*0a6a1f1dSLionel Sambuc
391*0a6a1f1dSLionel Sambucatf_test_case broken_results
392*0a6a1f1dSLionel Sambucbroken_results_head()
393*0a6a1f1dSLionel Sambuc{
394*0a6a1f1dSLionel Sambuc    atf_set "descr" "Ensures that atf-run reports test programs that" \
395*0a6a1f1dSLionel Sambuc                    "provide a bogus results output as broken programs"
396*0a6a1f1dSLionel Sambuc}
397*0a6a1f1dSLionel Sambucbroken_results_body()
398*0a6a1f1dSLionel Sambuc{
399*0a6a1f1dSLionel Sambuc    # We produce two errors from the header to ensure that the parse
400*0a6a1f1dSLionel Sambuc    # errors are printed on a single line on the output file.  Printing
401*0a6a1f1dSLionel Sambuc    # them on separate lines would be incorrect.
402*0a6a1f1dSLionel Sambuc    create_helper_stdin helper 1 <<EOF
403*0a6a1f1dSLionel Sambucecho 'line 1' >\${resfile}
404*0a6a1f1dSLionel Sambucecho 'line 2' >>\${resfile}
405*0a6a1f1dSLionel Sambucexit 0
406*0a6a1f1dSLionel SambucEOF
407*0a6a1f1dSLionel Sambuc    chmod +x helper
408*0a6a1f1dSLionel Sambuc
409*0a6a1f1dSLionel Sambuc    create_atffile helper
410*0a6a1f1dSLionel Sambuc
411*0a6a1f1dSLionel Sambuc    re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
412*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o match:"${re} .*line 1.*line 2" -e empty atf-run
413*0a6a1f1dSLionel Sambuc}
414*0a6a1f1dSLionel Sambuc
415*0a6a1f1dSLionel Sambucatf_test_case broken_tp_list
416*0a6a1f1dSLionel Sambucbroken_tp_list_head()
417*0a6a1f1dSLionel Sambuc{
418*0a6a1f1dSLionel Sambuc    atf_set "descr" "Ensures that atf-run reports test programs that" \
419*0a6a1f1dSLionel Sambuc                    "provide a bogus test case list"
420*0a6a1f1dSLionel Sambuc}
421*0a6a1f1dSLionel Sambucbroken_tp_list_body()
422*0a6a1f1dSLionel Sambuc{
423*0a6a1f1dSLionel Sambuc    cat >helper <<EOF
424*0a6a1f1dSLionel Sambuc#! $(atf-config -t atf_shell)
425*0a6a1f1dSLionel Sambucwhile [ \${#} -gt 0 ]; do
426*0a6a1f1dSLionel Sambuc    if [ \${1} = -l ]; then
427*0a6a1f1dSLionel Sambuc        echo 'Content-Type: application/X-atf-tp; version="1"'
428*0a6a1f1dSLionel Sambuc        echo
429*0a6a1f1dSLionel Sambuc        echo 'foo: bar'
430*0a6a1f1dSLionel Sambuc        exit 0
431*0a6a1f1dSLionel Sambuc    else
432*0a6a1f1dSLionel Sambuc        shift
433*0a6a1f1dSLionel Sambuc    fi
434*0a6a1f1dSLionel Sambucdone
435*0a6a1f1dSLionel Sambucexit 0
436*0a6a1f1dSLionel SambucEOF
437*0a6a1f1dSLionel Sambuc    chmod +x helper
438*0a6a1f1dSLionel Sambuc
439*0a6a1f1dSLionel Sambuc    create_atffile helper
440*0a6a1f1dSLionel Sambuc
441*0a6a1f1dSLionel Sambuc    re='^tp-end: [0-9][0-9]*\.[0-9]*, helper,'
442*0a6a1f1dSLionel Sambuc    re="${re} Invalid format for test case list:.*First property.*ident"
443*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o match:"${re}" -e empty atf-run
444*0a6a1f1dSLionel Sambuc}
445*0a6a1f1dSLionel Sambuc
446*0a6a1f1dSLionel Sambucatf_test_case zero_tcs
447*0a6a1f1dSLionel Sambuczero_tcs_head()
448*0a6a1f1dSLionel Sambuc{
449*0a6a1f1dSLionel Sambuc    atf_set "descr" "Ensures that atf-run reports test programs without" \
450*0a6a1f1dSLionel Sambuc                    "test cases as errors"
451*0a6a1f1dSLionel Sambuc}
452*0a6a1f1dSLionel Sambuczero_tcs_body()
453*0a6a1f1dSLionel Sambuc{
454*0a6a1f1dSLionel Sambuc    create_helper_stdin helper 0 <<EOF
455*0a6a1f1dSLionel Sambucecho 'Content-Type: application/X-atf-tp; version="1"'
456*0a6a1f1dSLionel Sambucecho
457*0a6a1f1dSLionel Sambucexit 1
458*0a6a1f1dSLionel SambucEOF
459*0a6a1f1dSLionel Sambuc    chmod +x helper
460*0a6a1f1dSLionel Sambuc
461*0a6a1f1dSLionel Sambuc    create_atffile helper
462*0a6a1f1dSLionel Sambuc
463*0a6a1f1dSLionel Sambuc    re='^tp-end: [0-9][0-9]*\.[0-9]*, helper,'
464*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 \
465*0a6a1f1dSLionel Sambuc        -o match:"${re} .*Invalid format for test case list" \
466*0a6a1f1dSLionel Sambuc        -e empty atf-run
467*0a6a1f1dSLionel Sambuc}
468*0a6a1f1dSLionel Sambuc
469*0a6a1f1dSLionel Sambucatf_test_case exit_codes
470*0a6a1f1dSLionel Sambucexit_codes_head()
471*0a6a1f1dSLionel Sambuc{
472*0a6a1f1dSLionel Sambuc    atf_set "descr" "Ensures that atf-run reports bogus exit codes for" \
473*0a6a1f1dSLionel Sambuc                    "programs correctly"
474*0a6a1f1dSLionel Sambuc}
475*0a6a1f1dSLionel Sambucexit_codes_body()
476*0a6a1f1dSLionel Sambuc{
477*0a6a1f1dSLionel Sambuc    create_helper_stdin helper 1 <<EOF
478*0a6a1f1dSLionel Sambucecho "failed: Yes, it failed" >\${resfile}
479*0a6a1f1dSLionel Sambucexit 0
480*0a6a1f1dSLionel SambucEOF
481*0a6a1f1dSLionel Sambuc    chmod +x helper
482*0a6a1f1dSLionel Sambuc
483*0a6a1f1dSLionel Sambuc    create_atffile helper
484*0a6a1f1dSLionel Sambuc
485*0a6a1f1dSLionel Sambuc    re='^tc-end: [0-9][0-9]*\.[0-9]*, tc1,'
486*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 \
487*0a6a1f1dSLionel Sambuc        -o match:"${re} .*exited successfully.*reported failure" \
488*0a6a1f1dSLionel Sambuc        -e empty atf-run
489*0a6a1f1dSLionel Sambuc}
490*0a6a1f1dSLionel Sambuc
491*0a6a1f1dSLionel Sambucatf_test_case signaled
492*0a6a1f1dSLionel Sambucsignaled_head()
493*0a6a1f1dSLionel Sambuc{
494*0a6a1f1dSLionel Sambuc    atf_set "descr" "Ensures that atf-run reports test program's crashes" \
495*0a6a1f1dSLionel Sambuc                    "correctly regardless of their actual results"
496*0a6a1f1dSLionel Sambuc}
497*0a6a1f1dSLionel Sambucsignaled_body()
498*0a6a1f1dSLionel Sambuc{
499*0a6a1f1dSLionel Sambuc    create_helper_stdin helper 2 <<EOF
500*0a6a1f1dSLionel Sambucecho "passed" >\${resfile}
501*0a6a1f1dSLionel Sambuccase \${testcase} in
502*0a6a1f1dSLionel Sambuc    tc1) ;;
503*0a6a1f1dSLionel Sambuc    tc2) echo "Killing myself!" ; kill -9 \$\$ ;;
504*0a6a1f1dSLionel Sambucesac
505*0a6a1f1dSLionel SambucEOF
506*0a6a1f1dSLionel Sambuc    chmod +x helper
507*0a6a1f1dSLionel Sambuc
508*0a6a1f1dSLionel Sambuc    create_atffile helper
509*0a6a1f1dSLionel Sambuc
510*0a6a1f1dSLionel Sambuc    re='^tc-end: [0-9][0-9]*\.[0-9]*, tc2,'
511*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o match:"${re} .*received signal 9" \
512*0a6a1f1dSLionel Sambuc        -e empty atf-run
513*0a6a1f1dSLionel Sambuc}
514*0a6a1f1dSLionel Sambuc
515*0a6a1f1dSLionel Sambucatf_test_case hooks
516*0a6a1f1dSLionel Sambuchooks_head()
517*0a6a1f1dSLionel Sambuc{
518*0a6a1f1dSLionel Sambuc    atf_set "descr" "Checks that the default hooks work and that they" \
519*0a6a1f1dSLionel Sambuc                    "can be overriden by the user"
520*0a6a1f1dSLionel Sambuc}
521*0a6a1f1dSLionel Sambuchooks_body()
522*0a6a1f1dSLionel Sambuc{
523*0a6a1f1dSLionel Sambuc    cp $(atf_get_srcdir)/pass_helper helper
524*0a6a1f1dSLionel Sambuc    create_atffile helper
525*0a6a1f1dSLionel Sambuc
526*0a6a1f1dSLionel Sambuc    mkdir atf
527*0a6a1f1dSLionel Sambuc    mkdir .atf
528*0a6a1f1dSLionel Sambuc
529*0a6a1f1dSLionel Sambuc    echo "Checking default hooks"
530*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'^info: time.start, ' \
531*0a6a1f1dSLionel Sambuc        -o match:'^info: time.end, ' -e empty -x \
532*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/atf atf-run"
533*0a6a1f1dSLionel Sambuc
534*0a6a1f1dSLionel Sambuc    echo "Checking the system-wide info_start hook"
535*0a6a1f1dSLionel Sambuc    cat >atf/atf-run.hooks <<EOF
536*0a6a1f1dSLionel Sambucinfo_start_hook()
537*0a6a1f1dSLionel Sambuc{
538*0a6a1f1dSLionel Sambuc    atf_tps_writer_info "test" "sw value"
539*0a6a1f1dSLionel Sambuc}
540*0a6a1f1dSLionel SambucEOF
541*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
542*0a6a1f1dSLionel Sambuc        -o match:'^info: test, sw value' \
543*0a6a1f1dSLionel Sambuc        -o not-match:'^info: time.start, ' \
544*0a6a1f1dSLionel Sambuc        -o match:'^info: time.end, ' \
545*0a6a1f1dSLionel Sambuc        -e empty -x \
546*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/atf atf-run"
547*0a6a1f1dSLionel Sambuc
548*0a6a1f1dSLionel Sambuc    echo "Checking the user-specific info_start hook"
549*0a6a1f1dSLionel Sambuc    cat >.atf/atf-run.hooks <<EOF
550*0a6a1f1dSLionel Sambucinfo_start_hook()
551*0a6a1f1dSLionel Sambuc{
552*0a6a1f1dSLionel Sambuc    atf_tps_writer_info "test" "user value"
553*0a6a1f1dSLionel Sambuc}
554*0a6a1f1dSLionel SambucEOF
555*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
556*0a6a1f1dSLionel Sambuc        -o match:'^info: test, user value' \
557*0a6a1f1dSLionel Sambuc        -o not-match:'^info: time.start, ' \
558*0a6a1f1dSLionel Sambuc        -o match:'^info: time.end, ' \
559*0a6a1f1dSLionel Sambuc        -e empty -x \
560*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/atf atf-run"
561*0a6a1f1dSLionel Sambuc
562*0a6a1f1dSLionel Sambuc    rm atf/atf-run.hooks
563*0a6a1f1dSLionel Sambuc    rm .atf/atf-run.hooks
564*0a6a1f1dSLionel Sambuc
565*0a6a1f1dSLionel Sambuc    echo "Checking the system-wide info_end hook"
566*0a6a1f1dSLionel Sambuc    cat >atf/atf-run.hooks <<EOF
567*0a6a1f1dSLionel Sambucinfo_end_hook()
568*0a6a1f1dSLionel Sambuc{
569*0a6a1f1dSLionel Sambuc    atf_tps_writer_info "test" "sw value"
570*0a6a1f1dSLionel Sambuc}
571*0a6a1f1dSLionel SambucEOF
572*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
573*0a6a1f1dSLionel Sambuc        -o match:'^info: time.start, ' \
574*0a6a1f1dSLionel Sambuc        -o not-match:'^info: time.end, ' \
575*0a6a1f1dSLionel Sambuc        -o match:'^info: test, sw value' \
576*0a6a1f1dSLionel Sambuc        -e empty -x \
577*0a6a1f1dSLionel Sambuc        "ATF_CONFDIR=$(pwd)/atf atf-run"
578*0a6a1f1dSLionel Sambuc
579*0a6a1f1dSLionel Sambuc    echo "Checking the user-specific info_end hook"
580*0a6a1f1dSLionel Sambuc    cat >.atf/atf-run.hooks <<EOF
581*0a6a1f1dSLionel Sambucinfo_end_hook()
582*0a6a1f1dSLionel Sambuc{
583*0a6a1f1dSLionel Sambuc    atf_tps_writer_info "test" "user value"
584*0a6a1f1dSLionel Sambuc}
585*0a6a1f1dSLionel SambucEOF
586*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
587*0a6a1f1dSLionel Sambuc        -o match:'^info: time.start, ' \
588*0a6a1f1dSLionel Sambuc        -o not-match:'^info: time.end, ' \
589*0a6a1f1dSLionel Sambuc        -o match:'^info: test, user value' \
590*0a6a1f1dSLionel Sambuc        -e empty -x \
591*0a6a1f1dSLionel Sambuc         "ATF_CONFDIR=$(pwd)/atf atf-run"
592*0a6a1f1dSLionel Sambuc}
593*0a6a1f1dSLionel Sambuc
594*0a6a1f1dSLionel Sambucatf_test_case isolation_env
595*0a6a1f1dSLionel Sambucisolation_env_head()
596*0a6a1f1dSLionel Sambuc{
597*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run sets a set of environment variables" \
598*0a6a1f1dSLionel Sambuc                    "to known sane values"
599*0a6a1f1dSLionel Sambuc}
600*0a6a1f1dSLionel Sambucisolation_env_body()
601*0a6a1f1dSLionel Sambuc{
602*0a6a1f1dSLionel Sambuc    undef_vars="LANG LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES LC_MONETARY \
603*0a6a1f1dSLionel Sambuc                LC_NUMERIC LC_TIME"
604*0a6a1f1dSLionel Sambuc    def_vars="HOME TZ"
605*0a6a1f1dSLionel Sambuc
606*0a6a1f1dSLionel Sambuc    mangleenv="env"
607*0a6a1f1dSLionel Sambuc    for v in ${undef_vars} ${def_vars}; do
608*0a6a1f1dSLionel Sambuc        mangleenv="${mangleenv} ${v}=bogus-value"
609*0a6a1f1dSLionel Sambuc    done
610*0a6a1f1dSLionel Sambuc
611*0a6a1f1dSLionel Sambuc    create_helper env_list
612*0a6a1f1dSLionel Sambuc    create_atffile helper
613*0a6a1f1dSLionel Sambuc
614*0a6a1f1dSLionel Sambuc    # We must ignore stderr in this call (instead of specifying -e empty)
615*0a6a1f1dSLionel Sambuc    # because, when atf-run invokes the shell to run the hooks, we may get
616*0a6a1f1dSLionel Sambuc    # error messages about an invalid locale.  This happens, at least, when
617*0a6a1f1dSLionel Sambuc    # the shell is bash 4.x.
618*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o save:stdout -e ignore ${mangleenv} atf-run helper
619*0a6a1f1dSLionel Sambuc
620*0a6a1f1dSLionel Sambuc    for v in ${undef_vars}; do
621*0a6a1f1dSLionel Sambuc        atf_check -s eq:1 -o empty -e empty grep "^tc-so:${v}=" stdout
622*0a6a1f1dSLionel Sambuc    done
623*0a6a1f1dSLionel Sambuc
624*0a6a1f1dSLionel Sambuc    for v in ${def_vars}; do
625*0a6a1f1dSLionel Sambuc        atf_check -s eq:0 -o ignore -e empty grep "^tc-so:${v}=" stdout
626*0a6a1f1dSLionel Sambuc    done
627*0a6a1f1dSLionel Sambuc
628*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o ignore -e empty grep "^tc-so:TZ=UTC" stdout
629*0a6a1f1dSLionel Sambuc}
630*0a6a1f1dSLionel Sambuc
631*0a6a1f1dSLionel Sambucatf_test_case isolation_home
632*0a6a1f1dSLionel Sambucisolation_home_head()
633*0a6a1f1dSLionel Sambuc{
634*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run sets HOME to a sane and valid value"
635*0a6a1f1dSLionel Sambuc}
636*0a6a1f1dSLionel Sambucisolation_home_body()
637*0a6a1f1dSLionel Sambuc{
638*0a6a1f1dSLionel Sambuc    create_helper env_home
639*0a6a1f1dSLionel Sambuc    create_atffile helper
640*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o ignore -e ignore env HOME=foo atf-run helper
641*0a6a1f1dSLionel Sambuc}
642*0a6a1f1dSLionel Sambuc
643*0a6a1f1dSLionel Sambucatf_test_case isolation_stdin
644*0a6a1f1dSLionel Sambucisolation_stdin_head()
645*0a6a1f1dSLionel Sambuc{
646*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run nullifies the stdin of test cases"
647*0a6a1f1dSLionel Sambuc}
648*0a6a1f1dSLionel Sambucisolation_stdin_body()
649*0a6a1f1dSLionel Sambuc{
650*0a6a1f1dSLionel Sambuc    create_helper read_stdin
651*0a6a1f1dSLionel Sambuc    create_atffile helper
652*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o ignore -e ignore -x 'echo hello world | atf-run helper'
653*0a6a1f1dSLionel Sambuc}
654*0a6a1f1dSLionel Sambuc
655*0a6a1f1dSLionel Sambucatf_test_case isolation_umask
656*0a6a1f1dSLionel Sambucisolation_umask_head()
657*0a6a1f1dSLionel Sambuc{
658*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run sets the umask to a known value"
659*0a6a1f1dSLionel Sambuc}
660*0a6a1f1dSLionel Sambucisolation_umask_body()
661*0a6a1f1dSLionel Sambuc{
662*0a6a1f1dSLionel Sambuc    create_helper umask
663*0a6a1f1dSLionel Sambuc    create_atffile helper
664*0a6a1f1dSLionel Sambuc
665*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'umask: 0022' -e ignore -x \
666*0a6a1f1dSLionel Sambuc        "umask 0000 && atf-run helper"
667*0a6a1f1dSLionel Sambuc}
668*0a6a1f1dSLionel Sambuc
669*0a6a1f1dSLionel Sambucatf_test_case cleanup_pass
670*0a6a1f1dSLionel Sambuccleanup_pass_head()
671*0a6a1f1dSLionel Sambuc{
672*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run calls the cleanup routine of the test" \
673*0a6a1f1dSLionel Sambuc        "case when the test case result is passed"
674*0a6a1f1dSLionel Sambuc}
675*0a6a1f1dSLionel Sambuccleanup_pass_body()
676*0a6a1f1dSLionel Sambuc{
677*0a6a1f1dSLionel Sambuc    create_helper cleanup_states
678*0a6a1f1dSLionel Sambuc    create_atffile helper
679*0a6a1f1dSLionel Sambuc
680*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'cleanup_states, passed' -e ignore atf-run \
681*0a6a1f1dSLionel Sambuc        -v state=pass -v statedir=$(pwd) helper
682*0a6a1f1dSLionel Sambuc    test -f to-stay || atf_fail "Test case body did not run correctly"
683*0a6a1f1dSLionel Sambuc    if [ -f to-delete ]; then
684*0a6a1f1dSLionel Sambuc        atf_fail "Test case cleanup did not run correctly"
685*0a6a1f1dSLionel Sambuc    fi
686*0a6a1f1dSLionel Sambuc}
687*0a6a1f1dSLionel Sambuc
688*0a6a1f1dSLionel Sambucatf_test_case cleanup_fail
689*0a6a1f1dSLionel Sambuccleanup_fail_head()
690*0a6a1f1dSLionel Sambuc{
691*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run calls the cleanup routine of the test" \
692*0a6a1f1dSLionel Sambuc        "case when the test case result is failed"
693*0a6a1f1dSLionel Sambuc}
694*0a6a1f1dSLionel Sambuccleanup_fail_body()
695*0a6a1f1dSLionel Sambuc{
696*0a6a1f1dSLionel Sambuc    create_helper cleanup_states
697*0a6a1f1dSLionel Sambuc    create_atffile helper
698*0a6a1f1dSLionel Sambuc
699*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o match:'cleanup_states, failed' -e ignore atf-run \
700*0a6a1f1dSLionel Sambuc        -v state=fail -v statedir=$(pwd) helper
701*0a6a1f1dSLionel Sambuc    test -f to-stay || atf_fail "Test case body did not run correctly"
702*0a6a1f1dSLionel Sambuc    if [ -f to-delete ]; then
703*0a6a1f1dSLionel Sambuc        atf_fail "Test case cleanup did not run correctly"
704*0a6a1f1dSLionel Sambuc    fi
705*0a6a1f1dSLionel Sambuc}
706*0a6a1f1dSLionel Sambuc
707*0a6a1f1dSLionel Sambucatf_test_case cleanup_skip
708*0a6a1f1dSLionel Sambuccleanup_skip_head()
709*0a6a1f1dSLionel Sambuc{
710*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run calls the cleanup routine of the test" \
711*0a6a1f1dSLionel Sambuc        "case when the test case result is skipped"
712*0a6a1f1dSLionel Sambuc}
713*0a6a1f1dSLionel Sambuccleanup_skip_body()
714*0a6a1f1dSLionel Sambuc{
715*0a6a1f1dSLionel Sambuc    create_helper cleanup_states
716*0a6a1f1dSLionel Sambuc    create_atffile helper
717*0a6a1f1dSLionel Sambuc
718*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'cleanup_states, skipped' -e ignore atf-run \
719*0a6a1f1dSLionel Sambuc        -v state=skip -v statedir=$(pwd) helper
720*0a6a1f1dSLionel Sambuc    test -f to-stay || atf_fail "Test case body did not run correctly"
721*0a6a1f1dSLionel Sambuc    if [ -f to-delete ]; then
722*0a6a1f1dSLionel Sambuc        atf_fail "Test case cleanup did not run correctly"
723*0a6a1f1dSLionel Sambuc    fi
724*0a6a1f1dSLionel Sambuc}
725*0a6a1f1dSLionel Sambuc
726*0a6a1f1dSLionel Sambucatf_test_case cleanup_curdir
727*0a6a1f1dSLionel Sambuccleanup_curdir_head()
728*0a6a1f1dSLionel Sambuc{
729*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run calls the cleanup routine in the same" \
730*0a6a1f1dSLionel Sambuc        "work directory as the body so that they can share data"
731*0a6a1f1dSLionel Sambuc}
732*0a6a1f1dSLionel Sambuccleanup_curdir_body()
733*0a6a1f1dSLionel Sambuc{
734*0a6a1f1dSLionel Sambuc    create_helper cleanup_curdir
735*0a6a1f1dSLionel Sambuc    create_atffile helper
736*0a6a1f1dSLionel Sambuc
737*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:'cleanup_curdir, passed' \
738*0a6a1f1dSLionel Sambuc        -o match:'Old value: 1234' -e ignore atf-run helper
739*0a6a1f1dSLionel Sambuc}
740*0a6a1f1dSLionel Sambuc
741*0a6a1f1dSLionel Sambucatf_test_case cleanup_signal
742*0a6a1f1dSLionel Sambuccleanup_signal_head()
743*0a6a1f1dSLionel Sambuc{
744*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run calls the cleanup routine if it gets" \
745*0a6a1f1dSLionel Sambuc        "a termination signal while running the body"
746*0a6a1f1dSLionel Sambuc}
747*0a6a1f1dSLionel Sambuccleanup_signal_body()
748*0a6a1f1dSLionel Sambuc{
749*0a6a1f1dSLionel Sambuc    : # TODO: Write this.
750*0a6a1f1dSLionel Sambuc}
751*0a6a1f1dSLionel Sambuc
752*0a6a1f1dSLionel Sambucatf_test_case cleanup_mount
753*0a6a1f1dSLionel Sambuccleanup_mount_head()
754*0a6a1f1dSLionel Sambuc{
755*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that the removal algorithm does not cross" \
756*0a6a1f1dSLionel Sambuc                    "mount points"
757*0a6a1f1dSLionel Sambuc    atf_set "require.user" "root"
758*0a6a1f1dSLionel Sambuc}
759*0a6a1f1dSLionel Sambuccleanup_mount_body()
760*0a6a1f1dSLionel Sambuc{
761*0a6a1f1dSLionel Sambuc    ROOT="$(pwd)/root"; export ROOT
762*0a6a1f1dSLionel Sambuc
763*0a6a1f1dSLionel Sambuc    create_mount_helper helper <<EOF
764*0a6a1f1dSLionel Sambucecho \$(pwd) >\${ROOT}
765*0a6a1f1dSLionel Sambucmkdir foo
766*0a6a1f1dSLionel Sambucmkdir foo/bar
767*0a6a1f1dSLionel Sambucmkdir foo/bar/mnt
768*0a6a1f1dSLionel Sambucdo_mount foo/bar/mnt
769*0a6a1f1dSLionel Sambucmkdir foo/baz
770*0a6a1f1dSLionel Sambucdo_mount foo/baz
771*0a6a1f1dSLionel Sambucmkdir foo/baz/foo
772*0a6a1f1dSLionel Sambucmkdir foo/baz/foo/bar
773*0a6a1f1dSLionel Sambucdo_mount foo/baz/foo/bar
774*0a6a1f1dSLionel SambucEOF
775*0a6a1f1dSLionel Sambuc    create_atffile helper
776*0a6a1f1dSLionel Sambuc    chmod +x helper
777*0a6a1f1dSLionel Sambuc
778*0a6a1f1dSLionel Sambuc    platform=$(uname)
779*0a6a1f1dSLionel Sambuc    case ${platform} in
780*0a6a1f1dSLionel Sambuc    Linux|FreeBSD|NetBSD|SunOS)
781*0a6a1f1dSLionel Sambuc        ;;
782*0a6a1f1dSLionel Sambuc    *)
783*0a6a1f1dSLionel Sambuc        # XXX Possibly specify in meta-data too.
784*0a6a1f1dSLionel Sambuc        atf_skip "Test unimplemented in this platform (${platform})"
785*0a6a1f1dSLionel Sambuc        ;;
786*0a6a1f1dSLionel Sambuc    esac
787*0a6a1f1dSLionel Sambuc
788*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"main, passed" -e ignore atf-run helper
789*0a6a1f1dSLionel Sambuc    mount | grep $(cat root) && atf_fail "Some file systems remain mounted"
790*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o empty -e empty test -d $(cat root)/foo
791*0a6a1f1dSLionel Sambuc}
792*0a6a1f1dSLionel Sambuc
793*0a6a1f1dSLionel Sambucatf_test_case cleanup_symlink
794*0a6a1f1dSLionel Sambuccleanup_symlink_head()
795*0a6a1f1dSLionel Sambuc{
796*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that the removal algorithm does not follow" \
797*0a6a1f1dSLionel Sambuc                    "symlinks, which may live in another device and thus" \
798*0a6a1f1dSLionel Sambuc                    "be treated as mount points"
799*0a6a1f1dSLionel Sambuc    atf_set "require.user" "root"
800*0a6a1f1dSLionel Sambuc}
801*0a6a1f1dSLionel Sambuccleanup_symlink_body()
802*0a6a1f1dSLionel Sambuc{
803*0a6a1f1dSLionel Sambuc    ROOT="$(pwd)/root"; export ROOT
804*0a6a1f1dSLionel Sambuc
805*0a6a1f1dSLionel Sambuc    create_mount_helper helper <<EOF
806*0a6a1f1dSLionel Sambucecho \$(pwd) >\${ROOT}
807*0a6a1f1dSLionel Sambucatf_check -s eq:0 -o empty -e empty mkdir foo
808*0a6a1f1dSLionel Sambucatf_check -s eq:0 -o empty -e empty mkdir foo/bar
809*0a6a1f1dSLionel Sambucdo_mount foo/bar
810*0a6a1f1dSLionel Sambucatf_check -s eq:0 -o empty -e empty touch a
811*0a6a1f1dSLionel Sambucatf_check -s eq:0 -o empty -e empty ln -s "\$(pwd)/a" foo/bar
812*0a6a1f1dSLionel SambucEOF
813*0a6a1f1dSLionel Sambuc    create_atffile helper
814*0a6a1f1dSLionel Sambuc    chmod +x helper
815*0a6a1f1dSLionel Sambuc
816*0a6a1f1dSLionel Sambuc    platform=$(uname)
817*0a6a1f1dSLionel Sambuc    case ${platform} in
818*0a6a1f1dSLionel Sambuc    Linux|FreeBSD|NetBSD|SunOS)
819*0a6a1f1dSLionel Sambuc        ;;
820*0a6a1f1dSLionel Sambuc    *)
821*0a6a1f1dSLionel Sambuc        # XXX Possibly specify in meta-data too.
822*0a6a1f1dSLionel Sambuc        atf_skip "Test unimplemented in this platform (${platform})"
823*0a6a1f1dSLionel Sambuc        ;;
824*0a6a1f1dSLionel Sambuc    esac
825*0a6a1f1dSLionel Sambuc
826*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"main, passed" -e ignore atf-run helper
827*0a6a1f1dSLionel Sambuc    mount | grep $(cat root) && atf_fail "Some file systems remain mounted"
828*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o empty -e empty test -d $(cat root)/foo
829*0a6a1f1dSLionel Sambuc}
830*0a6a1f1dSLionel Sambuc
831*0a6a1f1dSLionel Sambucatf_test_case require_arch
832*0a6a1f1dSLionel Sambucrequire_arch_head()
833*0a6a1f1dSLionel Sambuc{
834*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run validates the require.arch property"
835*0a6a1f1dSLionel Sambuc}
836*0a6a1f1dSLionel Sambucrequire_arch_body()
837*0a6a1f1dSLionel Sambuc{
838*0a6a1f1dSLionel Sambuc    create_helper require_arch
839*0a6a1f1dSLionel Sambuc    create_atffile helper
840*0a6a1f1dSLionel Sambuc
841*0a6a1f1dSLionel Sambuc    echo "Checking for the real architecture"
842*0a6a1f1dSLionel Sambuc    arch=$(atf-config -t atf_arch)
843*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
844*0a6a1f1dSLionel Sambuc        -v arch="${arch}" helper
845*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
846*0a6a1f1dSLionel Sambuc        -v arch="foo ${arch}" helper
847*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
848*0a6a1f1dSLionel Sambuc        -v arch="${arch} foo" helper
849*0a6a1f1dSLionel Sambuc
850*0a6a1f1dSLionel Sambuc    echo "Checking for a fictitious architecture"
851*0a6a1f1dSLionel Sambuc    arch=fictitious
852*0a6a1f1dSLionel Sambuc    export ATF_ARCH=fictitious
853*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
854*0a6a1f1dSLionel Sambuc        -v arch="${arch}" helper
855*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
856*0a6a1f1dSLionel Sambuc        -v arch="foo ${arch}" helper
857*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
858*0a6a1f1dSLionel Sambuc        -v arch="${arch} foo" helper
859*0a6a1f1dSLionel Sambuc
860*0a6a1f1dSLionel Sambuc    echo "Triggering some failures"
861*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, skipped, .*foo.*architecture" \
862*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v arch="foo" helper
863*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
864*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, skipped, .*foo bar.*architectures" -e ignore \
865*0a6a1f1dSLionel Sambuc        atf-run -v arch="foo bar" helper
866*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
867*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, skipped, .*fictitiousxxx.*architecture" \
868*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v arch="${arch}xxx" helper
869*0a6a1f1dSLionel Sambuc}
870*0a6a1f1dSLionel Sambuc
871*0a6a1f1dSLionel Sambucatf_test_case require_config
872*0a6a1f1dSLionel Sambucrequire_config_head()
873*0a6a1f1dSLionel Sambuc{
874*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run validates the require.config property"
875*0a6a1f1dSLionel Sambuc}
876*0a6a1f1dSLionel Sambucrequire_config_body()
877*0a6a1f1dSLionel Sambuc{
878*0a6a1f1dSLionel Sambuc    create_helper require_config
879*0a6a1f1dSLionel Sambuc    create_atffile helper
880*0a6a1f1dSLionel Sambuc
881*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, skipped, .*var1.*not defined" \
882*0a6a1f1dSLionel Sambuc        -e ignore atf-run helper
883*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, skipped, .*var2.*not defined" \
884*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v var1=foo helper
885*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
886*0a6a1f1dSLionel Sambuc        -v var1=a -v var2=' ' helper
887*0a6a1f1dSLionel Sambuc}
888*0a6a1f1dSLionel Sambuc
889*0a6a1f1dSLionel Sambucatf_test_case require_files
890*0a6a1f1dSLionel Sambucrequire_files_head()
891*0a6a1f1dSLionel Sambuc{
892*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run validates the require.files property"
893*0a6a1f1dSLionel Sambuc}
894*0a6a1f1dSLionel Sambucrequire_files_body()
895*0a6a1f1dSLionel Sambuc{
896*0a6a1f1dSLionel Sambuc    create_helper require_files
897*0a6a1f1dSLionel Sambuc    create_atffile helper
898*0a6a1f1dSLionel Sambuc
899*0a6a1f1dSLionel Sambuc    touch i-exist
900*0a6a1f1dSLionel Sambuc
901*0a6a1f1dSLionel Sambuc    echo "Checking absolute paths"
902*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
903*0a6a1f1dSLionel Sambuc        -v files='/bin/cp' helper
904*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
905*0a6a1f1dSLionel Sambuc        -v files="$(pwd)/i-exist" helper
906*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
907*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, skipped, .*/dont-exist" \
908*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v files="$(pwd)/i-exist $(pwd)/dont-exist" helper
909*0a6a1f1dSLionel Sambuc
910*0a6a1f1dSLionel Sambuc    echo "Checking that relative paths are not allowed"
911*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 \
912*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, failed, Relative paths.*not allowed.*hello" \
913*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v files='hello' helper
914*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 \
915*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, failed, Relative paths.*not allowed.*a/b" \
916*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v files='a/b' helper
917*0a6a1f1dSLionel Sambuc}
918*0a6a1f1dSLionel Sambuc
919*0a6a1f1dSLionel Sambucatf_test_case require_machine
920*0a6a1f1dSLionel Sambucrequire_machine_head()
921*0a6a1f1dSLionel Sambuc{
922*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run validates the require.machine property"
923*0a6a1f1dSLionel Sambuc}
924*0a6a1f1dSLionel Sambucrequire_machine_body()
925*0a6a1f1dSLionel Sambuc{
926*0a6a1f1dSLionel Sambuc    create_helper require_machine
927*0a6a1f1dSLionel Sambuc    create_atffile helper
928*0a6a1f1dSLionel Sambuc
929*0a6a1f1dSLionel Sambuc    echo "Checking for the real machine type"
930*0a6a1f1dSLionel Sambuc    machine=$(atf-config -t atf_machine)
931*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
932*0a6a1f1dSLionel Sambuc        -v machine="${machine}" helper
933*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
934*0a6a1f1dSLionel Sambuc        -v machine="foo ${machine}" helper
935*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
936*0a6a1f1dSLionel Sambuc        -v machine="${machine} foo" helper
937*0a6a1f1dSLionel Sambuc
938*0a6a1f1dSLionel Sambuc    echo "Checking for a fictitious machine type"
939*0a6a1f1dSLionel Sambuc    machine=fictitious
940*0a6a1f1dSLionel Sambuc    export ATF_MACHINE=fictitious
941*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
942*0a6a1f1dSLionel Sambuc        -v machine="${machine}" helper
943*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
944*0a6a1f1dSLionel Sambuc        -v machine="foo ${machine}" helper
945*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
946*0a6a1f1dSLionel Sambuc        -v machine="${machine} foo" helper
947*0a6a1f1dSLionel Sambuc
948*0a6a1f1dSLionel Sambuc    echo "Triggering some failures"
949*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, skipped, .*foo.*machine type" \
950*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v machine="foo" helper
951*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
952*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, skipped, .*foo bar.*machine types" -e ignore \
953*0a6a1f1dSLionel Sambuc        atf-run -v machine="foo bar" helper
954*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
955*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, skipped, .*fictitiousxxx.*machine type" \
956*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v machine="${machine}xxx" helper
957*0a6a1f1dSLionel Sambuc}
958*0a6a1f1dSLionel Sambuc
959*0a6a1f1dSLionel Sambucatf_test_case require_progs
960*0a6a1f1dSLionel Sambucrequire_progs_head()
961*0a6a1f1dSLionel Sambuc{
962*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run validates the require.progs property"
963*0a6a1f1dSLionel Sambuc}
964*0a6a1f1dSLionel Sambucrequire_progs_body()
965*0a6a1f1dSLionel Sambuc{
966*0a6a1f1dSLionel Sambuc    create_helper require_progs
967*0a6a1f1dSLionel Sambuc    create_atffile helper
968*0a6a1f1dSLionel Sambuc
969*0a6a1f1dSLionel Sambuc    echo "Checking absolute paths"
970*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
971*0a6a1f1dSLionel Sambuc        -v progs='/bin/cp' helper
972*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
973*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, skipped, .*/bin/__non-existent__.*PATH" \
974*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v progs='/bin/__non-existent__' helper
975*0a6a1f1dSLionel Sambuc
976*0a6a1f1dSLionel Sambuc    echo "Checking that relative paths are not allowed"
977*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 \
978*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, failed, Relative paths.*not allowed.*bin/cp" \
979*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v progs='bin/cp' helper
980*0a6a1f1dSLionel Sambuc
981*0a6a1f1dSLionel Sambuc    echo "Check plain file names, searching them in the PATH."
982*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
983*0a6a1f1dSLionel Sambuc        -v progs='cp' helper
984*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 \
985*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, skipped, .*__non-existent__.*PATH" -e ignore \
986*0a6a1f1dSLionel Sambuc        atf-run -v progs='__non-existent__' helper
987*0a6a1f1dSLionel Sambuc}
988*0a6a1f1dSLionel Sambuc
989*0a6a1f1dSLionel Sambucatf_test_case require_user_root
990*0a6a1f1dSLionel Sambucrequire_user_root_head()
991*0a6a1f1dSLionel Sambuc{
992*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run validates the require.user property" \
993*0a6a1f1dSLionel Sambuc        "when it is set to 'root'"
994*0a6a1f1dSLionel Sambuc}
995*0a6a1f1dSLionel Sambucrequire_user_root_body()
996*0a6a1f1dSLionel Sambuc{
997*0a6a1f1dSLionel Sambuc    create_helper require_user
998*0a6a1f1dSLionel Sambuc    create_atffile helper
999*0a6a1f1dSLionel Sambuc
1000*0a6a1f1dSLionel Sambuc    if [ $(id -u) -eq 0 ]; then
1001*0a6a1f1dSLionel Sambuc        exp=passed
1002*0a6a1f1dSLionel Sambuc    else
1003*0a6a1f1dSLionel Sambuc        exp=skipped
1004*0a6a1f1dSLionel Sambuc    fi
1005*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, ${exp}" -e ignore atf-run \
1006*0a6a1f1dSLionel Sambuc        -v user=root helper
1007*0a6a1f1dSLionel Sambuc}
1008*0a6a1f1dSLionel Sambuc
1009*0a6a1f1dSLionel Sambucatf_test_case require_user_unprivileged
1010*0a6a1f1dSLionel Sambucrequire_user_unprivileged_head()
1011*0a6a1f1dSLionel Sambuc{
1012*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run validates the require.user property" \
1013*0a6a1f1dSLionel Sambuc        "when it is set to 'root'"
1014*0a6a1f1dSLionel Sambuc}
1015*0a6a1f1dSLionel Sambucrequire_user_unprivileged_body()
1016*0a6a1f1dSLionel Sambuc{
1017*0a6a1f1dSLionel Sambuc    create_helper require_user
1018*0a6a1f1dSLionel Sambuc    create_atffile helper
1019*0a6a1f1dSLionel Sambuc
1020*0a6a1f1dSLionel Sambuc    if [ $(id -u) -eq 0 ]; then
1021*0a6a1f1dSLionel Sambuc        exp=skipped
1022*0a6a1f1dSLionel Sambuc    else
1023*0a6a1f1dSLionel Sambuc        exp=passed
1024*0a6a1f1dSLionel Sambuc    fi
1025*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, ${exp}" -e ignore atf-run \
1026*0a6a1f1dSLionel Sambuc        -v user=unprivileged helper
1027*0a6a1f1dSLionel Sambuc}
1028*0a6a1f1dSLionel Sambuc
1029*0a6a1f1dSLionel Sambucatf_test_case require_user_bad
1030*0a6a1f1dSLionel Sambucrequire_user_bad_head()
1031*0a6a1f1dSLionel Sambuc{
1032*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run validates the require.user property" \
1033*0a6a1f1dSLionel Sambuc        "when it is set to 'root'"
1034*0a6a1f1dSLionel Sambuc}
1035*0a6a1f1dSLionel Sambucrequire_user_bad_body()
1036*0a6a1f1dSLionel Sambuc{
1037*0a6a1f1dSLionel Sambuc    create_helper require_user
1038*0a6a1f1dSLionel Sambuc    create_atffile helper
1039*0a6a1f1dSLionel Sambuc
1040*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 -o match:"${TESTCASE}, failed, Invalid value.*foobar" \
1041*0a6a1f1dSLionel Sambuc        -e ignore atf-run -v user=foobar helper
1042*0a6a1f1dSLionel Sambuc}
1043*0a6a1f1dSLionel Sambuc
1044*0a6a1f1dSLionel Sambucatf_test_case timeout
1045*0a6a1f1dSLionel Sambuctimeout_head()
1046*0a6a1f1dSLionel Sambuc{
1047*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run kills a test case that times out"
1048*0a6a1f1dSLionel Sambuc}
1049*0a6a1f1dSLionel Sambuctimeout_body()
1050*0a6a1f1dSLionel Sambuc{
1051*0a6a1f1dSLionel Sambuc    create_helper timeout
1052*0a6a1f1dSLionel Sambuc    create_atffile helper
1053*0a6a1f1dSLionel Sambuc
1054*0a6a1f1dSLionel Sambuc    atf_check -s eq:1 \
1055*0a6a1f1dSLionel Sambuc        -o match:"${TESTCASE}, failed, .*timed out after 1 second" -e ignore \
1056*0a6a1f1dSLionel Sambuc        atf-run -v statedir=$(pwd) helper
1057*0a6a1f1dSLionel Sambuc    if [ -f finished ]; then
1058*0a6a1f1dSLionel Sambuc        atf_fail "Test case was not killed after time out"
1059*0a6a1f1dSLionel Sambuc    fi
1060*0a6a1f1dSLionel Sambuc}
1061*0a6a1f1dSLionel Sambuc
1062*0a6a1f1dSLionel Sambucatf_test_case timeout_forkexit
1063*0a6a1f1dSLionel Sambuctimeout_forkexit_head()
1064*0a6a1f1dSLionel Sambuc{
1065*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run deals gracefully with a test program" \
1066*0a6a1f1dSLionel Sambuc        "that forks, exits, but the child process hangs"
1067*0a6a1f1dSLionel Sambuc}
1068*0a6a1f1dSLionel Sambuctimeout_forkexit_body()
1069*0a6a1f1dSLionel Sambuc{
1070*0a6a1f1dSLionel Sambuc    create_helper timeout_forkexit
1071*0a6a1f1dSLionel Sambuc    create_atffile helper
1072*0a6a1f1dSLionel Sambuc
1073*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o match:"${TESTCASE}, passed" -e ignore atf-run \
1074*0a6a1f1dSLionel Sambuc        -v statedir=$(pwd) helper
1075*0a6a1f1dSLionel Sambuc    test -f parent-finished || atf_fail "Parent did not exit as expected"
1076*0a6a1f1dSLionel Sambuc    test -f child-finished && atf_fail "Subprocess exited but it should have" \
1077*0a6a1f1dSLionel Sambuc        "been forcibly terminated" || true
1078*0a6a1f1dSLionel Sambuc}
1079*0a6a1f1dSLionel Sambuc
1080*0a6a1f1dSLionel Sambucatf_test_case ignore_deprecated_use_fs
1081*0a6a1f1dSLionel Sambucignore_deprecated_use_fs_head()
1082*0a6a1f1dSLionel Sambuc{
1083*0a6a1f1dSLionel Sambuc    atf_set "descr" "Tests that atf-run ignores the deprecated use.fs property"
1084*0a6a1f1dSLionel Sambuc}
1085*0a6a1f1dSLionel Sambucignore_deprecated_use_fs_body()
1086*0a6a1f1dSLionel Sambuc{
1087*0a6a1f1dSLionel Sambuc    create_helper use_fs
1088*0a6a1f1dSLionel Sambuc    create_atffile helper
1089*0a6a1f1dSLionel Sambuc
1090*0a6a1f1dSLionel Sambuc    atf_check -s eq:0 -o ignore -e ignore atf-run helper
1091*0a6a1f1dSLionel Sambuc}
1092*0a6a1f1dSLionel Sambuc
1093*0a6a1f1dSLionel Sambucatf_init_test_cases()
1094*0a6a1f1dSLionel Sambuc{
1095*0a6a1f1dSLionel Sambuc    atf_add_test_case no_warnings
1096*0a6a1f1dSLionel Sambuc    atf_add_test_case config
1097*0a6a1f1dSLionel Sambuc    atf_add_test_case vflag
1098*0a6a1f1dSLionel Sambuc    atf_add_test_case atffile
1099*0a6a1f1dSLionel Sambuc    atf_add_test_case atffile_recursive
1100*0a6a1f1dSLionel Sambuc    atf_add_test_case expect
1101*0a6a1f1dSLionel Sambuc    atf_add_test_case fds
1102*0a6a1f1dSLionel Sambuc    atf_add_test_case mux_streams
1103*0a6a1f1dSLionel Sambuc    atf_add_test_case missing_results
1104*0a6a1f1dSLionel Sambuc    atf_add_test_case broken_results
1105*0a6a1f1dSLionel Sambuc    atf_add_test_case broken_tp_list
1106*0a6a1f1dSLionel Sambuc    atf_add_test_case zero_tcs
1107*0a6a1f1dSLionel Sambuc    atf_add_test_case exit_codes
1108*0a6a1f1dSLionel Sambuc    atf_add_test_case signaled
1109*0a6a1f1dSLionel Sambuc    atf_add_test_case hooks
1110*0a6a1f1dSLionel Sambuc    atf_add_test_case isolation_env
1111*0a6a1f1dSLionel Sambuc    atf_add_test_case isolation_home
1112*0a6a1f1dSLionel Sambuc    atf_add_test_case isolation_stdin
1113*0a6a1f1dSLionel Sambuc    atf_add_test_case isolation_umask
1114*0a6a1f1dSLionel Sambuc    atf_add_test_case cleanup_pass
1115*0a6a1f1dSLionel Sambuc    atf_add_test_case cleanup_fail
1116*0a6a1f1dSLionel Sambuc    atf_add_test_case cleanup_skip
1117*0a6a1f1dSLionel Sambuc    atf_add_test_case cleanup_curdir
1118*0a6a1f1dSLionel Sambuc    atf_add_test_case cleanup_signal
1119*0a6a1f1dSLionel Sambuc    atf_add_test_case cleanup_mount
1120*0a6a1f1dSLionel Sambuc    atf_add_test_case cleanup_symlink
1121*0a6a1f1dSLionel Sambuc    atf_add_test_case require_arch
1122*0a6a1f1dSLionel Sambuc    atf_add_test_case require_config
1123*0a6a1f1dSLionel Sambuc    atf_add_test_case require_files
1124*0a6a1f1dSLionel Sambuc    atf_add_test_case require_machine
1125*0a6a1f1dSLionel Sambuc    atf_add_test_case require_progs
1126*0a6a1f1dSLionel Sambuc    atf_add_test_case require_user_root
1127*0a6a1f1dSLionel Sambuc    atf_add_test_case require_user_unprivileged
1128*0a6a1f1dSLionel Sambuc    atf_add_test_case require_user_bad
1129*0a6a1f1dSLionel Sambuc    atf_add_test_case timeout
1130*0a6a1f1dSLionel Sambuc    atf_add_test_case timeout_forkexit
1131*0a6a1f1dSLionel Sambuc    atf_add_test_case ignore_deprecated_use_fs
1132*0a6a1f1dSLionel Sambuc}
1133*0a6a1f1dSLionel Sambuc
1134*0a6a1f1dSLionel Sambuc# vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4
1135