Skip to content

Commit

Permalink
Merge pull request #271 from fnalacceleratormodeling/catch2_v3
Browse files Browse the repository at this point in the history
migrate tests to Catch2v3
  • Loading branch information
Sajid Ali authored Apr 29, 2024
2 parents ee24758 + fedaf1e commit 6c56c36
Show file tree
Hide file tree
Showing 321 changed files with 4,001 additions and 119,585 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/macos-clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env:

jobs:
build-and-test:
runs-on: macos-13
runs-on: macos-14

steps:
- name: Cancel Previous runs
Expand Down Expand Up @@ -62,9 +62,11 @@ jobs:

- name: CMake
run: |
uname -a
source ${{github.workspace}}/synergia-env/bin/activate
cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
-DGSV=DOUBLE \
-DCMAKE_PREFIX_PATH=$(brew --prefix libomp) \
-DPython_EXECUTABLE=${{github.workspace}}/synergia-env/bin/python${{env.PYTHON_VERSION}} \
-DENABLE_KOKKOS_BACKEND=OpenMP -DBUILD_PYTHON_BINDINGS=on -DBUILD_EXAMPLES=off -GNinja
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/macos-gcc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:

jobs:
build-and-test:
runs-on: macos-13
runs-on: macos-14

steps:
- name: Cancel Previous runs
Expand Down Expand Up @@ -49,11 +49,12 @@ jobs:
- name: CMake
run: |
uname -a
source ${{github.workspace}}/synergia-env/bin/activate
cmake -B ${{github.workspace}}/build \
-DCMAKE_OSX_ARCHITECTURES="x86_64" \
-DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 \
-DCMAKE_C_COMPILER=gcc-13 -DCMAKE_CXX_COMPILER=g++-13 \
-DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENABLE_KOKKOS_BACKEND=OpenMP \
-DGSV=DOUBLE \
-DPython_EXECUTABLE=${{github.workspace}}/synergia-env/bin/python${{env.PYTHON_VERSION}} \
-DBUILD_PYTHON_BINDINGS=on -DBUILD_EXAMPLES=off -GNinja
Expand Down
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
enable_testing()

# project specific cmake modules
set(CMAKE_MODULE_PATH "${SYNERGIA3_SOURCE_DIR}/CMake")
Expand Down Expand Up @@ -229,6 +228,24 @@ if(Kokkos_VERSION LESS 4.0.00)
message(FATAL_ERROR "Need at least Kokkos 4.0.00!")
endif()

# Catch2-v3 for testing! This has to happen after $kokkos_libs is defined!
if(USE_EXTERNAL_CATCH2)
find_package(Catch2 3 REQUIRED CONFIG)
message(STATUS "Using external catch2-v3")
else()
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.5.4)
FetchContent_MakeAvailable(Catch2)
endif()
set(testing_libs
Catch2::Catch2 ${kokkos_libs} MPI::MPI_C
$<$<STREQUAL:${BUILD_FD_SPACE_CHARGE_SOLVER},ON>:PkgConfig::PETSC>)
set(test_main "${CMAKE_SOURCE_DIR}/src/synergia/utils/catch_test_main.cc")
enable_testing()

# HDF5
set(HDF5_PREFER_PARALLEL true)
find_package(HDF5 REQUIRED)
Expand Down
186 changes: 186 additions & 0 deletions cmake_log
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
-- The CXX compiler identification is Clang 17.0.6
-- The C compiler identification is Clang 17.0.6
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Users/sasyed/Documents/packages/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/llvm-17.0.6-uzrfikeehxbzxp3x3twl6wjnh53hpvmr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Users/sasyed/Documents/packages/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/llvm-17.0.6-uzrfikeehxbzxp3x3twl6wjnh53hpvmr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Preparing to install Synergia3 version: 2024.04.17-06b47c68c
-- ENABLE_KOKKOS_BACKEND is OpenMP
-- Adding SYNERGIA_ENABLE_OPENMP to compiler definiions
-- Using clang++
-- Found PkgConfig: /Users/sasyed/Documents/packages/spack/var/spack/environments/synergia-debug/.spack-env/view/bin/pkg-config (found version "1.9.5")
-- Checking for one of the modules 'PETSc>=3.19.0'
-- Found PETSc version 3.21.0
-- Found MPI_C: /Users/sasyed/Documents/packages/spack/var/spack/environments/synergia-debug/.spack-env/view/lib/libmpi.dylib (found version "4.0")
-- Found MPI_CXX: /Users/sasyed/Documents/packages/spack/var/spack/environments/synergia-debug/.spack-env/view/lib/libmpicxx.dylib (found version "4.0")
-- Found MPI: TRUE (found version "4.0") found components: C CXX
-- MPI_VERSION is:
-- Found OpenMP_C: -fopenmp=libomp (found version "5.1")
-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.1")
-- Found OpenMP: TRUE (found version "5.1")
-- Found OpenMP_C: -fopenmp=libomp (found version "5.1")
-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.1")
-- Enabled Kokkos devices: OPENMP;SERIAL
-- Using external installation of kokkos
-- Using Kokkos version: 4.3.0
-- Performing Test HAVE_FLAG__ffile_prefix_map__Users_sasyed_Documents_packages_synergia2_build_debug__deps_catch2_src__
-- Performing Test HAVE_FLAG__ffile_prefix_map__Users_sasyed_Documents_packages_synergia2_build_debug__deps_catch2_src__ - Success
-- Found HDF5: hdf5-shared (found version "1.14.3")
-- Using parallel hdf5
-- Building openPMD I/O capabilities
-- fetching OpenPMD
-- Found MPI: TRUE (found version "4.0") found components: CXX
CMake Deprecation Warning at build_debug/_deps/openpmd-src/share/openPMD/thirdParty/json/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.

Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.


