1 /* Copyright (c) 2008 The NetBSD Foundation, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
26 #include "atf-c/detail/sanity.h"
28 #if defined(HAVE_CONFIG_H)
32 #include <sys/types.h>
43 #include "atf-c/detail/dynstr.h"
44 #include "atf-c/detail/process.h"
45 #include "atf-c/detail/test_helpers.h"
47 /* ---------------------------------------------------------------------
48 * Auxiliary functions.
49 * --------------------------------------------------------------------- */
51 enum type { inv, pre, post, unreachable };
58 static void do_test_child(void *) ATF_DEFS_ATTRIBUTE_NORETURN;
62 do_test_child(void *v)
64 struct test_data *td = v;
90 do_test(enum type t, bool cond)
92 atf_process_child_t child;
93 atf_process_status_t status;
98 atf_process_stream_t outsb, errsb;
99 struct test_data td = { t, cond };
101 RE(atf_process_stream_init_inherit(&outsb));
102 RE(atf_process_stream_init_capture(&errsb));
103 RE(atf_process_fork(&child, do_test_child, &outsb, &errsb, &td));
104 atf_process_stream_fini(&errsb);
105 atf_process_stream_fini(&outsb);
109 while (nlines < 3 && (lines[nlines] =
110 atf_utils_readline(atf_process_child_stderr(&child))) != NULL)
112 ATF_REQUIRE(nlines == 0 || nlines == 3);
114 RE(atf_process_child_wait(&child, &status));
116 ATF_REQUIRE(atf_process_status_signaled(&status));
117 ATF_REQUIRE(atf_process_status_termsig(&status) == SIGABRT);
119 ATF_REQUIRE(atf_process_status_exited(&status));
120 ATF_REQUIRE(atf_process_status_exitstatus(&status) == EXIT_SUCCESS);
122 atf_process_status_fini(&status);
127 ATF_REQUIRE(atf_utils_grep_string("Invariant", lines[0]));
131 ATF_REQUIRE(atf_utils_grep_string("Precondition", lines[0]));
135 ATF_REQUIRE(atf_utils_grep_string("Postcondition", lines[0]));
139 ATF_REQUIRE(atf_utils_grep_string("Invariant", lines[0]));
143 ATF_REQUIRE(atf_utils_grep_string(__FILE__, lines[0]));
144 ATF_REQUIRE(atf_utils_grep_string(PACKAGE_BUGREPORT, lines[2]));
158 atf_tc_skip("Sanity checks not available; code built with -DNDEBUG");
162 /* ---------------------------------------------------------------------
163 * Test cases for the free functions.
164 * --------------------------------------------------------------------- */
169 atf_tc_set_md_var(tc, "descr", "Tests the INV macro");
182 atf_tc_set_md_var(tc, "descr", "Tests the PRE macro");
193 ATF_TC_HEAD(post, tc)
195 atf_tc_set_md_var(tc, "descr", "Tests the POST macro");
197 ATF_TC_BODY(post, tc)
201 do_test(post, false);
206 ATF_TC_HEAD(unreachable, tc)
208 atf_tc_set_md_var(tc, "descr", "Tests the UNREACHABLE macro");
210 ATF_TC_BODY(unreachable, tc)
214 do_test(unreachable, false);
215 do_test(unreachable, true);
218 /* ---------------------------------------------------------------------
220 * --------------------------------------------------------------------- */
224 ATF_TP_ADD_TC(tp, inv);
225 ATF_TP_ADD_TC(tp, pre);
226 ATF_TP_ADD_TC(tp, post);
227 ATF_TP_ADD_TC(tp, unreachable);
229 return atf_no_error();