bugGNU Octave - Bugs: bug #67025, "pkg test arduino"...

 
 

bug #67025: "pkg test arduino" breaks octave

Submitter:  Dmitri A. Sergatskov <dasergatskov>
Submitted:  Mon 14 Apr 2025 12:37:03 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Segfault, Bus Error, etc.
Status:  Fixed Assigned to:  lostbard
Originator Name:  Open/Closed:  * Closed
Release:  * dev Release: 
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sat 19 Apr 2025 11:46:29 AM UTC, comment #30: 

Sure.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Sat 19 Apr 2025 11:44:56 AM UTC, comment #29: 

This can be closed as fixed?

John Donoghue <lostbard>
Group Member
Wed 16 Apr 2025 03:17:51 PM UTC, comment #28: 

New version of instrumtn control was released which should fix the initial reported bug.

A new release of arduino was also made, fixing the "if !ischar (board)"

John Donoghue <lostbard>
Group Member
Tue 15 Apr 2025 12:58:51 PM UTC, comment #27: 

I'll try put out a new instrument control release today that frees resoures on failed creation of serialports - its looks like was possible on a few other object types as well - so I have fixed them as well.

John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 11:42:58 PM UTC, comment #26: 

even with the issue - it wasnt creating a port that was being 'used' by arduino - it was erroring where it is still erroring - the only difference now is that it cleans up the file descriptor on ports that do error straight away.


John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 11:24:53 PM UTC, comment #25: 

But from "arduino" point of few error-our earlier is good -- it would not need to try to connect and figure out that there is no arduino board on the other end. I wonder if that explain why on linux scan is some much faster than on Mac -- it just fails earlier, so there is no latency with communication with a dead port.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 11:07:07 PM UTC, comment #24: 

By empty i was referring to in arduino - it would create valid serialport - just requesting data to it would never return anything since nothing was attached.


