m4/as-linux.m4: don't use backported pcmcia_loop_tuple()
[comedi.git] / scripts / check_cmdtest
1 #!/usr/bin/perl
2 # vi: set ts=4:
3
4 sub grab_function;
5 sub grab_def;
6 sub check_cmdtest_func;
7 sub echo_cmdtest_in;
8
9 @ARGV = ('-') unless @ARGV;
10
11 $ARGV=shift @ARGV;
12 if(!open(FILE,$ARGV)){
13         warn "Can't open $ARGV: $!\n";
14         exit 1;
15 }
16
17 #$func="parport_intr_cmdtest";
18
19 while(<FILE>) {
20         if( m/s->do_cmdtest.*=/ ){
21                 $func = $_;
22                 $func =~ s/^.*do_cmdtest\s*=[\s\&]*(\w*);.*\n/\1/;
23                 #chomp;
24                 push @funcs, $func;
25         }
26 }
27
28 if(!@funcs){
29         print "no cmdtest function\n";
30         exit 0;
31 }
32
33 foreach $func (@funcs) {
34         print "function: $func\n";
35         check_cmdtest_func($func);
36 }
37
38 sub grab_function
39 {
40         my $funcname = @_[0];
41         my $line="";
42         my $state=0;
43         my $ok=0;
44         seek FILE,0,SEEK_SET;
45         while(<FILE>) {
46                 if( $state==0 && m/$funcname/ ){
47                         $state=1;
48                         $line="";
49                 }
50                 if( $state==1 && m/;/ ){ $state=0; }
51                 if( $state==1 && m/\{/ ){
52                         #print COUT "static int cmd_test(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd)\n";
53                         print COUT "$line\n";
54                         $state=2;
55                 }
56                 if( $state==1){ $line="$line $_"; }
57                 if( $state==2 ){
58                         print COUT;
59                         if( m/^}/ ){ $state=0; }
60                         $ok=1;
61                 }
62         }
63         if(!$ok){
64                 print "E: couldn't grab function $funcname\n";
65         }
66         print COUT "\n";
67 }
68
69 sub grab_def
70 {
71         my $def = @_[0];
72         my $ok=0;
73         seek FILE,0,SEEK_SET;
74         while(<FILE>) {
75                 if( m/#define\s*$def/ ){
76                         print COUT;
77                         $ok=1;
78                 }
79         }
80         if(!$ok){
81                 print "E: couldn't grab definition $def\n";
82         }
83         print COUT "\n";
84 }
85
86 sub check_cmdtest_func
87 {
88         my $func = @_[0];
89         my $output;
90
91         open(COUT,"> cmdtest.c") || die("can't open cmdtest.c: $!");
92
93 #       open(CIN,"< cmdtest.in.c") || die("can't open cmdtest.in.c: $!");
94 #       while(<CIN>){print COUT;}
95 #       close CIN;
96         echo_cmdtest_in();
97
98         print COUT "#define $func cmd_test\n";
99
100         # Dependencies.  It's easy to do it manually
101         $func eq "dt2814_ai_cmdtest" && grab_def("DT2814_MAX_SPEED");
102         $func eq "pci9118_ai_cmdtest" && grab_def("PCI9118_BIPOLAR_RANGES");
103         $func eq "cb_pcidas_ai_cmdtest" && grab_def("TIMER_BASE");
104         $func eq "das16m1_cmd_test" && grab_def("DAS16M1_XTAL");
105         $func eq "das1800_ai_do_cmdtest" && grab_def("UNIPOLAR");
106         $func eq "das1800_ai_do_cmdtest" && grab_def("TIMER_BASE");
107         $func eq "das800_ai_do_cmdtest" && grab_def("N_CHAN_AI");
108         $func eq "das800_ai_do_cmdtest" && grab_def("TIMER_BASE");
109         $func eq "a2150_ai_cmdtest" && grab_def("CLOCK_MASK");
110         $func eq "a2150_ai_cmdtest" && grab_def("CLOCK_SELECT_BITS");
111         $func eq "a2150_ai_cmdtest" && grab_def("CLOCK_DIVISOR_BITS");
112         $func eq "ni_ai_cmdtest" && grab_def("TIMER_BASE");
113         $func eq "ni_ao_cmdtest" && grab_def("TIMER_BASE");
114         $func eq "rtd_ai_cmdtest" && grab_def("RTD_MAX_SPEED");
115         $func eq "rtd_ai_cmdtest" && grab_def("RTD_MIN_SPEED");
116         $func eq "rtd_ai_cmdtest" && grab_def("RTD_CLOCK_BASE");
117         $func eq "pci230_ai_cmdtest" && grab_function("PCI230_TIMEBASE_10MHZ");
118
119         $func eq "pci9118_ai_cmdtest" && grab_function("check_channel_list");
120         $func eq "pci171x_ai_cmdtest" && grab_function("check_channel_list");
121         $func eq "pci230_ai_cmdtest" && grab_function("pci230_ns_to_timer");
122         $func eq "cb_pcidda_ai_cmdtest" && grab_function("cb_pcidda_ns_to_timer");
123         $func eq "timer_cmdtest" && grab_function("cmdtest_helper");
124         $func eq "das1800_ai_do_cmdtest" && grab_function("burst_convert_arg");
125         $func eq "dt2814_ai_cmdtest" && grab_function("dt2814_ns_to_timer");
126         $func eq "dt282x_ai_cmdtest" && grab_function("dt282x_ns_to_timer");
127         $func eq "dt282x_ao_cmdtest" && grab_function("dt282x_ns_to_timer");
128         $func eq "a2150_ai_cmdtest" && grab_function("a2150_get_timing");
129         $func eq "ni_ai_cmdtest" && grab_function("ni_ns_to_timer");
130         $func eq "ni_ao_cmdtest" && grab_function("ni_ns_to_timer");
131         $func eq "rtd_ai_cmdtest" && grab_function("rtd_ns_to_timer");
132         $func eq "skel_ai_cmdtest" && grab_function("skel_ns_to_timer");
133
134         grab_function($func);
135
136         close COUT;
137
138         $output = `gcc -o cmdtest cmdtest.c -Wall -Wstrict-prototypes -O2 -g 2>&1`;
139
140         if ( "$output" ){
141                 print $output;
142                 print "E: $func: compilation failed!\n";
143                 return 1;
144         }
145
146         $output = `./cmdtest`;
147         print "$output";
148         return 0;
149 }
150
151
152 sub echo_cmdtest_in
153 {
154         print COUT <<'EOF';
155 /* cmdtest.in.c */
156
157 #include <comedi.h>
158 #include <stdio.h>
159 #include <stdlib.h>
160
161 #define CMDTEST
162 #include "8253.h"
163
164 typedef struct comedi_device_struct comedi_device;
165 typedef struct comedi_subdevice_struct comedi_subdevice;
166 typedef struct comedi_async_struct comedi_async;
167 typedef struct comedi_driver_struct comedi_driver;
168 typedef struct comedi_lrange_struct comedi_lrange;
169
170
171 struct comedi_subdevice_struct{
172         int type;
173         int n_chan;
174         int subdev_flags;
175         int len_chanlist;               /* length of channel/gain list, if available */
176
177         void            *private;
178
179         comedi_async *async;
180
181         void *lock;
182         void *busy;
183         unsigned int runflags;
184
185         int io_bits;
186
187         lsampl_t maxdata;               /* if maxdata==0, use list */
188         lsampl_t *maxdata_list;         /* list is channel specific */
189
190         unsigned int flags;
191         unsigned int *flaglist;
192
193         comedi_lrange *range_table;
194         comedi_lrange **range_table_list;
195
196         unsigned int *chanlist;         /* driver-owned chanlist (not used) */
197
198         int (*insn_read)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
199         int (*insn_write)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
200         int (*insn_bits)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
201         int (*insn_config)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
202
203         int (*do_cmd)(comedi_device *,comedi_subdevice *);
204         int (*do_cmdtest)(comedi_device *,comedi_subdevice *,comedi_cmd *);
205         int (*poll)(comedi_device *,comedi_subdevice *);
206         int (*cancel)(comedi_device *,comedi_subdevice *);
207
208         int (*buf_change)(comedi_device *,comedi_subdevice *s);
209
210         unsigned int state;
211 };
212
213 struct comedi_device_struct{
214         int use_count;
215         comedi_driver *driver;
216         void *private;
217         int minor;
218         char *board_name;
219         //int board;
220         void *board_ptr;
221         int attached;
222         int rt;
223         //spinlock_t spinlock;
224         int in_request_module;
225
226         int n_subdevices;
227         comedi_subdevice *subdevices;
228         int options[COMEDI_NDEVCONFOPTS];
229
230         /* dumb */
231         int iobase;
232         int irq;
233
234         comedi_subdevice *read_subdev;
235         //wait_queue_head_t read_wait;
236
237         comedi_subdevice *write_subdev;
238         //wait_queue_head_t write_wait;
239
240         //struct fasync_struct *async_queue;
241 };
242
243 struct priv_struct{
244         int divisor1;
245         int divisor2;
246         unsigned int config_bits;
247         unsigned int clockbase;
248         unsigned int i8254_osc_base;
249         int usemux;
250 };
251 struct priv_struct priv;
252 #define devpriv (&priv)
253
254 struct board_struct{
255         unsigned int ai_ns_min;
256         unsigned int n_aichanlist;
257         unsigned int ai_speed;
258         unsigned int size;
259         unsigned int clock[4];
260         unsigned int num_clocks;
261         unsigned int n_aichan;
262         unsigned int n_aichand;
263 };
264 struct board_struct __this_board;
265 #define this_board (&__this_board)
266 #define thisboard (&__this_board)
267 #define boardtype (__this_board)
268
269 #define printk printf
270 #define rt_printk printf
271 #define comedi_error(a,b) printf(b)
272
273 static int cmd_test(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd);
274
275 comedi_device device,*dev;
276 comedi_subdevice subdevice,*s;
277
278 void check_null(void);
279 void check_mask(void);
280 void check_mask_2(void);
281 void check_timed(void);
282
283 comedi_cmd cmd_mask;
284
285 int main(int argc,char *argv[])
286 {
287         dev=&device;
288         s=&subdevice;
289
290         check_null();
291         check_mask();
292         check_mask_2();
293         check_timed();
294
295         return 0;
296 }
297
298 void dump_cmd(comedi_cmd *cmd)
299 {
300         printf("start_src:       %08x\n",cmd->start_src       );
301         printf("scan_begin_src:  %08x\n",cmd->scan_begin_src  );
302         printf("convert_src:     %08x\n",cmd->convert_src     );
303         printf("scan_end_src:    %08x\n",cmd->scan_end_src    );
304         printf("stop_src:        %08x\n",cmd->stop_src        );
305 }
306
307 void check_null(void)
308 {
309         comedi_cmd cmd;
310         int ret;
311
312         memset(&cmd,0,sizeof(cmd));
313
314         ret = cmd_test(dev,s,&cmd);
315         if(ret!=1)printf("E: null returned %d\n",ret);
316 }
317
318 void check_mask(void)
319 {
320         comedi_cmd cmd;
321         int ret;
322
323         memset(&cmd,0,sizeof(cmd));
324         cmd.start_src=TRIG_ANY;
325         cmd.scan_begin_src=TRIG_ANY;
326         cmd.convert_src=TRIG_ANY;
327         cmd.scan_end_src=TRIG_ANY;
328         cmd.stop_src=TRIG_ANY;
329
330         ret = cmd_test(dev,s,&cmd);
331         if(ret!=1)printf("E: mask returned %d\n",ret);
332
333         dump_cmd(&cmd);
334
335         cmd_mask=cmd;
336 }
337
338 void check_mask_2(void)
339 {
340         int ret;
341         comedi_cmd cmd=cmd_mask;
342
343         ret = cmd_test(dev,s,&cmd);
344         if(ret<2)printf("E: mask_2 returned %d\n",ret);
345 }
346
347 void check_timed(void)
348 {
349         int ret;
350         int i;
351         unsigned int freq = 10000;
352         unsigned int n_scan = 10000;
353         unsigned int n_chan = 4;
354         unsigned int chanlist[4];
355         comedi_cmd c = {
356                 start_src: TRIG_NOW,
357                 start_arg: 0,
358                 scan_begin_src: TRIG_TIMER,
359                 scan_begin_arg: 1e9/freq,
360                 convert_src: TRIG_TIMER,
361                 convert_arg: 1,
362                 scan_end_src: TRIG_COUNT,
363                 scan_end_arg: n_chan,
364                 stop_src: TRIG_COUNT,
365                 stop_arg: n_scan,
366                 chanlist: chanlist,
367                 chanlist_len: n_chan,
368         };
369         comedi_cmd *cmd = &c;
370
371         for(i=0;i<n_chan;i++){
372                 chanlist[i]=CR_PACK(i,0,AREF_GROUND);
373         }
374
375         ret = cmd_test(dev,s,cmd);
376         if(ret<3)printf("W: timed returned %d\n",ret);
377         printf("timed returned %d\n",ret);
378
379         dump_cmd(cmd);
380
381 }
382
383
384 /* begin autogenerated */
385
386 EOF
387 }
388