bugGNU Octave - Bugs: bug #57087, [instrument-control] tests fail on...

 
 

bug #57087: [instrument-control] tests fail on macOS for tcp/udp read/write

Submitter:  Andrew Janke <apjanke>
Submitted:  Sun 20 Oct 2019 12:00:55 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  lostbard
Originator Name:  Open/Closed:  * Closed
Release:  * 4.4.1 Operating System:  * Mac OS
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 25 Dec 2019 04:18:05 PM UTC, comment #10: 

Assuming fixed from previous commit, so closing report

John Donoghue <lostbard>
Group Member
Mon 28 Oct 2019 10:15:19 AM UTC, comment #9: 
John Donoghue <lostbard>
Group Member
Wed 23 Oct 2019 09:02:43 PM UTC, comment #8: 

Ohhh, I get it now. Will revise.

Andrew Janke <apjanke>
Wed 23 Oct 2019 08:52:59 PM UTC, comment #7: 

It needs to limit the value to 1 second  so that it loops each second rather than locking for the full timeout value.


John Donoghue <lostbard>
Group Member
Wed 23 Oct 2019 08:44:08 PM UTC, comment #6: 

Here's a patch that I think will work, but I haven't been able to test because I can't get instrument-control to build from a local working copy. (I'm not very good with Hg and the Octave Forge build system yet.)

https://savannah.gnu.org/bugs/download.php?file_id=47734

Andrew Janke <apjanke>
Wed 23 Oct 2019 08:09:10 PM UTC, comment #5: 

Makes sense looking back at the code, that that would be the issue.

Since the are psedo polling the port with select so that ctrl-c will work, the max value we will normally have is the 1 sec.

So changing  to simiar to that in comment #1 should work.

I'll work on that in the next day or so

John Donoghue <lostbard>
Group Member
Wed 23 Oct 2019 07:40:13 PM UTC, comment #4: 

Good test. I tweaked it a bit and attached an update.

In a Homebrewed Octave 5.1.0 on macOS 10.14.6:


octave:1> testselect
starting
select for 999,999 usecs ...
ok
select 1 second in secs ...
ok
select for 1,000,000 usecs ...
error: udp_read: Error while reading/select: 22 - Invalid argument
octave:1>


That's exactly what I'd expect to see if the tv_usec value was constrained to be less than 1,000,000 on this system.

I think what needs to happen for portability is that the instrument-control tcp_read and udp_read functions need to add logic to "carry over" tv_usec values > 999,999 into the whole-seconds tv_sec field.

Andrew Janke <apjanke>
Wed 23 Oct 2019 06:18:47 PM UTC, comment #3: 

A small test oct file taht maybe will tell something?

In linux i can compile it using mkoctfile selectest.cc


#include <iostream>
#include <string>
#include <unistd.h>
#include <errno.h>
#include <octave/oct.h>

DEFUN_DLD (selecttest, args, nargout,
        "-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} testselect (])\n \
Test function\n \
@end deftypefn")
{
  struct timeval tv;

  printf("starting\n");

  printf("select 1 second in usecs ...\n");

  tv.tv_sec = 0;
  tv.tv_usec = 1000 * 1000;

  if (::select(0, NULL, NULL, NULL, &tv) < 0)
    {
      error("udp_read: Error while reading/select: %d - %s\n", errno, strerror(errno));
    }
  else
    printf("ok\n");


  printf("select 1 second in secs ...\n");

  FD_ZERO (&readfds);

  tv.tv_sec = 1;
  tv.tv_usec = 0;

  if (::select(0, NULL, NULL, NULL, &tv) < 0)
    {
      error("udp_read: Error while reading/select: %d - %s\n", errno, strerror(errno));
    }
  else
    printf("ok\n");

  return octave_value();
}


John Donoghue <lostbard>
Group Member
Sun 20 Oct 2019 09:37:46 PM UTC, comment #2: 

Ah! Maybe macOS/BSD is more picky about proper formatting of `struct timeval` values than Windows or Linux, and wants tv_usec to be strictly between 0 and 999,999 (so it represents only fractional seconds), and you're supposed to "carry over" 1,000,000 or more usec into the tv_sec field as whole seconds. I'll fiddle around with that and see if I can get a behavior change.

Andrew Janke <apjanke>
Sun 20 Oct 2019 08:50:38 PM UTC, comment #1: 

It looks like its failing where ever it has to wait more than 1 second.

In the code of octave_udp::read:

There is a section:


else
{
  tv.tv_sec = 0;
  if (readtimeout > 1000)
    tv.tv_usec = 1000 * 1000;
  else
    tv.tv_usec = readtimeout * 1000;
}


Perhaps it should be:


else
{
  if (readtimeout >= 1000)
  {
    tv.tv_sec = 1;
    tv.tv_usec = 0;
  }
  else
  {
    tv.tv_usec = readtimeout * 1000;
    tv.tv_sec = 0;
  }
}







John Donoghue <lostbard>
Group Member
Sun 20 Oct 2019 12:00:55 PM UTC, original submission:  

On macOS 10.14.6, under Octave.app 4.4.1, the Octave Forge package instrument-control will install for me, but has test failures in tcp/udp read/write tests. It looks like the failures all happen when it's doing a tcp_read or tcp_write, and in all cases the error is an "invalid argument" error returned by select().


