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