-- Using the single-header code from /Users/sasyed/Documents/packages/synergia2/build_debug/_deps/openpmd-src/share/openPMD/thirdParty/json/single_include/
-- nlohmann-json: Using INTERNAL version '3.9.1'
CMake Deprecation Warning at build_debug/_deps/openpmd-src/share/openPMD/thirdParty/toml11/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.

Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.


-- toml11: Using INTERNAL version '3.7.1'
-- Found HDF5: hdf5-shared (found version "1.14.3") found components: C
CMake Deprecation Warning at build_debug/_deps/openpmd-src/share/openPMD/cmake/FindADIOS.cmake:91 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.

Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
Call Stack (most recent call first):
build_debug/_deps/openpmd-src/CMakeLists.txt:384 (find_package)


-- Could NOT find ADIOS2 (missing: ADIOS2_DIR)
-- Found Python: /Users/sasyed/Documents/packages/spack/opt/spack/darwin-sonoma-m1/clang-17.0.6/python-3.11.7-znr5l76khnnq5dt4mm4fobxdqeozzbcw/bin/python3.11 (found version "3.11.7") found components: Interpreter Development.Module
CMake Deprecation Warning at build_debug/_deps/openpmd-src/share/openPMD/thirdParty/pybind11/CMakeLists.txt:8 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.

Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.


-- pybind11 v2.10.1
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- Performing Test HAS_FLTO_THIN
-- Performing Test HAS_FLTO_THIN - Success
-- pybind11: Using INTERNAL version 2.10.1
-- Python LTO/IPO: ON

openPMD build configuration:
library Version: 0.15.2
openPMD Standard: 1.1.0
C++ Compiler: Clang 17.0.6
/Users/sasyed/Documents/packages/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/llvm-17.0.6-uzrfikeehxbzxp3x3twl6wjnh53hpvmr/bin/clang++

Installation: OFF

Build Type: Debug
Library: static
CLI Tools: OFF
Examples: OFF
Testing: OFF
Invasive Tests: OFF
Internal VERIFY: ON
Build Options:
MPI: ON
HDF5: ON
ADIOS1: OFF
ADIOS2: OFF
PYTHON: ON
CUDA_EXAMPLES: OFF

