Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / unit / atf-src / atf-c / tp.c
blobee72034c1d730d56464410a3e72138c4ac675a96
1 /* $NetBSD: tp.c,v 1.3 2014/12/10 04:38:03 christos Exp $ */
3 /*
4 * Automated Testing Framework (atf)
6 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
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.
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <unistd.h>
37 #include "atf-c/error.h"
38 #include "atf-c/tc.h"
39 #include "atf-c/tp.h"
41 #include "detail/fs.h"
42 #include "detail/map.h"
43 #include "detail/sanity.h"
45 struct atf_tp_impl {
46 atf_list_t m_tcs;
47 atf_map_t m_config;
50 /* ---------------------------------------------------------------------
51 * Auxiliary functions.
52 * --------------------------------------------------------------------- */
54 static
55 const atf_tc_t *
56 find_tc(const atf_tp_t *tp, const char *ident)
58 const atf_tc_t *tc;
59 atf_list_citer_t iter;
61 tc = NULL;
62 atf_list_for_each_c(iter, &tp->pimpl->m_tcs) {
63 const atf_tc_t *tc2;
64 tc2 = atf_list_citer_data(iter);
65 if (strcmp(atf_tc_get_ident(tc2), ident) == 0) {
66 tc = tc2;
67 break;
70 return tc;
73 /* ---------------------------------------------------------------------
74 * The "atf_tp" type.
75 * --------------------------------------------------------------------- */
78 * Constructors/destructors.
81 atf_error_t
82 atf_tp_init(atf_tp_t *tp, const char *const *config)
84 atf_error_t err;
86 PRE(config != NULL);
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))
94 goto out;
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);
99 goto out;
102 INV(!atf_is_error(err));
103 out:
104 return err;
107 void
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);
116 atf_tc_fini(tc);
118 atf_list_fini(&tp->pimpl->m_tcs);
120 free(tp->pimpl);
124 * Getters.
127 char **
128 atf_tp_get_config(const atf_tp_t *tp)
130 return atf_map_to_charpp(&tp->pimpl->m_config);
133 bool
134 atf_tp_has_tc(const atf_tp_t *tp, const char *id)
136 const atf_tc_t *tc = find_tc(tp, id);
137 return tc != NULL;
140 const atf_tc_t *
141 atf_tp_get_tc(const atf_tp_t *tp, const char *id)
143 const atf_tc_t *tc = find_tc(tp, id);
144 PRE(tc != NULL);
145 return tc;
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;
153 size_t i;
155 array = malloc(sizeof(atf_tc_t *) *
156 (atf_list_size(&tp->pimpl->m_tcs) + 1));
157 if (array == NULL)
158 goto out;
160 i = 0;
161 atf_list_for_each_c(iter, &tp->pimpl->m_tcs) {
162 array[i] = atf_list_citer_data(iter);
163 if (array[i] == NULL) {
164 free(array);
165 array = NULL;
166 goto out;
169 i++;
171 array[i] = NULL;
173 out:
174 return array;
178 * Modifiers.
181 atf_error_t
182 atf_tp_add_tc(atf_tp_t *tp, atf_tc_t *tc)
184 atf_error_t err;
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);
192 return err;
195 /* ---------------------------------------------------------------------
196 * Free functions.
197 * --------------------------------------------------------------------- */
199 atf_error_t
200 atf_tp_run(const atf_tp_t *tp, const char *tcname, const char *resfile)
202 const atf_tc_t *tc;
204 tc = find_tc(tp, tcname);
205 PRE(tc != NULL);
207 return atf_tc_run(tc, resfile);
210 atf_error_t
211 atf_tp_cleanup(const atf_tp_t *tp, const char *tcname)
213 const atf_tc_t *tc;
215 tc = find_tc(tp, tcname);
216 PRE(tc != NULL);
218 return atf_tc_cleanup(tc);