From 6c1cb39e2306799dfad3edf8ee3f7ef818976a28 Mon Sep 17 00:00:00 2001 From: tbeltzun <129868353+tbeltzun@users.noreply.github.com> Date: Wed, 27 Sep 2023 16:25:45 +0200 Subject: [PATCH] add `DNDEBUG` test case --- src/coreComponents/unitTests/CMakeLists.txt | 1 + .../unitTests/toolchain/CMakeLists.txt | 34 +++++++++++++++++++ .../unitTests/toolchain/testDebug.cpp | 29 ++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/coreComponents/unitTests/toolchain/CMakeLists.txt create mode 100644 src/coreComponents/unitTests/toolchain/testDebug.cpp diff --git a/src/coreComponents/unitTests/CMakeLists.txt b/src/coreComponents/unitTests/CMakeLists.txt index c36ec70d92a..358bb90ba8f 100644 --- a/src/coreComponents/unitTests/CMakeLists.txt +++ b/src/coreComponents/unitTests/CMakeLists.txt @@ -11,3 +11,4 @@ add_subdirectory( fileIOTests ) add_subdirectory( fluidFlowTests ) add_subdirectory( wellsTests ) add_subdirectory( wavePropagationTests ) +add_subdirectory( toolchain ) diff --git a/src/coreComponents/unitTests/toolchain/CMakeLists.txt b/src/coreComponents/unitTests/toolchain/CMakeLists.txt new file mode 100644 index 00000000000..be4ecbbf2ce --- /dev/null +++ b/src/coreComponents/unitTests/toolchain/CMakeLists.txt @@ -0,0 +1,34 @@ +# +# Specify list of tests +# + +set( gtest_geosx_tests + testDebug.cpp ) + +set( dependencyList ${parallelDeps} gtest ) + +if ( GEOSX_BUILD_SHARED_LIBS ) + set (dependencyList ${dependencyList} geosx_core ) +else() + set (dependencyList ${dependencyList} ${geosx_core_libs} ) +endif() + +# +# Add gtest C++ based tests +# +foreach(test ${gtest_geosx_tests}) + get_filename_component( test_name ${test} NAME_WE ) + + blt_add_executable( NAME ${test_name} + SOURCES ${test} + OUTPUT_DIR ${TEST_OUTPUT_DIRECTORY} + DEPENDS_ON ${dependencyList} ) + + blt_add_test( NAME ${test_name} + COMMAND ${test_name} ) + + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set_tests_properties(${test_name} PROPERTIES WILL_FAIL TRUE) + endif() + +endforeach() diff --git a/src/coreComponents/unitTests/toolchain/testDebug.cpp b/src/coreComponents/unitTests/toolchain/testDebug.cpp new file mode 100644 index 00000000000..35d93461e9a --- /dev/null +++ b/src/coreComponents/unitTests/toolchain/testDebug.cpp @@ -0,0 +1,29 @@ +/* + * ------------------------------------------------------------------------------------------------------------ + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC + * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University + * Copyright (c) 2018-2020 Total, S.A + * Copyright (c) 2020- GEOS Contributors + * All right reserved + * + * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details. + * ------------------------------------------------------------------------------------------------------------ + */ + +int main( int, char * * ) +{ + /* + * This test guards against spurious propagation of -DNDEBUG preprocessor flag (HDF5 in our case), + * which has the effect of disabling LvArray assertions: + * instead, we always check that this test fails in CMake Debug mode, whilst it should always + * pass in RelWithDebInfo or Release builds. + */ +#ifdef NDEBUG + return 0; +#else + return 1; +#endif + +}