xref: /openbsd-src/regress/sys/kern/signal/sigio/main.c (revision 6bcfccda660a0ea1c51395cf0b89694d927c87dd)
1*6bcfccdaSmpi /*	$OpenBSD: main.c,v 1.1 2020/09/16 14:02:23 mpi Exp $	*/
2*6bcfccdaSmpi 
3*6bcfccdaSmpi /*
4*6bcfccdaSmpi  * Copyright (c) 2018 Visa Hankala
5*6bcfccdaSmpi  *
6*6bcfccdaSmpi  * Permission to use, copy, modify, and distribute this software for any
7*6bcfccdaSmpi  * purpose with or without fee is hereby granted, provided that the above
8*6bcfccdaSmpi  * copyright notice and this permission notice appear in all copies.
9*6bcfccdaSmpi  *
10*6bcfccdaSmpi  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*6bcfccdaSmpi  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*6bcfccdaSmpi  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*6bcfccdaSmpi  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*6bcfccdaSmpi  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15*6bcfccdaSmpi  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16*6bcfccdaSmpi  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*6bcfccdaSmpi  */
18*6bcfccdaSmpi 
19*6bcfccdaSmpi #include <err.h>
20*6bcfccdaSmpi #include <signal.h>
21*6bcfccdaSmpi #include <stdio.h>
22*6bcfccdaSmpi #include <stdlib.h>
23*6bcfccdaSmpi #include <string.h>
24*6bcfccdaSmpi #include <unistd.h>
25*6bcfccdaSmpi 
26*6bcfccdaSmpi #include "common.h"
27*6bcfccdaSmpi 
28*6bcfccdaSmpi static struct {
29*6bcfccdaSmpi 	const char	*t_name;
30*6bcfccdaSmpi 	int		(*t_func)(void);
31*6bcfccdaSmpi } tests[] = {
32*6bcfccdaSmpi 	{ "pipe_badpgid",	test_pipe_badpgid },
33*6bcfccdaSmpi 	{ "pipe_badsession",	test_pipe_badsession },
34*6bcfccdaSmpi 	{ "pipe_cansigio",	test_pipe_cansigio },
35*6bcfccdaSmpi 	{ "pipe_getown",	test_pipe_getown },
36*6bcfccdaSmpi 	{ "pipe_read",		test_pipe_read },
37*6bcfccdaSmpi 	{ "pipe_write",		test_pipe_write },
38*6bcfccdaSmpi 	{ "socket_badpgid",	test_socket_badpgid },
39*6bcfccdaSmpi 	{ "socket_badsession",	test_socket_badsession },
40*6bcfccdaSmpi 	{ "socket_cansigio",	test_socket_cansigio },
41*6bcfccdaSmpi 	{ "socket_getown",	test_socket_getown },
42*6bcfccdaSmpi 	{ "socket_inherit",	test_socket_inherit },
43*6bcfccdaSmpi 	{ "socket_read",	test_socket_read },
44*6bcfccdaSmpi 	{ "socket_write",	test_socket_write },
45*6bcfccdaSmpi 	{ NULL,			NULL }
46*6bcfccdaSmpi };
47*6bcfccdaSmpi 
48*6bcfccdaSmpi int
main(int argc,char * argv[])49*6bcfccdaSmpi main(int argc, char *argv[])
50*6bcfccdaSmpi {
51*6bcfccdaSmpi 	const char *t_name;
52*6bcfccdaSmpi 	int (*t_func)(void) = NULL;
53*6bcfccdaSmpi 	int i;
54*6bcfccdaSmpi 
55*6bcfccdaSmpi 	if (argc < 2) {
56*6bcfccdaSmpi 		fprintf(stderr, "usage: %s testname\n", getprogname());
57*6bcfccdaSmpi 		exit(1);
58*6bcfccdaSmpi 	}
59*6bcfccdaSmpi 	t_name = argv[1];
60*6bcfccdaSmpi 
61*6bcfccdaSmpi 	for (i = 0; tests[i].t_name != NULL; i++) {
62*6bcfccdaSmpi 		if (strcmp(tests[i].t_name, t_name) == 0) {
63*6bcfccdaSmpi 			t_func = tests[i].t_func;
64*6bcfccdaSmpi 			break;
65*6bcfccdaSmpi 		}
66*6bcfccdaSmpi 	}
67*6bcfccdaSmpi 	if (t_func == NULL)
68*6bcfccdaSmpi 		errx(1, "unknown test: %s", t_name);
69*6bcfccdaSmpi 
70*6bcfccdaSmpi 	test_init();
71*6bcfccdaSmpi 
72*6bcfccdaSmpi 	return t_func();
73*6bcfccdaSmpi }
74