From 7a3ba6027b29d98add56693ec8b43012b83263b9 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Thu, 1 Aug 2024 17:38:12 -0400 Subject: [PATCH] add option to skip death tests for use with valgrind checking of unit tests --- doc/src/Build_development.rst | 7 ++++++- unittest/CMakeLists.txt | 5 +++++ unittest/testing/core.h | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/src/Build_development.rst b/doc/src/Build_development.rst index 8e103b089a..8dd4a6f874 100644 --- a/doc/src/Build_development.rst +++ b/doc/src/Build_development.rst @@ -153,7 +153,12 @@ development headers to compile (if those are not found locally a recent version of that library will be downloaded and compiled along with LAMMPS and the test programs) and will download and compile a specific version of the `GoogleTest `_ C++ -test framework that is used to implement the tests. +test framework that is used to implement the tests. Those unit tests +may be combined with memory access and leak checking with valgrind +(see below for how to enabled it). In that case, running so-called +death tests will create a lot of false positives and thus they can be +disabled by configuring compilation with the additional setting +``-D SKIP_DEATH_TESTS=on``. .. admonition:: Software version and LAMMPS configuration requirements :class: note diff --git a/unittest/CMakeLists.txt b/unittest/CMakeLists.txt index bf4c6b50a8..7c94cad4e3 100644 --- a/unittest/CMakeLists.txt +++ b/unittest/CMakeLists.txt @@ -28,6 +28,11 @@ add_library(GTest::GMock ALIAS gmock) add_library(GTest::GTestMain ALIAS gtest_main) add_library(GTest::GMockMain ALIAS gmock_main) +option(SKIP_DEATH_TESTS "Do not run 'death tests' to reduce false positives in valgrind" OFF) +mark_as_advanced(SKIP_DEATH_TESTS) +if(SKIP_DEATH_TESTS) + add_compile_definitions(LAMMPS_SKIP_DEATH_TESTS) +endif() # import foreach(_FLAG ${CMAKE_TUNE_FLAGS}) add_compile_options(${_FLAG}) diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 79a2560fae..a6687003b5 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -32,6 +32,12 @@ using LAMMPS_NS::LAMMPSException; using ::testing::ContainsRegex; +#if defined(LAMMPS_SKIP_DEATH_TESTS) +#define TEST_FAILURE(errmsg, ...) \ + { \ + ; \ + } +#else #define TEST_FAILURE(errmsg, ...) \ { \ ::testing::internal::CaptureStdout(); \ @@ -39,6 +45,7 @@ using ::testing::ContainsRegex; auto mesg = ::testing::internal::GetCapturedStdout(); \ ASSERT_THAT(mesg, ContainsRegex(errmsg)); \ } +#endif // whether to print verbose output (i.e. not capturing LAMMPS screen output). extern bool verbose;