-- Found GSL: /Users/sasyed/Documents/packages/spack/var/spack/environments/synergia-debug/.spack-env/view/include (found version "2.7.1")
-- Found FFTW3: /Users/sasyed/Documents/packages/spack/var/spack/environments/synergia-debug/.spack-env/view/lib/libfftw3.dylib
-- Using external cereal with cmake configuration from /Users/sasyed/Documents/packages/spack/var/spack/environments/synergia-debug/.spack-env/view/lib/cmake/cereal
-- Building python bindings
-- Found Python: /Users/sasyed/Documents/packages/spack/opt/spack/darwin-sonoma-m1/clang-17.0.6/python-3.11.7-znr5l76khnnq5dt4mm4fobxdqeozzbcw/bin/python3.11 (found version "3.11.7") found components: Interpreter Development Development.Module Development.Embed
-- Using external pybind11
-- Simple timer 2 profiling enabled
-- Particle array padding disabled
-- using double for gsvector
-- Configuring Eigen3 for use in host routines.
-- Performing Test standard_math_library_linked_to_automatically
-- Performing Test standard_math_library_linked_to_automatically - Success
-- Standard libraries to link to explicitly: none
-- Performing Test COMPILER_SUPPORT_WERROR
-- Performing Test COMPILER_SUPPORT_WERROR - Success
-- Performing Test COMPILER_SUPPORT_pedantic
-- Performing Test COMPILER_SUPPORT_pedantic - Success
-- Performing Test COMPILER_SUPPORT_Wall
-- Performing Test COMPILER_SUPPORT_Wall - Success
-- Performing Test COMPILER_SUPPORT_Wextra
-- Performing Test COMPILER_SUPPORT_Wextra - Success
-- Performing Test COMPILER_SUPPORT_Wundef
-- Performing Test COMPILER_SUPPORT_Wundef - Success
-- Performing Test COMPILER_SUPPORT_Wcastalign
-- Performing Test COMPILER_SUPPORT_Wcastalign - Success
-- Performing Test COMPILER_SUPPORT_Wcharsubscripts
-- Performing Test COMPILER_SUPPORT_Wcharsubscripts - Success
-- Performing Test COMPILER_SUPPORT_Wnonvirtualdtor
-- Performing Test COMPILER_SUPPORT_Wnonvirtualdtor - Success
-- Performing Test COMPILER_SUPPORT_Wunusedlocaltypedefs
-- Performing Test COMPILER_SUPPORT_Wunusedlocaltypedefs - Success
-- Performing Test COMPILER_SUPPORT_Wpointerarith
-- Performing Test COMPILER_SUPPORT_Wpointerarith - Success
-- Performing Test COMPILER_SUPPORT_Wwritestrings
-- Performing Test COMPILER_SUPPORT_Wwritestrings - Success
-- Performing Test COMPILER_SUPPORT_Wformatsecurity
-- Performing Test COMPILER_SUPPORT_Wformatsecurity - Success
-- Performing Test COMPILER_SUPPORT_Wshorten64to32
-- Performing Test COMPILER_SUPPORT_Wshorten64to32 - Success
-- Performing Test COMPILER_SUPPORT_Wlogicalop
-- Performing Test COMPILER_SUPPORT_Wlogicalop - Failed
-- Performing Test COMPILER_SUPPORT_Wenumconversion
-- Performing Test COMPILER_SUPPORT_Wenumconversion - Success
-- Performing Test COMPILER_SUPPORT_Wcpp11extensions
-- Performing Test COMPILER_SUPPORT_Wcpp11extensions - Success
-- Performing Test COMPILER_SUPPORT_Wdoublepromotion
-- Performing Test COMPILER_SUPPORT_Wdoublepromotion - Success
-- Performing Test COMPILER_SUPPORT_Wshadow
-- Performing Test COMPILER_SUPPORT_Wshadow - Success
-- Performing Test COMPILER_SUPPORT_Wnopsabi
-- Performing Test COMPILER_SUPPORT_Wnopsabi - Success
-- Performing Test COMPILER_SUPPORT_Wnovariadicmacros
-- Performing Test COMPILER_SUPPORT_Wnovariadicmacros - Success
-- Performing Test COMPILER_SUPPORT_Wnolonglong
-- Performing Test COMPILER_SUPPORT_Wnolonglong - Success
-- Performing Test COMPILER_SUPPORT_fnochecknew
-- Performing Test COMPILER_SUPPORT_fnochecknew - Success
-- Performing Test COMPILER_SUPPORT_fnocommon
-- Performing Test COMPILER_SUPPORT_fnocommon - Failed
-- Performing Test COMPILER_SUPPORT_fstrictaliasing
-- Performing Test COMPILER_SUPPORT_fstrictaliasing - Failed
-- Performing Test COMPILER_SUPPORT_wd981
-- Performing Test COMPILER_SUPPORT_wd981 - Failed
-- Performing Test COMPILER_SUPPORT_wd2304
-- Performing Test COMPILER_SUPPORT_wd2304 - Failed
-- Performing Test COMPILER_SUPPORT_OPENMP
-- Performing Test COMPILER_SUPPORT_OPENMP - Success
-- The Fortran compiler identification is unknown
-- Found unsuitable Qt version "" from NOTFOUND
-- Qt4 not found, so disabling the mandelbrot and opengl demos
-- Could NOT find CLANG_FORMAT: Found unsuitable version "17.0.6", but required is exact version "9" (found /Users/sasyed/Documents/packages/spack/opt/spack/darwin-sonoma-m1/apple-clang-15.0.0/llvm-17.0.6-uzrfikeehxbzxp3x3twl6wjnh53hpvmr/bin/clang-format)
--
-- Configured Eigen 3.4.90
--
-- Configuring done (16.3s)
-- Generating done (0.4s)
-- Build files have been written to: /Users/sasyed/Documents/packages/synergia2/build_debug
13 changes: 7 additions & 6 deletions src/synergia/bunch/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
add_executable(test_bunch_traits test_bunch_traits.cc)
target_link_libraries(test_bunch_traits ${kokkos_libs})
add_executable(test_bunch_traits test_bunch_traits.cc ${test_main})
target_link_libraries(test_bunch_traits PRIVATE synergia_bunch ${testing_libs})
add_mpi_test(test_bunch_traits 1)

