added tests and created main
[comedilib.git] / testing / main.c
1 /*
2  */
3
4 #include <stdio.h>
5 #include <comedilib.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <sys/ioctl.h>
9 #include <errno.h>
10 #include <getopt.h>
11 #include <ctype.h>
12 #include <malloc.h>
13
14 #include "comedi_test.h"
15
16 char *filename="/dev/comedi0";
17 int verbose_flag;
18 comedi_t *device;
19
20 int subdevice;
21 int channel;
22 int aref;
23 int range;
24
25 int test_info(void);
26 int test_mode0_read(void);
27 int test_insn_read(void);
28
29 struct test_struct{
30         char *name;
31         int (*do_test)(void);
32 };
33 struct test_struct tests[]={
34         { "info", test_info },
35         { "mode0_read", test_mode0_read },
36         { "insn_read", test_insn_read },
37 };
38 static int n_tests = sizeof(tests)/sizeof(tests[0]);
39
40 int main(int argc, char *argv[])
41 {
42         int c;
43         int i;
44
45         while (1) {
46                 c = getopt(argc, argv, "f");
47                 if (c == -1)
48                         break;
49                 switch (c) {
50                 case 'f':
51                         filename = argv[optind];
52                         break;
53                 default:
54                         printf("bad option\n");
55                         exit(1);
56                 }
57         }
58
59         device = comedi_open(filename);
60
61         for(subdevice=0;subdevice<comedi_get_n_subdevices(device);subdevice++){
62                 printf("I:\n");
63                 printf("I: subdevice %d\n",subdevice);
64                 for(i=0;i<n_tests;i++){
65                         printf("I: testing %s...\n",tests[i].name);
66                         tests[i].do_test();
67                 }
68         }
69
70         return 0;
71 }
72
73
74