added output command test
authorDavid Schleef <ds@schleef.org>
Mon, 18 Mar 2002 21:48:14 +0000 (21:48 +0000)
committerDavid Schleef <ds@schleef.org>
Mon, 18 Mar 2002 21:48:14 +0000 (21:48 +0000)
testing/cmd_1.c
testing/main.c
testing/mmap.c

index 404905ce497d694161d0a05ee9d0d7009f1cf364..de40842cd0f5ced1061d9a539493ec7ea961c821 100644 (file)
@@ -152,6 +152,90 @@ int test_cmd_read_fast_1chan(void)
        return 0;
 }
 
+int test_cmd_write_fast_1chan(void)
+{
+       comedi_cmd cmd;
+       char buf[BUFSZ];
+       unsigned int chanlist[1];
+       int go;
+       int total=0;
+       int ret;
+       unsigned int flags = comedi_get_subdevice_flags(device,subdevice);
+
+       if(!(flags&SDF_CMD) || !(flags&SDF_WRITEABLE)){
+               printf("not applicable\n");
+               return 0;
+       }
+
+       if(comedi_get_cmd_generic_timed(device,subdevice,&cmd,1)<0){
+               printf("  not supported\n");
+               return 0;
+       }
+
+       if(realtime)cmd.flags |= TRIG_RT;
+       cmd.chanlist = chanlist;
+       cmd.scan_end_arg = 1;
+       cmd.stop_arg = 1000000;
+       cmd.chanlist_len = 1;
+       chanlist[0] = CR_PACK(0,0,0);
+
+       memset(buf,0,BUFSZ);
+
+       ret = comedi_command(device,&cmd);
+       if(ret<0){
+               perror("comedi_command");
+       }
+
+       go = 1;
+       while(go){
+               ret = write(comedi_fileno(device), buf, BUFSZ);
+               if(ret<0){
+                       perror("write");
+                       return 0;
+               }
+               if(ret<BUFSZ){
+                       go = 0;
+                       break;
+               }
+
+               total += ret;
+               if(verbose)printf("write %d %d\n",ret,total);
+       }
+       
+       {
+               comedi_insn insn;
+               memset(&insn, 0, sizeof(comedi_insn));
+               insn.insn = INSN_INTTRIG;
+               insn.subdev = subdevice;
+               ret = comedi_do_insn(device, &insn);
+               if(ret<0){
+                       perror("comedi_inttrig");
+                       return 0;
+               }
+               if(verbose)printf("inttrig\n");
+       }
+
+       go=1;
+       while(go){
+               ret = write(comedi_fileno(device),buf,BUFSZ);
+               if(ret<0){
+                       if(errno==EAGAIN){
+                               usleep(10000);
+                       }else{
+                               go = 0;
+                               perror("write");
+                       }
+               }else if(ret==0){
+                       go = 0;
+               }else{
+                       total += ret;
+                       if(verbose)printf("write %d %d\n",ret,total);
+               }
+       }
+
+       return 0;
+}
+
 int test_cmd_logic_bug(void)
 {
        comedi_cmd cmd;
index b28a460cf0bc1c6da36464df8af3f586e8ead8b7..d6f394537c00085d742f802def014448d9986d94 100644 (file)
@@ -31,6 +31,7 @@ int test_cmd_no_cmd(void);
 int test_cmd_probe_src_mask(void);
 int test_cmd_probe_fast_1chan(void);
 int test_cmd_read_fast_1chan(void);
+int test_cmd_write_fast_1chan(void);
 int test_cmd_logic_bug(void);
 int test_cmd_fifo_depth_check(void);
 int test_cmd_start_inttrig(void);
@@ -56,6 +57,7 @@ struct test_struct tests[]={
        { "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_write_fast_1chan", test_cmd_write_fast_1chan, TEST_STD },
        { "cmd_logic_bug", test_cmd_logic_bug, TEST_STD },
        { "cmd_fifo_depth_check", test_cmd_fifo_depth_check, TEST_STD },
        { "cmd_start_inttrig", test_cmd_start_inttrig, TEST_STD },
index 3cb66378b5b4aa7902aee6b3606fd5dfea1ae03f..8f68c32285d7e66752722e4c67b0fefc81b068dd 100644 (file)
@@ -63,6 +63,7 @@ int test_mmap(void)
        void *b, *adr;
        sampl_t *map;
        unsigned int flags;
+       int i;
 
        flags = comedi_get_subdevice_flags(device,subdevice);
 
@@ -125,11 +126,19 @@ int test_mmap(void)
                        if(verbose) printf("read %d %d\n",ret,total);
                }
        }
-       if(memcmp(buf,map,total)){
-               printf("E: mmap compare failed\n");
-       }else{
-               printf("compare ok\n");
+
+       go = 1;
+       for(i=0;i<total;i++){
+               if(buf[i]!=((char *)map)[i]){
+                       printf("E: mmap compare failed\n");
+                       printf("offset %d (read=%02x mmap=%02x)\n",i,
+                               buf[i], ((char *)map)[i]);
+                       go = 0;
+                       break;
+               }
        }
+       if(go) printf("compare ok\n");
+
        munmap(map,MAPLEN);
 
        /* test if area is really unmapped */