1*11be35a1SLionel Sambuc // Copyright 2012 Google Inc.
2*11be35a1SLionel Sambuc // All rights reserved.
3*11be35a1SLionel Sambuc //
4*11be35a1SLionel Sambuc // Redistribution and use in source and binary forms, with or without
5*11be35a1SLionel Sambuc // modification, are permitted provided that the following conditions are
6*11be35a1SLionel Sambuc // met:
7*11be35a1SLionel Sambuc //
8*11be35a1SLionel Sambuc // * Redistributions of source code must retain the above copyright
9*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer.
10*11be35a1SLionel Sambuc // * Redistributions in binary form must reproduce the above copyright
11*11be35a1SLionel Sambuc // notice, this list of conditions and the following disclaimer in the
12*11be35a1SLionel Sambuc // documentation and/or other materials provided with the distribution.
13*11be35a1SLionel Sambuc // * Neither the name of Google Inc. nor the names of its contributors
14*11be35a1SLionel Sambuc // may be used to endorse or promote products derived from this software
15*11be35a1SLionel Sambuc // without specific prior written permission.
16*11be35a1SLionel Sambuc //
17*11be35a1SLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18*11be35a1SLionel Sambuc // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19*11be35a1SLionel Sambuc // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20*11be35a1SLionel Sambuc // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21*11be35a1SLionel Sambuc // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22*11be35a1SLionel Sambuc // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23*11be35a1SLionel Sambuc // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*11be35a1SLionel Sambuc // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*11be35a1SLionel Sambuc // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*11be35a1SLionel Sambuc // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27*11be35a1SLionel Sambuc // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*11be35a1SLionel Sambuc
29*11be35a1SLionel Sambuc #include <stdlib.h>
30*11be35a1SLionel Sambuc
31*11be35a1SLionel Sambuc #include <atf-c.h>
32*11be35a1SLionel Sambuc
33*11be35a1SLionel Sambuc #define INTERFACE "plain"
34*11be35a1SLionel Sambuc #include "common_inttest.h"
35*11be35a1SLionel Sambuc
36*11be35a1SLionel Sambuc
37*11be35a1SLionel Sambuc /// Sets up a particular helper.
38*11be35a1SLionel Sambuc ///
39*11be35a1SLionel Sambuc /// \param tc The test case calling this function.
40*11be35a1SLionel Sambuc /// \param helper_name Name of the desired helper.
41*11be35a1SLionel Sambuc ///
42*11be35a1SLionel Sambuc /// \return The return value of helpers_path().
43*11be35a1SLionel Sambuc static char*
select_helper(const atf_tc_t * tc,const char * helper_name)44*11be35a1SLionel Sambuc select_helper(const atf_tc_t* tc, const char* helper_name)
45*11be35a1SLionel Sambuc {
46*11be35a1SLionel Sambuc ATF_REQUIRE(setenv("HELPER", helper_name, 1) != -1);
47*11be35a1SLionel Sambuc return helpers_path(tc);
48*11be35a1SLionel Sambuc }
49*11be35a1SLionel Sambuc
50*11be35a1SLionel Sambuc
51*11be35a1SLionel Sambuc ATF_TC(list__ok);
ATF_TC_HEAD(list__ok,tc)52*11be35a1SLionel Sambuc ATF_TC_HEAD(list__ok, tc) { setup(tc, false); }
ATF_TC_BODY(list__ok,tc)53*11be35a1SLionel Sambuc ATF_TC_BODY(list__ok, tc)
54*11be35a1SLionel Sambuc {
55*11be35a1SLionel Sambuc check(EXIT_SUCCESS, "test_case{name='main'}\n", "",
56*11be35a1SLionel Sambuc "list", "irrelevant-program", NULL);
57*11be35a1SLionel Sambuc }
58*11be35a1SLionel Sambuc
59*11be35a1SLionel Sambuc
60*11be35a1SLionel Sambuc ATF_TC(test__pass);
ATF_TC_HEAD(test__pass,tc)61*11be35a1SLionel Sambuc ATF_TC_HEAD(test__pass, tc) { setup(tc, true); }
ATF_TC_BODY(test__pass,tc)62*11be35a1SLionel Sambuc ATF_TC_BODY(test__pass, tc)
63*11be35a1SLionel Sambuc {
64*11be35a1SLionel Sambuc char* helpers = select_helper(tc, "pass");
65*11be35a1SLionel Sambuc check(EXIT_SUCCESS,
66*11be35a1SLionel Sambuc "First line to stdout\nSecond line to stdout\n",
67*11be35a1SLionel Sambuc "First line to stderr\nSecond line to stderr\n",
68*11be35a1SLionel Sambuc "test", helpers, "main", "test-result", NULL);
69*11be35a1SLionel Sambuc free(helpers);
70*11be35a1SLionel Sambuc
71*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_compare_file("test-result", "passed\n"));
72*11be35a1SLionel Sambuc }
73*11be35a1SLionel Sambuc
74*11be35a1SLionel Sambuc
75*11be35a1SLionel Sambuc ATF_TC(test__fail);
ATF_TC_HEAD(test__fail,tc)76*11be35a1SLionel Sambuc ATF_TC_HEAD(test__fail, tc) { setup(tc, true); }
ATF_TC_BODY(test__fail,tc)77*11be35a1SLionel Sambuc ATF_TC_BODY(test__fail, tc)
78*11be35a1SLionel Sambuc {
79*11be35a1SLionel Sambuc char* helpers = select_helper(tc, "fail");
80*11be35a1SLionel Sambuc check(EXIT_FAILURE, "First line to stdout\n", "First line to stderr\n",
81*11be35a1SLionel Sambuc "test", helpers, "main", "test-result", NULL);
82*11be35a1SLionel Sambuc free(helpers);
83*11be35a1SLionel Sambuc
84*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_compare_file("test-result",
85*11be35a1SLionel Sambuc "failed: Returned non-success exit status 78\n"));
86*11be35a1SLionel Sambuc }
87*11be35a1SLionel Sambuc
88*11be35a1SLionel Sambuc
89*11be35a1SLionel Sambuc ATF_TC(test__crash);
ATF_TC_HEAD(test__crash,tc)90*11be35a1SLionel Sambuc ATF_TC_HEAD(test__crash, tc) { setup(tc, true); }
ATF_TC_BODY(test__crash,tc)91*11be35a1SLionel Sambuc ATF_TC_BODY(test__crash, tc)
92*11be35a1SLionel Sambuc {
93*11be35a1SLionel Sambuc char* helpers = select_helper(tc, "signal");
94*11be35a1SLionel Sambuc check(EXIT_FAILURE, "", "save:crash.err",
95*11be35a1SLionel Sambuc "test", helpers, "main", "test-result", NULL);
96*11be35a1SLionel Sambuc free(helpers);
97*11be35a1SLionel Sambuc
98*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_compare_file("test-result",
99*11be35a1SLionel Sambuc "broken: Received signal 6\n"));
100*11be35a1SLionel Sambuc
101*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_grep_file("About to die due to SIGABRT!",
102*11be35a1SLionel Sambuc "crash.err"));
103*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_grep_file("attempting to gather stack trace",
104*11be35a1SLionel Sambuc "crash.err"));
105*11be35a1SLionel Sambuc }
106*11be35a1SLionel Sambuc
107*11be35a1SLionel Sambuc
108*11be35a1SLionel Sambuc ATF_TC(test__timeout);
ATF_TC_HEAD(test__timeout,tc)109*11be35a1SLionel Sambuc ATF_TC_HEAD(test__timeout, tc) { setup(tc, true); }
ATF_TC_BODY(test__timeout,tc)110*11be35a1SLionel Sambuc ATF_TC_BODY(test__timeout, tc)
111*11be35a1SLionel Sambuc {
112*11be35a1SLionel Sambuc char* helpers = select_helper(tc, "sleep");
113*11be35a1SLionel Sambuc check(EXIT_FAILURE, "", "Subprocess timed out; sending KILL signal...\n",
114*11be35a1SLionel Sambuc "-t1", "test", helpers, "main", "test-result", NULL);
115*11be35a1SLionel Sambuc free(helpers);
116*11be35a1SLionel Sambuc
117*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_compare_file("test-result", "broken: Test case "
118*11be35a1SLionel Sambuc "timed out\n"));
119*11be35a1SLionel Sambuc }
120*11be35a1SLionel Sambuc
121*11be35a1SLionel Sambuc
122*11be35a1SLionel Sambuc ATF_TC(test__config_ignored);
ATF_TC_HEAD(test__config_ignored,tc)123*11be35a1SLionel Sambuc ATF_TC_HEAD(test__config_ignored, tc) { setup(tc, true); }
ATF_TC_BODY(test__config_ignored,tc)124*11be35a1SLionel Sambuc ATF_TC_BODY(test__config_ignored, tc)
125*11be35a1SLionel Sambuc {
126*11be35a1SLionel Sambuc char* helpers = select_helper(tc, "pass");
127*11be35a1SLionel Sambuc check(EXIT_SUCCESS,
128*11be35a1SLionel Sambuc "First line to stdout\nSecond line to stdout\n",
129*11be35a1SLionel Sambuc "save:stderr.txt",
130*11be35a1SLionel Sambuc "test", "-va=b", "-vfoo=a b c", helpers, "main", "test-result", NULL);
131*11be35a1SLionel Sambuc free(helpers);
132*11be35a1SLionel Sambuc
133*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_grep_file("ignoring 'a=b'", "stderr.txt"));
134*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_grep_file("ignoring 'foo=a b c'", "stderr.txt"));
135*11be35a1SLionel Sambuc ATF_REQUIRE(atf_utils_compare_file("test-result", "passed\n"));
136*11be35a1SLionel Sambuc }
137*11be35a1SLionel Sambuc
138*11be35a1SLionel Sambuc
139*11be35a1SLionel Sambuc ATF_TC(test__missing_test_program);
ATF_TC_HEAD(test__missing_test_program,tc)140*11be35a1SLionel Sambuc ATF_TC_HEAD(test__missing_test_program, tc) { setup(tc, false); }
ATF_TC_BODY(test__missing_test_program,tc)141*11be35a1SLionel Sambuc ATF_TC_BODY(test__missing_test_program, tc)
142*11be35a1SLionel Sambuc {
143*11be35a1SLionel Sambuc check(EXIT_INTERNAL_ERROR, "",
144*11be35a1SLionel Sambuc "kyua-plain-tester: execvp failed: No such file or directory\n",
145*11be35a1SLionel Sambuc "test", "./non-existent", "main", "test-result", NULL);
146*11be35a1SLionel Sambuc
147*11be35a1SLionel Sambuc ATF_REQUIRE(!atf_utils_file_exists("test-result"));
148*11be35a1SLionel Sambuc }
149*11be35a1SLionel Sambuc
150*11be35a1SLionel Sambuc
151*11be35a1SLionel Sambuc ATF_TC(test__invalid_test_case_name);
ATF_TC_HEAD(test__invalid_test_case_name,tc)152*11be35a1SLionel Sambuc ATF_TC_HEAD(test__invalid_test_case_name, tc) { setup(tc, false); }
ATF_TC_BODY(test__invalid_test_case_name,tc)153*11be35a1SLionel Sambuc ATF_TC_BODY(test__invalid_test_case_name, tc)
154*11be35a1SLionel Sambuc {
155*11be35a1SLionel Sambuc check(EXIT_INTERNAL_ERROR, "",
156*11be35a1SLionel Sambuc "kyua-plain-tester: Unknown test case 'foo'\n",
157*11be35a1SLionel Sambuc "test", "./non-existent", "foo", "test-result", NULL);
158*11be35a1SLionel Sambuc
159*11be35a1SLionel Sambuc ATF_REQUIRE(!atf_utils_file_exists("test-result"));
160*11be35a1SLionel Sambuc }
161*11be35a1SLionel Sambuc
162*11be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)163*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
164*11be35a1SLionel Sambuc {
165*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, top__missing_command);
166*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, top__unknown_command);
167*11be35a1SLionel Sambuc
168*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, list__ok);
169*11be35a1SLionel Sambuc
170*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, test__pass);
171*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, test__fail);
172*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, test__crash);
173*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, test__timeout);
174*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, test__config_ignored);
175*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, test__missing_test_program);
176*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, test__invalid_test_case_name);
177*11be35a1SLionel Sambuc
178*11be35a1SLionel Sambuc return atf_no_error();
179*11be35a1SLionel Sambuc }
180