2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #if defined(HAVE_CONFIG_H)
34 #include <sys/types.h>
48 #include "test_helpers.h"
50 /* ---------------------------------------------------------------------
51 * Auxiliary functions.
52 * --------------------------------------------------------------------- */
54 enum type
{ inv
, pre
, post
, unreachable
};
61 static void do_test_child(void *) ATF_DEFS_ATTRIBUTE_NORETURN
;
65 do_test_child(void *v
)
67 struct test_data
*td
= v
;
93 do_test(enum type t
, bool cond
)
95 atf_process_child_t child
;
96 atf_process_status_t status
;
101 atf_process_stream_t outsb
, errsb
;
102 struct test_data td
= { t
, cond
};
104 RE(atf_process_stream_init_inherit(&outsb
));
105 RE(atf_process_stream_init_capture(&errsb
));
106 RE(atf_process_fork(&child
, do_test_child
, &outsb
, &errsb
, &td
));
107 atf_process_stream_fini(&errsb
);
108 atf_process_stream_fini(&outsb
);
112 while (nlines
< 3 && (lines
[nlines
] =
113 atf_utils_readline(atf_process_child_stderr(&child
))) != NULL
)
115 ATF_REQUIRE(nlines
== 0 || nlines
== 3);
117 RE(atf_process_child_wait(&child
, &status
));
119 ATF_REQUIRE(atf_process_status_signaled(&status
));
120 ATF_REQUIRE(atf_process_status_termsig(&status
) == SIGABRT
);
122 ATF_REQUIRE(atf_process_status_exited(&status
));
123 ATF_REQUIRE(atf_process_status_exitstatus(&status
) == EXIT_SUCCESS
);
125 atf_process_status_fini(&status
);
130 ATF_REQUIRE(atf_utils_grep_string("Invariant", lines
[0]));
134 ATF_REQUIRE(atf_utils_grep_string("Precondition", lines
[0]));
138 ATF_REQUIRE(atf_utils_grep_string("Postcondition", lines
[0]));
142 ATF_REQUIRE(atf_utils_grep_string("Invariant", lines
[0]));
146 ATF_REQUIRE(atf_utils_grep_string(__FILE__
, lines
[0]));
147 ATF_REQUIRE(atf_utils_grep_string(PACKAGE_BUGREPORT
, lines
[2]));
161 atf_tc_skip("Sanity checks not available; code built with -DNDEBUG");
165 /* ---------------------------------------------------------------------
166 * Test cases for the free functions.
167 * --------------------------------------------------------------------- */
172 atf_tc_set_md_var(tc
, "descr", "Tests the INV macro");
185 atf_tc_set_md_var(tc
, "descr", "Tests the PRE macro");
196 ATF_TC_HEAD(post
, tc
)
198 atf_tc_set_md_var(tc
, "descr", "Tests the POST macro");
200 ATF_TC_BODY(post
, tc
)
204 do_test(post
, false);
209 ATF_TC_HEAD(unreachable
, tc
)
211 atf_tc_set_md_var(tc
, "descr", "Tests the UNREACHABLE macro");
213 ATF_TC_BODY(unreachable
, tc
)
217 do_test(unreachable
, false);
218 do_test(unreachable
, true);
221 /* ---------------------------------------------------------------------
223 * --------------------------------------------------------------------- */
227 ATF_TP_ADD_TC(tp
, inv
);
228 ATF_TP_ADD_TC(tp
, pre
);
229 ATF_TP_ADD_TC(tp
, post
);
230 ATF_TP_ADD_TC(tp
, unreachable
);
232 return atf_no_error();