1 /* $NetBSD: tp.c,v 1.3 2014/12/10 04:38:03 christos Exp $ */
4 * Automated Testing Framework (atf)
6 * Copyright (c) 2008 The NetBSD Foundation, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "atf-c/error.h"
41 #include "detail/fs.h"
42 #include "detail/map.h"
43 #include "detail/sanity.h"
50 /* ---------------------------------------------------------------------
51 * Auxiliary functions.
52 * --------------------------------------------------------------------- */
56 find_tc(const atf_tp_t
*tp
, const char *ident
)
59 atf_list_citer_t iter
;
62 atf_list_for_each_c(iter
, &tp
->pimpl
->m_tcs
) {
64 tc2
= atf_list_citer_data(iter
);
65 if (strcmp(atf_tc_get_ident(tc2
), ident
) == 0) {
73 /* ---------------------------------------------------------------------
75 * --------------------------------------------------------------------- */
78 * Constructors/destructors.
82 atf_tp_init(atf_tp_t
*tp
, const char *const *config
)
88 tp
->pimpl
= malloc(sizeof(struct atf_tp_impl
));
89 if (tp
->pimpl
== NULL
)
90 return atf_no_memory_error();
92 err
= atf_list_init(&tp
->pimpl
->m_tcs
);
93 if (atf_is_error(err
))
96 err
= atf_map_init_charpp(&tp
->pimpl
->m_config
, config
);
97 if (atf_is_error(err
)) {
98 atf_list_fini(&tp
->pimpl
->m_tcs
);
102 INV(!atf_is_error(err
));
108 atf_tp_fini(atf_tp_t
*tp
)
110 atf_list_iter_t iter
;
112 atf_map_fini(&tp
->pimpl
->m_config
);
114 atf_list_for_each(iter
, &tp
->pimpl
->m_tcs
) {
115 atf_tc_t
*tc
= atf_list_iter_data(iter
);
118 atf_list_fini(&tp
->pimpl
->m_tcs
);
128 atf_tp_get_config(const atf_tp_t
*tp
)
130 return atf_map_to_charpp(&tp
->pimpl
->m_config
);
134 atf_tp_has_tc(const atf_tp_t
*tp
, const char *id
)
136 const atf_tc_t
*tc
= find_tc(tp
, id
);
141 atf_tp_get_tc(const atf_tp_t
*tp
, const char *id
)
143 const atf_tc_t
*tc
= find_tc(tp
, id
);
148 const atf_tc_t
*const *
149 atf_tp_get_tcs(const atf_tp_t
*tp
)
151 const atf_tc_t
**array
;
152 atf_list_citer_t iter
;
155 array
= malloc(sizeof(atf_tc_t
*) *
156 (atf_list_size(&tp
->pimpl
->m_tcs
) + 1));
161 atf_list_for_each_c(iter
, &tp
->pimpl
->m_tcs
) {
162 array
[i
] = atf_list_citer_data(iter
);
163 if (array
[i
] == NULL
) {
182 atf_tp_add_tc(atf_tp_t
*tp
, atf_tc_t
*tc
)
186 PRE(find_tc(tp
, atf_tc_get_ident(tc
)) == NULL
);
188 err
= atf_list_append(&tp
->pimpl
->m_tcs
, tc
, false);
190 POST(find_tc(tp
, atf_tc_get_ident(tc
)) != NULL
);
195 /* ---------------------------------------------------------------------
197 * --------------------------------------------------------------------- */
200 atf_tp_run(const atf_tp_t
*tp
, const char *tcname
, const char *resfile
)
204 tc
= find_tc(tp
, tcname
);
207 return atf_tc_run(tc
, resfile
);
211 atf_tp_cleanup(const atf_tp_t
*tp
, const char *tcname
)
215 tc
= find_tc(tp
, tcname
);
218 return atf_tc_cleanup(tc
);