From: David Schleef Date: Tue, 10 Oct 2000 00:52:10 +0000 (+0000) Subject: added tests and created main X-Git-Tag: r0_7_12~13 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=809aaa48b9d800bcf09c4c526c46c6b41d0d412f;p=comedilib.git added tests and created main --- diff --git a/testing/Makefile b/testing/Makefile index 2c04b65..ba2cb11 100644 --- a/testing/Makefile +++ b/testing/Makefile @@ -6,7 +6,7 @@ LDFLAGS=-L../lib/ -lcomedi TARG=comedi_test -OBJS=main.o mode1.o +OBJS=main.o mode0_read.o insn_read.o info.o all: $(TARG) diff --git a/testing/comedi_test.h b/testing/comedi_test.h new file mode 100644 index 0000000..2732062 --- /dev/null +++ b/testing/comedi_test.h @@ -0,0 +1,11 @@ + +#ifndef _COMEDI_TEST_H_ +#define _COMEDI_TEST_H_ + +extern char *filename; +extern comedi_t *device; + +extern int subdevice; + +#endif + diff --git a/testing/info.c b/testing/info.c new file mode 100644 index 0000000..d863f5c --- /dev/null +++ b/testing/info.c @@ -0,0 +1,79 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "comedi_test.h" + + +static char *subdevice_types[]={ + "unused", + "analog input", + "analog output", + "digital input", + "digital output", + "digital I/O", + "counter", + "timer", + "memory", + "calibration", + "processor" +}; + + +int test_info(void) +{ + int j; + int type; + int chan,n_chans; + int n_ranges; + comedi_range *rng; + + printf("rev 1\n"); + + type = comedi_get_subdevice_type(device,subdevice); + printf("I: subdevice type: %d (%s)\n",type,subdevice_types[type]); + if(type==COMEDI_SUBD_UNUSED) + return 0; + n_chans=comedi_get_n_channels(device,subdevice); + printf(" number of channels: %d\n",n_chans); + if(!comedi_maxdata_is_chan_specific(device,subdevice)){ + printf(" max data value: %d\n",comedi_get_maxdata(device,subdevice,0)); + }else{ + printf(" max data value: (channel specific)\n"); + for(chan=0;chanmin,rng->max); + } + printf("\n"); + }else{ + for(chan=0;chanmin,rng->max); + } + printf("\n"); + } + } + + return 0; +} + diff --git a/testing/inpn.c b/testing/inpn.c deleted file mode 100644 index 4268121..0000000 --- a/testing/inpn.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - This demo opens /dev/comedi0 and looks for an analog input - subdevice. If it finds one, it measures one sample on each - channel for each input range. The value NaN indicates that - the measurement was out of range. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern char *filename; - -comedi_t *device; - - -int main(int argc, char *argv[]) -{ - int n_subdevs; - int n_chans,chan; - int n_ranges; - int range; - int rangetype; - int maxdata; - lsampl_t data; - double voltage; - - parse_options(argc,argv); - - device=comedi_open(filename); - if(!device){ - comedi_perror(filename); - exit(0); - } - - subdevice=comedi_find_subdevice_by_type(device,COMEDI_SUBD_AI,0); - if(subdevice<0){ - printf("no analog input subdevice found\n"); - exit(0); - } - - n_chans=comedi_get_n_channels(device,subdevice); - for(chan=0;chan +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "comedi_test.h" + + +int test_insn_read(void) +{ + comedi_insn it; + lsampl_t data; + int save_errno; + int ret; + + printf("rev 1\n"); + + memset(&it,0,sizeof(it)); + it.subdev = subdevice; + it.insn = INSN_READ; + it.n = 1; + it.chanspec = CR_PACK(0,0,0); + it.data = &data; + + ret = comedi_do_insn(device,&it); + save_errno = errno; + + printf("comedi_do_insn: %d\n",ret); + if(ret<0){ + printf("W: comedi_do_insn: errno=%d %s\n",save_errno,strerror(save_errno)); + } + + return 0; +} + diff --git a/testing/main.c b/testing/main.c index e591eb2..59bf598 100644 --- a/testing/main.c +++ b/testing/main.c @@ -11,6 +11,7 @@ #include #include +#include "comedi_test.h" char *filename="/dev/comedi0"; int verbose_flag; @@ -21,54 +22,52 @@ int channel; int aref; int range; +int test_info(void); +int test_mode0_read(void); +int test_insn_read(void); -int parse_options(int argc, char *argv[]) +struct test_struct{ + char *name; + int (*do_test)(void); +}; +struct test_struct tests[]={ + { "info", test_info }, + { "mode0_read", test_mode0_read }, + { "insn_read", test_insn_read }, +}; +static int n_tests = sizeof(tests)/sizeof(tests[0]); + +int main(int argc, char *argv[]) { int c; - + int i; while (1) { - c = getopt(argc, argv, "acsrfvdgom"); + c = getopt(argc, argv, "f"); if (c == -1) break; switch (c) { case 'f': filename = argv[optind]; break; - case 's': - sscanf(argv[optind],"%d",&subdevice); - break; - case 'c': - sscanf(argv[optind],"%d",&channel); - break; - case 'a': - sscanf(argv[optind],"%d",&aref); - break; - case 'r': - sscanf(argv[optind],"%d",&range); - break; - case 'v': - verbose_flag = 1; - break; - case 'd': - aref=AREF_DIFF; - break; - case 'g': - aref=AREF_GROUND; - break; - case 'o': - aref=AREF_OTHER; - break; - case 'm': - aref=AREF_COMMON; - break; default: printf("bad option\n"); exit(1); } } - return argc; + device = comedi_open(filename); + + for(subdevice=0;subdevice +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "comedi_test.h" + + +int test_mode0_read(void) +{ + comedi_trig it; + lsampl_t data; + unsigned int chanspec; + int save_errno; + int ret; + + printf("rev 1\n"); + + memset(&it,0,sizeof(it)); + it.subdev = subdevice; + it.mode = 0; + it.n_chan = 1; + it.chanlist = &chanspec; + it.data = (sampl_t *)&data; + it.n = 1; + + chanspec = CR_PACK(0,0,0); + + ret = comedi_trigger(device,&it); + save_errno = errno; + + printf("comedi_trig_ioctl: %d\n",ret); + if(ret<0){ + printf("W: comedi_trig_ioctl: errno=%d %s\n",save_errno, + strerror(save_errno)); + } + + return 0; +} + diff --git a/testing/mode1.c b/testing/mode1.c deleted file mode 100644 index 6c7752c..0000000 --- a/testing/mode1.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - A little input demo for mode 1 - - Mode 1 uses a timer to acquire samples at regular intervals. - It scans through the channel list, and then repeats. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BUFSZ 1000 -#define N_CHANS 1000 - -extern int verbose_flag; -extern int subdevice; -extern int range; -extern int channel; -extern int aref; -extern char *filename; - -comedi_t *device; - -void parse_options(int argc,char *argv[]); - -sampl_t data[BUFSZ]; - -unsigned int chanlist[N_CHANS]; - -int ai_mode1_test(double freq,int n_chans,int n_scans); - -int main(int argc, char *argv[]) -{ - parse_options(argc,argv); - - device=comedi_open(filename); - if(!device){ - comedi_perror(filename); - exit(0); - } - - subdevice=comedi_find_subdevice_by_type(device,COMEDI_SUBD_AI,0); - if(subdevice<0){ - printf("no analog input subdevice found\n"); - exit(0); - } - -while(1){ - printf("Testing mode 1:\n"); - - printf("10 hz, 1 chan\n"); - ai_mode1_test(10.0,1,10); - - printf("100 hz, 1 chan\n"); - ai_mode1_test(100.0,1,100); - - printf("1000 hz, 1 chan\n"); - ai_mode1_test(1000.0,1,1000); - - printf("10000 hz, 1 chan\n"); - ai_mode1_test(10000.0,1,10000); - - printf("100000 hz, 1 chan\n"); - ai_mode1_test(100000.0,1,100000); - - printf("100000 hz, 2 chan\n"); - ai_mode1_test(100000.0,2,50000); - - printf("100000 hz, 16 chans\n"); - ai_mode1_test(100000.0,16,100000/16); -} - - - return 0; -} - -int ai_mode1_test(double freq,int n_chans,int n_scans) -{ - comedi_trig it; - int err; - int n,i; - double actual_freq; - void *data_ptr; - int n_left; - int maxchan; - struct timeval start,stop; - int m; - - memset(&it,0,sizeof(it)); - it.subdev = subdevice; - it.mode = 1; - it.n_chan = n_chans; - it.chanlist = chanlist; - it.data = data; - it.n = n_scans; - - maxchan = comedi_get_n_channels(device,subdevice); - - /* pack the channel list */ - for(i=0;i0){ - m=n_left; - if(m>=BUFSZ)m=BUFSZ; - if((n=read(comedi_fileno(device),data_ptr,m))<0){ - perror("read"); - exit(1); - } - //printf("read %d\n",n); - n_left-=n; - //data_ptr+=n; - } - - gettimeofday(&stop,NULL); - - if(stop.tv_usec<=start.tv_usec){ - stop.tv_usec+=1000000; - stop.tv_sec--; - } - stop.tv_sec-=start.tv_sec; - stop.tv_usec-=start.tv_usec; - - printf("actual time elapsed: %d.%06d s.\n",(int)stop.tv_sec,(int)stop.tv_usec); - printf("expected time: %g\n",n_scans*n_chans/actual_freq); - - return 0; -} - diff --git a/testing/mode2.c b/testing/mode2.c deleted file mode 100644 index 45013e3..0000000 --- a/testing/mode2.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - A little input demo for mode 2 - - Mode 2 uses two different timers to convert samples. - The primary timer determines the time between scans, - and the secondary timer determines the time between - samples in a scan. - - The time between scans is in trigval; the time - between samples is selected by trigval1. Conversion - from seconds or Hz is done using the standard timer - routines. - - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#define N_SCANS 10 -#define N_CHANS 16 - -int subdevice = 0; -int chan=0; -int range = 0; -int aref = AREF_GROUND; -double freq = 1000; - -#define N_SAMPLES 1000 - -double data[N_SAMPLES]; - - -int main(int argc, char *argv[]) -{ - char *fn = NULL; - int i; - comedi_t *dev; - - fn = "/dev/comedi0"; - - dev = comedi_open(fn); - -#if 0 - for(i=0;i<10;i++){ - range=comedi_find_range(dev,subdevice,chan,0,-i,i); - printf("%d\n",range); - } -#endif - comedi_timed_1chan(dev,subdevice,chan,range,aref,freq,N_SAMPLES,data); - - for(i=0;i