Subject: DejaGnu randomly truncates lines in runtest output

From: Alex Coplan <[email-masked]>
Date: Thu, 16 Jul 2020 15:30:46 +0100

Hello,

I've run into a DejaGnu bug while working on the GCC testsuite
(specifically the libgccjit testsuite). The issue is that runtest ends
up randomly truncating lines in the output.

To reproduce the issue, in a new directory, create a file bug.c with the
following contents:

  #include <dejagnu.h>

  int main(void)
  {
    for (int i = 0; i < 200; i++) {
      pass("This is a really long string and maybe it will be truncated because of the bug.");
    }
  }

Then, create a subdirectory bug.dg, containing a single file bug.exp
with the following contents:

  global text

  spawn "./a.out"

  set prefix "\[^\r\n\]*"
  expect {
    -re "^$prefix\tPASSED:${text}*" {
      regsub "\[\n\r\t\]*PASSED: $text\r\n" $expect_out(0,string) "" output
      set output [string range $output 8 end]
      pass "$output"
      exp_continue
    }
    -re "^$prefix\r\n" {
      exp_continue
    }
  }

Now compile bug.c, and verify the output is as expected:

$ gcc bug.c
$ ./a.out | uniq -c
    200         PASSED: This is a really long string and maybe it will be truncated because of the bug.

Now to reproduce the bug:

$ runtest --all 2>&1 | uniq -c

I see:

   1 WARNING: No tool specified
   1 Test run by alecop01 on Thu Jul 16 14:33:58 2020
   1 Native configuration is x86_64-pc-linux-gnu
   1 
   1 		===  tests ===
   1 
   1 Schedule of variations:
   1     unix
   1 
   1 Running target unix
   1 Using /usr/share/dejagnu/baseboards/unix.exp as board description file for target.
   1 Using /usr/share/dejagnu/config/unix.exp as generic interface file for target.
   1 WARNING: Couldn't find tool config file for unix, using default.
   1 Running ./bug.dg/bug.exp ...
  49 PASS:  This is a really long string and maybe it will be truncated because of the bug.
   1 PASS:  This is a really long string and mayb
  90 PASS:  This is a really long string and maybe it will be truncated because of the bug.
   1 PASS:  This is a really long string and mayb
  59 PASS:  This is a really long string and maybe it will be truncated because of the bug.
   1 
   1 		===  Summary ===
   1 
   1 # of expected passes		200

That is, some of the lines in the output have been truncated.

Running the last step multiple times, you should be able to see that the
truncation happens at different points in the output each time. This
nondeterministic behaviour makes it especially problematic since it is
now quite difficult to compare results across multiple test runs.

If it helps with reproducing the issue, I'm running Ubuntu 18.04 on
x86_64 and my software versions are as follows:

$ runtest --version
DejaGnu version	1.6.1
Expect version	5.45.4
Tcl version	8.6

Many thanks in advance for any assistance with this issue.

Best Regards,
Alex