xref: /freebsd/tools/regression/p1003_1b/main.c (revision be8aff81c11e51d25e7a134298b6aa0300f4b7fc)
1 /* $FreeBSD$ */
2 
3 #include <sys/param.h>
4 
5 #include <stdio.h>
6 #include <string.h>
7 
8 int fifo(int argc, char *argv[]);
9 int memlock(int argc, char *argv[]);
10 int p26(int argc, char *argv[]);
11 int sched(int argc, char *argv[]);
12 int yield(int argc, char *argv[]);
13 
14 static struct {
15 	const char *t;
16 	int (*f)(int, char *[]);
17 	int works;
18 } tab[] = {
19 	{ "fifo", fifo, 1 },
20 	{ "memlock", memlock, 0 },
21 	{ "p26", p26, 1 },
22 	{ "sched", sched, 1 },
23 	{ "yield", yield, 1 },
24 };
25 
26 static int usage(int argc, char *argv[])
27 {
28 	int i;
29 	if (argc > 1)
30 		fprintf(stderr, "%s is unknown\n", argv[1]);
31 
32 	fprintf(stderr, "usage: %s [-a] or one of [", argv[0]);
33 	for (i = 0; i < (sizeof(tab) / sizeof(tab[0])); i++)
34 		fprintf(stderr, "%s%s", (i)? " | " : "", tab[i].t);
35 	fprintf(stderr, "]\n");
36 
37 	return -1;
38 }
39 
40 int main(int argc, char *argv[])
41 {
42 	int i;
43 
44 	if (argc == 2 && strcmp(argv[1], "-a") == 0) {
45 #if 1
46 		fprintf(stderr,
47 			"-a should but doesn't really work"
48 			" (my notes say \"because things detach\");\n"
49 			"meanwhile do these individual tests and look"
50 			" for a non-zero exit code:\n");
51 		for (i = 0; i < nitems(tab); i++)
52 			if (tab[i].works)
53 				fprintf(stderr, "p1003_1b %s\n", tab[i].t);
54 		return -1;
55 #else
56 		{
57 			int r;
58 			for (i = 0; i < nitems(tab); i++) {
59 				if (tab[i].works) {
60 					if ( (r =
61 					(*tab[i].f)(argc - 1, argv + 1)) ) {
62 						fprintf(stderr,
63 						"%s failed\n", tab[i].t);
64 						return r;
65 					}
66 				}
67 			}
68 			return 0;
69 		}
70 #endif
71 	}
72 
73 	if (argc > 1) {
74 		for (i = 0; i < nitems(tab); i++)
75 			if (strcmp(tab[i].t, argv[1]) == 0)
76 				return (*tab[i].f)(argc - 1, argv + 1);
77 	}
78 
79 	return usage(argc, argv);
80 }
81