CTest hangs indefinitely if a child of the test keeps running
When CTest runs a process (the test) which in turn creates another process, and when the test process exits, but the child keeps running, CTest keeps running too, even when the timeout is reached.
For instance on Linux to reproduce: CMakeLists.txt
cmake_minimum_required(VERSION 3.14.6)
project(spawn-child)
enable_testing()
add_executable(spawn-child main.c)
add_test(NAME spawn-child COMMAND spawn-child)
set_tests_properties(spawn-child PROPERTIES TIMEOUT 10)
main.c
#include <unistd.h>
int main()
{
pid_t pid = fork();
if(pid == 0) {
sleep(30);
}
return 0;
}
Here I would expect that the test fails after 10 seconds, instead CTest waits 30 seconds and then exits.
In the case you have a child which never exits, unless told otherwise, this creates an indefinite hang.
This seems to be caused by the fact that CTest not only waits on the test process to be closed, but also for the stdout
and stderr
to be closed too.
Moreover when the timeout triggers, there's a check for the test process state, and if it results as exited, it does nothing.
This happens on Windows too.