File: check_cmdtest

package info (click to toggle)
comedi 0.7.76%2B20080817cvs-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,660 kB
  • ctags: 14,259
  • sloc: ansic: 104,304; sh: 1,417; makefile: 625; perl: 457
file content (388 lines) | stat: -rwxr-xr-x 8,775 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
#!/usr/bin/perl
# vi: set ts=4:

sub grab_function;
sub grab_def;
sub check_cmdtest_func;
sub echo_cmdtest_in;

@ARGV = ('-') unless @ARGV;

$ARGV=shift @ARGV;
if(!open(FILE,$ARGV)){
	warn "Can't open $ARGV: $!\n";
	exit 1;
}

#$func="parport_intr_cmdtest";

while(<FILE>) {
	if( m/s->do_cmdtest.*=/ ){
		$func = $_;
		$func =~ s/^.*do_cmdtest\s*=[\s\&]*(\w*);.*\n/\1/;
		#chomp;
		push @funcs, $func;
	}
}

if(!@funcs){
	print "no cmdtest function\n";
	exit 0;
}

foreach $func (@funcs) {
	print "function: $func\n";
	check_cmdtest_func($func);
}

sub grab_function
{
	my $funcname = @_[0];
	my $line="";
	my $state=0;
	my $ok=0;
	seek FILE,0,SEEK_SET;
	while(<FILE>) {
		if( $state==0 && m/$funcname/ ){
			$state=1;
			$line="";
		}
		if( $state==1 && m/;/ ){ $state=0; }
		if( $state==1 && m/\{/ ){
			#print COUT "static int cmd_test(comedi_device *dev,comedi_subdevice *s,comedi_cmd *cmd)\n";
			print COUT "$line\n";
			$state=2;
		}
		if( $state==1){ $line="$line $_"; }
		if( $state==2 ){
			print COUT;
			if( m/^}/ ){ $state=0; }
			$ok=1;
		}
	}
	if(!$ok){
		print "E: couldn't grab function $funcname\n";
	}
	print COUT "\n";
}

sub grab_def
{
	my $def = @_[0];
	my $ok=0;
	seek FILE,0,SEEK_SET;
	while(<FILE>) {
		if( m/#define\s*$def/ ){
			print COUT;
			$ok=1;
		}
	}
	if(!$ok){
		print "E: couldn't grab definition $def\n";
	}
	print COUT "\n";
}

