Building tests
You may need to write tests to debug code on the C side. This guide explains how to compile and run those tests.
Adding the file to CMake
Section titled “Adding the file to CMake”Before you can compile you need to tell CMake to actually build the file for you. If you are not creating a new set of tests, you may skip this section. The following steps show how to add a test file to CMake.
-
Navigate to the directory where you have written your test. As of writing this directory can be any one of the following.
test_interfaces/unit
test_gs/unit
(Note: As of writing you will need to do extra work to get this to work. Contact a lead if you need to build this directory)test_obc/unit
-
Open the
CMakeLists.txt
file. -
Add the correct files and dependencies to the
CMakeLists.txt
. Usually this will be a file path in theTEST_SOURCES
variable to your.cpp
file that contains the tests you want to run. As an example theTEST_SOURCES
CMake variable inCMakeLists.txt
under thetest_interfaces/unit
directory is shown below.set(TEST_SOURCES${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/main.cpp${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_pack_unpack_utils.cpp${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_command_pack_unpack.cpp${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_telemetry_pack_unpack.cpp${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_obc_gs_ax25.cpp${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_obc_gs_fec.cpp${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_command_response_pack_unpack.cpp${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_encode_decode_pipeline.cpp# Add a new file name here)
Compiling and running tests
Section titled “Compiling and running tests”With the file defined in CMake, we can now run tests. Or if there are no new tests this section still applies.
-
From the root directory run the following commands.
Terminal window mkdir -p build && cd buildcmake .. -DCMAKE_BUILD_TYPE=Testcmake --build .ctest --verbose -
If the tests pass, well done! If you find that there is a failed test check your test’s logic and then check your code!