add_executable(test_bunch test_bunch.cc)
target_link_libraries(test_bunch synergia_bunch synergia_test_main)
add_executable(test_bunch test_bunch.cc ${test_main})
target_link_libraries(test_bunch PRIVATE synergia_bunch ${testing_libs})
add_mpi_test(test_bunch 1)

add_executable(test_bunch_particles test_bunch_particles.cc)
target_link_libraries(test_bunch_particles synergia_bunch synergia_test_main)
add_executable(test_bunch_particles test_bunch_particles.cc ${test_main})
target_link_libraries(test_bunch_particles PRIVATE synergia_bunch
${testing_libs})
add_mpi_test(test_bunch_particles 1)

if(BUILD_PYTHON_BINDINGS)
Expand Down
16 changes: 10 additions & 6 deletions src/synergia/bunch/tests/test_bunch.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#include "synergia/bunch/bunch.h"
#include "synergia/bunch/bunch_particles.h"
#include "synergia/foundation/physical_constants.h"
#include "synergia/utils/catch.hpp"


#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>

#include <Kokkos_Core.hpp>
#include <Kokkos_NumericTraits.hpp>
#include <Kokkos_Random.hpp>

#include "synergia/bunch/bunch.h"
#include "synergia/bunch/bunch_particles.h"
#include "synergia/foundation/physical_constants.h"

constexpr double mass = 100.0;
constexpr double total_energy = 125.0;
constexpr int total_num = 100;
Expand Down Expand Up @@ -42,9 +46,9 @@ TEST_CASE("Bunch", "[Bunch]")
CHECK(p2(1, 6) == 124);
CHECK(p2(4, 6) == 127);

CHECK(bunch.get_real_num() == Approx(1e13));
REQUIRE_THAT(bunch.get_real_num(), Catch::Matchers::WithinRel(1e13));
bunch.set_real_num(1.2e13);
CHECK(bunch.get_real_num() == Approx(1.2e13));
REQUIRE_THAT(bunch.get_real_num(), Catch::Matchers::WithinRel(1.2e13));
}

#if defined SYNERGIA_HAVE_OPENPMD
Expand Down
3 changes: 2 additions & 1 deletion src/synergia/bunch/tests/test_bunch_particles.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "synergia/utils/catch.hpp"

#include <catch2/catch_test_macros.hpp>

#include "synergia/bunch/bunch_particles.h"

Expand Down
19 changes: 8 additions & 11 deletions src/synergia/bunch/tests/test_bunch_traits.cc
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@
#define CATCH_CONFIG_MAIN
#include "synergia/utils/catch.hpp"
#include <catch2/catch_test_macros.hpp>

#include <Kokkos_Core.hpp>

#include <map>
#include <vector>
#include <memory>
#include <type_traits>
#include <vector>

struct TinyBunch
{
explicit TinyBunch(int s) : size(s) { }
struct TinyBunch {
explicit TinyBunch(int s) : size(s) {}

TinyBunch(TinyBunch const&) = delete;
TinyBunch(TinyBunch &&) = default;
TinyBunch(TinyBunch&&) = default;

int size;
Kokkos::View<double*> particles;
std::map<std::string, std::unique_ptr<int>> diags;
//std::unique_ptr<int> pi;
// std::unique_ptr<int> pi;
};

static_assert(std::is_move_constructible<TinyBunch>::value,
"TinyBunch isn't move constructible");
"TinyBunch isn't move constructible");

TEST_CASE("Bunch traits", "[Bunch]")
{
CHECK( true );
CHECK(true);

std::vector<TinyBunch> bunches;
bunches.emplace_back(3);
}

Loading

0 comments on commit 6c56c36

Please sign in to comment.