1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
14 */
15
16 /*
17 * Common handling for test programs.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <pthread.h>
26 #include <ctype.h>
27 #include <unistd.h>
28 #include <sys/param.h>
29 #include "test_common.h"
30
31 static int debug = 0;
32 static int force = 0;
33 static pthread_mutex_t lk;
154 }
155 (void) fflush(stdout);
156 (void) pthread_mutex_unlock(&lk);
157 free(t->name);
158 if (t->tids) {
159 free(t->tids);
160 }
161 free(t);
162 }
163
164 void
165 test_summary(void)
166 {
167 if (passes == tests) {
168 (void) printf("TEST SUMMARY: %d / %d (ok)\n", passes, tests);
169 } else {
170 (void) printf("TEST SUMMARY: %d / %d (%d failing)\n",
171 passes, tests, tests - passes);
172 }
173 }
174 void
175 test_debugf(test_t t, const char *format, ...)
176 {
177 va_list args;
178
179 if (!debug)
180 return;
181
182 (void) pthread_mutex_lock(&lk);
183 if (t) {
184 (void) printf("TEST DEBUG %s: ", t->name);
185 } else {
186 (void) printf("TEST DEBUG: ");
187 }
188 va_start(args, format);
189 (void) vprintf(format, args);
190 va_end(args);
191 (void) printf("\n");
192 (void) fflush(stdout);
193 (void) pthread_mutex_unlock(&lk);
262 int
263 test_load_config(test_t t, const char *fname, ...)
264 {
265 va_list va;
266 const char *keyws[MAXCB];
267 test_cfg_func_t callbs[MAXCB];
268 char *fields[MAXFIELD];
269 int nfields;
270
271 FILE *cfg;
272 char line[1024];
273 char buf[1024];
274 int done;
275 char *ptr;
276 char *tok;
277 char *err;
278 int lineno;
279 int rv;
280 int found;
281 char path[MAXPATHLEN];
282
283 va_start(va, fname);
284 for (int i = 0; i < MAXCB; i++) {
285 keyws[i] = (const char *)va_arg(va, const char *);
286 if (keyws[i] == NULL)
287 break;
288 callbs[i] = (test_cfg_func_t)va_arg(va, test_cfg_func_t);
289 }
290 va_end(va);
291
292 found = 0;
293
294 if (access(fname, F_OK) == 0) {
295 found++;
296 }
297 if (!found && fname[0] != '/') {
298 char *stf = getenv("STF_SUITE");
299 if (stf == NULL) {
300 stf = "../..";
301 }
302 (void) snprintf(path, sizeof (path), "%s/cfg/%s", stf, fname);
303 if (access(path, F_OK) == 0) {
304 fname = path;
305 found++;
306 } else {
307 (void) snprintf(path, sizeof (path), "cfg/%s", fname);
308 if (access(path, F_OK) == 0) {
309 fname = path;
310 found++;
|
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2015 Garrett D'Amore <garrett@damore.org>
14 */
15
16 /*
17 * Common handling for test programs.
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <stdarg.h>
23 #include <string.h>
24 #include <errno.h>
25 #include <pthread.h>
26 #include <ctype.h>
27 #include <unistd.h>
28 #include <sys/param.h>
29 #include "test_common.h"
30
31 static int debug = 0;
32 static int force = 0;
33 static pthread_mutex_t lk;
154 }
155 (void) fflush(stdout);
156 (void) pthread_mutex_unlock(&lk);
157 free(t->name);
158 if (t->tids) {
159 free(t->tids);
160 }
161 free(t);
162 }
163
164 void
165 test_summary(void)
166 {
167 if (passes == tests) {
168 (void) printf("TEST SUMMARY: %d / %d (ok)\n", passes, tests);
169 } else {
170 (void) printf("TEST SUMMARY: %d / %d (%d failing)\n",
171 passes, tests, tests - passes);
172 }
173 }
174
175 void
176 test_debugf(test_t t, const char *format, ...)
177 {
178 va_list args;
179
180 if (!debug)
181 return;
182
183 (void) pthread_mutex_lock(&lk);
184 if (t) {
185 (void) printf("TEST DEBUG %s: ", t->name);
186 } else {
187 (void) printf("TEST DEBUG: ");
188 }
189 va_start(args, format);
190 (void) vprintf(format, args);
191 va_end(args);
192 (void) printf("\n");
193 (void) fflush(stdout);
194 (void) pthread_mutex_unlock(&lk);
263 int
264 test_load_config(test_t t, const char *fname, ...)
265 {
266 va_list va;
267 const char *keyws[MAXCB];
268 test_cfg_func_t callbs[MAXCB];
269 char *fields[MAXFIELD];
270 int nfields;
271
272 FILE *cfg;
273 char line[1024];
274 char buf[1024];
275 int done;
276 char *ptr;
277 char *tok;
278 char *err;
279 int lineno;
280 int rv;
281 int found;
282 char path[MAXPATHLEN];
283 int i;
284
285 va_start(va, fname);
286 for (i = 0; i < MAXCB; i++) {
287 keyws[i] = (const char *)va_arg(va, const char *);
288 if (keyws[i] == NULL)
289 break;
290 callbs[i] = (test_cfg_func_t)va_arg(va, test_cfg_func_t);
291 }
292 va_end(va);
293 if (i == MAXCB) {
294 test_debugf(t, "too many arguments to function >= %d", MAXCB);
295 }
296
297 found = 0;
298
299 if (access(fname, F_OK) == 0) {
300 found++;
301 }
302 if (!found && fname[0] != '/') {
303 char *stf = getenv("STF_SUITE");
304 if (stf == NULL) {
305 stf = "../..";
306 }
307 (void) snprintf(path, sizeof (path), "%s/cfg/%s", stf, fname);
308 if (access(path, F_OK) == 0) {
309 fname = path;
310 found++;
311 } else {
312 (void) snprintf(path, sizeof (path), "cfg/%s", fname);
313 if (access(path, F_OK) == 0) {
314 fname = path;
315 found++;
|