Skip to content

Commit

Permalink
Upgrade to Catch2 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Jan 10, 2025
1 parent 7c3e164 commit 7eaf5c2
Show file tree
Hide file tree
Showing 36 changed files with 54 additions and 89 deletions.
5 changes: 2 additions & 3 deletions c/parallel/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

#include <iostream>

#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>
#include <catch2/catch_session.hpp>

int device_guard(int device_id)
{
Expand All @@ -40,7 +39,7 @@ int main(int argc, char* argv[])
int device_id{};

// Build a new parser on top of Catch's
using namespace Catch::clara;
using namespace Catch::Clara;
auto cli = session.cli() | Opt(device_id, "device")["-d"]["--device"]("device id to use");
session.cli(cli);

Expand Down
4 changes: 3 additions & 1 deletion c/parallel/test/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include <type_traits>
#include <vector>

#include <catch2/catch.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators_all.hpp>
#include <cccl/c/reduce.h>
#include <nvrtc.h>

Expand Down
12 changes: 4 additions & 8 deletions c2h/include/c2h/catch2_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,9 @@
//! executable, this header is included into each test. On the other hand, when all the tests are compiled into a single
//! executable, this header is excluded from the tests and included into catch2_runner.cpp

#ifdef CUB_CONFIG_MAIN
# define CATCH_CONFIG_RUNNER
#endif

#include <catch2/catch.hpp>
#include <catch2/catch_session.hpp>

#if defined(CUB_CONFIG_MAIN)
#ifdef CUB_CONFIG_MAIN
# if THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
# include <c2h/catch2_runner_helper.h>

Expand All @@ -59,7 +55,7 @@ int main(int argc, char* argv[])
int device_id{};

// Build a new parser on top of Catch's
using namespace Catch::clara;
using namespace Catch::Clara;
auto cli = session.cli() | Opt(device_id, "device")["-d"]["--device"]("device id to use");
session.cli(cli);

Expand All @@ -73,4 +69,4 @@ int main(int argc, char* argv[])
# endif // THRUST_DEVICE_SYSTEM == THRUST_DEVICE_SYSTEM_CUDA
return session.run(argc, argv);
}
#endif
#endif // CUB_CONFIG_MAIN
17 changes: 11 additions & 6 deletions c2h/include/c2h/catch2_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ _CCCL_NV_DIAG_SUPPRESS(177) // catch2 may contain unused variables
#include <c2h/test_util_vec.h>
#include <c2h/utility.h>
#include <c2h/vector.h>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators_all.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_vector.hpp>

#ifndef VAR_IDX
# define VAR_IDX 0
Expand Down Expand Up @@ -110,11 +115,11 @@ std::vector<T> to_vec(std::vector<T> const& vec)
}
} // namespace detail

#define REQUIRE_APPROX_EQ(ref, out) \
{ \
auto vec_ref = detail::to_vec(ref); \
auto vec_out = detail::to_vec(out); \
REQUIRE_THAT(vec_ref, Catch::Approx(vec_out)); \
#define REQUIRE_APPROX_EQ(ref, out) \
{ \
auto vec_ref = detail::to_vec(ref); \
auto vec_out = detail::to_vec(out); \
REQUIRE_THAT(vec_ref, Catch::Matchers::Approx(vec_out)); \
}

namespace detail
Expand All @@ -140,7 +145,7 @@ struct bitwise_equal

// Catch2 Matcher that calls `std::equal` with a default-constructable custom predicate
template <typename Range, typename Pred>
struct CustomEqualsRangeMatcher : Catch::MatcherBase<Range>
struct CustomEqualsRangeMatcher : Catch::Matchers::MatcherBase<Range>
{
CustomEqualsRangeMatcher(Range const& range)
: range{range}
Expand Down
2 changes: 1 addition & 1 deletion cmake/CCCLGetDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endmacro()

macro(cccl_get_catch2)
include("${_cccl_cpm_file}")
CPMAddPackage("gh:catchorg/Catch2@2.13.9")
CPMAddPackage("gh:catchorg/Catch2@3.8.0")
endmacro()

macro(cccl_get_fmt)
Expand Down
5 changes: 2 additions & 3 deletions cub/benchmarks/nvbench_helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ if (CUB_ENABLE_NVBENCH_HELPER_TESTS)
test/gen_range.cu
test/gen_entropy.cu
test/gen_uniform_distribution.cu
test/gen_power_law_distribution.cu
test/main.cpp)
test/gen_power_law_distribution.cu)
cccl_configure_target(${nvbench_helper_test_target} DIALECT 17)
target_link_libraries(${nvbench_helper_test_target} PRIVATE nvbench_helper Catch2::Catch2 Boost::math)
target_link_libraries(${nvbench_helper_test_target} PRIVATE nvbench_helper Catch2::Catch2WithMain Boost::math)
if ("${device_system}" STREQUAL "cpp")
target_compile_definitions(${nvbench_helper_test_target} PRIVATE THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CPP)
endif()
Expand Down
3 changes: 2 additions & 1 deletion cub/benchmarks/nvbench_helper/test/gen_entropy.cu
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
#include <algorithm>
#include <array>

