2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008, 2009 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.
34 #include "atf-c/error.h"
37 #include "atf-c/sanity.h"
39 #include "atf-c/tcr.h"
42 /* ---------------------------------------------------------------------
43 * Auxiliary functions.
44 * --------------------------------------------------------------------- */
48 find_tc(const atf_tp_t
*tp
, const char *ident
)
51 atf_list_citer_t iter
;
54 atf_list_for_each_c(iter
, &tp
->m_tcs
) {
56 tc2
= atf_list_citer_data(iter
);
57 if (strcmp(tc2
->m_ident
, ident
) == 0) {
65 /* ---------------------------------------------------------------------
67 * --------------------------------------------------------------------- */
70 * Constructors/destructors.
74 atf_tp_init(atf_tp_t
*tp
, struct atf_map
*config
)
80 atf_object_init(&tp
->m_object
);
82 err
= atf_list_init(&tp
->m_tcs
);
83 if (atf_is_error(err
))
86 tp
->m_config
= config
;
88 INV(!atf_is_error(err
));
92 atf_object_fini(&tp
->m_object
);
97 atf_tp_fini(atf_tp_t
*tp
)
101 atf_list_for_each(iter
, &tp
->m_tcs
) {
102 atf_tc_t
*tc
= atf_list_iter_data(iter
);
105 atf_list_fini(&tp
->m_tcs
);
107 atf_object_fini(&tp
->m_object
);
114 const struct atf_map
*
115 atf_tp_get_config(const atf_tp_t
*tp
)
121 atf_tp_get_tc(const atf_tp_t
*tp
, const char *id
)
123 const atf_tc_t
*tc
= find_tc(tp
, id
);
129 atf_tp_get_tcs(const atf_tp_t
*tp
)
139 atf_tp_add_tc(atf_tp_t
*tp
, atf_tc_t
*tc
)
143 PRE(find_tc(tp
, tc
->m_ident
) == NULL
);
145 err
= atf_list_append(&tp
->m_tcs
, tc
, false);
147 POST(find_tc(tp
, tc
->m_ident
) != NULL
);
152 /* ---------------------------------------------------------------------
154 * --------------------------------------------------------------------- */
157 atf_tp_run(const atf_tp_t
*tp
, const atf_list_t
*ids
, int fd
,
158 const atf_fs_path_t
*workdir
, size_t *failcount
)
161 atf_list_citer_t iter
;
164 err
= atf_io_write_fmt(fd
, "Content-Type: application/X-atf-tcs; "
165 "version=\"1\"\n\n");
166 if (atf_is_error(err
))
168 err
= atf_io_write_fmt(fd
, "tcs-count: %d\n", atf_list_size(ids
));
169 if (atf_is_error(err
))
172 *failcount
= count
= 0;
173 atf_list_for_each_c(iter
, ids
) {
174 const char *ident
= atf_list_citer_data(iter
);
179 err
= atf_io_write_fmt(fd
, "tc-start: %s\n", ident
);
180 if (atf_is_error(err
))
183 tc
= find_tc(tp
, ident
);
186 err
= atf_tc_run(tc
, &tcr
, STDOUT_FILENO
, STDERR_FILENO
, workdir
);
187 if (atf_is_error(err
))
191 if (count
< atf_list_size(ids
)) {
192 fprintf(stdout
, "__atf_tc_separator__\n");
193 fprintf(stderr
, "__atf_tc_separator__\n");
198 state
= atf_tcr_get_state(&tcr
);
199 if (state
== atf_tcr_passed_state
) {
200 err
= atf_io_write_fmt(fd
, "tc-end: %s, passed\n", ident
);
201 } else if (state
== atf_tcr_failed_state
) {
202 const atf_dynstr_t
*reason
= atf_tcr_get_reason(&tcr
);
203 err
= atf_io_write_fmt(fd
, "tc-end: %s, failed, %s\n", ident
,
204 atf_dynstr_cstring(reason
));
206 } else if (state
== atf_tcr_skipped_state
) {
207 const atf_dynstr_t
*reason
= atf_tcr_get_reason(&tcr
);
208 err
= atf_io_write_fmt(fd
, "tc-end: %s, skipped, %s\n", ident
,
209 atf_dynstr_cstring(reason
));
213 if (atf_is_error(err
))