From 981a9e2c22c33b5fef1dd29e21ca9c4d9770f07b Mon Sep 17 00:00:00 2001 From: David Schleef Date: Thu, 30 Nov 2000 22:57:04 +0000 Subject: [PATCH] testing additions --- testing/Makefile | 2 +- testing/README | 22 ++ testing/cmd_1.c | 9 +- testing/cmd_2.c | 139 ++++++++++ testing/cmd_3.c | 177 +++++++++++++ testing/comedi_test.h | 2 + testing/insn_read_time.c | 64 +++++ testing/main.c | 64 +++-- testing/results/DAQCard-ai-16xe-50 | 393 +++++++++++++++++++++++++++++ testing/select.c | 144 +++++++++++ 10 files changed, 997 insertions(+), 19 deletions(-) create mode 100644 testing/README create mode 100644 testing/cmd_2.c create mode 100644 testing/cmd_3.c create mode 100644 testing/insn_read_time.c create mode 100644 testing/results/DAQCard-ai-16xe-50 create mode 100644 testing/select.c diff --git a/testing/Makefile b/testing/Makefile index 46c6654..bcd2d75 100644 --- a/testing/Makefile +++ b/testing/Makefile @@ -7,7 +7,7 @@ LDFLAGS=-L../lib/ -lcomedi TARG=comedi_test OBJS=main.o mode0_read.o insn_read.o info.o cmd_1.o insn_read_time.o \ - cmd_2.o mmap.o + cmd_2.o mmap.o select.o cmd_3.o all: $(TARG) diff --git a/testing/README b/testing/README new file mode 100644 index 0000000..00f146c --- /dev/null +++ b/testing/README @@ -0,0 +1,22 @@ + +The results directory contains last-known testing results that have +been contributed by users. If your board is listed there, +please compare it the output of comedi_test and if it differs +significantly, send me a copy and/or diff. I'll either update +the file, or it indicates that there is a bug. If your board +is not listed here, send me a copy of the output so it can +be included. + +comedi_test tends to create a lot of output. The important +information has lines beginning with either I:, W:, or E:, +indicating information, warning, or error, respectively. +You can grep for this information using the regexp '^.:'. +Errors are usually problems that need to be fixed, but are +not necessarily significant bugs. Warnings need to be +audited by ds to know whether or not they are significant, +since comedi_test isn't very smart about some checks. (That's +why they're warnings and not errors.) + + + + diff --git a/testing/cmd_1.c b/testing/cmd_1.c index 1542d2a..df7cdc7 100644 --- a/testing/cmd_1.c +++ b/testing/cmd_1.c @@ -65,7 +65,7 @@ int test_cmd_probe_fast_1chan(void) return 0; } -#define BUFSZ 1000 +#define BUFSZ 2000 int test_cmd_read_fast_1chan(void) { @@ -83,7 +83,7 @@ int test_cmd_read_fast_1chan(void) cmd.chanlist = chanlist; cmd.scan_end_arg = 1; - cmd.stop_arg = 10000; + cmd.stop_arg = 100000; cmd.chanlist_len = 1; chanlist[0] = CR_PACK(0,0,0); @@ -103,7 +103,8 @@ int test_cmd_read_fast_1chan(void) go = 0; }else{ total += ret; - printf("read %d %d\n",ret,total); + if(verbose) + printf("read %d %d\n",ret,total); } } @@ -200,12 +201,14 @@ int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd) ret=comedi_command_test(it,cmd); if(ret==3){ + printf("ret==3\n"); /* good */ ret=comedi_command_test(it,cmd); } if(ret==4 || ret==0){ return 0; } + printf("W: comedi_command_test() returned %d\n",ret); return -1; } diff --git a/testing/cmd_2.c b/testing/cmd_2.c new file mode 100644 index 0000000..da50870 --- /dev/null +++ b/testing/cmd_2.c @@ -0,0 +1,139 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "comedi_test.h" + +static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd); +static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd); +static int get_chunks_per_length(int length); + +#define BUFSZ 10000 + +int test_cmd_fifo_depth_check(void) +{ + int len; + + for(len=64;len<65536;len<<=1){ + printf("%d, %d\n",len,get_chunks_per_length(len)); + } + + return 0; +} + +static int get_chunks_per_length(int length) +{ + comedi_cmd cmd; + char buf[BUFSZ]; + unsigned int chanlist[1]; + int go; + int total=0; + int ret; + int chunks=0; + + if(comedi_get_cmd_fast_1chan(device,subdevice,&cmd)<0){ + printf(" not supported\n"); + return 0; + } + + cmd.chanlist = chanlist; + cmd.scan_end_arg = 1; + cmd.stop_arg = length; + cmd.chanlist_len = 1; + chanlist[0] = CR_PACK(0,0,0); + + comedi_command(device,&cmd); + + go=1; + while(go){ + ret = read(comedi_fileno(device),buf,BUFSZ); + if(ret<0){ + if(errno==EAGAIN){ + usleep(10000); + }else{ + go = 0; + perror("read"); + } + }else if(ret==0){ + go = 0; + }else{ + total += ret; + chunks++; + } + } + + return chunks; +} + +static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd) +{ + memset(cmd,0,sizeof(*cmd)); + + cmd->subdev = s; + + cmd->flags = 0; + + 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; + + return comedi_command_test(it,cmd); +} + + +static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd) +{ + int ret; + + ret = comedi_get_cmd_src_mask(it,s,cmd); + if(ret<0)return ret; + + cmd->chanlist_len = 1; + + cmd->scan_end_src = TRIG_COUNT; + cmd->scan_end_arg = 1; + + if(cmd->convert_src&TRIG_TIMER){ + if(cmd->scan_begin_src&TRIG_FOLLOW){ + cmd->convert_src = TRIG_TIMER; + cmd->scan_begin_src = TRIG_FOLLOW; + }else{ + cmd->convert_src = TRIG_TIMER; + cmd->scan_begin_src = TRIG_TIMER; + } + }else{ + printf("can't do timed?!?\n"); + return -1; + } + if(cmd->stop_src&TRIG_COUNT){ + cmd->stop_src=TRIG_COUNT; + cmd->stop_arg=2; + }else if(cmd->stop_src&TRIG_NONE){ + cmd->stop_src=TRIG_NONE; + cmd->stop_arg=0; + }else{ + printf("can't find a good stop_src\n"); + return -1; + } + + ret=comedi_command_test(it,cmd); + if(ret==3){ + /* good */ + ret=comedi_command_test(it,cmd); + } + if(ret==4 || ret==0){ + return 0; + } + return -1; +} + diff --git a/testing/cmd_3.c b/testing/cmd_3.c new file mode 100644 index 0000000..fbab887 --- /dev/null +++ b/testing/cmd_3.c @@ -0,0 +1,177 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "comedi_test.h" + +static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd); +static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd); +static int do_continuous(int multiplier); + +#define BUFSZ 10000 + +int test_cmd_continuous(void) +{ + int mult; + + /* as if doing _one_ infinite loop wasn't slow enough, + * we loop through with higher and higher multipliers, + * in case the test fails because of latency problems */ + + for(mult=1;mult<1024;mult*=2){ + do_continuous(mult); + } + + return 0; +} + +static int do_continuous(int multiplier) +{ + comedi_cmd cmd; + char buf[BUFSZ]; + unsigned int chanlist[1]; + int go; + int total=0; + int ret; + int chunks=0; + unsigned long total_secs = 0; + struct timeval tv,start_tv; + + if(comedi_get_cmd_fast_1chan(device,subdevice,&cmd)<0){ + printf(" not supported\n"); + return 0; + } + + cmd.chanlist = chanlist; + cmd.scan_end_arg = 1; + cmd.stop_src = TRIG_NONE; + cmd.stop_arg = 0; + cmd.chanlist_len = 1; + chanlist[0] = CR_PACK(0,0,0); + + // slow down a bit + cmd.scan_begin_arg *= multiplier; + printf("multiplier=%d, scan_begin_arg=%d\n", + multiplier, + cmd.scan_begin_arg); + + ret=comedi_command(device,&cmd); + if(ret<0){ + perror("comedi_command"); + }else{ + printf("ret==%d\n",ret); + } + + gettimeofday(&start_tv,NULL); + + go=1; + while(go){ + ret = read(comedi_fileno(device),buf,BUFSZ); + if(ret<0){ + if(errno==EAGAIN){ + usleep(10000); + }else{ + go = 0; + perror("read"); + } + }else if(ret==0){ + go = 0; + }else{ + total += ret; + chunks++; + + gettimeofday(&tv,NULL); + tv.tv_sec-=start_tv.tv_sec; + tv.tv_usec-=start_tv.tv_usec; + if(tv.tv_usec<0){ + tv.tv_usec+=1000000; + tv.tv_sec--; + } + if(tv.tv_sec>total_secs){ + double t; + + t=tv.tv_sec+1e-6*tv.tv_usec; + printf("%0.3f %d (%g) %d (%g)\n", + t, + chunks,chunks/t, + total,total/t); + total_secs++; + } + } + } + + return 0; +} + +static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd) +{ + memset(cmd,0,sizeof(*cmd)); + + cmd->subdev = s; + + cmd->flags = 0; + + 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; + + return comedi_command_test(it,cmd); +} + + +static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd) +{ + int ret; + + ret = comedi_get_cmd_src_mask(it,s,cmd); + if(ret<0)return ret; + + cmd->chanlist_len = 1; + + cmd->scan_end_src = TRIG_COUNT; + cmd->scan_end_arg = 1; + + if(cmd->convert_src&TRIG_TIMER){ + if(cmd->scan_begin_src&TRIG_FOLLOW){ + cmd->convert_src = TRIG_TIMER; + cmd->scan_begin_src = TRIG_FOLLOW; + }else{ + cmd->convert_src = TRIG_TIMER; + cmd->scan_begin_src = TRIG_TIMER; + } + }else{ + printf("can't do timed?!?\n"); + return -1; + } + if(cmd->stop_src&TRIG_COUNT){ + cmd->stop_src=TRIG_COUNT; + cmd->stop_arg=2; + }else if(cmd->stop_src&TRIG_NONE){ + cmd->stop_src=TRIG_NONE; + cmd->stop_arg=0; + }else{ + printf("can't find a good stop_src\n"); + return -1; + } + + ret=comedi_command_test(it,cmd); + if(ret==3){ + /* good */ + ret=comedi_command_test(it,cmd); + } + if(ret==4 || ret==0){ + return 0; + } + return -1; +} + diff --git a/testing/comedi_test.h b/testing/comedi_test.h index 2732062..4a37512 100644 --- a/testing/comedi_test.h +++ b/testing/comedi_test.h @@ -7,5 +7,7 @@ extern comedi_t *device; extern int subdevice; +extern int verbose; + #endif diff --git a/testing/insn_read_time.c b/testing/insn_read_time.c new file mode 100644 index 0000000..3b6c0b1 --- /dev/null +++ b/testing/insn_read_time.c @@ -0,0 +1,64 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "comedi_test.h" + + +int test_insn_read_time(void) +{ + comedi_insn insn[3]; + comedi_insnlist il; + struct timeval t1,t2; + lsampl_t data; + int save_errno; + int ret; + + printf("rev 1\n"); + + memset(&il,0,sizeof(il)); + memset(insn,0,sizeof(insn)); + + il.n_insns = 3; + il.insns = insn; + + insn[0].insn = INSN_GTOD; + insn[0].n=2; + insn[0].data = (void *)&t1; + + insn[1].subdev = subdevice; + insn[1].insn = INSN_READ; + insn[1].n = 1; + insn[1].chanspec = CR_PACK(0,0,0); + insn[1].data = &data; + + insn[2].insn = INSN_GTOD; + insn[2].n=2; + insn[2].data = (void *)&t2; + + ret = comedi_do_insnlist(device,&il); + 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)); + } + if(ret<2){ + printf("W: comedi_do_insn: returned %d (expected 3)\n",ret); + } + + printf("read time: %ld us\n", + (t2.tv_sec-t1.tv_sec)*1000000+(t2.tv_usec-t1.tv_usec)); + + + return 0; +} + diff --git a/testing/main.c b/testing/main.c index e8e42e3..c095fe9 100644 --- a/testing/main.c +++ b/testing/main.c @@ -32,36 +32,58 @@ int test_cmd_probe_fast_1chan(void); int test_cmd_read_fast_1chan(void); int test_cmd_fifo_depth_check(void); int test_mmap(void); +int test_read_select(void); +int test_cmd_continuous(void); + +#define TEST_NEVER 0 +#define TEST_STD 1 struct test_struct{ char *name; int (*do_test)(void); + int flags; }; struct test_struct tests[]={ - { "info", test_info }, - { "mode0_read", test_mode0_read }, - { "insn_read", test_insn_read }, - { "insn_read_time", test_insn_read_time }, - { "cmd_probe_src_mask", test_cmd_probe_src_mask }, - { "cmd_probe_fast_1chan", test_cmd_probe_fast_1chan }, - { "cmd_read_fast_1chan", test_cmd_read_fast_1chan }, - { "cmd_fifo_depth_check", test_cmd_fifo_depth_check }, - { "mmap", test_mmap }, + { "info", test_info, TEST_STD }, + { "mode0_read", test_mode0_read, TEST_STD }, + { "insn_read", test_insn_read, TEST_STD }, + { "insn_read_time", test_insn_read_time, TEST_STD }, + { "cmd_probe_src_mask", test_cmd_probe_src_mask, TEST_STD }, + { "cmd_probe_fast_1chan", test_cmd_probe_fast_1chan, TEST_STD }, + { "cmd_read_fast_1chan", test_cmd_read_fast_1chan, TEST_STD }, + { "cmd_fifo_depth_check", test_cmd_fifo_depth_check, TEST_STD }, + { "mmap", test_mmap, TEST_STD }, + { "read_select", test_read_select, TEST_STD }, + { "cmd_continuous", test_cmd_continuous, TEST_NEVER }, }; static int n_tests = sizeof(tests)/sizeof(tests[0]); +int only_subdevice; +int verbose; +char *only_test; + int main(int argc, char *argv[]) { int c; int i; while (1) { - c = getopt(argc, argv, "f"); + c = getopt(argc, argv, "f:s:t:v"); if (c == -1) break; switch (c) { case 'f': - filename = argv[optind]; + filename = optarg; + break; + case 's': + only_subdevice = 1; + sscanf(optarg,"%d",&subdevice); + break; + case 't': + only_test = optarg; + break; + case 'v': + verbose = 1; break; default: printf("bad option\n"); @@ -74,13 +96,25 @@ int main(int argc, char *argv[]) printf("E: comedi_open(\"%s\"): %s\n",filename,strerror(errno)); } - for(subdevice=0;subdevice +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "comedi_test.h" + +static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd); +static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd); + +#define BUFSZ 10000 + +int test_read_select(void) +{ + comedi_cmd cmd; + char buf[BUFSZ]; + unsigned int chanlist[1]; + int go; + int total=0; + int ret; + int chunks=0; + int length=100000; + fd_set rdset; + struct timeval timeout; + + if(comedi_get_cmd_fast_1chan(device,subdevice,&cmd)<0){ + printf(" not supported\n"); + return 0; + } + + cmd.chanlist = chanlist; + cmd.scan_end_arg = 1; + cmd.stop_arg = length; + cmd.chanlist_len = 1; + chanlist[0] = CR_PACK(0,0,0); + + //fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK); + + comedi_command(device,&cmd); + + go=1; + while(go){ + FD_ZERO(&rdset); + FD_SET(comedi_fileno(device),&rdset); + timeout.tv_sec = 0; + timeout.tv_usec = 10000; + ret = select(comedi_fileno(device)+1,&rdset,NULL,NULL,&timeout); + if(ret<0){ + perror("select"); + }else if(ret==0){ + if(verbose)printf("timeout\n"); + }else{ + ret = read(comedi_fileno(device),buf,BUFSZ); + if(verbose)printf("read==%d\n",ret); + if(ret<0){ + if(errno==EAGAIN){ + printf("E: got EAGAIN!\n"); + }else{ + go = 0; + perror("read"); + } + }else if(ret==0){ + go = 0; + }else{ + total += ret; + chunks++; + } + } + } + + return 0; +} + +static int comedi_get_cmd_src_mask(comedi_t *it,unsigned int s,comedi_cmd *cmd) +{ + memset(cmd,0,sizeof(*cmd)); + + cmd->subdev = s; + + cmd->flags = 0; + + 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; + + return comedi_command_test(it,cmd); +} + + +static int comedi_get_cmd_fast_1chan(comedi_t *it,unsigned int s,comedi_cmd *cmd) +{ + int ret; + + ret = comedi_get_cmd_src_mask(it,s,cmd); + if(ret<0)return ret; + + cmd->chanlist_len = 1; + + cmd->scan_end_src = TRIG_COUNT; + cmd->scan_end_arg = 1; + + if(cmd->convert_src&TRIG_TIMER){ + if(cmd->scan_begin_src&TRIG_FOLLOW){ + cmd->convert_src = TRIG_TIMER; + cmd->scan_begin_src = TRIG_FOLLOW; + }else{ + cmd->convert_src = TRIG_TIMER; + cmd->scan_begin_src = TRIG_TIMER; + } + }else{ + printf("can't do timed?!?\n"); + return -1; + } + if(cmd->stop_src&TRIG_COUNT){ + cmd->stop_src=TRIG_COUNT; + cmd->stop_arg=2; + }else if(cmd->stop_src&TRIG_NONE){ + cmd->stop_src=TRIG_NONE; + cmd->stop_arg=0; + }else{ + printf("can't find a good stop_src\n"); + return -1; + } + + ret=comedi_command_test(it,cmd); + if(ret==3){ + /* good */ + ret=comedi_command_test(it,cmd); + } + if(ret==4 || ret==0){ + return 0; + } + return -1; +} + -- 2.26.2