Skip to content

Commit a137269

Browse files
committed
Added how to build tests
1 parent eb3ece9 commit a137269

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

docs/src/content/docs/builds/build-tests.mdx

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,57 @@ title: Building tests
33
description: On how to build tests
44
sidebar:
55
badge:
6-
text: WIP
7-
variant: caution
6+
text: New
7+
variant: success
88
order: 3
99
---
10-
The following guide outlines a procedure to build tests for code.
10+
import { Steps } from '@astrojs/starlight/components';
11+
12+
Sometimes you will have to write tests to debug c-side code. This guide will be a guide on how to compile and run these tests.
13+
14+
## Adding the file to CMake
15+
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.
16+
<Steps>
17+
1. Navigate to the directory where you have written your test. As of writing this directory can be any one of the following.
18+
* `test_interfaces/unit`
19+
* `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)
20+
* `test_obc/unit`
21+
2. Open the `CMakeLists.txt` file.
22+
3. Add the correct files and dependencies to the `CMakeLists.txt`. Usually this will be a file path in the `TEST_SOURCES` variable to your `.cpp` file that contains the tests you want to run. As an example the `TEST_SOURCES` CMake variable in `CMakeLists.txt` under the `test_interfaces/unit` directory is shown below.
23+
24+
```cmake
25+
set(TEST_SOURCES
26+
${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/main.cpp
27+
${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_pack_unpack_utils.cpp
28+
${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_command_pack_unpack.cpp
29+
${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_telemetry_pack_unpack.cpp
30+
${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_obc_gs_ax25.cpp
31+
${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_obc_gs_fec.cpp
32+
${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_command_response_pack_unpack.cpp
33+
${CMAKE_SOURCE_DIR}/test/test_interfaces/unit/test_encode_decode_pipeline.cpp
34+
# Add a new file name here
35+
)
36+
```
37+
38+
:::note
39+
`CMAKE_SOURCE_DIR` is the repository's root directory.
40+
:::
41+
</Steps>
42+
43+
## Compiling and running tests
44+
With the file defined in CMake, we can now run tests. Or if there are no new tests this section still applies.
45+
46+
<Steps>
47+
1. From the root directory run the following commands.
48+
49+
```shell
50+
mkdir -p build && cd build
51+
cmake .. -DCMAKE_BUILD_TYPE=Test
52+
cmake --build .
53+
ctest --verbose
54+
```
55+
:::note
56+
To speed up the `cmake --build .` command you can use the `make -j 16` or the `make -j 32` (if your computer can handle 32 parallel jobs)
57+
:::
58+
2. 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!
59+
</Steps>

0 commit comments

Comments
 (0)