0

I have a CMake-based C++ project that I need to integrate into a CI/CD pipeline. The pipeline has two steps, one for building, the other for testing. Creating this environment in a Docker container works like a charm, but results in a 2GB container. So I am trying to implement a multi-stage Docker build where I copy the executables into an Alpine base image. All that works, except for the cmake/ctest functionality. I want to expose the command "make test" which will execute the CMake generate target.

This is the target that CMake has created for running ctest.

# Targets provided globally by CMake.

# Special rule for the target test
test:
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..."
        /usr/bin/ctest --force-new-ctest-process $(ARGS)
.PHONY : test

The problem I can't figure out is where ctest gets the test configuration from. When I issue

ctest -N

in the container it shows no tests.

Looking for an SME on CMake to educate me how this is supposed to work.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Ravenwater
  • 735
  • 1
  • 5
  • 14
  • ARGS should be a variable in the same Makefile that CMake generated – Marco Pantaleoni Apr 19 '18 at 14:54
  • Unfortunately, that does not appear to be the case. – Ravenwater Apr 19 '18 at 15:14
  • I've found a reference in [this answer](https://stackoverflow.com/a/38866947/1363486) that ARGS is meant to pass options to `ctest` from command line, as with `ARGS='your ctest options here'` – Marco Pantaleoni Apr 19 '18 at 15:24
  • Mm, from that it appears that my problem isn't an ARGS problem. I don't need to pass arguments to ctest, I need to pass the test configuration to ctest. Right now, _ctest -N_ showns 0 tests. I need to edit the question. – Ravenwater Apr 19 '18 at 15:29
  • I suppose you do have proper `add_test()` lines in your CMakeLists.txt – Marco Pantaleoni Apr 19 '18 at 15:33
  • yes, the reference container is completely functional. The goal is to lift just the executables and the ctest infrastructure into the deployment container so it supports the command _make test_ and reports on the test results so that the CI/CD pipeline can report a green build after successfully running all the tests. – Ravenwater Apr 19 '18 at 16:41
  • `The problem I can't figure out is where ctest gets the test configuration from.` - If by "configuration" you mean "list of tests", then CTest reads it from `CTestTestfile.cmake` file in the directory where `ctest` is run. – Tsyvarev Apr 19 '18 at 17:07
  • It appears to be processing the subdir() commands in that file, and the context of the processing appears to require more than just that file. Still getting 0 tests when running ctest -N. So the question remain, how to you copy the minimum state from one container to another so that the ctest functionality remains correct? – Ravenwater Apr 19 '18 at 19:01

1 Answers1

0

Ok, I straced ctest in the container and discovered that it was hunting down a CTestTestfile.cmake file in each of the directories that have test executables. Adding that file to the deployment container along side the executables, basically where the file is found in the build container, solves the problem.

There is a CTestTestfile.cmake at the root of the build tree, and then individual CTestTestfile.cmake files along side the test executables.

strace is your friend, although I had to learn a new trick for docker, as strace is privileged. This was the command I used to strace ctest

docker run --rm --security-opt seccomp:unconfined strace ctest -N

Ravenwater
  • 735
  • 1
  • 5
  • 14