1 /* $NetBSD: sanity_test.c,v 1.3 2014/12/10 04:38:03 christos Exp $ */
4 * Automated Testing Framework (atf)
6 * Copyright (c) 2008 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.
32 #if defined(HAVE_CONFIG_H)
36 #include <sys/types.h>
50 #include "test_helpers.h"
52 /* ---------------------------------------------------------------------
53 * Auxiliary functions.
54 * --------------------------------------------------------------------- */
56 enum type
{ inv
, pre
, post
, unreachable
};
63 static void do_test_child(void *) ATF_DEFS_ATTRIBUTE_NORETURN
;
67 do_test_child(void *v
)
69 struct test_data
*td
= v
;
95 do_test(enum type t
, bool cond
)
97 atf_process_child_t child
;
98 atf_process_status_t status
;
103 atf_process_stream_t outsb
, errsb
;
104 struct test_data td
= { t
, cond
};
106 RE(atf_process_stream_init_inherit(&outsb
));
107 RE(atf_process_stream_init_capture(&errsb
));
108 RE(atf_process_fork(&child
, do_test_child
, &outsb
, &errsb
, &td
));
109 atf_process_stream_fini(&errsb
);
110 atf_process_stream_fini(&outsb
);
114 while (nlines
< 3 && (lines
[nlines
] =
115 atf_utils_readline(atf_process_child_stderr(&child
))) != NULL
)
117 ATF_REQUIRE(nlines
== 0 || nlines
== 3);
119 RE(atf_process_child_wait(&child
, &status
));
121 ATF_REQUIRE(atf_process_status_signaled(&status
));
122 ATF_REQUIRE(atf_process_status_termsig(&status
) == SIGABRT
);
124 ATF_REQUIRE(atf_process_status_exited(&status
));
125 ATF_REQUIRE(atf_process_status_exitstatus(&status
) == EXIT_SUCCESS
);
127 atf_process_status_fini(&status
);
132 ATF_REQUIRE(atf_utils_grep_string("Invariant", lines
[0]));
136 ATF_REQUIRE(atf_utils_grep_string("Precondition", lines
[0]));
140 ATF_REQUIRE(atf_utils_grep_string("Postcondition", lines
[0]));
144 ATF_REQUIRE(atf_utils_grep_string("Invariant", lines
[0]));
148 ATF_REQUIRE(atf_utils_grep_string(__FILE__
, lines
[0]));
149 ATF_REQUIRE(atf_utils_grep_string(PACKAGE_BUGREPORT
, lines
[2]));
163 atf_tc_skip("Sanity checks not available; code built with -DNDEBUG");
167 /* ---------------------------------------------------------------------
168 * Test cases for the free functions.
169 * --------------------------------------------------------------------- */
174 atf_tc_set_md_var(tc
, "descr", "Tests the INV macro");
187 atf_tc_set_md_var(tc
, "descr", "Tests the PRE macro");
198 ATF_TC_HEAD(post
, tc
)
200 atf_tc_set_md_var(tc
, "descr", "Tests the POST macro");
202 ATF_TC_BODY(post
, tc
)
206 do_test(post
, false);
211 ATF_TC_HEAD(unreachable
, tc
)
213 atf_tc_set_md_var(tc
, "descr", "Tests the UNREACHABLE macro");
215 ATF_TC_BODY(unreachable
, tc
)
219 do_test(unreachable
, false);
220 do_test(unreachable
, true);
223 /* ---------------------------------------------------------------------
225 * --------------------------------------------------------------------- */
229 ATF_TP_ADD_TC(tp
, inv
);
230 ATF_TP_ADD_TC(tp
, pre
);
231 ATF_TP_ADD_TC(tp
, post
);
232 ATF_TP_ADD_TC(tp
, unreachable
);
234 return atf_no_error();