For the case of where it couldnt open a serial port at all (whether the open failed, or it could set up the initial setting of it - it would error and not return an object 


John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 10:55:12 PM UTC, comment #23: 


comment #19:

> You can try commenting out teh check if you want, I would imagine the next call tcgetattr will probally fail ? and cause the same issue ?


Absolutely! This is not simple fix, that is why I was asking what 
should "s = serialport("/dev/ttySx")". If it is something else than error, then this part really needs to be re-coded.

But I also do not see a problem returning just error. What are you gonna do with an empty serial port?

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 10:54:41 PM UTC, comment #22: 

Not currently - when you load instrument control in loads all of instrument-control otherwise it wouldnt know about the functions


I guess you could modify teh PKG_ADD file to not autoload them - on my install its ~/.local/share/octave/api-v60/packages/instrument-control-0.9.4/x86_64-pc-linux-gnu-api-v60/PKG_ADD

But would be whereever it installed the oct files

John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 10:48:26 PM UTC, comment #21: 

Also, somewhat off-topic, but since we are all here.
When I was looking around I noticed in "arduino.m":

154         if !ischar (port)
155           error ("arduino: board must be a string");
156         endif


I assume it should be "if !ischar (board)"

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 10:46:07 PM UTC, comment #20: 


comment #17:

> I pushed a change for serialport to the instrument-control repo to ensure it closes the port before showing an errorin the open function which should fix this issue
>
> I will need look at the other instrument-control objest to verify they dont have similar issues


OK it works for me. I see a lot of extra ".oct" files loaded (like 11), but no serial ports.

Is there a way to unload those "oct" files?

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 10:40:53 PM UTC, comment #19: 

You can try commenting out teh check if you want, I would imagine the next call tcgetattr will probally fail ? and cause the same issue ?

John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 10:18:47 PM UTC, comment #18: 

I have theese on my computer:

$ setserial -g -G /dev/ttyS* | sort -V
/dev/ttyS0 uart unknown port 0x03f8 irq 4 baud_base 115200 spd_normal skip_test
/dev/ttyS1 uart unknown port 0x02f8 irq 3 baud_base 115200 spd_normal skip_test
/dev/ttyS2 uart unknown port 0x03e8 irq 4 baud_base 115200 spd_normal skip_test
/dev/ttyS3 uart unknown port 0x02e8 irq 3 baud_base 115200 spd_normal
/dev/ttyS4 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS5 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
/dev/ttyS6 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal
...
/dev/ttyS31 uart unknown port 0x0000 irq 0 baud_base 0 spd_normal

I def do not have D-Sub connectors, but may be a serial header on the M/B.
"serialport()" fails the same way on all of them:

octave:3> s = serialport("/dev/ttyS0")
error: serialport: Interface does not refer to a terminal: Input/output error
octave:4> s = serialport("/dev/ttyS1")
error: serialport: Interface does not refer to a terminal: Input/output error
octave:5> s = serialport("/dev/ttyS10")
error: serialport: Interface does not refer to a terminal: Input/output error


Dmitri.
--


Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 10:17:06 PM UTC, comment #17: 

I pushed a change for serialport to the instrument-control repo to ensure it closes the port before showing an errorin the open function which should fix this issue

I will need look at the other instrument-control objest to verify they dont have similar issues

John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 10:01:36 PM UTC, comment #16: 

it would return a serial port object in that case.

The issue in linux is that there is a difference between a device and a device that has some hardware to.

ie: my desktop has 2 real serial ports - jus noting hangling off of them

vs the other 20 /dev/ttySXX port devices that dont have any actual hardware connected to them. (which is where the istty will fail)

 




John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 09:38:31 PM UTC, comment #15: 

What do you expect for "s=serialport("dev/ttyS0")" to return if nothing is connected to the port (but post is valid)?

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 09:34:20 PM UTC, comment #14: 

Issue isnt the check - the issue if that on an error we dont clean up the opened file as nothing after the error call is performed.


John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 09:31:54 PM UTC, comment #13: 

I figured that !isatty is not good if nothing connected to the port. I think we can check if it is a char device.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 09:17:44 PM UTC, comment #12: 

ttyS0 is a real port on my system
ttyS4 is a device but not actually hooked to any phsical hardware
ttyUSB0 is an arduino I had connected


The issue as an example is:


      if(! isatty (fd))
        {
          error("serialportX: Interface does not refer to a terminal: %s\n", strerror (errno));
          octave_serialport::close ();
          return;
        }


The error is shown but none of the code after error ever gets run so it doesnt close the port.

I need update instrument-control to fix it


John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 08:06:53 PM UTC, comment #11: 

What is the difference between ttyS0 and ttyS4? I got the same error for them. Do you have an actual board on ttyUSB0?

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 06:47:25 PM UTC, comment #10: 

I think its actually a instrument-control issue

This works:

a = arduino("/dev/ttyUSB")
a = [];


This works:

a = arduino("/dev/ttyS0")
a = [];


This leaves a open port

a = arduino("/dev/ttyS4")
error: serialport: Interface does not refer to a terminal: Input/output error


At this point arduino doesnt have a seriaport to close


Indeed, instrument control:

> a = serialport("/dev/ttyS4")

error: serialport: Interface does not refer to a terminal: Input/output error


Ill take a look at serialport interface

John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 05:46:32 PM UTC, comment #9: 

In arduino %!test blocks you could see a lot of things like:

%!test
%! ar = arduino();
%! assert(!isempty(ar));
%! assert(ar.port, arduinos{1}.port);
%! assert(ar.board, arduinos{1}.board);
%! assert(numel(ar.availablepins) > 0);

I just did:


octave:2> ar = arduino
error: arduino: No arduinos found on serial scan
error: called from
    arduino at line 114 column 11


Number of open files increase from 275 to 307.

"arduino()" probes (means open) all serial ports, and no-one closes them. And "test" cannot close then either.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 05:36:13 PM UTC, comment #8: 

That has been fixed:
https://github.com/gnu-octave/octave-arduino/issues/6

You need to get git snapshot.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 05:34:25 PM UTC, comment #7: 

Seems like the arduino package is screwing this up.  Using release version of Octave 10.1.0 I can't even install arduino package:


pkg install -verbose -forge arduino
downloading tarball(s) from:
- https://packages.octave.org/download/arduino-0.12.1.tar.gz
mkdir (/tmp/oct-woKFkA)
untar (/tmp/arduino-0.12.1-ZjqhY7.tar.gz, /tmp/oct-woKFkA)
warning: doc_cache_create: unusable help text found in file 'example_spi_mcp3002'
warning: called from
    doc_cache_create>handle_function at line 98 column 5
    doc_cache_create>create_cache at line 118 column 6
    gen_doc_cache_in_dir>@<anonymous> at line 150 column 20
    doc_cache_create>gen_doc_cache_in_dir at line 151 column 3
    doc_cache_create at line 62 column 6
    install>generate_lookfor_cache at line 846 column 5
    install at line 241 column 7
    pkg at line 619 column 9

error: duplicate property 'LSM6DSO_REG_FIFO_DATA_OUT_X_H' in class 'lsm6dso' in file '/home/rik/.octavepkg/arduino-0.12.1/sensors/lsm6dso.m'
error: called from
    <unknown>
    doc_cache_create>create_cache at line 116 column 6
    gen_doc_cache_in_dir>@<anonymous> at line 150 column 20
    doc_cache_create>gen_doc_cache_in_dir at line 151 column 3
    doc_cache_create at line 62 column 6
    install>generate_lookfor_cache at line 846 column 5
    install at line 241 column 7
    pkg at line 619 column 9




Rik <rik5>
Group administrator
Mon 14 Apr 2025 05:18:50 PM UTC, comment #6: 

I ran "lsof -p<PID> | wc -l" where is PID is octave process.
Just after the start (261) and after I run "pkg test arduino" (2739).
And if I look at lsof -p<PID> I see it is all those "/dev/ttyS*"
there. Should "pkg test" close them even if "arduino" did not?

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 04:54:00 PM UTC, comment #5: 

Yes. Of course. It is 1024 now, and increasing it to 2048 does not help. With 4196, it passes. But this looks way too excessive. I think we are leaking file descriptors somewhere.

As I said adding unwrap_protect in the pkg.m helped somewhat already.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 04:42:05 PM UTC, comment #4: 

Is it possible that the shell you are using has a small limit on the number of file descriptors?  Assuming bash, what does this return?


ulimit -Hn
ulimit -Sn


If the soft limit is small then you could try increasing that.

Rik <rik5>
Group administrator
Mon 14 Apr 2025 03:15:44 PM UTC, comment #3: 

Yes, it is still shows the problem. But regardless of whether it is an arduino problem (I have some suspicions, but I have not checked them yet), octave should handle it.

I think "load-path.cc" needs some review especially wrt directory traversing (  load_path::dir_info::get_file_list ).

Dmitri.
--


Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 03:08:02 PM UTC, comment #2: 

I believe i saw this happen to me once as well? Can you try the latest code (modified today) ?

John Donoghue <lostbard>
Group Member
Mon 14 Apr 2025 01:45:40 PM UTC, comment #1: 

If I put unwind_protect around  "__run_test_suite__" in pkg.m

             ## FIXME invoke another test routine once that is available.
             ## Until then __run_test_suite__.m will do the job fine enough
+            unwind_protect
             __run_test_suite__ ({installed_pkgs_dirs{:}}, {});
+            unwind_protect_cleanup fclose ("all"); end_unwind_protect
           endif

then things get a little better, but I still see those:

octave:5> fclose all
warning: load_path: /usr/local/share/octave/11.0.0/m/+containers: Too many open files
warning: load_path: /usr/local/share/octave/11.0.0/m/+matlab: Too many open files
warning: load_path: /usr/local/share/octave/11.0.0/m/@ftp: Too many open files
warning: load_path: /usr/local/share/octave/11.0.0/m/audio/@audioplayer: Too many open files
warning: load_path: /usr/local/share/octave/11.0.0/m/audio/@audiorecorder: Too many open files
warning: load_path: /usr/local/share/octave/11.0.0/m/legacy/@inline: Too many open files
ans = 0


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Mon 14 Apr 2025 12:37:03 PM UTC, original submission:  

Testing latest (git snapshot) of arduino on both octave 10.1.1 and octave 11 I see:

..hare/octave/api-v60/packages/arduino-0.12.1/@arduino/uptime.m  pass    0/1    [ 0.014s /  0.014s]
                                                                   FAIL    1
  ..octave/api-v60/packages/arduino-0.12.1/@arduino/validatePin.m  pass    1/6    [ 0.032s /  0.032s]
                                                                   FAIL    5
__run_test_suite__: fopen failed: /home/dmitri/.local/share/octave/api-v60/packages/arduino-0.12.1/@arduino/version.m
warning: load_path: .: Too many open files
warning: called from
    pkg at line 833 column 9

warning: load_path: /usr/local/lib/octave/10.1.1/site/oct/x86_64-pc-linux-gnu: Too many open files
warning: called from
    pkg at line 833 column 9

...<deleted>...


After that octave is unusable and needs to be restarted.
That should not happen.

Dmitri.
--


Dmitri A. Sergatskov <dasergatskov>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by lostbard (Posted a comment)
  • -email is unavailable- added by dasergatskov (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2025-04-21 lostbard StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2025-04-16 lostbard StatusNone Ready For Test
        Assigned toNone lostbard

    Back to the top

    Powered by Savane 3.14-962f.
    Corresponding source code