1*0a6a1f1dSLionel Sambuc /*
2*0a6a1f1dSLionel Sambuc * Automated Testing Framework (atf)
3*0a6a1f1dSLionel Sambuc *
4*0a6a1f1dSLionel Sambuc * Copyright (c) 2010 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 Sambuc #include <signal.h>
31*0a6a1f1dSLionel Sambuc #include <stdlib.h>
32*0a6a1f1dSLionel Sambuc #include <unistd.h>
33*0a6a1f1dSLionel Sambuc
34*0a6a1f1dSLionel Sambuc #include <atf-c.h>
35*0a6a1f1dSLionel Sambuc
36*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(pass_and_pass);
ATF_TC_BODY(pass_and_pass,tc)37*0a6a1f1dSLionel Sambuc ATF_TC_BODY(pass_and_pass, tc)
38*0a6a1f1dSLionel Sambuc {
39*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
40*0a6a1f1dSLionel Sambuc }
41*0a6a1f1dSLionel Sambuc
42*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(pass_but_fail_requirement);
ATF_TC_BODY(pass_but_fail_requirement,tc)43*0a6a1f1dSLionel Sambuc ATF_TC_BODY(pass_but_fail_requirement, tc)
44*0a6a1f1dSLionel Sambuc {
45*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
46*0a6a1f1dSLionel Sambuc atf_tc_fail("Some reason");
47*0a6a1f1dSLionel Sambuc }
48*0a6a1f1dSLionel Sambuc
49*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(pass_but_fail_check);
ATF_TC_BODY(pass_but_fail_check,tc)50*0a6a1f1dSLionel Sambuc ATF_TC_BODY(pass_but_fail_check, tc)
51*0a6a1f1dSLionel Sambuc {
52*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
53*0a6a1f1dSLionel Sambuc atf_tc_fail_nonfatal("Some reason");
54*0a6a1f1dSLionel Sambuc }
55*0a6a1f1dSLionel Sambuc
56*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(fail_and_fail_requirement);
ATF_TC_BODY(fail_and_fail_requirement,tc)57*0a6a1f1dSLionel Sambuc ATF_TC_BODY(fail_and_fail_requirement, tc)
58*0a6a1f1dSLionel Sambuc {
59*0a6a1f1dSLionel Sambuc atf_tc_expect_fail("Fail %s", "reason");
60*0a6a1f1dSLionel Sambuc atf_tc_fail("The failure");
61*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
62*0a6a1f1dSLionel Sambuc }
63*0a6a1f1dSLionel Sambuc
64*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(fail_and_fail_check);
ATF_TC_BODY(fail_and_fail_check,tc)65*0a6a1f1dSLionel Sambuc ATF_TC_BODY(fail_and_fail_check, tc)
66*0a6a1f1dSLionel Sambuc {
67*0a6a1f1dSLionel Sambuc atf_tc_expect_fail("Fail first");
68*0a6a1f1dSLionel Sambuc atf_tc_fail_nonfatal("abc");
69*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
70*0a6a1f1dSLionel Sambuc
71*0a6a1f1dSLionel Sambuc atf_tc_expect_fail("And fail again");
72*0a6a1f1dSLionel Sambuc atf_tc_fail_nonfatal("def");
73*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
74*0a6a1f1dSLionel Sambuc }
75*0a6a1f1dSLionel Sambuc
76*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(fail_but_pass);
ATF_TC_BODY(fail_but_pass,tc)77*0a6a1f1dSLionel Sambuc ATF_TC_BODY(fail_but_pass, tc)
78*0a6a1f1dSLionel Sambuc {
79*0a6a1f1dSLionel Sambuc atf_tc_expect_fail("Fail first");
80*0a6a1f1dSLionel Sambuc atf_tc_fail_nonfatal("abc");
81*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
82*0a6a1f1dSLionel Sambuc
83*0a6a1f1dSLionel Sambuc atf_tc_expect_fail("Will not fail");
84*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
85*0a6a1f1dSLionel Sambuc
86*0a6a1f1dSLionel Sambuc atf_tc_expect_fail("And fail again");
87*0a6a1f1dSLionel Sambuc atf_tc_fail_nonfatal("def");
88*0a6a1f1dSLionel Sambuc atf_tc_expect_pass();
89*0a6a1f1dSLionel Sambuc }
90*0a6a1f1dSLionel Sambuc
91*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(exit_any_and_exit);
ATF_TC_BODY(exit_any_and_exit,tc)92*0a6a1f1dSLionel Sambuc ATF_TC_BODY(exit_any_and_exit, tc)
93*0a6a1f1dSLionel Sambuc {
94*0a6a1f1dSLionel Sambuc atf_tc_expect_exit(-1, "Call will exit");
95*0a6a1f1dSLionel Sambuc exit(EXIT_SUCCESS);
96*0a6a1f1dSLionel Sambuc }
97*0a6a1f1dSLionel Sambuc
98*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(exit_code_and_exit);
ATF_TC_BODY(exit_code_and_exit,tc)99*0a6a1f1dSLionel Sambuc ATF_TC_BODY(exit_code_and_exit, tc)
100*0a6a1f1dSLionel Sambuc {
101*0a6a1f1dSLionel Sambuc atf_tc_expect_exit(123, "Call will exit");
102*0a6a1f1dSLionel Sambuc exit(123);
103*0a6a1f1dSLionel Sambuc }
104*0a6a1f1dSLionel Sambuc
105*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(exit_but_pass);
ATF_TC_BODY(exit_but_pass,tc)106*0a6a1f1dSLionel Sambuc ATF_TC_BODY(exit_but_pass, tc)
107*0a6a1f1dSLionel Sambuc {
108*0a6a1f1dSLionel Sambuc atf_tc_expect_exit(-1, "Call won't exit");
109*0a6a1f1dSLionel Sambuc }
110*0a6a1f1dSLionel Sambuc
111*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(signal_any_and_signal);
ATF_TC_BODY(signal_any_and_signal,tc)112*0a6a1f1dSLionel Sambuc ATF_TC_BODY(signal_any_and_signal, tc)
113*0a6a1f1dSLionel Sambuc {
114*0a6a1f1dSLionel Sambuc atf_tc_expect_signal(-1, "Call will signal");
115*0a6a1f1dSLionel Sambuc kill(getpid(), SIGKILL);
116*0a6a1f1dSLionel Sambuc }
117*0a6a1f1dSLionel Sambuc
118*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(signal_no_and_signal);
ATF_TC_BODY(signal_no_and_signal,tc)119*0a6a1f1dSLionel Sambuc ATF_TC_BODY(signal_no_and_signal, tc)
120*0a6a1f1dSLionel Sambuc {
121*0a6a1f1dSLionel Sambuc atf_tc_expect_signal(SIGHUP, "Call will signal");
122*0a6a1f1dSLionel Sambuc kill(getpid(), SIGHUP);
123*0a6a1f1dSLionel Sambuc }
124*0a6a1f1dSLionel Sambuc
125*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(signal_but_pass);
ATF_TC_BODY(signal_but_pass,tc)126*0a6a1f1dSLionel Sambuc ATF_TC_BODY(signal_but_pass, tc)
127*0a6a1f1dSLionel Sambuc {
128*0a6a1f1dSLionel Sambuc atf_tc_expect_signal(-1, "Call won't signal");
129*0a6a1f1dSLionel Sambuc }
130*0a6a1f1dSLionel Sambuc
131*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(death_and_exit);
ATF_TC_BODY(death_and_exit,tc)132*0a6a1f1dSLionel Sambuc ATF_TC_BODY(death_and_exit, tc)
133*0a6a1f1dSLionel Sambuc {
134*0a6a1f1dSLionel Sambuc atf_tc_expect_death("Exit case");
135*0a6a1f1dSLionel Sambuc exit(123);
136*0a6a1f1dSLionel Sambuc }
137*0a6a1f1dSLionel Sambuc
138*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(death_and_signal);
ATF_TC_BODY(death_and_signal,tc)139*0a6a1f1dSLionel Sambuc ATF_TC_BODY(death_and_signal, tc)
140*0a6a1f1dSLionel Sambuc {
141*0a6a1f1dSLionel Sambuc atf_tc_expect_death("Signal case");
142*0a6a1f1dSLionel Sambuc kill(getpid(), SIGKILL);
143*0a6a1f1dSLionel Sambuc }
144*0a6a1f1dSLionel Sambuc
145*0a6a1f1dSLionel Sambuc ATF_TC_WITHOUT_HEAD(death_but_pass);
ATF_TC_BODY(death_but_pass,tc)146*0a6a1f1dSLionel Sambuc ATF_TC_BODY(death_but_pass, tc)
147*0a6a1f1dSLionel Sambuc {
148*0a6a1f1dSLionel Sambuc atf_tc_expect_death("Call won't die");
149*0a6a1f1dSLionel Sambuc }
150*0a6a1f1dSLionel Sambuc
151*0a6a1f1dSLionel Sambuc ATF_TC(timeout_and_hang);
ATF_TC_HEAD(timeout_and_hang,tc)152*0a6a1f1dSLionel Sambuc ATF_TC_HEAD(timeout_and_hang, tc)
153*0a6a1f1dSLionel Sambuc {
154*0a6a1f1dSLionel Sambuc atf_tc_set_md_var(tc, "timeout", "1");
155*0a6a1f1dSLionel Sambuc }
ATF_TC_BODY(timeout_and_hang,tc)156*0a6a1f1dSLionel Sambuc ATF_TC_BODY(timeout_and_hang, tc)
157*0a6a1f1dSLionel Sambuc {
158*0a6a1f1dSLionel Sambuc atf_tc_expect_timeout("Will overrun");
159*0a6a1f1dSLionel Sambuc sleep(5);
160*0a6a1f1dSLionel Sambuc }
161*0a6a1f1dSLionel Sambuc
162*0a6a1f1dSLionel Sambuc ATF_TC(timeout_but_pass);
ATF_TC_HEAD(timeout_but_pass,tc)163*0a6a1f1dSLionel Sambuc ATF_TC_HEAD(timeout_but_pass, tc)
164*0a6a1f1dSLionel Sambuc {
165*0a6a1f1dSLionel Sambuc atf_tc_set_md_var(tc, "timeout", "1");
166*0a6a1f1dSLionel Sambuc }
ATF_TC_BODY(timeout_but_pass,tc)167*0a6a1f1dSLionel Sambuc ATF_TC_BODY(timeout_but_pass, tc)
168*0a6a1f1dSLionel Sambuc {
169*0a6a1f1dSLionel Sambuc atf_tc_expect_timeout("Will just exit");
170*0a6a1f1dSLionel Sambuc }
171*0a6a1f1dSLionel Sambuc
ATF_TP_ADD_TCS(tp)172*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TCS(tp)
173*0a6a1f1dSLionel Sambuc {
174*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, pass_and_pass);
175*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, pass_but_fail_requirement);
176*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, pass_but_fail_check);
177*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, fail_and_fail_requirement);
178*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, fail_and_fail_check);
179*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, fail_but_pass);
180*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, exit_any_and_exit);
181*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, exit_code_and_exit);
182*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, exit_but_pass);
183*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, signal_any_and_signal);
184*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, signal_no_and_signal);
185*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, signal_but_pass);
186*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, death_and_exit);
187*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, death_and_signal);
188*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, death_but_pass);
189*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, timeout_and_hang);
190*0a6a1f1dSLionel Sambuc ATF_TP_ADD_TC(tp, timeout_but_pass);
191*0a6a1f1dSLionel Sambuc
192*0a6a1f1dSLionel Sambuc return atf_no_error();
193*0a6a1f1dSLionel Sambuc }
194