>> runtests2 -pkg instrument-control -log-file instrument-control_tests.txt
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/instrhwinfo.m  PASS      4/4
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/seriallist.m  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/tcpip.m  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/__instr_hwinfo__.cc-tst  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/__tcp_properties__.cc-tst  PASS      6/6
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/__udp_properties__.cc-tst  PASS      6/6
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/gpib.cc-tst  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/i2c.cc-tst  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/parallel.cc-tst  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/pp_close.cc-tst  PASS      3/3
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/pp_ctrl.cc-tst  PASS      2/2
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/pp_data.cc-tst  PASS      2/2
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/pp_datadir.cc-tst  PASS      2/2
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/pp_stat.cc-tst  PASS      2/2
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/resolvehost.cc-tst  PASS      7/7
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/serial.cc-tst  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/tcp.cc-tst  PASS      3/3
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/tcp_close.cc-tst  PASS      3/3
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/tcp_read.cc-tst  PASS      2/3
                                                                FAIL      1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/tcp_write.cc-tst  PASS      2/3
                                                                FAIL      1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp.cc-tst  PASS      4/4
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp_close.cc-tst  PASS      3/3
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp_read.cc-tst  PASS      3/4
                                                                FAIL      1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp_timeout.cc-tst  PASS      3/3
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp_write.cc-tst  PASS      4/5
                                                                FAIL      1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/usbtmc.cc-tst  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/vxi11.cc-tst  PASS      1/1
  /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/udp_demo.m  PASS      3/3

Summary:

  GNU Octave Version: 4.4.1 (hg id: 1f46d371968c + patches)
  Tests run on eilonwy.local (macOS) at 20-Oct-2019 04:39:38
  Test execution time: 00:00:09

  PASS                               73
  FAIL                                4

  Failed tests:
     /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/tcp_read.cc-tst
     /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/tcp_write.cc-tst
     /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp_read.cc-tst
     /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp_write.cc-tst


Test failure details:


>>>>> /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/tcp_read.cc-tst
***** test block 1: test
  is_test=1 is_xtest=0
Code:
 addr = resolvehost ('gnu.org', 'address');
 a = tcp (addr, 80);
 assert (! isnull (a));
 # server should be waiting for us to send request
 fail ("tcp_read (a, 10, 0, 0)", "Invalid call to tcp_read");

 [d,c] = tcp_read (a, 1, 0);
 assert (0, c);
 assert (isempty (d));

 tic;
 [d,c] = tcp_read (a, 1, 1000);
 t = toc;
 assert (c, 0);
 assert (isempty (d));
 assert (t, 1.0, 0.1)

 tcp_close (a);
--> success=0, msg=test failed: raised error: tcp_read: Error while reading/select: 22 - Invalid argument

[...]

>>>>> /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/tcp_write.cc-tst
[...]
***** test block 3: test
  is_test=1 is_xtest=0
Code:
 addr = resolvehost ('gnu.org', 'address');
 a = tcp (addr, 80);;
 # call HTTP HEAD
 req = "HEAD / HTTP/1.1\r\n\r\n";
 assert (length (req), tcp_write (a, req));
 [d, c] = tcp_read (a, 12, 5000);
 tcp_close (a);
 assert (12, c);
 assert (c, length (d));
--> success=0, msg=test failed: raised error: tcp_read: Error while reading/select: 22 - Invalid argument

[...]

>>>>> /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp_read.cc-tst
[...]
***** test block 4: test
  is_test=1 is_xtest=0
Code:
 # does read wait
 a = udp ();
 assert (! isnull (a));
 tic;
 [d,c] = udp_read (a, 1, 1000);
 t = toc;
 assert (c, 0);
 assert (isempty (d));
 assert (t, 1.0, 0.1)
 udp_close (a);
--> success=0, msg=test failed: raised error: udp_read: Error while reading/select: 22 - Invalid argument

[...]

>>>>> /Users/janke/Library/Application Support/Octave.app/4.4.1/pkg/instrument-control-0.4.0/test/udp_write.cc-tst
***** test block 1: test
  is_test=1 is_xtest=0
Code:
 a = udp ();
 b = udp ();
 p = get (a, 'localport');
 set (b, 'remoteport', p);
 p = get (b, 'localport');
 set (a, 'remoteport', p);
 assert (5, udp_write (a, uint8 ([104  101  108  108  111])));
 [d, c] = udp_read (b, 5, 1000);
 assert (c, 5);
 assert (d, uint8 ([104  101  108  108  111]));
 udp_close (a);
 udp_close (b);
--> success=0, msg=test failed: raised error: udp_read: Error while reading/select: 22 - Invalid argument


I'm attaching a file with the full test run details.

Andrew Janke <apjanke>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by lostbard (Posted a comment)
  • -email is unavailable- added by apjanke (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-12-25 lostbard StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2019-10-28 lostbard StatusNone Ready For Test
        Assigned toNone lostbard
    2019-10-23 apjanke Attached File- Added octave-instrument-control-normalize-timeval_01a.patch, #47735
    2019-10-23 apjanke Attached File- Added octave-instrument-control-normalize-timeval_01.patch, #47734
    2019-10-20 apjanke Attached File- Added instrument-control_tests.txt, #47721

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code