aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/catch2/extras/CatchShardTestsImpl.cmake
diff options
context:
space:
mode:
authorLexi Winter <lexi@le-fay.org>2025-06-29 19:28:09 +0100
committerLexi Winter <lexi@le-fay.org>2025-06-29 19:28:09 +0100
commit67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b (patch)
tree1ecd818f4bcf7d12622d43dc92c4d4bb9b746d0f /contrib/catch2/extras/CatchShardTestsImpl.cmake
parenta8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df (diff)
parentbc524d70253a4ab2fe40c3ca3e5666e267c0a4d1 (diff)
downloadnihil-67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b.tar.gz
nihil-67b2fae1fa8b033045a44c1355d9dfd8f83e0d9b.tar.bz2
Add 'contrib/catch2/' from commit 'bc524d70253a4ab2fe40c3ca3e5666e267c0a4d1'
git-subtree-dir: contrib/catch2 git-subtree-mainline: a8b0ea58e60bb0326b7f7c8f3c736d89ce9ef1df git-subtree-split: bc524d70253a4ab2fe40c3ca3e5666e267c0a4d1
Diffstat (limited to 'contrib/catch2/extras/CatchShardTestsImpl.cmake')
-rw-r--r--contrib/catch2/extras/CatchShardTestsImpl.cmake52
1 files changed, 52 insertions, 0 deletions
diff --git a/contrib/catch2/extras/CatchShardTestsImpl.cmake b/contrib/catch2/extras/CatchShardTestsImpl.cmake
new file mode 100644
index 0000000..bb2fc3e
--- /dev/null
+++ b/contrib/catch2/extras/CatchShardTestsImpl.cmake
@@ -0,0 +1,52 @@
+
+# Copyright Catch2 Authors
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE.txt or copy at
+# https://www.boost.org/LICENSE_1_0.txt)
+
+# SPDX-License-Identifier: BSL-1.0
+
+# Indirection for CatchShardTests that allows us to delay the script
+# file generation until build time.
+
+# Expected args:
+# * TEST_BINARY - full path to the test binary to run sharded
+# * CTEST_FILE - full path to ctest script file to write to
+# * TARGET_NAME - name of the target to shard (used for test names)
+# * SHARD_COUNT - number of shards to split the binary into
+# Optional args:
+# * REPORTER_SPEC - reporter specs to be passed down to the binary
+# * TEST_SPEC - test spec to pass down to the test binary
+
+if(NOT EXISTS "${TEST_BINARY}")
+ message(FATAL_ERROR
+ "Specified test binary '${TEST_BINARY}' does not exist"
+ )
+endif()
+
+set(other_args "")
+if (TEST_SPEC)
+ set(other_args "${other_args} ${TEST_SPEC}")
+endif()
+if (REPORTER_SPEC)
+ set(other_args "${other_args} --reporter ${REPORTER_SPEC}")
+endif()
+
+# foreach RANGE in cmake is inclusive of the end, so we have to adjust it
+math(EXPR adjusted_shard_count "${SHARD_COUNT} - 1")
+
+file(WRITE "${CTEST_FILE}"
+ "string(RANDOM LENGTH 8 ALPHABET \"0123456789abcdef\" rng_seed)\n"
+ "\n"
+ "foreach(shard_idx RANGE ${adjusted_shard_count})\n"
+ " add_test(${TARGET_NAME}-shard-" [[${shard_idx}]] "/${adjusted_shard_count}\n"
+ " ${TEST_BINARY}"
+ " --shard-index " [[${shard_idx}]]
+ " --shard-count ${SHARD_COUNT}"
+ " --rng-seed " [[0x${rng_seed}]]
+ " --order rand"
+ "${other_args}"
+ "\n"
+ " )\n"
+ "endforeach()\n"
+)