sub check_cmdtest_func
{
	my $func = @_[0];
	my $output;

	open(COUT,"> cmdtest.c") || die("can't open cmdtest.c: $!");

#	open(CIN,"< cmdtest.in.c") || die("can't open cmdtest.in.c: $!");
#	while(<CIN>){print COUT;}
#	close CIN;
	echo_cmdtest_in();

	print COUT "#define $func cmd_test\n";

	# Dependencies.  It's easy to do it manually
	$func eq "dt2814_ai_cmdtest" && grab_def("DT2814_MAX_SPEED");
	$func eq "pci9118_ai_cmdtest" && grab_def("PCI9118_BIPOLAR_RANGES");
	$func eq "cb_pcidas_ai_cmdtest" && grab_def("TIMER_BASE");
	$func eq "das16m1_cmd_test" && grab_def("DAS16M1_XTAL");
	$func eq "das1800_ai_do_cmdtest" && grab_def("UNIPOLAR");
	$func eq "das1800_ai_do_cmdtest" && grab_def("TIMER_BASE");
	$func eq "das800_ai_do_cmdtest" && grab_def("N_CHAN_AI");
	$func eq "das800_ai_do_cmdtest" && grab_def("TIMER_BASE");
	$func eq "a2150_ai_cmdtest" && grab_def("CLOCK_MASK");
	$func eq "a2150_ai_cmdtest" && grab_def("CLOCK_SELECT_BITS");
	$func eq "a2150_ai_cmdtest" && grab_def("CLOCK_DIVISOR_BITS");
	$func eq "ni_ai_cmdtest" && grab_def("TIMER_BASE");
	$func eq "ni_ao_cmdtest" && grab_def("TIMER_BASE");
	$func eq "rtd_ai_cmdtest" && grab_def("RTD_MAX_SPEED");
	$func eq "rtd_ai_cmdtest" && grab_def("RTD_MIN_SPEED");
	$func eq "rtd_ai_cmdtest" && grab_def("RTD_CLOCK_BASE");
	$func eq "pci230_ai_cmdtest" && grab_function("PCI230_TIMEBASE_10MHZ");

	$func eq "pci9118_ai_cmdtest" && grab_function("check_channel_list");
	$func eq "pci171x_ai_cmdtest" && grab_function("check_channel_list");
	$func eq "pci230_ai_cmdtest" && grab_function("pci230_ns_to_timer");
	$func eq "cb_pcidda_ai_cmdtest" && grab_function("cb_pcidda_ns_to_timer");
	$func eq "timer_cmdtest" && grab_function("cmdtest_helper");
	$func eq "das1800_ai_do_cmdtest" && grab_function("burst_convert_arg");
	$func eq "dt2814_ai_cmdtest" && grab_function("dt2814_ns_to_timer");
	$func eq "dt282x_ai_cmdtest" && grab_function("dt282x_ns_to_timer");
	$func eq "dt282x_ao_cmdtest" && grab_function("dt282x_ns_to_timer");
	$func eq "a2150_ai_cmdtest" && grab_function("a2150_get_timing");
	$func eq "ni_ai_cmdtest" && grab_function("ni_ns_to_timer");
	$func eq "ni_ao_cmdtest" && grab_function("ni_ns_to_timer");
	$func eq "rtd_ai_cmdtest" && grab_function("rtd_ns_to_timer");
	$func eq "skel_ai_cmdtest" && grab_function("skel_ns_to_timer");

	grab_function($func);

	close COUT;

	$output = `gcc -o cmdtest cmdtest.c -Wall -Wstrict-prototypes -O2 -g 2>&1`;

	if ( "$output" ){
		print $output;
		print "E: $func: compilation failed!\n";
		return 1;
	}

	$output = `./cmdtest`;
	print "$output";
	return 0;
}


sub echo_cmdtest_in
{
	print COUT <<'EOF';
/* cmdtest.in.c */

#include <comedi.h>
#include <stdio.h>
#include <stdlib.h>

#define CMDTEST
#include "8253.h"

typedef struct comedi_device_struct comedi_device;
typedef struct comedi_subdevice_struct comedi_subdevice;
typedef struct comedi_async_struct comedi_async;
typedef struct comedi_driver_struct comedi_driver;
typedef struct comedi_lrange_struct comedi_lrange;


struct comedi_subdevice_struct{
	int type;
	int n_chan;
	int subdev_flags;
	int len_chanlist;		/* length of channel/gain list, if available */

	void		*private;

	comedi_async *async;

	void *lock;
	void *busy;
	unsigned int runflags;

	int io_bits;

	lsampl_t maxdata;		/* if maxdata==0, use list */
	lsampl_t *maxdata_list;		/* list is channel specific */

	unsigned int flags;
	unsigned int *flaglist;

	comedi_lrange *range_table;
	comedi_lrange **range_table_list;

	unsigned int *chanlist;		/* driver-owned chanlist (not used) */

	int (*insn_read)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
	int (*insn_write)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
	int (*insn_bits)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);
	int (*insn_config)(comedi_device *,comedi_subdevice *,comedi_insn *,lsampl_t *);

	int (*do_cmd)(comedi_device *,comedi_subdevice *);
	int (*do_cmdtest)(comedi_device *,comedi_subdevice *,comedi_cmd *);
	int (*poll)(comedi_device *,comedi_subdevice *);
	int (*cancel)(comedi_device *,comedi_subdevice *);

	int (*buf_change)(comedi_device *,comedi_subdevice *s);

	unsigned int state;
};

struct comedi_device_struct{
	int use_count;
	comedi_driver *driver;
	void *private;
	int minor;
	char *board_name;
	//int board;
	void *board_ptr;
	int attached;
	int rt;
	//spinlock_t spinlock;
	int in_request_module;

	int n_subdevices;
	comedi_subdevice *subdevices;
	int options[COMEDI_NDEVCONFOPTS];

