CatchShardTestsImpl.cmake 1.6 KB

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