Skip to content

Commit

Permalink
add NDEBUG test - add build_test target - fix asserts (#2721)
Browse files Browse the repository at this point in the history
* add `DNDEBUG` test case

* add `build_unittests` to build all the test targets

* implement `geos_add_test`

* enforce `CMake` consistency (tests)
  • Loading branch information
tbeltzun authored Nov 29, 2023
1 parent e064ae1 commit 5a72966
Show file tree
Hide file tree
Showing 47 changed files with 420 additions and 522 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"build": {
"dockerfile": "Dockerfile",
"args": {
"GEOS_TPL_TAG": "250-92"
"GEOS_TPL_TAG": "248-93"
}
},
"runArgs": [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ jobs:
ENABLE_HYPRE_DEVICE: CUDA
ENABLE_HYPRE: ON
ENABLE_TRILINOS: OFF
RUNS_ON: Runner_4core_16GB
RUNS_ON: Runner_8core_32GB

- name: Ubuntu CUDA (20.04, clang 10.0.0 + gcc 9.4.0, open-mpi 4.0.3, cuda-11.8.89)
BUILD_AND_TEST_CLI_ARGS: "--no-run-unit-tests --no-install-schema"
Expand Down
2 changes: 1 addition & 1 deletion integratedTests
Submodule integratedTests updated 1669 files
3 changes: 3 additions & 0 deletions scripts/ci_build_and_test_in_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ echo "Running CLI ${SCRIPT_NAME} $@"
echo "running nproc"
nproc

# docs.docker.com/config/containers/resource_constraints
# Inside the container, tools like free report the host's available swap, not what's available inside the container.
# Don't rely on the output of free or similar tools to determine whether swap is present.
echo "running free -m"
free -m

Expand Down
42 changes: 25 additions & 17 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ else()
endif()
set( CMAKE_ENABLE_EXPORTS ON )

#set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
# populated by `geos_add_test` (private list of all geos tests, keep in sync with the macro definition)
set_property( GLOBAL PROPERTY geos_tests_exe_list )

################################
# Include blt
Expand All @@ -32,27 +33,27 @@ include( cmake/blt/SetupBLT.cmake )
set( BLT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/cmake/blt/ )

# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set( CMAKE_SKIP_BUILD_RPATH FALSE )

# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib")
set( CMAKE_BUILD_WITH_INSTALL_RPATH FALSE )
set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" )
set( CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib" )

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )

# the RPATH to be used when installing, but only if it's not a system directory
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set( CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" )
endif()

# Removes -pthread from BLT CUDA libraries lists
if( ENABLE_CUDA )
set( _cuda_libraries )
unset( _cuda_libraries )
foreach( _lib ${BLT_CUDA_LIBRARIES} )
if( "${_lib}" STREQUAL "-pthread" )
list( APPEND _cuda_libraries "-lpthread" )
Expand Down Expand Up @@ -81,7 +82,7 @@ add_subdirectory( thirdparty )
################################
# Add components
################################
set( externalComponentsLinkList "" )
unset( externalComponentsLinkList )
add_subdirectory( coreComponents )
add_subdirectory( externalComponents )
add_subdirectory( main )
Expand Down Expand Up @@ -116,28 +117,28 @@ include( cmake/GeosxConfig.cmake )
################################
# Add main
################################
set( extraComponentsLinkList "" )
unset( extraComponentsLinkList )

if( ENABLE_OPENMP )
set( extraComponentsLinkList ${extraComponentsLinkList} openmp )
list( APPEND extraComponentsLinkList openmp )
endif()

if( ENABLE_CUDA )
set( extraComponentsLinkList ${extraComponentsLinkList} cuda )
list( APPEND extraComponentsLinkList cuda )
endif()

if( ENABLE_CUDA_NVTOOLSEXT )
set( extraComponentsLinkList ${extraComponentsLinkList} CUDA::nvToolsExt )
list( APPEND extraComponentsLinkList CUDA::nvToolsExt )
endif()

if( ENABLE_HIP )
set( extraComponentsLinkList ${extraComponentsLinkList} blt::hip )
list( APPEND extraComponentsLinkList blt::hip )
endif()

if ( GEOSX_BUILD_SHARED_LIBS )
set( extraComponentsLinkList ${extraComponentsLinkList} geosx_core )
list( APPEND extraComponentsLinkList geosx_core )
else()
set( extraComponentsLinkList ${extraComponentsLinkList} ${geosx_core_libs} )
list( APPEND extraComponentsLinkList ${geosx_core_libs} )
endif()

blt_add_executable( NAME geosx
Expand Down Expand Up @@ -220,7 +221,7 @@ add_custom_target( geosx_generate_install_schema
COMMENT "Generating XML schema to install"
)

if (NOT GEOSX_INSTALL_SCHEMA)
if( NOT GEOSX_INSTALL_SCHEMA )
set_target_properties(geosx_generate_install_schema PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1)
endif()

Expand All @@ -236,3 +237,10 @@ if( EXISTS "${CMAKE_SOURCE_DIR}/../integratedTests/CMakeLists.txt")
else()
message( "Could not find the integratedTests submodule" )
endif()

# the following adds a `build_test` CMake target such that running `$ make build_test test`
# builds the unit tests before running them
get_property( tmp GLOBAL PROPERTY geos_tests_exe_list )
add_custom_target( build_test COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS ${tmp} )

message( DEBUG "geos_tests: ${tmp} " )
37 changes: 36 additions & 1 deletion src/cmake/GeosxMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ macro( geosx_add_code_checks )
if( NOT DEFINED arg_EXCLUDES )
set( _sources ${_all_sources} )
else()
set( _sources )
unset( _sources )
foreach( _source ${_all_sources} )
set( _to_be_excluded FALSE )
foreach( _exclude ${arg_EXCLUDES} )
Expand All @@ -54,3 +54,38 @@ macro( geosx_add_code_checks )
endif()

endmacro( geosx_add_code_checks )

##------------------------------------------------------------------------------
## geos_add_test( NAME [name]
## COMMAND [command]
## EXECUTABLE [executable] )
##
## Adds a test to the project, remaining arguments are forwarded to `blt_add_test`
## As a side effect, uses and populates a global property named `geos_tests_exe_list`
## initialized in `src/CMakeLists.txt`.
##------------------------------------------------------------------------------
macro( geos_add_test )

set( options )
set( singleValueArgs NAME EXECUTABLE )
set( multiValueArgs COMMAND )

# Parse the arguments to the macro
cmake_parse_arguments( arg
"${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGN} )

if( NOT arg_EXECUTABLE )
list( GET arg_COMMAND 0 _test_executable )
set( arg_EXECUTABLE ${_test_executable} )
endif()

get_property( tmp GLOBAL PROPERTY geos_tests_exe_list )
list( APPEND tmp ${arg_EXECUTABLE} )
set_property( GLOBAL PROPERTY geos_tests_exe_list "${tmp}" )

message( DEBUG "arg_NAME=${arg_NAME} arg_EXECUTABLE=${arg_EXECUTABLE} arg_COMMAND=${arg_COMMAND} ARGN=${ARGN}" ) # debug

blt_add_test( NAME ${arg_NAME}
COMMAND ${arg_COMMAND} ${ARGN} )

endmacro( geos_add_test )
21 changes: 9 additions & 12 deletions src/coreComponents/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,28 @@ set( subdirs
physicsSolvers
events
mainInterface
python
)
python )

set( parallelDeps "" )
unset( parallelDeps )

if ( ENABLE_OPENMP )
set( parallelDeps ${parallelDeps} openmp )
list( APPEND parallelDeps openmp )
endif()

if ( ENABLE_CUDA )
set( parallelDeps ${parallelDeps} cuda )
list( APPEND parallelDeps cuda )
endif()

if( ENABLE_CUDA_NVTOOLSEXT )
set( parallelDeps ${parallelDeps} CUDA::nvToolsExt )
list( APPEND parallelDeps CUDA::nvToolsExt )
endif()

if( ENABLE_HIP )
set( parallelDeps ${parallelDeps} blt::hip )
list( APPEND parallelDeps blt::hip )
endif()

if( ENABLE_MPI )
set( parallelDeps ${parallelDeps} mpi )
list( APPEND parallelDeps mpi )
endif()

if ( GEOSX_BUILD_OBJ_LIBS )
Expand Down Expand Up @@ -76,17 +75,15 @@ if( GEOSX_BUILD_SHARED_LIBS AND GEOSX_BUILD_OBJ_LIBS )
blt_add_library ( NAME geosx_core
SOURCES dummy.cpp
DEPENDS_ON mainInterface physicsSolvers
SHARED TRUE
)
SHARED TRUE )

elseif( GEOSX_BUILD_SHARED_LIBS AND NOT GEOSX_BUILD_OBJ_LIBS )
message( "Building shared geosx_core library with static coreComponents, executables link to geosx_core" )
blt_combine_static_libraries( NAME geosx_core
SOURCE_LIBS ${coreLibs}
LIB_TYPE SHARED
LINK_PREPEND ${GEOSX_LINK_PREPEND_FLAG}
LINK_POSTPEND ${GEOSX_LINK_POSTPEND_FLAG}
)
LINK_POSTPEND ${GEOSX_LINK_POSTPEND_FLAG} )

elseif( NOT GEOSX_BUILD_SHARED_LIBS AND GEOSX_BUILD_OBJ_LIBS )
message( "Building object coreComponents, executables link to coreComponents" )
Expand Down
15 changes: 4 additions & 11 deletions src/coreComponents/codingUtilities/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
#
# Specify list of tests
#

set( testSources
testGeosxTraits.cpp
testStringUtilities.cpp
testParsing.cpp
)
testParsing.cpp )

set(dependencyList gtest codingUtilities ${parallelDeps} )
set( dependencyList gtest codingUtilities ${parallelDeps} )

#
# Add gtest C++ based tests
#
foreach( test ${testSources} )
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}
)
geos_add_test( NAME ${test_name}
COMMAND ${test_name} )

