CTest Coverage Cmake Error

I’m getting a CMake error from a CTest script calling
ctest_coverage( ... CAPTURE_CMAKE_ERROR xyz RETURN_VALUE abc )
abc is 0 but xyz is 255 on return from the function. But I can’t figure what what’s going wrong. It’s running gcov on linux (RHEL7 but with my own compiled version of GCC 8.3.0). The results seem reasonable. Can someone suggest where to look for an error?
Thanks,
Allen

That means there was an error on the cmake side of things. However, gcov ran with no error. So, you should look at all the output from the ctest script running and see if there are any errors reported.

Hi Bill. Thanks for the pointer.

I think my primary problem was running ctest with -VV. There was so much output that I couldn’t spot the actual error. Without -VV it more or less pointed right at the problem.

The issue happened to occur while processing a Fortran file which used the Fortran “include” statement (i.e., not the preprocessor #include directive). In this case, gfortran does not put the whole path to the included file in the debug information. gcov reports that it cannot find the file referenced in the debug info and ctest exits with an error. gcov itself exits with status 0, so I’m not sure why ctest thinks a problem has occurred. (Maybe because gcov writes something to stderr?)

At any rate, we learned something about Fortran “include”.

Thanks,
Allen

Was there an error from CMake in the output? I think it means there was a cmake error message sent that would cause this. Something along the lines of this for example:

cmCTestLog(this->CTest, ERROR_MESSAGE,
"Cannot open file: " << lcovFile << std::endl);

Yes. That’s it.

OK, so CMake is unable to read a file that gcov is telling it should be there and it gets an error. This is sort of why the cmake errors and the gcov errors are separated.

This is the output from gcov run by itself (with the same command that ctest is using):

$ gcov -o CMakeFiles/example.dir/ CMakeFiles/example.dir/example.F90.gcda 
File '/home/allen/vms/bugs/ctest-gcov/src/example.F90'
Lines executed:100.00% of 2
Creating 'example.F90.gcov'

File 'header.txt'
Lines executed:100.00% of 1
Creating 'header.txt.gcov'
Cannot open source file header.txt

It points out that it can’t find “header.txt”. gcov writes the last line to stderr. However, gcov exits with return code 0.

Running my ctest coverage script yields:

$ ctest -S ../do_coverage.ctest 
Cannot find file: /home/allen/vms/bugs/ctest-gcov/build/Testing/CoverageInfo/header.txt

and exits with $? == 255.

So, it is a little confusing exactly what ctest is complaining about. Especially since the coverage file Testing/CoverageInfo/header.txt.gcov exists.

See the ctest_coverage command:
https://cmake.org/cmake/help/v3.7/command/ctest_coverage.html
CAPTURE_CMAKE_ERROR <result-var>

Store in the <result-var> variable -1 if there are any errors running the command and prevent ctest from returning non-zero if an error occurs.

1 Like

That helps my Jenkins job since ctest now doesn’t exit with an error and fail the job.

But I’m not sure what the right thing to do is. It’s true that gcov can’t find the file; but it gets the right coverage results. Is that to be construed as success or failure?

Anyway, I understand what CMake’s up to now.

Thanks,
Allen