1#ifndef KOKKOS_UTILS_CALLBACKS_HELPERS_HPP
2#define KOKKOS_UTILS_CALLBACKS_HELPERS_HPP
4#include "gmock/gmock.h"
11#define TEST_F_WITH_CB_MGR(__test_fixture_name__, __test_name__) \
12 class __test_fixture_name__ : public ::testing::Test, \
13 public scoped::callbacks::Manager {}; \
14 TEST_F(__test_fixture_name__, __test_name__)
16#define DEFINE_EVENT_MATCHER_IN(__namespace__, __eventtype__) \
17 template <typename... Matchers> \
18 auto A##__eventtype__(Matchers&&... matchers) \
20 using EventType = __namespace__::__eventtype__; \
21 if constexpr (sizeof...(Matchers) == 0) \
22 return ::testing::VariantWith<EventType>(::testing::_); \
24 return ::testing::VariantWith<EventType>(::testing::AllOf(std::forward<Matchers>(matchers)...)); \
27#define DEFINE_EVENT_MATCHER(__eventtype__) DEFINE_EVENT_MATCHER_IN(Kokkos::utils::callbacks, __eventtype__)
49#define DEFINE_EVENT_WITH_NAME_MATCHER_IN(__namespace__, __eventtype__) \
50 template <typename Matcher> \
51 auto A##__eventtype__##WithName(Matcher&& matcher) \
53 using EventType = __namespace__::__eventtype__; \
54 return ::testing::VariantWith<EventType>(::testing::Field(&EventType::name, std::forward<Matcher>(matcher))); \
57#define DEFINE_EVENT_WITH_NAME_MATCHER(__eventtype__) DEFINE_EVENT_WITH_NAME_MATCHER_IN(Kokkos::utils::callbacks, __eventtype__)
70template <
typename T,
typename... Matchers>
74 template <
typename... Matchers_>
requires std::conjunction_v<std::is_same<std::remove_cvref_t<Matchers_>, Matchers>...>
76 :
matchers{std::forward<Matchers_>(matchers_)...} {}
78 template <
typename IterableType>
79 bool MatchAndExplain([[maybe_unused]]
const IterableType& arg, [[maybe_unused]]::testing::MatchResultListener*
const listener)
const
81 if constexpr(
sizeof...(Matchers) == 0) {
90 *out <<
"contains in order elements that match ";
96 *out <<
"does not contain in order elements that match ";
101 template <
size_t Idx,
typename IteratorType>
102 bool MatchAndExplainImpl(
const IteratorType& it_first,
const IteratorType& it_last, ::testing::MatchResultListener*
const listener)
const
104 if (it_first == it_last) {;
105 *listener <<
"does not contain in order an element that "
106 << ::testing::DescribeMatcher<T>(std::get<Idx>(
matchers),
false);
110 if (::testing::Matches(std::get<Idx>(
matchers))(*it_first)) {
111 if constexpr (Idx ==
sizeof...(Matchers) - 1) {
124 if constexpr (
sizeof...(Matchers) >= 2)
126 [&] <
size_t... Idxs>(std::index_sequence<Idxs...>) {
127 ((*out << ::testing::DescribeMatcher<T>(std::get<Idxs>(
matchers),
false) <<
", "), ...);
128 }(std::make_index_sequence<
sizeof...(Matchers) - 1>{});
130 if constexpr (
sizeof...(Matchers) >= 1)
131 *out << ::testing::DescribeMatcher<T>(std::get<
sizeof...(Matchers) - 1>(
matchers),
false);
139template <
typename ElementType,
typename ElementMatcher>
146 template <
typename IterableType>
147 bool MatchAndExplain(
const IterableType& arg, ::testing::MatchResultListener*
const listener)
const
150 *listener <<
"index " <<
m_index <<
" is out of bounds (size " << arg.size() <<
")";
158 *out <<
"element at index " <<
m_index <<
" "
159 << ::testing::DescribeMatcher<ElementType>(
m_matcher,
false);
164 *out <<
"element at index " <<
m_index <<
" "
165 << ::testing::DescribeMatcher<ElementType>(
m_matcher,
true);
175template <
typename T,
typename... Matchers>
177 return ::testing::MakePolymorphicMatcher(
impl::ContainsInOrderMatcher<T, std::remove_cvref_t<Matchers>...>(std::forward<Matchers>(matchers)...));
187template <
typename ElementType,
typename ElementMatcher>
188auto ElementAt(
const size_t index, ElementMatcher&& matcher) {
189 return ::testing::MakePolymorphicMatcher(
190 impl::ElementAtMatcher<ElementType, std::remove_cvref_t<ElementMatcher>>{index, std::forward<ElementMatcher>(matcher)});
205 return ::testing::AllOf(
208 ::testing::Field(&Kokkos_Profiling_SpaceHandle::name, ::testing::StrEq(descr.kpsh.name))
212 ::testing::StrEq(descr.name)
216 ::testing::Eq(descr.size)
231 return ::testing::AllOf(
bool MatchAndExplain(const IterableType &arg, ::testing::MatchResultListener *const listener) const
void DescribeTo(std::ostream *out) const
void DescribeNegationTo(std::ostream *out) const
void DescribeInnerMatchersImpl(std::ostream *out) const
std::tuple< Matchers... > matchers
ContainsInOrderMatcher(Matchers_ &&... matchers_)
bool MatchAndExplainImpl(const IteratorType &it_first, const IteratorType &it_last, ::testing::MatchResultListener *const listener) const
void DescribeTo(std::ostream *out) const
void DescribeNegationTo(std::ostream *out) const
ElementAtMatcher(const size_t index, ElementMatcher matcher)
bool MatchAndExplain(const IterableType &arg, ::testing::MatchResultListener *const listener) const
#define DEFINE_EVENT_MATCHER(__eventtype__)
#define DEFINE_EVENT_WITH_NAME_MATCHER(__eventtype__)
auto ElementAt(const size_t index, ElementMatcher &&matcher)
Check that an element at a given index matches.
auto ContainsInOrder(Matchers &&... matchers)
Helper struct to hold descriptors of a data allocation.
Kokkos_Profiling_SpaceHandle kpsh
Allocate-data event associated with Kokkos::Tools::Experimental::EventSet::allocate_data.
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Begin-fence event associated with Kokkos::Tools::Experimental::EventSet::begin_fence.
Begin-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_red...
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
Deallocate-data event associated with Kokkos::Tools::Experimental::EventSet::deallocate_data.
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
End-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::end_deep_copy.
End-fence event associated with Kokkos::Tools::Experimental::EventSet::end_fence.
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
End-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_reduce.
End-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_scan.
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
Start-profile-section event associated with Kokkos::Tools::Experimental::EventSet::start_profile_sect...
Stop-profile-section event associated with Kokkos::Tools::Experimental::EventSet::stop_profile_sectio...