added get_subdevice_flags()
[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 #include <string.h>
14
15 #include "comedi_test.h"
16
17 char *filename="/dev/comedi0";
18 int verbose_flag;
19 comedi_t *device;
20
21 int subdevice;
22 int channel;
23 int aref;
24 int range;
25
26 int test_info(void);
27 int test_mode0_read(void);
28 int test_insn_read(void);
29 int test_insn_read_time(void);
30 int test_cmd_probe_src_mask(void);
31 int test_cmd_probe_fast_1chan(void);
32 int test_cmd_read_fast_1chan(void);
33 int test_cmd_fifo_depth_check(void);
34 int test_mmap(void);
35 int test_read_select(void);
36 int test_cmd_continuous(void);
37 int test_bufconfig(void);
38
39 #define TEST_NEVER 0
40 #define TEST_STD 1
41
42 struct test_struct{
43         char *name;
44         int (*do_test)(void);
45         int flags;
46 };
47 struct test_struct tests[]={
48         { "info", test_info, TEST_STD },
49         { "mode0_read", test_mode0_read, TEST_STD },
50         { "insn_read", test_insn_read, TEST_STD },
51         { "insn_read_time", test_insn_read_time, TEST_STD },
52         { "cmd_probe_src_mask", test_cmd_probe_src_mask, TEST_STD },
53         { "cmd_probe_fast_1chan", test_cmd_probe_fast_1chan, TEST_STD },
54         { "cmd_read_fast_1chan", test_cmd_read_fast_1chan, TEST_STD },
55         { "cmd_fifo_depth_check", test_cmd_fifo_depth_check, TEST_STD },
56         { "mmap", test_mmap, TEST_STD },
57         { "read_select", test_read_select, TEST_STD },
58         { "cmd_continuous", test_cmd_continuous, TEST_NEVER },
59         { "bufconfig", test_bufconfig, TEST_STD },
60 };
61 static int n_tests = sizeof(tests)/sizeof(tests[0]);
62
63 int only_subdevice;
64 int verbose;
65 char *only_test;
66
67 int main(int argc, char *argv[])
68 {
69         int c;
70         int i;
71
72         while (1) {
73                 c = getopt(argc, argv, "f:s:t:v");
74                 if (c == -1)
75                         break;
76                 switch (c) {
77                 case 'f':
78                         filename = optarg;
79                         break;
80                 case 's':
81                         only_subdevice = 1;
82                         sscanf(optarg,"%d",&subdevice);
83                         break;
84                 case 't':
85                         only_test = optarg;
86                         break;
87                 case 'v':
88                         verbose = 1;
89                         break;
90                 default:
91                         printf("bad option\n");
92                         exit(1);
93                 }
94         }
95
96         device = comedi_open(filename);
97         if(!device){
98                 printf("E: comedi_open(\"%s\"): %s\n",filename,strerror(errno));
99         }
100
101         for(;subdevice<comedi_get_n_subdevices(device);subdevice++){
102                 printf("I:\n");
103                 printf("I: subdevice %d\n",subdevice);
104                 if(only_test){
105                         for(i=0;i<n_tests;i++){
106                                 if(!strcmp(tests[i].name,only_test)){
107                                         printf("I: testing %s...\n",tests[i].name);
108                                         tests[i].do_test();
109                                 }
110                         }
111                 }else{
112                         for(i=0;i<n_tests;i++){
113                                 if(tests[i].flags&TEST_STD){
114                                         printf("I: testing %s...\n",tests[i].name);
115                                         tests[i].do_test();
116                                 }
117                         }
118                 }
119                 if(only_subdevice)break;
120         }
121
122         return 0;
123 }
124
125
126