endforeach()
10 changes: 5 additions & 5 deletions src/coreComponents/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ set( common_sources
set( dependencyList ${parallelDeps} lvarray pugixml::pugixml RAJA chai conduit::conduit fmt::fmt )

if ( ENABLE_MKL )
set( dependencyList ${dependencyList} mkl )
list( APPEND dependencyList mkl )
endif()

if( ENABLE_CALIPER )
set( dependencyList ${dependencyList} caliper )
list( APPEND dependencyList caliper )
endif()

if( ENABLE_CALIPER )
set( dependencyList ${dependencyList} caliper )
list( APPEND dependencyList caliper )

if (TARGET adiak::adiak)
set( dependencyList ${dependencyList} adiak::adiak )
list( APPEND dependencyList adiak::adiak )
endif()

if (TARGET adiak)
set( dependencyList ${dependencyList} adiak )
list( APPEND dependencyList adiak )
endif()
endif()

Expand Down
25 changes: 9 additions & 16 deletions src/coreComponents/common/unitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
#
# Specify list of tests
#

set(gtest_geosx_tests
testDataTypes.cpp
testFixedSizeDeque.cpp
testTypeDispatch.cpp
testLifoStorage.cpp
)
set( gtest_geosx_tests
testDataTypes.cpp
testFixedSizeDeque.cpp
testTypeDispatch.cpp
testLifoStorage.cpp )

if ( ENABLE_CALIPER )
list( APPEND gtest_geosx_tests
testCaliperSmoke.cpp )
endif()

set( dependencyList ${parallelDeps} common hdf5 gtest )
#

# 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}
)
DEPENDS_ON ${dependencyList} )