#include <catch2/catch.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <nvbench_helper.cuh>

template <class T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

#include <boost/math/statistics/anderson_darling.hpp>
#include <boost/math/statistics/univariate_statistics.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <nvbench_helper.cuh>

bool is_normal(thrust::host_vector<double> data)
Expand Down
3 changes: 2 additions & 1 deletion cub/benchmarks/nvbench_helper/test/gen_range.cu
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

#include <limits>

#include <catch2/catch.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/generators/catch_generators_all.hpp>
#include <nvbench_helper.cuh>

using types =
Expand Down
2 changes: 1 addition & 1 deletion cub/benchmarks/nvbench_helper/test/gen_seed.cu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <thrust/device_vector.h>
#include <thrust/equal.h>

#include <catch2/catch.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <nvbench_helper.cuh>

using types =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
#include <map>

#include <boost/math/distributions/chi_squared.hpp>
#include <catch2/catch.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators_all.hpp>
#include <nvbench_helper.cuh>

template <typename T>
Expand Down
29 changes: 0 additions & 29 deletions cub/benchmarks/nvbench_helper/test/main.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include <cstdint>

#include "catch2/catch.hpp"
#include "catch2_test_launch_helper.h"
#include <c2h/catch2_test_helper.h>

Expand Down
1 change: 0 additions & 1 deletion cub/test/catch2_test_vsmem.cu
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <cub/util_type.cuh>
#include <cub/util_vsmem.cuh>

#include "catch2/catch.hpp"
#include "catch2_test_launch_helper.h"
#include <c2h/catch2_test_helper.h>

Expand Down
2 changes: 1 addition & 1 deletion cub/test/insert_nested_NVTX_range_guard.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <cstdio>
#include <cstdlib>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

#if defined(__cpp_inline_variables)
inline thread_local bool entered = false;
Expand Down
3 changes: 2 additions & 1 deletion cub/test/thread_reduce/catch2_test_thread_reduce.cu
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "c2h/custom_type.h"
#include "c2h/extended_types.h"
#include "c2h/generators.h"
#include <catch2/matchers/catch_matchers_floating_point.hpp>

