Debian Codegraph @

3rdparty/catch2/extras/CatchShardTestsImpl.cmake

raw
1
2 # Copyright Catch2 Authors
3 # Distributed under the Boost Software License, Version 1.0.
4 # (See accompanying file LICENSE.txt or copy at
5 # https://www.boost.org/LICENSE_1_0.txt)
6
7 # SPDX-License-Identifier: BSL-1.0
8
9 # Indirection for CatchShardTests that allows us to delay the script
10 # file generation until build time.
11
12 # Expected args:
13 # * TEST_BINARY - full path to the test binary to run sharded
14 # * CTEST_FILE - full path to ctest script file to write to
15 # * TARGET_NAME - name of the target to shard (used for test names)
16 # * SHARD_COUNT - number of shards to split the binary into
17 # Optional args:
18 # * REPORTER_SPEC - reporter specs to be passed down to the binary
19 # * TEST_SPEC - test spec to pass down to the test binary
20
21 if(NOT EXISTS "${TEST_BINARY}")
22 message(FATAL_ERROR
23 "Specified test binary '${TEST_BINARY}' does not exist"
24 )
25 endif()
26
27 set(other_args "")
28 if (TEST_SPEC)
29 set(other_args "${other_args} ${TEST_SPEC}")
30 endif()
31 if (REPORTER_SPEC)
32 set(other_args "${other_args} --reporter ${REPORTER_SPEC}")
33 endif()
34
35 # foreach RANGE in cmake is inclusive of the end, so we have to adjust it
36 math(EXPR adjusted_shard_count "${SHARD_COUNT} - 1")
37
38 file(WRITE "${CTEST_FILE}"
39 "string(RANDOM LENGTH 8 ALPHABET \"0123456789abcdef\" rng_seed)\n"
40 "\n"
41 "foreach(shard_idx RANGE ${adjusted_shard_count})\n"
42 " add_test(${TARGET_NAME}-shard-" [[${shard_idx}]] "/${adjusted_shard_count}\n"
43 " ${TEST_BINARY}"
44 " --shard-index " [[${shard_idx}]]
45 " --shard-count ${SHARD_COUNT}"
46 " --rng-seed " [[0x${rng_seed}]]
47 " --order rand"
48 "${other_args}"
49 "\n"
50 " )\n"
51 "endforeach()\n"
52 )