Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ add_subdirectory(examples)
include(CTest) #adds option BUILD_TESTING (default ON)

message(STATUS "VT_LB_TESTS_ENABLED: ${VT_LB_TESTS_ENABLED}")
if (BUILD_TESTING AND VT_TV_TESTS_ENABLED)
if (BUILD_TESTING AND VT_LB_TESTS_ENABLED)
set(CTEST_SOURCE_DIRECTORY ${SOURCE_DIR}/src)
add_custom_target(unit_tests)
add_subdirectory(tests)
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(
algo
algo/baselb algo/temperedlb algo/driver
comm
comm/MPI comm/VT
comm/MPI comm/vt
input
model
)
Expand Down
24 changes: 14 additions & 10 deletions src/vt-lb/comm/MPI/comm_mpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,7 @@ struct CommMPI {
template <typename T>
using HandleType = ClassHandle<T>;

/**
* \brief Construct a new CommMPI instance
* \param comm The MPI communicator to use (defaults to MPI_COMM_WORLD)
*/
explicit CommMPI(MPI_Comm comm = MPI_COMM_WORLD) : comm_(comm) { }

CommMPI() = default;
CommMPI(CommMPI const&) = delete;
CommMPI(CommMPI&&) = delete;
CommMPI& operator=(CommMPI const&) = delete;
Expand All @@ -194,8 +189,14 @@ struct CommMPI {
* \param argc Pointer to argument count
* \param argv Pointer to argument array
*/
void init(int& argc, char**& argv) {
MPI_Init(&argc, &argv);
void init(int& argc, char**& argv, MPI_Comm comm = MPI_COMM_NULL) {
if (comm == MPI_COMM_NULL) {
MPI_Init(&argc, &argv);
comm_ = MPI_COMM_WORLD;
} else {
interop_mode_ = true;
comm_ = comm;
}
MPI_Comm_rank(comm_, &cached_rank_);
MPI_Comm_size(comm_, &cached_size_);
initTermination();
Expand All @@ -216,8 +217,10 @@ struct CommMPI {
* \brief Finalize MPI
*/
void finalize() {
// printf("%d: Finalizing MPI\n", cached_rank_);
MPI_Finalize();
if (!interop_mode_) {
// printf("%d: Finalizing MPI\n", cached_rank_);
MPI_Finalize();
}
comm_ = MPI_COMM_NULL;
}

Expand Down Expand Up @@ -444,6 +447,7 @@ struct CommMPI {
private:
void initTermination();

bool interop_mode_ = false;
MPI_Comm comm_ = MPI_COMM_NULL;
std::list<std::tuple<MPI_Request, std::unique_ptr<char[]>>> pending_;
int next_class_index_ = 0;
Expand Down
9 changes: 7 additions & 2 deletions src/vt-lb/comm/vt/comm_vt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,13 @@

namespace vt_lb::comm {

void CommVT::init(int& argc, char**& argv) {
vt::initialize(argc, argv);
void CommVT::init(int& argc, char**& argv, MPI_Comm comm) {
if (comm == MPI_COMM_NULL) {
vt::initialize(argc, argv);
} else {
// interop mode
vt::initialize(argc, argv, &comm);
}
vt::theTerm()->addDefaultAction([this]{ terminated_ = true; });
}

Expand Down
2 changes: 1 addition & 1 deletion src/vt-lb/comm/vt/comm_vt.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct CommVT {
CommVT(vt::EpochType epoch);

public:
void init(int& argc, char**& argv);
void init(int& argc, char**& argv, MPI_Comm comm = MPI_COMM_NULL);
void finalize();
int numRanks() const;
int getRank() const;
Expand Down
216 changes: 216 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
################################################################################
# CMake for gtests #
################################################################################

option(VT_LB_EXTENDED_TESTS_ENABLED "Build the extended testing for VT" ON)
message(STATUS "VT_LB_EXTENDED_TESTS_ENABLED: ${VT_LB_EXTENDED_TESTS_ENABLED}")

set(PROJECT_TEST_CONFIG_DIR ${CMAKE_CURRENT_SOURCE_DIR}/config)
set(PROJECT_TEST_UNIT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/unit)
set(PROJECT_TEST_PERF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/perf)
set(PROJECT_GTEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/extern/googletest/googletest/include)

function(subdirlist result curdir)
file(
GLOB children
LIST_DIRECTORIES true
RELATIVE ${curdir} ${curdir}/*
)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
list(APPEND dirlist ${child})
endif()
endforeach()
set(${result} ${dirlist} PARENT_SCOPE)
endfunction()

subdirlist(
UNIT_TEST_SUBDIRS_LIST
${PROJECT_TEST_UNIT_DIR}
)

#
# Setup/add googletest CMake configuration
#

# Add dependency googletest CMake - gtest is exported via 'cxx_library'.
# Override googletest options.
set(BUILD_GMOCK OFF CACHE BOOL "Builds the googlemock subproject" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" FORCE)

if (NOT TARGET gtest)
add_subdirectory(extern/googletest)
endif()
set(GOOGLETEST_LIBRARY gtest)
#set_darma_compiler_flags(${GOOGLETEST_LIBRARY})

# Hide various options from UI-based property editors
mark_as_advanced(
BUILD_GTEST INSTALL_GTEST BUILD_SHARED_LIBS
gtest_build_samples gtest_build_tests
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
)

# Group targets, in IDEs supporting such
set_target_properties(gtest PROPERTIES FOLDER extern)
set_target_properties(gtest_main PROPERTIES FOLDER extern)

include(GoogleTest)
include(turn_on_warnings)

function(add_unit_test unit_test_name unit_test_files uses_mpi additional_args)
add_executable(
${unit_test_name}
${TEST_SOURCE_FILES}
${TEST_HEADER_FILES}
${${unit_test_files}}
)

add_dependencies(unit_tests ${unit_test_name})

target_include_directories(${unit_test_name} PRIVATE ${PROJECT_TEST_UNIT_DIR})
target_include_directories(${unit_test_name} PRIVATE ${PROJECT_GTEST_INCLUDE_DIR})

turn_on_warnings(${unit_test_name})

target_link_libraries(${unit_test_name} PUBLIC ${VT_LB_LIBRARY_NS})
target_link_libraries(${unit_test_name} PRIVATE ${GOOGLETEST_LIBRARY})

#if (vt_unity_build_enabled)
# set_target_properties(${unit_test_name} PROPERTIES UNITY_BUILD ON)
#endif()

if(uses_mpi)
foreach(PROC ${PROC_TEST_LIST})
gtest_add_tests(
TARGET ${unit_test_name}
EXTRA_ARGS ${additional_args}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
TEST_SUFFIX _proc_${PROC}
TEST_PREFIX vt-lb:
TEST_LIST ${CUR_TEST_LIST}
EXECUTE_COMMAND ${MPI_RUN_COMMAND} ${MPI_EXTRA_FLAGS_LIST} ${MPI_NUMPROC_FLAG} ${PROC}
)

set_tests_properties(
${${CUR_TEST_LIST}}
PROPERTIES TIMEOUT 60
PROCESSORS ${PROC}
FAIL_REGULAR_EXPRESSION "FAILED;should be deleted but never is;Segmentation fault"
PASS_REGULAR_EXPRESSION "PASSED"
SKIP_REGULAR_EXPRESSION "SKIPPED"
LABELS "unit_test"
)
endforeach()
else()
gtest_add_tests(
TARGET ${unit_test_name}
EXTRA_ARGS ${additional_args}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
TEST_SUFFIX _no_mpi
TEST_PREFIX vt-lb:
TEST_LIST ${CUR_TEST_LIST}
)

set_tests_properties(
${${CUR_TEST_LIST}}
PROPERTIES TIMEOUT 60
PROCESSORS 1
FAIL_REGULAR_EXPRESSION "FAILED;should be deleted but never is;Segmentation fault"
PASS_REGULAR_EXPRESSION "PASSED"
SKIP_REGULAR_EXPRESSION "SKIPPED"
LABELS "unit_test"
)
endif()

endfunction()

#
# Unit Tests
#

set(
TEST_HEADER_FILES
${PROJECT_TEST_UNIT_DIR}/test_harness.h
)

set(
TEST_SOURCE_FILES
${PROJECT_TEST_UNIT_DIR}/main.cc
)

# List of unit test files that should be excluded
set(
EXCLUDED_UNIT_TEST_FILES
)

foreach(SUB_DIR ${UNIT_TEST_SUBDIRS_LIST})
file(
GLOB
"${SUB_DIR}_UNIT_TEST_SOURCE_FILES"
RELATIVE
""
"${PROJECT_TEST_UNIT_DIR}/${SUB_DIR}/*.cc"
)

set(CUR_TEST_LIST "${SUB_DIR}_test_list")

set(UNIT_LIST_EXTENDED "")
set(UNIT_LIST_BASIC "")
set(UNIT_LIST_NOMPI "")
set(ADDITIONAL_ARGS "")

foreach (unit_test_file ${${SUB_DIR}_UNIT_TEST_SOURCE_FILES})
#message(STATUS "Considering ${unit_test_file}")

if (${unit_test_file} IN_LIST EXCLUDED_UNIT_TEST_FILES)
message(STATUS "Test file ${unit_test_file} is present on EXCLUDED_UNIT_TEST_FILES list. Skipping!")
continue()
endif()

get_filename_component(
UNIT_TEST
${unit_test_file}
NAME_WE
)

get_filename_component(
UNIT_TEST_FULL_EXTENSION
${unit_test_file}
EXT
)

# Extended tests are designated with an particular extension: *.extended.cc
if(UNIT_TEST_FULL_EXTENSION MATCHES "[.]extended[.]")
list(APPEND UNIT_LIST_EXTENDED ${unit_test_file})
else()
if(UNIT_TEST_FULL_EXTENSION MATCHES "[.]nompi[.]")
list(APPEND UNIT_LIST_NOMPI ${unit_test_file})
else()
list(APPEND UNIT_LIST_BASIC ${unit_test_file})
endif()
endif()
endforeach()

#if (vt_tv_enabled)
# list(APPEND ADDITIONAL_ARGS "--vt_tv")
# list(APPEND ADDITIONAL_ARGS "--vt_tv_config_file=${PROJECT_TEST_CONFIG_DIR}/test_vttv.yaml")
#endif()

add_unit_test("${SUB_DIR}_basic" UNIT_LIST_BASIC ON "${ADDITIONAL_ARGS}")
add_unit_test("${SUB_DIR}_nompi" UNIT_LIST_NOMPI OFF "${ADDITIONAL_ARGS}")

if (VT_LB_EXTENDED_TESTS_ENABLED)
add_unit_test("${SUB_DIR}_extended" UNIT_LIST_EXTENDED ON "${ADDITIONAL_ARGS}")
endif()
endforeach()

# Copy synthetic blocks data files to <build-dir>/tests/synthetic-blocks-data
#set(SYNTHETIC_BLOCKS_DATA_DEST "${CMAKE_BINARY_DIR}/tests/synthetic-blocks-data")
#file(MAKE_DIRECTORY ${SYNTHETIC_BLOCKS_DATA_DEST})
#file(GLOB SYNTHETIC_BLOCKS_DATA_FILES "${CMAKE_SOURCE_DIR}/tests/data/synthetic-blocks/*")
#foreach(SYNTHETIC_BLOCKS_DATA_FILE ${SYNTHETIC_BLOCKS_DATA_FILES})
# get_filename_component(FILE_NAME ${SYNTHETIC_BLOCKS_DATA_FILE} NAME)
# configure_file(${SYNTHETIC_BLOCKS_DATA_FILE} ${SYNTHETIC_BLOCKS_DATA_DEST} COPYONLY)
#endforeach()
18 changes: 18 additions & 0 deletions tests/extern/fetch-googletest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#! /bin/sh

GTEST_BRANCHTAG=release-1.12.1

# Fetch googletest from Github.
# GitHub does not support git-archive - however this endpoint works (MAR 2020)
mkdir -p googletest && rm -fr googletest/*
curl -L https://github.com/google/googletest/archive/refs/tags/$GTEST_BRANCHTAG.tar.gz \
| tar zxf - -C googletest --strip-components 1

# Remove googletest artifacts - set cmake BUILD_GMOCK=0, don't install, don't build test.
pushd googletest
rm -fr .[!.]* BUILD.bazel WORKSPACE appveyor.yml library.json platformio.ini
rm -fr ci/
rm -fr googlemock/
rm -fr googletest/test/ googletest/samples/ googletest/docs/ googletest/scripts/
rm -fr docs
popd
34 changes: 34 additions & 0 deletions tests/extern/googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Note: CMake support is community-based. The maintainers do not use CMake
# internally.

cmake_minimum_required(VERSION 3.5)

if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)

if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif (POLICY CMP0077)

project(googletest-distribution)
set(GOOGLETEST_VERSION 1.12.1)

if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

enable_testing()

include(CMakeDependentOption)
include(GNUInstallDirs)

#Note that googlemock target already builds googletest
option(BUILD_GMOCK "Builds the googlemock subproject" ON)
option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" ON)

if(BUILD_GMOCK)
add_subdirectory( googlemock )
else()
add_subdirectory( googletest )
endif()
Loading