Skip to content

Commit

Permalink
Merge pull request #50 from lanl/bkk_testing
Browse files Browse the repository at this point in the history
Revise testing system to make it easier to add new tests
  • Loading branch information
Yurlungur authored Aug 28, 2024
2 parents c7aa009 + 63f1972 commit b22d992
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 19 deletions.
11 changes: 11 additions & 0 deletions doc/sphinx/src/developing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ internal tests will not be run automatically. So when the code is
ready for merge, you must ask a project maintainer to trigger the
remaining tests for you.

Tests
-------

``ports-of-call`` uses the `Catch2`_ unit testing infrastructure,
v3. To add a test, add a new ``cpp`` file in the ``test`` directory
that implements your ``catch2`` scenarios and/or test cases and then
add it to the ``target_sources`` line at the bottom of
``test/CMakeLists.txt``.

.. _Catch2: https://github.com/catchorg/Catch2

Expectations for code review
-----------------------------

Expand Down
22 changes: 18 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2021. Triad National Security, LLC. All rights reserved. This
# © 2024. Triad National Security, LLC. All rights reserved. This
# program was produced under U.S. Government contract 89233218CNA000001
# for Los Alamos National Laboratory (LANL), which is operated by Triad
# National Security, LLC for the U.S. Department of Energy/National
Expand All @@ -10,7 +10,21 @@
# prepare derivative works, distribute copies to the public, perform
# publicly and display publicly, and to permit others to do so.

find_package(Catch2 REQUIRED)
if(NOT TARGET Catch2::Catch2)
find_package(Catch2 QUIET)
if(NOT Catch2_FOUND)
message(STATUS "Fetching Catch2 as needed")
# idiomatic FetchContent
include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
# or later is fine too
GIT_TAG v3.0.1)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/contrib)
endif()
endif()

# this interface target is to collect
# compile/link options for the test
Expand All @@ -26,9 +40,8 @@ if (PORTABILITY_STRATEGY_KOKKOS)
endif()

target_link_libraries(portsofcall_iface INTERFACE Catch2::Catch2)
# add unit tests
add_executable(test_portsofcall test_portsofcall.cpp)

add_executable(test_portsofcall test_main.cpp)
target_link_libraries(test_portsofcall
PRIVATE
ports-of-call::ports-of-call
Expand All @@ -38,3 +51,4 @@ target_link_libraries(test_portsofcall
include(Catch)
catch_discover_tests(test_portsofcall)

target_sources(test_portsofcall PRIVATE test_portability.cpp)
32 changes: 32 additions & 0 deletions test/test_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//------------------------------------------------------------------------------
// © 2024. Triad National Security, LLC. All rights reserved. This
// program was produced under U.S. Government contract 89233218CNA000001
// for Los Alamos National Laboratory (LANL), which is operated by Triad
// National Security, LLC for the U.S. Department of Energy/National
// Nuclear Security Administration. All rights in the program are
// reserved by Triad National Security, LLC, and the U.S. Department of
// Energy/National Nuclear Security Administration. The Government is
// granted for itself and others acting on its behalf a nonexclusive,
// paid-up, irrevocable worldwide license in this material to reproduce,
// prepare derivative works, distribute copies to the public, perform
// publicly and display publicly, and to permit others to do so.
//------------------------------------------------------------------------------

#include <catch2/catch_session.hpp>
#include <ports-of-call/portability.hpp>

#ifdef PORTABILITY_STRATEGY_KOKKOS
#include <Kokkos_Core.hpp>
#endif

int main(int argc, char *argv[]) {
#ifdef PORTABILITY_STRATEGY_KOKKOS
Kokkos::initialize();
#endif
int result;
{ result = Catch::Session().run(argc, argv); }
#ifdef PORTABILITY_STRATEGY_KOKKOS
Kokkos::finalize();
#endif
return result;
}
19 changes: 4 additions & 15 deletions test/test_portsofcall.cpp → test/test_portability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#include <ports-of-call/portable_arrays.hpp>
#include <vector>

#define CATCH_CONFIG_RUNNER
#include "catch2/catch.hpp"
#ifndef CATCH_CONFIG_FAST_COMPILE
#define CATCH_CONFIG_FAST_COMPILE
#include <catch2/catch_test_macros.hpp>
#endif

TEST_CASE("EXECUTION_IS_HOST is set correctly", "[PortsOfCall]") {
// testing this is maybe nontrivial?
Expand Down Expand Up @@ -130,16 +132,3 @@ TEST_CASE("portableCopy works with all portability strategies", "[portableCopy]"
// free device memory
PORTABLE_FREE(a);
}

int main(int argc, char *argv[]) {

#ifdef PORTABILITY_STRATEGY_KOKKOS
Kokkos::initialize();
#endif
int result;
{ result = Catch::Session().run(argc, argv); }
#ifdef PORTABILITY_STRATEGY_KOKKOS
Kokkos::finalize();
#endif
return result;
}

0 comments on commit b22d992

Please sign in to comment.