1 /* $NetBSD: expect_helpers.c,v 1.1.1.3 2014/12/10 03:34:48 christos Exp $ */
4 * Automated Testing Framework (atf)
6 * Copyright (c) 2010 The NetBSD Foundation, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 ATF_TC_WITHOUT_HEAD(pass_and_pass
);
39 ATF_TC_BODY(pass_and_pass
, tc
)
44 ATF_TC_WITHOUT_HEAD(pass_but_fail_requirement
);
45 ATF_TC_BODY(pass_but_fail_requirement
, tc
)
48 atf_tc_fail("Some reason");
51 ATF_TC_WITHOUT_HEAD(pass_but_fail_check
);
52 ATF_TC_BODY(pass_but_fail_check
, tc
)
55 atf_tc_fail_nonfatal("Some reason");
58 ATF_TC_WITHOUT_HEAD(fail_and_fail_requirement
);
59 ATF_TC_BODY(fail_and_fail_requirement
, tc
)
61 atf_tc_expect_fail("Fail %s", "reason");
62 atf_tc_fail("The failure");
66 ATF_TC_WITHOUT_HEAD(fail_and_fail_check
);
67 ATF_TC_BODY(fail_and_fail_check
, tc
)
69 atf_tc_expect_fail("Fail first");
70 atf_tc_fail_nonfatal("abc");
73 atf_tc_expect_fail("And fail again");
74 atf_tc_fail_nonfatal("def");
78 ATF_TC_WITHOUT_HEAD(fail_but_pass
);
79 ATF_TC_BODY(fail_but_pass
, tc
)
81 atf_tc_expect_fail("Fail first");
82 atf_tc_fail_nonfatal("abc");
85 atf_tc_expect_fail("Will not fail");
88 atf_tc_expect_fail("And fail again");
89 atf_tc_fail_nonfatal("def");
93 ATF_TC_WITHOUT_HEAD(exit_any_and_exit
);
94 ATF_TC_BODY(exit_any_and_exit
, tc
)
96 atf_tc_expect_exit(-1, "Call will exit");
100 ATF_TC_WITHOUT_HEAD(exit_code_and_exit
);
101 ATF_TC_BODY(exit_code_and_exit
, tc
)
103 atf_tc_expect_exit(123, "Call will exit");
107 ATF_TC_WITHOUT_HEAD(exit_but_pass
);
108 ATF_TC_BODY(exit_but_pass
, tc
)
110 atf_tc_expect_exit(-1, "Call won't exit");
113 ATF_TC_WITHOUT_HEAD(signal_any_and_signal
);
114 ATF_TC_BODY(signal_any_and_signal
, tc
)
116 atf_tc_expect_signal(-1, "Call will signal");
117 kill(getpid(), SIGKILL
);
120 ATF_TC_WITHOUT_HEAD(signal_no_and_signal
);
121 ATF_TC_BODY(signal_no_and_signal
, tc
)
123 atf_tc_expect_signal(SIGHUP
, "Call will signal");
124 kill(getpid(), SIGHUP
);
127 ATF_TC_WITHOUT_HEAD(signal_but_pass
);
128 ATF_TC_BODY(signal_but_pass
, tc
)
130 atf_tc_expect_signal(-1, "Call won't signal");
133 ATF_TC_WITHOUT_HEAD(death_and_exit
);
134 ATF_TC_BODY(death_and_exit
, tc
)
136 atf_tc_expect_death("Exit case");
140 ATF_TC_WITHOUT_HEAD(death_and_signal
);
141 ATF_TC_BODY(death_and_signal
, tc
)
143 atf_tc_expect_death("Signal case");
144 kill(getpid(), SIGKILL
);
147 ATF_TC_WITHOUT_HEAD(death_but_pass
);
148 ATF_TC_BODY(death_but_pass
, tc
)
150 atf_tc_expect_death("Call won't die");
153 ATF_TC(timeout_and_hang
);
154 ATF_TC_HEAD(timeout_and_hang
, tc
)
156 atf_tc_set_md_var(tc
, "timeout", "1");
158 ATF_TC_BODY(timeout_and_hang
, tc
)
160 atf_tc_expect_timeout("Will overrun");
164 ATF_TC(timeout_but_pass
);
165 ATF_TC_HEAD(timeout_but_pass
, tc
)
167 atf_tc_set_md_var(tc
, "timeout", "1");
169 ATF_TC_BODY(timeout_but_pass
, tc
)
171 atf_tc_expect_timeout("Will just exit");
176 ATF_TP_ADD_TC(tp
, pass_and_pass
);
177 ATF_TP_ADD_TC(tp
, pass_but_fail_requirement
);
178 ATF_TP_ADD_TC(tp
, pass_but_fail_check
);
179 ATF_TP_ADD_TC(tp
, fail_and_fail_requirement
);
180 ATF_TP_ADD_TC(tp
, fail_and_fail_check
);
181 ATF_TP_ADD_TC(tp
, fail_but_pass
);
182 ATF_TP_ADD_TC(tp
, exit_any_and_exit
);
183 ATF_TP_ADD_TC(tp
, exit_code_and_exit
);
184 ATF_TP_ADD_TC(tp
, exit_but_pass
);
185 ATF_TP_ADD_TC(tp
, signal_any_and_signal
);
186 ATF_TP_ADD_TC(tp
, signal_no_and_signal
);
187 ATF_TP_ADD_TC(tp
, signal_but_pass
);
188 ATF_TP_ADD_TC(tp
, death_and_exit
);
189 ATF_TP_ADD_TC(tp
, death_and_signal
);
190 ATF_TP_ADD_TC(tp
, death_but_pass
);
191 ATF_TP_ADD_TC(tp
, timeout_and_hang
);
192 ATF_TP_ADD_TC(tp
, timeout_but_pass
);
194 return atf_no_error();