Remove building with NOCRYPTO option
[minix3.git] / external / bsd / kyua-testers / dist / atf_inttest.c
blob374089f4ecd10f82e33d78f60b88d5a7e8e15752
1 // Copyright 2012 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <stdlib.h>
31 #include <atf-c.h>
33 #define INTERFACE "atf"
34 #include "common_inttest.h"
37 ATF_TC(list__ok);
38 ATF_TC_HEAD(list__ok, tc) { setup(tc, true); }
39 ATF_TC_BODY(list__ok, tc)
41 char* helpers = helpers_path(tc);
42 check(EXIT_SUCCESS,
43 "test_case{name='fail'}\n"
44 "test_case{name='pass'}\n"
45 "test_case{name='signal'}\n"
46 "test_case{name='sleep'}\n"
47 "test_case{name='cleanup_check_work_directory', has_cleanup='true'}\n"
48 "test_case{name='cleanup_fail', has_cleanup='true'}\n"
49 "test_case{name='cleanup_signal', has_cleanup='true'}\n"
50 "test_case{name='cleanup_sleep', has_cleanup='true'}\n"
51 "test_case{name='body_and_cleanup_fail', has_cleanup='true'}\n"
52 "test_case{name='print_config', has_cleanup='true'}\n",
53 "",
54 "list", helpers, NULL);
55 free(helpers);
59 ATF_TC(test__pass);
60 ATF_TC_HEAD(test__pass, tc) { setup(tc, true); }
61 ATF_TC_BODY(test__pass, tc)
63 char* helpers = helpers_path(tc);
64 check(EXIT_SUCCESS,
65 "First line to stdout\nSecond line to stdout\n",
66 "First line to stderr\nSecond line to stderr\n",
67 "test", helpers, "pass", "test-result", NULL);
68 free(helpers);
70 ATF_REQUIRE(atf_utils_compare_file("test-result", "passed\n"));
74 ATF_TC(test__fail);
75 ATF_TC_HEAD(test__fail, tc) { setup(tc, true); }
76 ATF_TC_BODY(test__fail, tc)
78 char* helpers = helpers_path(tc);
79 check(EXIT_FAILURE, "First line to stdout\n", "First line to stderr\n",
80 "test", helpers, "fail", "test-result", NULL);
81 free(helpers);
83 ATF_REQUIRE(atf_utils_compare_file("test-result",
84 "failed: This is the failure message\n"));
88 ATF_TC(test__crash);
89 ATF_TC_HEAD(test__crash, tc) { setup(tc, true); }
90 ATF_TC_BODY(test__crash, tc)
92 char* helpers = helpers_path(tc);
93 check(EXIT_FAILURE, "", "save:crash.err",
94 "test", helpers, "signal", "test-result", NULL);
95 free(helpers);
97 ATF_REQUIRE(atf_utils_compare_file("test-result",
98 "broken: Premature exit; test case received signal 6 (core dumped)\n"));
100 ATF_REQUIRE(atf_utils_grep_file("About to die due to SIGABRT!",
101 "crash.err"));
102 ATF_REQUIRE(atf_utils_grep_file("attempting to gather stack trace",
103 "crash.err"));
107 ATF_TC(test__timeout);
108 ATF_TC_HEAD(test__timeout, tc) { setup(tc, true); }
109 ATF_TC_BODY(test__timeout, tc)
111 char* helpers = helpers_path(tc);
112 check(EXIT_FAILURE, "", "Subprocess timed out; sending KILL signal...\n",
113 "-t1", "test", helpers, "sleep", "test-result", NULL);
114 free(helpers);
116 ATF_REQUIRE(atf_utils_compare_file("test-result",
117 "broken: Test case body timed out\n"));
121 ATF_TC(test__result_priority);
122 ATF_TC_HEAD(test__result_priority, tc) { setup(tc, true); }
123 ATF_TC_BODY(test__result_priority, tc)
125 char* helpers = helpers_path(tc);
126 check(EXIT_FAILURE, "Killing cleanup\n", "",
127 "test", "-vhas.cleanup=true", helpers, "body_and_cleanup_fail",
128 "test-result", NULL);
129 free(helpers);
131 ATF_REQUIRE(atf_utils_compare_file("test-result", "failed: Body fails\n"));
135 ATF_TC(test__cleanup__ok);
136 ATF_TC_HEAD(test__cleanup__ok, tc) { setup(tc, true); }
137 ATF_TC_BODY(test__cleanup__ok, tc)
139 char* helpers = helpers_path(tc);
140 check(EXIT_SUCCESS,
141 "Body stdout\nCleanup stdout\n"
142 "Cleanup properly ran in the same directory as the body\n",
143 "Body stderr\nCleanup stderr\n",
144 "test", "-vhas.cleanup=true", helpers, "cleanup_check_work_directory",
145 "test-result", NULL);
146 free(helpers);
148 ATF_REQUIRE(atf_utils_compare_file("test-result", "passed\n"));
152 ATF_TC(test__cleanup__fail);
153 ATF_TC_HEAD(test__cleanup__fail, tc) { setup(tc, true); }
154 ATF_TC_BODY(test__cleanup__fail, tc)
156 char* helpers = helpers_path(tc);
157 check(EXIT_FAILURE, "", "",
158 "test", "-vhas.cleanup=true", helpers, "cleanup_fail", "test-result",
159 NULL);
160 free(helpers);
162 ATF_REQUIRE(atf_utils_compare_file("test-result", "broken: Test case "
163 "cleanup exited with code 1\n"));
167 ATF_TC(test__cleanup__crash);
168 ATF_TC_HEAD(test__cleanup__crash, tc) { setup(tc, true); }
169 ATF_TC_BODY(test__cleanup__crash, tc)
171 char* helpers = helpers_path(tc);
172 check(EXIT_FAILURE, "", "save:crash.err",
173 "test", "-vhas.cleanup=true", helpers, "cleanup_signal",
174 "test-result", NULL);
175 free(helpers);
177 ATF_REQUIRE(atf_utils_compare_file("test-result",
178 "broken: Test case cleanup received signal 6 (core dumped)\n"));
180 ATF_REQUIRE(atf_utils_grep_file("About to die due to SIGABRT!",
181 "crash.err"));
182 ATF_REQUIRE(atf_utils_grep_file("attempting to gather stack trace",
183 "crash.err"));
187 ATF_TC(test__cleanup__timeout);
188 ATF_TC_HEAD(test__cleanup__timeout, tc) { setup(tc, true); }
189 ATF_TC_BODY(test__cleanup__timeout, tc)
191 char* helpers = helpers_path(tc);
192 check(EXIT_FAILURE, "", "Subprocess timed out; sending KILL signal...\n",
193 "-t1", "test", "-vhas.cleanup=true", helpers, "cleanup_sleep",
194 "test-result", NULL);
195 free(helpers);
197 ATF_REQUIRE(atf_utils_compare_file("test-result", "broken: Test case "
198 "cleanup timed out\n"));
202 ATF_TC(test__config__builtin);
203 ATF_TC_HEAD(test__config__builtin, tc) { setup(tc, true); }
204 ATF_TC_BODY(test__config__builtin, tc)
206 char* helpers = helpers_path(tc);
207 check(EXIT_SUCCESS, "", "",
208 "test", helpers, "print_config", "test-result", NULL);
209 free(helpers);
211 ATF_REQUIRE(atf_utils_compare_file("test-result", "passed\n"));
215 ATF_TC(test__config__custom);
216 ATF_TC_HEAD(test__config__custom, tc) { setup(tc, true); }
217 ATF_TC_BODY(test__config__custom, tc)
219 char* helpers = helpers_path(tc);
220 check(EXIT_SUCCESS,
221 "body my-var1 value1\n"
222 "body v2 a b c foo\n"
223 "cleanup my-var1 value1\n"
224 "cleanup v2 a b c foo\n",
226 "test", "-vmy-var1=value1", "-vv2=a b c foo", helpers,
227 "print_config", "test-result", NULL);
228 free(helpers);
230 ATF_REQUIRE(atf_utils_compare_file("test-result", "passed\n"));
234 ATF_TC(test__invalid_test_case_name);
235 ATF_TC_HEAD(test__invalid_test_case_name, tc) { setup(tc, false); }
236 ATF_TC_BODY(test__invalid_test_case_name, tc)
238 char* helpers = helpers_path(tc);
239 check(EXIT_FAILURE, "", // TODO(jmmv): Should be EXIT_INTERNAL_ERROR.
240 "atf_helpers: ERROR: Unknown test case `foo'\n"
241 "atf_helpers: See atf-test-program(1) for usage details.\n",
242 "test", "-vhas.cleanup=false", helpers, "foo", "test-result", NULL);
243 free(helpers);
245 ATF_REQUIRE(atf_utils_compare_file("test-result",
246 "broken: Premature exit; test case exited with code 1\n"));
250 ATF_TC(test__missing_test_program);
251 ATF_TC_HEAD(test__missing_test_program, tc) { setup(tc, false); }
252 ATF_TC_BODY(test__missing_test_program, tc)
254 check(EXIT_INTERNAL_ERROR, "",
255 "kyua-atf-tester: execvp failed: No such file or directory\n",
256 "test", "./non-existent", "pass", "test-result", NULL);
258 ATF_REQUIRE(!atf_utils_file_exists("test-result"));
262 ATF_TP_ADD_TCS(tp)
264 ATF_TP_ADD_TC(tp, top__missing_command);
265 ATF_TP_ADD_TC(tp, top__unknown_command);
267 ATF_TP_ADD_TC(tp, list__ok);
269 ATF_TP_ADD_TC(tp, test__pass);
270 ATF_TP_ADD_TC(tp, test__fail);
271 ATF_TP_ADD_TC(tp, test__crash);
272 ATF_TP_ADD_TC(tp, test__timeout);
273 ATF_TP_ADD_TC(tp, test__result_priority);
274 ATF_TP_ADD_TC(tp, test__cleanup__ok);
275 ATF_TP_ADD_TC(tp, test__cleanup__fail);
276 ATF_TP_ADD_TC(tp, test__cleanup__crash);
277 ATF_TP_ADD_TC(tp, test__cleanup__timeout);
278 ATF_TP_ADD_TC(tp, test__config__builtin);
279 ATF_TP_ADD_TC(tp, test__config__custom);
280 ATF_TP_ADD_TC(tp, test__missing_test_program);
281 ATF_TP_ADD_TC(tp, test__invalid_test_case_name);
283 return atf_no_error();