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