1 /* Copyright (c) 2008 The NetBSD Foundation, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
33 #include "atf-c/detail/fs.h"
34 #include "atf-c/detail/map.h"
35 #include "atf-c/detail/sanity.h"
36 #include "atf-c/error.h"
44 /* ---------------------------------------------------------------------
45 * Auxiliary functions.
46 * --------------------------------------------------------------------- */
50 find_tc(const atf_tp_t *tp, const char *ident)
53 atf_list_citer_t iter;
56 atf_list_for_each_c(iter, &tp->pimpl->m_tcs) {
58 tc2 = atf_list_citer_data(iter);
59 if (strcmp(atf_tc_get_ident(tc2), ident) == 0) {
67 /* ---------------------------------------------------------------------
69 * --------------------------------------------------------------------- */
72 * Constructors/destructors.
76 atf_tp_init(atf_tp_t *tp, const char *const *config)
82 tp->pimpl = malloc(sizeof(struct atf_tp_impl));
83 if (tp->pimpl == NULL)
84 return atf_no_memory_error();
86 err = atf_list_init(&tp->pimpl->m_tcs);
87 if (atf_is_error(err))
90 err = atf_map_init_charpp(&tp->pimpl->m_config, config);
91 if (atf_is_error(err)) {
92 atf_list_fini(&tp->pimpl->m_tcs);
96 INV(!atf_is_error(err));
102 atf_tp_fini(atf_tp_t *tp)
104 atf_list_iter_t iter;
106 atf_map_fini(&tp->pimpl->m_config);
108 atf_list_for_each(iter, &tp->pimpl->m_tcs) {
109 atf_tc_t *tc = atf_list_iter_data(iter);
112 atf_list_fini(&tp->pimpl->m_tcs);
122 atf_tp_get_config(const atf_tp_t *tp)
124 return atf_map_to_charpp(&tp->pimpl->m_config);
128 atf_tp_has_tc(const atf_tp_t *tp, const char *id)
130 const atf_tc_t *tc = find_tc(tp, id);
135 atf_tp_get_tc(const atf_tp_t *tp, const char *id)
137 const atf_tc_t *tc = find_tc(tp, id);
142 const atf_tc_t *const *
143 atf_tp_get_tcs(const atf_tp_t *tp)
145 const atf_tc_t **array;
146 atf_list_citer_t iter;
149 array = malloc(sizeof(atf_tc_t *) *
150 (atf_list_size(&tp->pimpl->m_tcs) + 1));
155 atf_list_for_each_c(iter, &tp->pimpl->m_tcs) {
156 array[i] = atf_list_citer_data(iter);
157 if (array[i] == NULL) {
176 atf_tp_add_tc(atf_tp_t *tp, atf_tc_t *tc)
180 PRE(find_tc(tp, atf_tc_get_ident(tc)) == NULL);
182 err = atf_list_append(&tp->pimpl->m_tcs, tc, false);
184 POST(find_tc(tp, atf_tc_get_ident(tc)) != NULL);
189 /* ---------------------------------------------------------------------
191 * --------------------------------------------------------------------- */
194 atf_tp_run(const atf_tp_t *tp, const char *tcname, const char *resfile)
198 tc = find_tc(tp, tcname);
201 return atf_tc_run(tc, resfile);
205 atf_tp_cleanup(const atf_tp_t *tp, const char *tcname)
209 tc = find_tc(tp, tcname);
212 return atf_tc_cleanup(tc);