2

Suppose a source file called xmpl.cpp (the one described by Fröhlich, for instance). When compiling this file with gcc with the flags -fprofile-arcs and -ftest-coverage, it generates in the usual binary executable file xmpl and a gcov data file xmpl.gcno. Then, when the program is executed another gcov data file xmpl.gcna is generated, this one containing information gathered during the execution.

However, when I use an expect script to run that same program no xmpl.gcna is generated. More specifically, the problem is with the spawn command, with exec everything is fine (but then, why use expect, right?).

I'm interested in solving this issue because we have lots of expect scripts performing some tests in our project and currently no coverage information is being generated for those tests. The code for the example described above can be fetched here.

freitass
  • 6,542
  • 5
  • 40
  • 44

1 Answers1

1

Both spawn and exec create a new process to execute the program. The difference between them is that exec suspends the execution of TCL (Expect) until the execution completes. Since the program never reaches it's "natural end" when running the program with spawn, no coverage information get to be generated.

To fix the problem, one have to wait until the subprocess finishes before letting the expect script to end its execution, which can be achieved by expecting an eof. This is what the expect script should look like:

#!/usr/bin/expect -f

spawn ./xmpl Hey! xxx

expect eof
Community
  • 1
  • 1
freitass
  • 6,542
  • 5
  • 40
  • 44