Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code coverage test #262

Merged
merged 14 commits into from
Aug 17, 2020
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CATCH2_COVERAGE_TAG "")
if(CODE_COVERAGE)
set(CATCH2_COVERAGE_TAG "[coverage]")
JoshuaSBrown marked this conversation as resolved.
Show resolved Hide resolved
if( NOT COVERAGE_NAME)
SET(COVERAGE_NAME "coverage_reports")
endif()
Expand Down
10 changes: 9 additions & 1 deletion cmake/Lint.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,20 @@ function(lint_file SOURCE_DIR INPUT OUTPUT)
set(MKDIR_COMMAND COMMAND ${CMAKE_COMMAND} -E make_directory ${OUTPUT_DIR})
endif()

if( EXISTS ${INPUT} )
set(FILE_TO_LINT ${INPUT} )
elseif( EXISTS ${SOURCE_DIR}/${INPUT})
set(FILE_TO_LINT ${SOURCE_DIR}/${INPUT})
else()
message(WARNING "Cannot lint file ${INPUT} does not appear to exist.")
endif()

add_custom_command(
OUTPUT ${OUTPUT}
COMMAND
${PROJECT_SOURCE_DIR}/tst/style/cpplint.py
--counting=detailed
--quiet ${SOURCE_DIR}/${INPUT}
--quiet ${FILE_TO_LINT}
${MKDIR_COMMAND}
COMMAND ${CMAKE_COMMAND} -E touch ${OUTPUT}
DEPENDS ${INPUT}
Expand Down
46 changes: 25 additions & 21 deletions cmake/TestSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ endfunction()
# test output will be sent to /tst/regression/outputs/dir_cov
# test property labels: regression, mpi-no; coverage
function(setup_test_coverage dir arg)
separate_arguments(arg)
add_test( NAME regression_coverage_test:${dir} COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/run_test.py"
${arg}
--coverage
--test_dir "${CMAKE_CURRENT_SOURCE_DIR}/test_suites/${dir}"
--output_dir "${PROJECT_BINARY_DIR}/tst/regression/outputs/${dir}_cov")
set_tests_properties(regression_coverage_test:${dir} PROPERTIES LABELS "regression;coverage;mpi-no" )
record_driver("${arg}")
if( CODE_COVERAGE )
separate_arguments(arg)
add_test( NAME regression_coverage_test:${dir} COMMAND python "${CMAKE_CURRENT_SOURCE_DIR}/run_test.py"
${arg}
--coverage
--test_dir "${CMAKE_CURRENT_SOURCE_DIR}/test_suites/${dir}"
--output_dir "${PROJECT_BINARY_DIR}/tst/regression/outputs/${dir}_cov")
set_tests_properties(regression_coverage_test:${dir} PROPERTIES LABELS "regression;coverage;mpi-no" )
record_driver("${arg}")
endif()
endfunction()

# Adds test that will run in parallel with mpi
Expand All @@ -75,19 +77,21 @@ endfunction()
# test output will be sent to /tst/regression/outputs/dir_mpi_cov
# test property labels: regression, mpi-yes, coverage
function(setup_test_mpi_coverage nproc dir arg)
if( MPI_FOUND )
separate_arguments(arg)
add_test( NAME regression_mpi_coverage_test:${dir} COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/run_test.py
--coverage
--mpirun ${MPIEXEC_EXECUTABLE}
--mpirun_opts=${MPIEXEC_NUMPROC_FLAG} --mpirun_opts=${nproc}
--mpirun_opts=${MPIEXEC_PREFLAGS} ${arg}
--test_dir ${CMAKE_CURRENT_SOURCE_DIR}/test_suites/${dir}
--output_dir "${PROJECT_BINARY_DIR}/tst/regression/outputs/${dir}_mpi_cov"
)
set_tests_properties(regression_mpi_coverage_test:${dir} PROPERTIES LABELS "regression;coverage;mpi-yes" RUN_SERIAL ON )
else()
message(STATUS "MPI not found, not building coverage regression tests with mpi")
if( CODE_COVERAGE )
if( MPI_FOUND )
separate_arguments(arg)
add_test( NAME regression_mpi_coverage_test:${dir} COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/run_test.py
--coverage
--mpirun ${MPIEXEC_EXECUTABLE}
--mpirun_opts=${MPIEXEC_NUMPROC_FLAG} --mpirun_opts=${nproc}
--mpirun_opts=${MPIEXEC_PREFLAGS} ${arg}
--test_dir ${CMAKE_CURRENT_SOURCE_DIR}/test_suites/${dir}
--output_dir "${PROJECT_BINARY_DIR}/tst/regression/outputs/${dir}_mpi_cov"
)
set_tests_properties(regression_mpi_coverage_test:${dir} PROPERTIES LABELS "regression;coverage;mpi-yes" RUN_SERIAL ON )
else()
message(STATUS "MPI not found, not building coverage regression tests with mpi")
endif()
endif()
endfunction()

Expand Down
17 changes: 14 additions & 3 deletions tst/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
## the public, perform publicly and display publicly, and to permit others to do so.
##========================================================================================

list(APPEND unit_tests_SOURCES


list(APPEND unit_tests_SOURCES_PRECONFIGURED
test_taskid.cpp
test_unit_face_variables.cpp
test_unit_params.cpp
Expand All @@ -29,15 +30,25 @@ list(APPEND unit_tests_SOURCES
test_container_iterator.cpp
test_required_desired.cpp
test_error_checking.cpp

)

add_executable(unit_tests ${unit_tests_SOURCES})
# This is required, to resolve cmake variables that are present in the test files
# E.g. the @CATCH2_COVERAGE_TAG@
foreach( TEST_FILE IN LISTS unit_tests_SOURCES_PRECONFIGURED)
configure_file(${TEST_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${TEST_FILE} @ONLY)
list(APPEND unit_tests_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/${TEST_FILE}")
endforeach()

add_executable(unit_tests "${unit_tests_SOURCES}")

target_link_libraries(unit_tests PRIVATE parthenon catch2_define Kokkos::kokkos)

if (TEST_ERROR_CHECKING)
message(WARNING "\tTesting error checking. This test will FAIL.")
target_compile_definitions(unit_tests PRIVATE PARTHENON_TEST_ERROR_CHECKING)
endif()

lint_target(unit_tests)

ParseAndAddCatchTests(unit_tests)

4 changes: 2 additions & 2 deletions tst/unit/kokkos_abstraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ bool test_wrapper_4d(T loop_pattern, DevExecSpace exec_space) {
return all_same;
}

TEST_CASE("par_for loops", "[wrapper][coverage]") {
TEST_CASE("par_for loops", "[wrapper]@CATCH2_COVERAGE_TAG@") {
auto default_exec_space = DevExecSpace();

SECTION("1D loops") {
Expand Down Expand Up @@ -401,7 +401,7 @@ bool test_wrapper_nested_4d(OuterLoopPattern outer_loop_pattern,
return max_rel_err < rel_tol;
}

TEST_CASE("nested par_for loops", "[wrapper][coverage]") {
TEST_CASE("nested par_for loops", "[wrapper]@CATCH2_COVERAGE_TAG@") {
auto default_exec_space = DevExecSpace();

SECTION("3D nested loops") {
Expand Down
2 changes: 1 addition & 1 deletion tst/unit/test_container_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool intervals_intersect(const std::pair<int, int> &i1, const std::pair<int, int
}

TEST_CASE("Can pull variables from containers based on Metadata",
"[ContainerIterator][coverage]") {
"[ContainerIterator]@CATCH2_COVERAGE_TAG@") {
GIVEN("A Container with a set of variables initialized to zero") {
Container<Real> rc;
Metadata m_in({Metadata::Independent, Metadata::FillGhost});
Expand Down
3 changes: 2 additions & 1 deletion tst/unit/test_error_checking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

#include "utils/error_checking.hpp"

TEST_CASE("Parthenon Error Checking", "[ErrorChecking][Kokkos][coverage]") {
TEST_CASE("Parthenon Error Checking", \
"[ErrorChecking][Kokkos]@CATCH2_COVERAGE_TAG@") {
SECTION("PARTHENON_REQUIRE passes if condition true") {
PARTHENON_REQUIRE(true, "This shouldn't fail");
}
Expand Down
8 changes: 5 additions & 3 deletions tst/unit/test_metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@

using parthenon::Metadata;

TEST_CASE("Built-in flags are registered", "[Metadata][coverage]") {
TEST_CASE("Built-in flags are registered", \
"[Metadata]@CATCH2_COVERAGE_TAG@") {
GIVEN("The Built-In Flags") {
#define PARTHENON_INTERNAL_FOR_FLAG(name) REQUIRE(#name == Metadata::name.Name());
PARTHENON_INTERNAL_FOREACH_BUILTIN_FLAG
#undef PARTHENON_INTERNAL_FOR_FLAG
}
}

TEST_CASE("A Metadata flag is allocated", "[Metadata][coverage]") {
TEST_CASE("A Metadata flag is allocated", "[Metadata]@CATCH2_COVERAGE_TAG@") {
GIVEN("A User Flag") {
auto const f = Metadata::AllocateNewFlag("TestFlag");
// Note: `parthenon::internal` is subject to change, and so this test may
Expand All @@ -42,7 +43,8 @@ TEST_CASE("A Metadata flag is allocated", "[Metadata][coverage]") {
}
}

TEST_CASE("A Metadata struct is created", "[Metadata][coverage]") {
TEST_CASE("A Metadata struct is created", \
"[Metadata]@CATCH2_COVERAGE_TAG@") {
GIVEN("A default Metadata struct") {
Metadata m;

Expand Down
6 changes: 4 additions & 2 deletions tst/unit/test_pararrays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ void profile_wrapper_3d(T loop_pattern) {
<< std::endl;
}

TEST_CASE("ParArrayND", "[ParArrayND][Kokkos][coverage]") {
TEST_CASE("ParArrayND", \
"[ParArrayND][Kokkos]@CATCH2_COVERAGE_TAG@") {
GIVEN("A ParArrayND allocated with no label") {
ParArrayND<Real> a(PARARRAY_TEMP, 5, 4, 3, 2);
THEN("The label is the correct default") {
Expand Down Expand Up @@ -300,7 +301,8 @@ TEST_CASE("ParArrayND", "[ParArrayND][Kokkos][coverage]") {
}
}

TEST_CASE("ParArrayND with LayoutLeft", "[ParArrayND][Kokkos][LayoutLeft][coverage]") {
TEST_CASE("ParArrayND with LayoutLeft", \
"[ParArrayND][Kokkos][LayoutLeft]@CATCH2_COVERAGE_TAG@") {
GIVEN("A ParArrayND with some dimensions") {
constexpr int N1 = 2;
constexpr int N2 = 3;
Expand Down
3 changes: 2 additions & 1 deletion tst/unit/test_required_desired.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

using parthenon::ParameterInput;

TEST_CASE("Test required/desired checking from inputs", "[ParameterInput][coverage]") {
TEST_CASE("Test required/desired checking from inputs", \
"[ParameterInput]@CATCH2_COVERAGE_TAG@") {
GIVEN("A ParameterInput object already populated") {
ParameterInput in;
std::stringstream ss;
Expand Down
4 changes: 2 additions & 2 deletions tst/unit/test_taskid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

using parthenon::TaskID;

TEST_CASE("Just check everything",
"[CheckDependencies][SetFinished][equal][or][coverage]") {
TEST_CASE("Just check everything",\
"[CheckDependencies][SetFinished][equal][or]@CATCH2_COVERAGE_TAG@") {
GIVEN("Some TaskIDs") {
TaskID a(1);
TaskID b(2);
Expand Down
2 changes: 1 addition & 1 deletion tst/unit/test_unit_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ using parthenon::constants::CGS;
using parthenon::constants::PhysicalConstants;
using parthenon::constants::SI;

TEST_CASE("Physical constants", "[SI, CGS]") {
TEST_CASE("Physical constants", "[SI, CGS]@CATCH2_COVERAGE_TAG@") {
SECTION("SI units") {
PhysicalConstants<SI> pc;
REQUIRE(pc.avogadro == Approx(6.02214129e23));
Expand Down
7 changes: 5 additions & 2 deletions tst/unit/test_unit_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
// the public, perform publicly and display publicly, and to permit others to do so.
//========================================================================================

#include <iostream>
#include <string>

#include "mesh/domain.hpp"

#include <catch2/catch.hpp>

TEST_CASE("Checking IndexShape indices", "[is,ie,js,je,ks,ke][coverage]") {
TEST_CASE("Checking IndexShape indices", \
"[is,ie,js,je,ks,ke]@CATCH2_COVERAGE_TAG@") {
const parthenon::IndexDomain interior = parthenon::IndexDomain::interior;
const parthenon::IndexDomain entire = parthenon::IndexDomain::entire;
GIVEN("A 1D Index Shape") {
Expand Down Expand Up @@ -134,7 +136,8 @@ TEST_CASE("Checking IndexShape indices", "[is,ie,js,je,ks,ke][coverage]") {
}
}

TEST_CASE("Checking IndexShape cell counts", "[ncellsi,ncellsj,ncellsk][coverage]") {
TEST_CASE("Checking IndexShape cell counts", \
"[ncellsi,ncellsj,ncellsk]@CATCH2_COVERAGE_TAG@") {
const parthenon::IndexDomain interior = parthenon::IndexDomain::interior;
const parthenon::IndexDomain entire = parthenon::IndexDomain::entire;
GIVEN("A 1D Index Shape, check the numbers of cells") {
Expand Down
4 changes: 2 additions & 2 deletions tst/unit/test_unit_face_variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ using parthenon::Metadata;
using parthenon::par_for;
using parthenon::Real;

TEST_CASE("Can create a vector-valued face-variable",
"[FaceVariable][Constructor][Get][Set][coverage]") {
TEST_CASE("Can create a vector-valued face-variable",\
"[FaceVariable][Constructor][Get][Set]@CATCH2_COVERAGE_TAG@") {
GIVEN("One-copy, vector metadata, meshblock size, and vector shape") {
constexpr int blockShape[] = {14, 12, 10}; // arbitrary
std::vector<int> array_size({1}); // 1-vector
Expand Down
7 changes: 4 additions & 3 deletions tst/unit/test_unit_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@

using parthenon::Params;

TEST_CASE("Add and Get is called", "[Add,Get][coverage]") {
TEST_CASE("Add and Get is called", \
"[Add,Get]@CATCH2_COVERAGE_TAG@") {
GIVEN("A key") {
Params params;
std::string key = "test_key";
Expand All @@ -49,7 +50,7 @@ TEST_CASE("Add and Get is called", "[Add,Get][coverage]") {
}
}

TEST_CASE("reset is called", "[reset][coverage]") {
TEST_CASE("reset is called", "[reset]@CATCH2_COVERAGE_TAG@") {
GIVEN("A key is added") {
Params params;
std::string key = "test_key";
Expand All @@ -62,7 +63,7 @@ TEST_CASE("reset is called", "[reset][coverage]") {
}
}

TEST_CASE("when hasKey is called", "[hasKey][coverage]") {
TEST_CASE("when hasKey is called", "[hasKey]@CATCH2_COVERAGE_TAG@") {
GIVEN("A key is added") {
Params params;
std::string key = "test_key";
Expand Down