How to mimic the behavior of CMAKE_TEST_LAUNCHER in an earlier version of cmake / ctest

26 Views Asked by At

The CMAKE_TEST_LAUNCHER variable (docs) is introduced in cmake 3.29. It seems to allow the functionality to run a test defined with CTest's add_test through some simulator or similar. I require this functionality as I build a RISC-V executable containing some tests, and I want to run it in the Spike RISC-V ISA simulator.

This variable is not implemented in earlier versions of CMake, so I wondered how this used to be done. I cannot update cmake on my server as it is not a personal one, so need to reproduce the behaviour otherwise.

Currently I do

        add_test(
            NAME "Test: ${executable}"
            COMMAND "${TOOLCHAIN_TEST_SIMULATOR} $<TARGET_FILE:${executable}>"
        )

where TOOLCHAIN_TEST_SIMULATOR is the path to spike and some arguments, set in a toolchain file. This results in the error

Could not find executable /home/.../tools/riscv-isa-sim/build/spike --isa=rv32gc /home/.../tools/riscv-pk/build/pk /home/..../projects/project/build/test/<executable>

However, if I run the above as a command, it works fine and runs through spike. It is like CTest is treating the entire TOOLCHAIN_TEST_SIMULATOR string as a single long command.

I got this far by trying to copy the add_test example usage:

add_test(NAME mytest
         COMMAND testDriver --config $<CONFIG>
                            --exe $<TARGET_FILE:myexe>)

How can I direct the tests to run in my simulator? I am on cmake 3.26.

0

There are 0 best solutions below