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

Upgrade to Catch2 3.8 #3310

Merged
merged 7 commits into from
Jan 15, 2025
Merged
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
5 changes: 2 additions & 3 deletions c/parallel/test/test_main.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
@@ -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);

4 changes: 3 additions & 1 deletion c/parallel/test/test_util.h
Original file line number Diff line number Diff line change
@@ -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>

12 changes: 4 additions & 8 deletions c2h/include/c2h/catch2_main.h
Original file line number Diff line number Diff line change
@@ -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>

@@ -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);

@@ -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
42 changes: 32 additions & 10 deletions c2h/include/c2h/catch2_test_helper.h
Original file line number Diff line number Diff line change
@@ -39,15 +39,37 @@
#include <tuple>
#include <type_traits>

#if __CUDACC_VER_MAJOR__ == 11
_CCCL_NV_DIAG_SUPPRESS(177) // catch2 may contain unused variables
#endif // nvcc-11

#include <c2h/catch2_main.h>
#include <c2h/device_policy.h>
#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>

// workaround for error #3185-D: no '#pragma diagnostic push' was found to match this 'diagnostic pop'
#if _CCCL_COMPILER(NVHPC)
# undef CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
# undef CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma("diag push")
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma("diag pop")
#endif
// workaround for error
// * MSVC14.39: #3185-D: no '#pragma diagnostic push' was found to match this 'diagnostic pop'
// * MSVC14.29: internal error: assertion failed: alloc_copy_of_pending_pragma: copied pragma has source sequence entry
// (pragma.c, line 526 in alloc_copy_of_pending_pragma)
// see also upstream Catch2 issue: https://github.com/catchorg/Catch2/issues/2636
#if _CCCL_COMPILER(MSVC)
# undef CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
# undef CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
# undef CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
# define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS
#endif

#ifndef VAR_IDX
# define VAR_IDX 0
@@ -110,11 +132,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
@@ -140,7 +162,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}
2 changes: 1 addition & 1 deletion cmake/CCCLGetDependencies.cmake
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 2 additions & 3 deletions cub/benchmarks/nvbench_helper/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <cub/thread/thread_operators.cuh>

#include <thrust/device_vector.h>
#include <thrust/execution_policy.h>

3 changes: 2 additions & 1 deletion cub/benchmarks/nvbench_helper/test/gen_entropy.cu
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion cub/benchmarks/nvbench_helper/test/gen_range.cu
Original file line number Diff line number Diff line change
@@ -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 =
2 changes: 1 addition & 1 deletion cub/benchmarks/nvbench_helper/test/gen_seed.cu
Original file line number Diff line number Diff line change
@@ -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 =
Original file line number Diff line number Diff line change
@@ -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>
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
@@ -34,7 +34,6 @@

#include <cstdint>

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

1 change: 0 additions & 1 deletion cub/test/catch2_test_vsmem.cu
Original file line number Diff line number Diff line change
@@ -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>

2 changes: 1 addition & 1 deletion cub/test/insert_nested_NVTX_range_guard.h
Original file line number Diff line number Diff line change
@@ -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;
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
@@ -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
@@ -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)
1 change: 1 addition & 0 deletions cudax/include/cuda/experimental/__stf/utility/memory.cuh
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@

#include <cuda/experimental/__stf/utility/cuda_safe_call.cuh>

#include <algorithm>
#include <cstdint>

namespace cuda::experimental::stf
6 changes: 1 addition & 5 deletions cudax/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.
@@ -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"
2 changes: 1 addition & 1 deletion cudax/test/algorithm/common.cuh
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
#include <cuda/experimental/buffer.cuh>
#include <cuda/experimental/memory_resource.cuh>

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

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

This file was deleted.

26 changes: 25 additions & 1 deletion cudax/test/common/testing.cuh
Original file line number Diff line number Diff line change
@@ -11,15 +11,39 @@
#ifndef __COMMON_TESTING_H__
#define __COMMON_TESTING_H__

#include <cuda/__cccl_config>

#include <cuda/experimental/launch.cuh>

#include <exception> // IWYU pragma: keep
#include <iostream>
#include <sstream>

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

// workaround for error #3185-D: no '#pragma diagnostic push' was found to match this 'diagnostic pop'
#if _CCCL_COMPILER(NVHPC)
# undef CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
# undef CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma("diag push")
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma("diag pop")
#endif
// workaround for error
// * MSVC14.39: #3185-D: no '#pragma diagnostic push' was found to match this 'diagnostic pop'
// * MSVC14.29: internal error: assertion failed: alloc_copy_of_pending_pragma: copied pragma has source sequence entry
// (pragma.c, line 526 in alloc_copy_of_pending_pragma)
// see also upstream Catch2 issue: https://github.com/catchorg/Catch2/issues/2636
#if _CCCL_COMPILER(MSVC)
# undef CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
# undef CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
# undef CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
# define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS
#endif

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

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

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

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

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

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

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

#include <cuda/experimental/execution.cuh>

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

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

Loading
Loading