patch from Ian Abbott <abbotti@mev.co.uk>:
authorFrank Mori Hess <fmhess@speakeasy.net>
Sun, 27 Feb 2005 22:45:14 +0000 (22:45 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Sun, 27 Feb 2005 22:45:14 +0000 (22:45 +0000)
I was running "comedi_test -v" on my new analog output driver and
noticed that it was getting stuck in a loop during the
"cmd_write_fast_1_chan" test.

It turned out that the test had written more data to the buffer than was
required to complete the acquisition (it was using cmd->stop_src =
TRIG_COUNT) and then got stuck in a loop waiting for the buffer to empty.

The attached patch stops the test_cmd_write_fast_1chan function writing
more data than is required to complete the acquisition.

testing/cmd_1.c

index b2b7d2dc587f24a79d1696edb12b2991bd8d9718..e9d337aacffa0d9dde539d12ef58df21841e6bfe 100644 (file)
@@ -163,6 +163,7 @@ int test_cmd_write_fast_1chan(void)
        unsigned int flags = comedi_get_subdevice_flags(device,subdevice);
        static const int num_samples = 100000;
        int num_bytes;
+       int wc;
        
        if((flags & SDF_LSAMPL))
        {
@@ -197,14 +198,17 @@ int test_cmd_write_fast_1chan(void)
 
        go = 1;
        while(go){
-               ret = write(comedi_fileno(device), buf, BUFSZ);
+               wc = num_bytes-total;
+               if(wc>BUFSZ){
+                       wc = BUFSZ;
+               }
+               ret = write(comedi_fileno(device), buf, wc);
                if(ret<0){
                        perror("write");
                        return 0;
                }
-               if(ret<BUFSZ){
+               if(ret<wc){
                        go = 0;
-                       break;
                }
 
                total += ret;
@@ -219,9 +223,13 @@ int test_cmd_write_fast_1chan(void)
        }
        if(verbose)printf("inttrig\n");
 
-       go=1;
+       go=(total<num_bytes);
        while(go){
-               ret = write(comedi_fileno(device),buf,BUFSZ);
+               wc = num_bytes-total;
+               if(wc>BUFSZ){
+                       wc = BUFSZ;
+               }
+               ret = write(comedi_fileno(device),buf,wc);
                if(ret<0){
                        if(errno==EAGAIN){
                                usleep(10000);