/***********************************************************************************************************************
* Thread Reduce Wrapper Kernels
Expand Down Expand Up @@ -285,7 +286,7 @@ _CCCL_TEMPLATE(typename T)
_CCCL_REQUIRES((::cuda::std::is_floating_point<T>::value))
void verify_results(const T& expected_data, const T& test_results)
{
REQUIRE(expected_data == Approx(test_results).epsilon(0.05));
REQUIRE_THAT(expected_data, Catch::Matchers::WithinRel(test_results, T{0.05}));
}

_CCCL_TEMPLATE(typename T)
Expand Down
6 changes: 1 addition & 5 deletions cudax/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ find_package(Thrust ${cudax_VERSION} EXACT CONFIG
)
thrust_create_target(cudax.test.thrust)

add_library(catch2_main STATIC catch2_helpers/catch2_main.cpp)
target_link_libraries(catch2_main PUBLIC Catch2::Catch2)

## cudax_add_test
#
# Add a catch2 test executable and register it with ctest.
Expand All @@ -34,8 +31,7 @@ function(cudax_add_catch2_test target_name_var test_name cn_target) # ARGN=test
target_link_libraries(${test_target} PRIVATE
${cn_target}
cudax.test.thrust
Catch2::Catch2
catch2_main
Catch2::Catch2WithMain
)
target_compile_options(${test_target} PRIVATE
"-DLIBCUDACXX_ENABLE_EXPERIMENTAL_MEMORY_RESOURCE"
Expand Down
2 changes: 1 addition & 1 deletion cudax/test/algorithm/common.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <cuda/experimental/buffer.cuh>
#include <cuda/experimental/memory_resource.cuh>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <utility.cuh>

inline constexpr uint8_t fill_byte = 1;
Expand Down
2 changes: 0 additions & 2 deletions cudax/test/catch2_helpers/catch2_main.cpp

This file was deleted.

3 changes: 2 additions & 1 deletion cudax/test/common/testing.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#include <iostream>
#include <sstream>

#include <catch2/catch.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <nv/target>

namespace cuda::experimental::__async
Expand Down
1 change: 0 additions & 1 deletion cudax/test/containers/uninitialized_async_buffer.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <cuda/experimental/memory_resource.cuh>

#include "testing.cuh"
#include <catch2/catch.hpp>

struct do_not_construct
{
Expand Down
2 changes: 1 addition & 1 deletion cudax/test/event/event_smoke.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cuda/experimental/event.cuh>
#include <cuda/experimental/stream.cuh>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <utility.cuh>

namespace
Expand Down
2 changes: 1 addition & 1 deletion cudax/test/execution/env.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <cuda/experimental/execution.cuh>
#include <cuda/experimental/memory_resource.cuh>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

namespace cudax = cuda::experimental;
using env_t = cudax::env_t<cuda::mr::device_accessible>;
Expand Down
2 changes: 1 addition & 1 deletion cudax/test/execution/policies/get_execution_policy.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <cuda/experimental/execution.cuh>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

using cuda::experimental::execution::execution_policy;

Expand Down
2 changes: 1 addition & 1 deletion cudax/test/execution/policies/policies.cu
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <cuda/experimental/execution.cuh>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>

namespace cudax = cuda::experimental;

Expand Down
8 changes: 4 additions & 4 deletions cudax/test/green_context/green_ctx_smoke.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cuda/experimental/green_context.cuh>
#include <cuda/experimental/stream.cuh>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <utility.cuh>

#if CUDART_VERSION >= 12050
Expand All @@ -23,7 +23,7 @@ TEST_CASE("Green context", "[green_context]")
}
else
{
INFO("Can create a green context")
INFO("Can create a green context");
{
{
[[maybe_unused]] cudax::green_context ctx(cudax::devices[0]);
Expand All @@ -35,7 +35,7 @@ TEST_CASE("Green context", "[green_context]")
}
}

INFO("Can create streams under green context")
INFO("Can create streams under green context");
{
cudax::green_context green_ctx_dev0(cudax::devices[0]);
cudax::stream stream_under_green_ctx(green_ctx_dev0);
Expand All @@ -47,7 +47,7 @@ TEST_CASE("Green context", "[green_context]")
CUDAX_REQUIRE(stream_dev1.device() == 1);
}

INFO("Can create a side stream")
INFO("Can create a side stream");
{
auto ldev1 = stream_under_green_ctx.logical_device();
CUDAX_REQUIRE(ldev1.get_kind() == cudax::logical_device::kinds::green_context);
Expand Down
1 change: 0 additions & 1 deletion cudax/test/memory_resource/any_async_resource.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <cuda/experimental/memory_resource.cuh>

#include "test_resource.cuh"
#include <catch2/catch.hpp>
#include <testing.cuh>

#ifndef __CUDA_ARCH__
Expand Down
1 change: 0 additions & 1 deletion cudax/test/memory_resource/device_memory_pool.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

#include <stdexcept>

#include <catch2/catch.hpp>
#include <testing.cuh>

namespace cudax = cuda::experimental;
Expand Down
2 changes: 1 addition & 1 deletion cudax/test/memory_resource/device_memory_resource.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <stdexcept>

#include <catch2/catch.hpp>
#include <catch2/catch_test_macros.hpp>
#include <utility.cuh>

namespace cudax = cuda::experimental;
Expand Down
1 change: 0 additions & 1 deletion cudax/test/memory_resource/get_memory_resource.cu
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <cuda/experimental/memory_resource.cuh>

#include "test_resource.cuh"
#include <catch2/catch.hpp>
#include <testing.cuh>

using device_resource = cuda::experimental::device_memory_resource;
Expand Down
Loading

0 comments on commit 7eaf5c2

Please sign in to comment.