kokkos-utils 0.0.1
 
Loading...
Searching...
No Matches
Helpers.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_UTILS_CALLBACKS_HELPERS_HPP
2#define KOKKOS_UTILS_CALLBACKS_HELPERS_HPP
3
4#include "gmock/gmock.h"
5
7
9{
10
17
18#define TEST_F_WITH_CB_MGR(__test_fixture_name__, __test_name__) \
19 class __test_fixture_name__ : public ManagerTestFixture {}; \
20 TEST_F(__test_fixture_name__, __test_name__)
21
22#define DEFINE_EVENT_MATCHER(__eventtype__) \
23 template <typename... Matchers> \
24 auto A##__eventtype__(Matchers&&... matchers) \
25 { \
26 using EventType = Kokkos::utils::callbacks::__eventtype__; \
27 if constexpr (sizeof...(Matchers) == 0) \
28 return ::testing::VariantWith<EventType>(::testing::_); \
29 else \
30 return ::testing::VariantWith<EventType>(::testing::AllOf(std::forward<Matchers>(matchers)...)); \
31 }
32
50
51#define DEFINE_EVENT_WITH_NAME_MATCHER(__eventtype__) \
52 template <typename Matcher> \
53 auto A##__eventtype__##WithName(Matcher&& matcher) \
54 { \
55 using EventType = Kokkos::utils::callbacks::__eventtype__; \
56 return ::testing::VariantWith<EventType>(::testing::Field(&EventType::name, std::forward<Matcher>(matcher))); \
57 }
58
66
67namespace impl
68{
69
70template <typename T, typename... Matchers>
72{
73public:
74 template <typename... Matchers_> requires std::conjunction_v<std::is_same<std::remove_cvref_t<Matchers_>, Matchers>...>
75 explicit ContainsInOrderMatcher(Matchers_&&... matchers_)
76 : matchers{std::forward<Matchers_>(matchers_)...} {}
77
78 template <typename IterableType>
79 bool MatchAndExplain([[maybe_unused]]const IterableType& arg, [[maybe_unused]]::testing::MatchResultListener* const listener) const
80 {
81 if constexpr(sizeof...(Matchers) == 0) {
82 return true;
83 } else {
84 return MatchAndExplainImpl<0>(arg.cbegin(), arg.cend(), listener);
85 }
86 }
87
88 void DescribeTo(std::ostream* out) const
89 {
90 *out << "contains in order elements that match ";
91 DescribeInnerMatchersImpl(out);
92 }
93
94 void DescribeNegationTo(std::ostream* out) const
95 {
96 *out << "does not contain in order elements that match ";
97 DescribeInnerMatchersImpl(out);
98 }
99
100private:
101 template <size_t Idx, typename IteratorType>
102 bool MatchAndExplainImpl(const IteratorType it_first, const IteratorType it_last, ::testing::MatchResultListener* const listener) const
103 {
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);
107 return false;
108 }
109
110 if (::testing::Matches(std::get<Idx>(matchers))(*it_first)) {
111 if constexpr (Idx == sizeof...(Matchers) - 1) {
112 return true;
113 } else {
114 return MatchAndExplainImpl<Idx + 1>(std::next(it_first), it_last, listener);
115 }
116 } else {
117 return MatchAndExplainImpl<Idx>(std::next(it_first), it_last, listener);
118 }
119 }
120
121 void DescribeInnerMatchersImpl(std::ostream* out) const
122 {
123 *out << "(";
124 if constexpr (sizeof...(Matchers) >= 2)
125 {
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>{});
129 }
130 if constexpr (sizeof...(Matchers) >= 1)
131 *out << ::testing::DescribeMatcher<T>(std::get<sizeof...(Matchers) - 1>(matchers), false);
132 *out << ")";
133 }
134
135private:
136 std::tuple<Matchers...> matchers;
137};
138
139} // namespace impl
140
141template <typename T, typename... Matchers>
142auto ContainsInOrder(Matchers&&... matchers) {
143 return ::testing::MakePolymorphicMatcher(impl::ContainsInOrderMatcher<T, std::remove_cvref_t<Matchers>...>(std::forward<Matchers>(matchers)...));
144}
145
146} // namespace Kokkos::utils::callbacks
147
148#endif // KOKKOS_UTILS_CALLBACKS_HELPERS_HPP
bool MatchAndExplain(const IterableType &arg, ::testing::MatchResultListener *const listener) const
Definition Helpers.hpp:79
void DescribeNegationTo(std::ostream *out) const
Definition Helpers.hpp:94
#define DEFINE_EVENT_MATCHER(__eventtype__)
Definition Helpers.hpp:22
#define DEFINE_EVENT_WITH_NAME_MATCHER(__eventtype__)
Definition Helpers.hpp:51
auto ContainsInOrder(Matchers &&... matchers)
Definition Helpers.hpp:142
Allocate-data event associated with Kokkos::Tools::Experimental::EventSet::allocate_data.
Definition Events.hpp:90
Begin-fence event associated with Kokkos::Tools::Experimental::EventSet::begin_fence.
Definition Events.hpp:67
Begin-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_red...
Definition Events.hpp:39
Begin-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::begin_parallel_scan.
Definition Events.hpp:53
Create-profile-section event associated with Kokkos::Tools::Experimental::EventSet::create_profile_se...
Definition Events.hpp:112
Deallocate-data event associated with Kokkos::Tools::Experimental::EventSet::deallocate_data.
Definition Events.hpp:96
Destroy-profile-section event associated with Kokkos::Tools::Experimental::EventSet::destroy_profile_...
Definition Events.hpp:131
End-fence event associated with Kokkos::Tools::Experimental::EventSet::end_fence.
Definition Events.hpp:75
End-parallel-for event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_for.
Definition Events.hpp:33
End-parallel-reduce event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_reduce.
Definition Events.hpp:47
End-parallel-scan event associated with Kokkos::Tools::Experimental::EventSet::end_parallel_scan.
Definition Events.hpp:61
Pop-region event associated with Kokkos::Tools::Experimental::EventSet::pop_region.
Definition Events.hpp:142
Profile event associated with Kokkos::Tools::Experimental::EventSet::profile_event.
Definition Events.hpp:146
Push-region event associated with Kokkos::Tools::Experimental::EventSet::push_region.
Definition Events.hpp:137
Start-profile-section event associated with Kokkos::Tools::Experimental::EventSet::start_profile_sect...
Definition Events.hpp:119
Stop-profile-section event associated with Kokkos::Tools::Experimental::EventSet::stop_profile_sectio...
Definition Events.hpp:125