0

When running CTest with --timeout 120 (or the default timeout), how is that number passed on to the test binary?

I have a C/C++ test binary and it appears that the timeout is neither passed on to the test binary on its command-line, nor its environment variables. Is there a CMake trick that inserts magic commands into CTestTestfile.cmake to forward that setting?

Christoph Wintersteiger
  • 8,234
  • 1
  • 16
  • 30
  • `how is that number passed on to the test binary?` Why would it be passed? It's the timeout for test execution, not an argument. – KamilCuk Jan 13 '21 at 12:58
  • Why would it not be passed on in some way? Tests may want to know about it. – Christoph Wintersteiger Jan 13 '21 at 13:00
  • `Test may want to know about it` Exactly - because it affects the test. From my perspective, timeout is irrelevant to the test itself. Test should run under the same environment, no mater if I am in a hurry on my local machine with `--timeout 1` or I'm executing tests on my gitlab-ci/cd pipeline with `--timeout 2000`. Ex. if I buy faster PC, so I'll pass a smaller timeout because of that, should the test be different? It should be the same test, it should test the same things. Test should stay the same, so to `Tests may want to know about it` then I do not see a reason why. – KamilCuk Jan 13 '21 at 13:02

1 Answers1

1

How do I pass the timeout setting of CTest to test binaries?

You could use environment variables.

how is that number passed on to the test binary?

It is not, not that I know of.

Is there a CMake trick that inserts magic

I would just use an environment variable.

add_test(... COMMAND wrapper_script.sh the_executable args...)

and then in wrapper_script.sh (or preferably similar code with a cmake script for portability, TODO):

#!/bin/sh
exec "$@" --the-timeout "${MY_TIMEOUT:-1500}"

and then when ctest is run the timeout has to be set and exported to environment variables:

export MY_TIMEOUT=200 ; ctest --timeout "$MY_TIMEOUT" ...

With such design it could be simpler if the test executable itself would just read the environment variable MY_TIMEOUT.

KamilCuk
  • 120,984
  • 8
  • 59
  • 111