https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121690

--- Comment #13 from Torbjorn SVENSSON <azoff at gcc dot gnu.org> ---
Created attachment 62259
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62259&action=edit
Patch to work around issue with read() in expect on macOS

The attached a patch (used
https://github.com/iains/darwin-expect/commit/565422b1c4576d9045346502dd1f3216b03bc6dd
as a baseline) works around the issue.
To make it more obvious what is happening, I've been able to reduce the problem
from running DejaGNU and the GCC testsuite to simply running the following:

exp_internal "-f" "expect.log" 1
set timeout -1
spawn ./myapp {*}$argv
expect {
    -re ".+" {
       set buf $expect_out(buffer)
       set start [string map [list "\r" "\\r" "\n" "\\n"] [string range $buf 0
9]]
       set end   [string map [list "\r" "\\r" "\n" "\\n"] [string range $buf
end-9 end]]
       set len [string length $buf]
       puts "\nGot buf; length=$len; starting with=$start; ending with=$end\n"
       exp_continue -continue_timer
    }
    timeout {
        puts "\nGot timeout"
    }
    eof {
        puts "\nGot EOF"
    }
}


What this does is run "myapp", an application that simply produces a long
stream of characters and inserts a LF at a given offset in the stream. When the
offset in the stream matches the amount of bytes returned by read() of the fd
connected to the PTY and the number of bytes appears to mach some internal
buffer in the PTY driver, the bug is triggered. Note, on macOS (at least on the
two systems that I have access to), this is 1024 bytes.

I've tried to do the same on NomadBSD (the easiest FreeBSD based system that I
could find that has live variant), but here, the 1024 byte limit does not
exist. Instead it's 6001 (yes, 6001), but even when hitting that limit, it
still works as expected.

To make sure that my patch actually fixes the GCC testing issue, I've done a
long session where I ran the testcase in GCC, that randomly failed with the
stock expect, with my patched one and there was not a single occasion reported
as failed with this patch applied, so I think it's safe to consider this patch
as fixing the issue.

The read that is subject in question is here:
https://github.com/iains/darwin-expect/blob/565422b1c4576d9045346502dd1f3216b03bc6dd/exp_chan.c#L219

Reply via email to