]> https://gitweb.dealii.org/ - dealii.git/commitdiff
CMake: add_test(): refactor shared target boolean
authorMatthias Maier <tamiko@43-1.org>
Tue, 24 Jan 2023 01:56:46 +0000 (19:56 -0600)
committerMatthias Maier <tamiko@43-1.org>
Wed, 25 Jan 2023 23:26:29 +0000 (17:26 -0600)
cmake/macros/macro_deal_ii_add_test.cmake

index 6cafff13853897183f8e552c75b735b1aa2a6ad3..90cff2e2189f4415657ff78a39bcfd5c932c5c4a 100644 (file)
@@ -412,6 +412,25 @@ function(deal_ii_add_test _category _test_name _comparison_file)
 
       file(MAKE_DIRECTORY ${_test_directory})
 
+      #
+      # Determine whether the test shares a common executable target. This
+      # involves tests with .threads=N. and .mpirun=N. annotation, as well
+      # as tests with parameter files (that might share a common executable
+      # target).
+      #
+      # In this case we have to make sure that concurrently invoking the
+      # test does not accidentally trigger a concurrent build of the
+      # executable target. We ensure this by declaring an additional test
+      # that only builds the shared target / ensures the shared target is
+      # present. All run tests then requires this test target as a "setup
+      # fixture", see
+      # https://cmake.org/cmake/help/latest/prop_test/FIXTURES_REQUIRED.html#prop_test:FIXTURES_REQUIRED
+      #
+      set(_shared_target FALSE)
+      if(NOT "${_n_cpu}${_n_threads}" STREQUAL "00" OR "${_source_file}" MATCHES "(prm|json)$")
+        set(_shared_target TRUE)
+      endif()
+
       #
       # Add an executable (for the first type of tests) and set up compile
       # definitions and the full link interface. Only add the target once.
@@ -577,8 +596,7 @@ function(deal_ii_add_test _category _test_name _comparison_file)
       # as tests with parameter files (that might share a common executable
       # target).
       #
-      if( NOT "${_n_cpu}${_n_threads}" STREQUAL "00" OR
-          "${_source_file}" MATCHES "(prm|json)$" )
+      if(_shared_target)
         #
         # Running multiple variants of tests with the same target
         # executable in parallel triggers a race condition where the same

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.