	/* dumb */
	int iobase;
	int irq;

	comedi_subdevice *read_subdev;
	//wait_queue_head_t read_wait;

	comedi_subdevice *write_subdev;
	//wait_queue_head_t write_wait;

	//struct fasync_struct *async_queue;
};

struct priv_struct{
	int divisor1;
	int divisor2;
	unsigned int config_bits;
	unsigned int clockbase;
	unsigned int i8254_osc_base;
	int usemux;
};
struct priv_struct priv;
#define devpriv (&priv)

struct board_struct{
	unsigned int ai_ns_min;
	unsigned int n_aichanlist;
	unsigned int ai_speed;
	unsigned int size;
	unsigned int clock[4];
	unsigned int num_clocks;
	unsigned int n_aichan;
	unsigned int n_aichand;
};
struct board_struct __this_board;
#define this_board (&__this_board)
#define thisboard (&__this_board)
#define boardtype (__this_board)

#define printk printf
#define rt_printk printf
#define comedi_error(a,b) printf(b)

static int cmd_test(comedi_device *dev,comedi_subdevice *s, comedi_cmd *cmd);

comedi_device device,*dev;
comedi_subdevice subdevice,*s;

void check_null(void);
void check_mask(void);
void check_mask_2(void);
void check_timed(void);

comedi_cmd cmd_mask;

int main(int argc,char *argv[])
{
	dev=&device;
	s=&subdevice;

	check_null();
	check_mask();
	check_mask_2();
	check_timed();

	return 0;
}

void dump_cmd(comedi_cmd *cmd)
{
	printf("start_src:       %08x\n",cmd->start_src       );
	printf("scan_begin_src:  %08x\n",cmd->scan_begin_src  );
	printf("convert_src:     %08x\n",cmd->convert_src     );
	printf("scan_end_src:    %08x\n",cmd->scan_end_src    );
	printf("stop_src:        %08x\n",cmd->stop_src        );
}

void check_null(void)
{
	comedi_cmd cmd;
	int ret;

	memset(&cmd,0,sizeof(cmd));

	ret = cmd_test(dev,s,&cmd);
	if(ret!=1)printf("E: null returned %d\n",ret);
}

void check_mask(void)
{
	comedi_cmd cmd;
	int ret;

	memset(&cmd,0,sizeof(cmd));
	cmd.start_src=TRIG_ANY;
	cmd.scan_begin_src=TRIG_ANY;
	cmd.convert_src=TRIG_ANY;
	cmd.scan_end_src=TRIG_ANY;
	cmd.stop_src=TRIG_ANY;

	ret = cmd_test(dev,s,&cmd);
	if(ret!=1)printf("E: mask returned %d\n",ret);

	dump_cmd(&cmd);

	cmd_mask=cmd;
}

void check_mask_2(void)
{
	int ret;
	comedi_cmd cmd=cmd_mask;

	ret = cmd_test(dev,s,&cmd);
	if(ret<2)printf("E: mask_2 returned %d\n",ret);
}

void check_timed(void)
{
	int ret;
	int i;
	unsigned int freq = 10000;
	unsigned int n_scan = 10000;
	unsigned int n_chan = 4;
	unsigned int chanlist[4];
	comedi_cmd c = {
		start_src: TRIG_NOW,
		start_arg: 0,
		scan_begin_src: TRIG_TIMER,
		scan_begin_arg: 1e9/freq,
		convert_src: TRIG_TIMER,
		convert_arg: 1,
		scan_end_src: TRIG_COUNT,
		scan_end_arg: n_chan,
		stop_src: TRIG_COUNT,
		stop_arg: n_scan,
		chanlist: chanlist,
		chanlist_len: n_chan,
	};
	comedi_cmd *cmd = &c;

	for(i=0;i<n_chan;i++){
		chanlist[i]=CR_PACK(i,0,AREF_GROUND);
	}

	ret = cmd_test(dev,s,cmd);
	if(ret<3)printf("W: timed returned %d\n",ret);
	printf("timed returned %d\n",ret);

	dump_cmd(cmd);

}


/* begin autogenerated */

EOF
}