blt_add_test( NAME ${test_name}
COMMAND ${test_name}
)
geos_add_test( NAME ${test_name}
COMMAND ${test_name} )

endforeach()
2 changes: 1 addition & 1 deletion src/coreComponents/constitutive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ if( ENABLE_PVTPackage )

add_subdirectory( PVTPackage )

set( dependencyList ${dependencyList} PVTPackage )
list( APPEND dependencyList PVTPackage )
endif()

blt_add_library( NAME constitutive
Expand Down
18 changes: 5 additions & 13 deletions src/coreComponents/constitutive/unitTests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#
# Specify list of tests
#

set( gtest_geosx_tests
testCompositionalProperties.cpp
testDamageUtilities.cpp
Expand All @@ -13,28 +10,23 @@ set( gtest_geosx_tests
testParticleFluidEnums.cpp
testPropertyConversions.cpp
testCubicEOS.cpp
testRachfordRice.cpp
)
testRachfordRice.cpp )

set( dependencyList gtest constitutive ${parallelDeps} )

if( ENABLE_CUDA_NVTOOLSEXT )
set( dependencyList ${dependencyList} CUDA::nvToolsExt )
list( APPEND dependencyList CUDA::nvToolsExt )
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}
)
DEPENDS_ON ${dependencyList} )

blt_add_test( NAME ${test_name}
COMMAND ${test_name}
)
geos_add_test( NAME ${test_name}
COMMAND ${test_name} )

endforeach()
Loading

0 comments on commit 5a72966

Please sign in to comment.