2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008 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.
35 #include "atf-c/error.h"
39 #include "detail/fs.h"
40 #include "detail/map.h"
41 #include "detail/sanity.h"
48 /* ---------------------------------------------------------------------
49 * Auxiliary functions.
50 * --------------------------------------------------------------------- */
54 find_tc(const atf_tp_t
*tp
, const char *ident
)
57 atf_list_citer_t iter
;
60 atf_list_for_each_c(iter
, &tp
->pimpl
->m_tcs
) {
62 tc2
= atf_list_citer_data(iter
);
63 if (strcmp(atf_tc_get_ident(tc2
), ident
) == 0) {
71 /* ---------------------------------------------------------------------
73 * --------------------------------------------------------------------- */
76 * Constructors/destructors.
80 atf_tp_init(atf_tp_t
*tp
, const char *const *config
)
86 tp
->pimpl
= malloc(sizeof(struct atf_tp_impl
));
87 if (tp
->pimpl
== NULL
)
88 return atf_no_memory_error();
90 err
= atf_list_init(&tp
->pimpl
->m_tcs
);
91 if (atf_is_error(err
))
94 err
= atf_map_init_charpp(&tp
->pimpl
->m_config
, config
);
95 if (atf_is_error(err
)) {
96 atf_list_fini(&tp
->pimpl
->m_tcs
);
100 INV(!atf_is_error(err
));
106 atf_tp_fini(atf_tp_t
*tp
)
108 atf_list_iter_t iter
;
110 atf_map_fini(&tp
->pimpl
->m_config
);
112 atf_list_for_each(iter
, &tp
->pimpl
->m_tcs
) {
113 atf_tc_t
*tc
= atf_list_iter_data(iter
);
116 atf_list_fini(&tp
->pimpl
->m_tcs
);
126 atf_tp_get_config(const atf_tp_t
*tp
)
128 return atf_map_to_charpp(&tp
->pimpl
->m_config
);
132 atf_tp_has_tc(const atf_tp_t
*tp
, const char *id
)
134 const atf_tc_t
*tc
= find_tc(tp
, id
);
139 atf_tp_get_tc(const atf_tp_t
*tp
, const char *id
)
141 const atf_tc_t
*tc
= find_tc(tp
, id
);
146 const atf_tc_t
*const *
147 atf_tp_get_tcs(const atf_tp_t
*tp
)
149 const atf_tc_t
**array
;
150 atf_list_citer_t iter
;
153 array
= malloc(sizeof(atf_tc_t
*) *
154 (atf_list_size(&tp
->pimpl
->m_tcs
) + 1));
159 atf_list_for_each_c(iter
, &tp
->pimpl
->m_tcs
) {
160 array
[i
] = atf_list_citer_data(iter
);
161 if (array
[i
] == NULL
) {
180 atf_tp_add_tc(atf_tp_t
*tp
, atf_tc_t
*tc
)
184 PRE(find_tc(tp
, atf_tc_get_ident(tc
)) == NULL
);
186 err
= atf_list_append(&tp
->pimpl
->m_tcs
, tc
, false);
188 POST(find_tc(tp
, atf_tc_get_ident(tc
)) != NULL
);
193 /* ---------------------------------------------------------------------
195 * --------------------------------------------------------------------- */
198 atf_tp_run(const atf_tp_t
*tp
, const char *tcname
, const char *resfile
)
202 tc
= find_tc(tp
, tcname
);
205 return atf_tc_run(tc
, resfile
);
209 atf_tp_cleanup(const atf_tp_t
*tp
, const char *tcname
)
213 tc
= find_tc(tp
, tcname
);
216 return atf_tc_cleanup(tc
);