cmcfarlen commented on code in PR #13658:
URL: https://github.com/apache/trafficserver/pull/13658#discussion_r3973352616
##########
lib/CMakeLists.txt:
##########
@@ -43,14 +44,38 @@ if(BUILD_TESTING)
target_compile_options(Catch2 INTERFACE -Wno-error=parentheses)
target_compile_options(Catch2WithMain INTERFACE -Wno-error=parentheses)
- # By default, as of v3.9.0, Catch2 runs tests in random order. Our tests are
- # written with the expectation that they are run in declared order, with
setup
- # done in one TEST_CASE expected to carry over into the next TEST_CASE. This
- # macro allows us to add common command line arguments to all tests. For now,
- # we ensure declaration order execution via --order decl.
+ # Register one ctest test per Catch2 TEST_CASE/SCENARIO rather than one per
+ # executable. ctest then names the failing case instead of the binary, can
+ # schedule cases in parallel, and can run a single case by name. Because each
+ # case gets its own process, cases must not depend on state set up by an
+ # earlier case in the same executable.
+ #
+ # ctest names are "<NAME>.<case name>" so the NAME given here stays a usable
+ # -R filter prefix even where it differs from the target name.
+ #
+ # Discovery is PRE_TEST so that configuring/building does not require running
+ # the test executables.
macro(add_catch2_test)
- cmake_parse_arguments(CATCH2_TEST "" "NAME" "COMMAND" ${ARGN})
- add_test(NAME ${CATCH2_TEST_NAME} COMMAND ${CATCH2_TEST_COMMAND} --order
decl)
+ cmake_parse_arguments(CATCH2_TEST "" "NAME" "COMMAND;ENVIRONMENT" ${ARGN})
+
+ list(GET CATCH2_TEST_COMMAND 0 _catch2_command)
+ if(_catch2_command MATCHES "^\\$<TARGET_FILE:(.+)>$")
+ set(_catch2_target "${CMAKE_MATCH_1}")
+ else()
+ set(_catch2_target "${_catch2_command}")
+ endif()
+
+ if(CATCH2_TEST_ENVIRONMENT)
+ # Not ctest's ENVIRONMENT property: catch_discover_tests flattens
PROPERTIES
+ # into one ;-joined string, so a multi-variable ENVIRONMENT loses every
+ # variable but the first and turns the rest into junk property names. The
+ # emulator prefix survives intact and also applies to test discovery.
+ set_property(
+ TARGET ${_catch2_target} PROPERTY CROSSCOMPILING_EMULATOR
"${CMAKE_COMMAND}" -E env ${CATCH2_TEST_ENVIRONMENT}
+ )
+ endif()
+
+ catch_discover_tests(${_catch2_target} TEST_PREFIX "${CATCH2_TEST_NAME}."
DISCOVERY_MODE PRE_TEST)
Review Comment:
Confirmed — that's a real defect and my sweep missed it because I only
grepped `src/`, `plugins/` and `example/` for shared temp paths, not `lib/`.
Fixed in 34b5586238 by giving each case its own directory, following the
convention `file::path::canonical` (`libswoc_can_*`) and `file::path::copy`
(`libswoc_cp_*`) in the same file already use:
- `file::path::create_directories` → `libswoc_mkdir_1` / `libswoc_mkdir_2`
- `ts_file::path::remove` → `libswoc_rm_1` / `libswoc_rm_2`
I went with distinct directories rather than a `RESOURCE_LOCK` for two
reasons: it keeps both cases parallel, and with `DISCOVERY_MODE PRE_TEST` the
test names don't exist at configure time, so `set_tests_properties` on the two
specific cases isn't available — the lock would have to go on all ~121 libswoc
cases.
Confirmed with your command, both directions:
```
# without the fix
ctest -R '^test_libswoc\..*(create_directories|path::remove)' -j2 --repeat
until-fail:100
-> 90 - test_libswoc.ts_file::path::remove (Failed)
# with the fix
-> 100% tests passed, 0 tests failed out of 2
```
Also swept the rest of that file — `"dir1"` was the only name used twice;
every other case was already uniquely named. And your find prompted me to stop
trusting single passes: the whole suite now runs clean under `ctest -j8
--repeat until-fail:10` (1014 × 10 executions), with only the known macOS-local
`test_jsonrpcserver` socket-bind failures, which are pre-existing and pass in
CI.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]