From 633e97dcd37cf4cd7cc8d472d80f6b0132a5878e Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Sat, 10 Dec 2022 00:38:49 -0600 Subject: [PATCH] tests: add a test target that runs the quick tests --- tests/CMakeLists.txt | 31 +++++++-- .../run.cmake => run_quick_tests.cmake} | 64 +++++++++---------- 2 files changed, 58 insertions(+), 37 deletions(-) rename tests/{quick_tests/run.cmake => run_quick_tests.cmake} (62%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5a3728162c..5a26ee7da6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -150,6 +150,30 @@ endforeach() if(DEFINED DEAL_II_HAVE_TESTS_DIRECTORY) + + # + # Define a top-level "test" target that runs our quick tests wrapper. + # + + if("${CMAKE_VERSION}" VERSION_LESS "3.11" AND POLICY CMP0037) + # allow to override "test" target for quick tests + cmake_policy(SET CMP0037 OLD) + endif() + + # Use the first available build type (this prefers debug mode if available): + list(GET DEAL_II_BUILD_TYPES 0 _my_build) + add_custom_target(test + COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=${_my_build} -P ${CMAKE_CURRENT_SOURCE_DIR}/run_quick_tests.cmake + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Running quicktests..." + ) + + # Depend on the library target to ensure that deal.II is actually + # compiled, as well as on the setup_tests_quick_tests target to ensure + # that quick tests are actually available. + add_dependencies(test library) + add_dependencies(test setup_tests_quick_tests) + # # Add a dummy target to make files known to IDEs like qtcreator # @@ -159,11 +183,8 @@ if(DEFINED DEAL_II_HAVE_TESTS_DIRECTORY) ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*/*.cc ${CMAKE_CURRENT_SOURCE_DIR}/*/*.h - ) - - add_custom_target(testsuite - SOURCES ${_misc} - ) + ) + add_custom_target(testsuite SOURCES ${_misc}) message(STATUS "Setting up testsuite - Done") endif() diff --git a/tests/quick_tests/run.cmake b/tests/run_quick_tests.cmake similarity index 62% rename from tests/quick_tests/run.cmake rename to tests/run_quick_tests.cmake index 991a82cd20..76dfc6e206 100644 --- a/tests/quick_tests/run.cmake +++ b/tests/run_quick_tests.cmake @@ -13,40 +13,48 @@ ## ## --------------------------------------------------------------------- +# # This file is run when "make test" is executed by the user and is -# responsible for running the tests and printing some helpful -# error messages. +# responsible for running the tests and printing some helpful error +# messages. +# + include(ProcessorCount) PROCESSORCOUNT(_n_processors) + if(_n_processors EQUAL 0) set(_n_processors "1") endif() - -# Windows quick tests have a race condition, so disable compiling/running -# tests in parallel. This avoid errors like: -# -# error MSB3491: Could not write lines to file -# "obj_boost_system_debug.dir\Debug\obj_boos.4A356C5C.tlog\obj_boost_system_debug.lastbuildstate". The -# process cannot access the file '...' because it is being used by another -# process. +# Avoid race conditions with native Windows build tools: if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") set(_n_processors "1") endif() -separate_arguments(ALL_TESTS) +if("${CMAKE_BUILD_TYPE}" STREQUAL "") + set(CMAKE_BUILD_TYPE "Debug") +endif() +message(STATUS "Running quick_tests in ${CMAKE_BUILD_TYPE} mode with -j${_n_processors}:") -execute_process(COMMAND ${CMAKE_CTEST_COMMAND} -j${_n_processors} - -C ${CMAKE_BUILD_TYPE} - --force-new-ctest-process - --output-on-failure - -O quicktests.log - RESULT_VARIABLE res_var) +# +# Always restrict quick tests with specified build type, but run the step +# and affinity quick tests in all available configuration: +# + +string(TOLOWER "${CMAKE_BUILD_TYPE}" _build_type) +execute_process(COMMAND ${CMAKE_CTEST_COMMAND} + -j${_n_processors} -C ${CMAKE_BUILD_TYPE} --force-new-ctest-process + -R "quick_tests/(step.debug|step.release|affinity|.*.${_build_type})" + OUTPUT_VARIABLE _output ERROR_VARIABLE _output RESULT_VARIABLE _return_value + ) +message(${_output}) -if(NOT "${res_var}" STREQUAL "0") +if(NOT "${_return_value}" STREQUAL "0") message(" *************************************************************************** +** ** ** Error: Some of the quick tests failed. ** +** ** *************************************************************************** Please scroll up or check the file tests/quick_tests/quicktests.log for the @@ -54,39 +62,31 @@ error messages. If you are unable to fix the problems, see the FAQ or write to the mailing list linked at http://www.dealii.org\n" ) - foreach(test ${ALL_TESTS}) - if (${test} MATCHES "^affinity" AND NOT EXISTS ${test}-OK) + string(REPLACE "\n" ";" _output "${_output}") + foreach(_line ${_output}) + if ("${_line}" MATCHES "affinity.*FAILED") message(" The affinity test can fail when you are linking in a library like BLAS which uses OpenMP. Even without calling any BLAS functions, OpenMP messes with the thread affinity which causes TBB to run single-threaded only. You -can fix this by exporting OMP_NUM_THREADS=1. Also see GOMP_CPU_AFFINITY +can fix this by exporting OMP_NUM_THREADS=1. Also see GOMP_CPU_AFFINITY and OMP_PROC_BIND.\n" ) endif() - if (${test} MATCHES "^step-petsc" AND NOT EXISTS ${test}-OK) + if (${_line} MATCHES "step-petsc.*FAILED") message(" Additional information about PETSc issues is available at:\nhttp://www.dealii.org/developer/external-libs/petsc.html\n" ) endif() - if (${test} MATCHES "^p4est" AND NOT EXISTS ${test}-OK) + if (${test} MATCHES "p4est.*FAILED" AND NOT EXISTS ${test}-OK) message(" The p4est test can fail if you are running an OpenMPI version before 1.5. This is a known problem and the only work around is to update to a more recent version or use a different MPI library like MPICH.\n" ) endif() - endforeach() - - # The CMake command message(SEND_ERROR ...) is, to the best of the authors' - # knowledge, the only way to set the exit status of CMake to a nonzero value. - # If we used message(SEND_ERROR ...) at the top (with the actual error - # message) then subsequent messages (i.e., the test specific help) would not - # be printed. Hence, do it down here. - message(SEND_ERROR "") - endif() -- 2.39.5