xref: /openbsd/regress/lib/libradius/main.c (revision 73471bf0)
1 #include "incs.h"
2 
3 #define TEST_MAX 100
4 
5 struct test_entry {
6 	testfunc func;
7 	const char *name;
8 } entries[TEST_MAX];
9 
10 int ntests = 0;
11 
12 int test_entry_cmp(const void *a, const void *b)
13 {
14 	return strcmp(
15 		((struct test_entry *)a)->name,
16 		((struct test_entry *)b)->name);
17 }
18 
19 int main(void)
20 {
21 	srandom_deterministic(time(NULL));
22 
23 	qsort(entries, ntests, sizeof(struct test_entry), test_entry_cmp);
24 
25 	for (int i = 0; i < ntests; i++) {
26 		fprintf(stderr, "running test %s\n", entries[i].name);
27 		entries[i].func();
28 	}
29 
30 	fprintf(stderr, "tests are successfully completed.\n");
31 	return 0;
32 }
33 
34 void check_failed(const char *expr, const char *file, int line)
35 {
36 	fprintf(stderr, "CHECK FAILED: %s at file %s line %d\n", expr, file, line);
37 	exit(1);
38 }
39 
40 void add_test(testfunc fn, const char *name)
41 {
42 	entries[ntests].func = fn;
43 	entries[ntests].name = name;
44 	ntests++;
45 }
46