raw: Add skeleton test suite for swift raw.
[swifty.git] / src / raw / test / test.c
1 /*
2  * Test swift. Imports functions from test_sw_* files and runs tests.
3  */
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8
9 #include "debug.h"
10 #include "util.h"
11
12 #include "test_sw.h"
13
14 static void (*test_fun_array[])(void) = {
15         NULL,
16         dummy_1_eq_1,
17         dummy_1_neq_0,
18         socket_dummy,
19         bind_dummy,
20         getsockname_dummy,
21         sendto_dummy,
22         recvfrom_dummy,
23         sendmsg_dummy,
24         recvmsg_dummy,
25         shutdown_dummy,
26         close_dummy,
27 };
28
29 static void usage(const char *argv0)
30 {
31         fprintf(stderr, "Usage: %s [test_no]\n\n", argv0);
32         exit(EXIT_FAILURE);
33 }
34
35 /*
36  * In case of no arguments call all functions defined in test_fun_array.
37  */
38
39 int main(int argc, char **argv)
40 {
41         int test_idx;
42
43         /* No arguments: call all test functions. */
44         if (argc == 1) {
45                 int i;
46                 for (i = 1; i < sizeof(test_fun_array)/sizeof(test_fun_array[0]); i++)
47                         test_fun_array[i]();
48                 return 0;
49         }
50
51         if (argc != 2)
52                 usage(argv[0]);
53
54         test_idx = atoi(argv[1]);
55
56         if (test_idx < 1 || test_idx >= sizeof(test_fun_array)/sizeof(test_fun_array[0])) {
57                 fprintf(stderr, "Error: test index %d is out of bounds\n", test_idx);
58                 exit(EXIT_FAILURE);
59         }
60
61         test_fun_array[test_idx]();
62
63         return 0;
64 }