kokkos-utils 0.0.4
 
Loading...
Searching...
No Matches
test_Helpers.cpp
Go to the documentation of this file.
1#include "gmock/gmock.h"
2#include "gtest/gtest.h"
3
5
16
17using execution_space = Kokkos::DefaultExecutionSpace;
18
20{
21
22using namespace Kokkos::utils::callbacks;
23
26{
27 const auto matcher = ABeginParallelForEventWithName(::testing::StrEq("computation - level 0 - pfor"));
28 ASSERT_EQ(::testing::DescribeMatcher<std::variant<BeginParallelForEvent>>(matcher), "is a variant<> with value of type 'Kokkos::utils::callbacks::BeginParallelForEvent' and the value is an object whose given field is equal to \"computation - level 0 - pfor\"");
29}
30
32TEST(ContainsInOrderMatcher, CanDescribeItself)
33{
34 const auto matcher = ContainsInOrder<int>(::testing::Eq(3), ::testing::Eq(4));
35 ASSERT_EQ(::testing::DescribeMatcher<std::vector<int>>(matcher), "contains in order elements that match (is equal to 3, is equal to 4)");
36
37 const auto matcher_not = ::testing::Not(ContainsInOrder<int>(::testing::Eq(3), ::testing::Eq(4)));
38 ASSERT_EQ(::testing::DescribeMatcher<std::vector<int>>(matcher_not), "does not contain in order elements that match (is equal to 3, is equal to 4)");
39}
40
42TEST(ContainsInOrderMatcher, Matches)
43{
44 const std::vector<int> vec{1, 2, 3, 4};
45 ASSERT_THAT(vec, ContainsInOrder<int>());
46 ASSERT_THAT(vec, ContainsInOrder<int>(::testing::Eq(2), ::testing::Eq(4)));
47 ASSERT_THAT(vec, ::testing::Not(ContainsInOrder<int>(::testing::Eq(2), ::testing::Eq(1))));
48}
49
51TEST(ElementAtMatcher, CanDescribeItself)
52{
53 const auto matcher = ElementAt<int>(42, ::testing::Eq(666));
54 ASSERT_EQ(::testing::DescribeMatcher<std::vector<int>>(matcher), "element at index 42 is equal to 666");
55
56 const auto matcher_not = ::testing::Not(ElementAt<int>(42, ::testing::Eq(666)));
57 ASSERT_EQ(::testing::DescribeMatcher<std::vector<int>>(matcher_not), "element at index 42 isn't equal to 666");
58}
59
61TEST(ElementAtMatcher, Matches)
62{
63 const std::vector<int> vec{1, 2, 3, 4};
64 ASSERT_THAT(vec, ElementAt<int>( 0, ::testing::Eq(1)));
65 ASSERT_THAT(vec, ElementAt<int>( 1, ::testing::Eq(2)));
66 ASSERT_THAT(vec, ElementAt<int>( 2, ::testing::Eq(3)));
67 ASSERT_THAT(vec, ElementAt<int>( 3, ::testing::Eq(4)));
68 ASSERT_THAT(vec, ::testing::Not(ElementAt<int>( 0, ::testing::Eq(2))));
69 ASSERT_THAT(vec, ::testing::Not(ElementAt<int>(42, ::testing::Eq(2))));
70}
71
74{
75 const AllocDescriptor event{.kpsh = {.name = "Cuda"}, .name = "my-label", .ptr = reinterpret_cast<void*>(0x7ffee2b9d8f0), .size = 128};
76
77 const AllocDescriptor partial_match {.kpsh = {.name = "Cuda"}, .name = "my-label", .size = 128};
78 const AllocDescriptor partial_no_match_kpsh_name {.kpsh = {.name = "osef"}, .name = "my-label", .size = 128};
79 const AllocDescriptor partial_no_match_name {.kpsh = {.name = "Cuda"}, .name = "my-xxxxx", .size = 128};
80 const AllocDescriptor partial_no_match_size {.kpsh = {.name = "Cuda"}, .name = "my-label", .size = 129};
81
82 ASSERT_THAT(event, PartialMatcher<AllocDescriptor>{}(partial_match));
83 ASSERT_THAT(event, ::testing::Not(PartialMatcher<AllocDescriptor>{}(partial_no_match_kpsh_name)));
84 ASSERT_THAT(event, ::testing::Not(PartialMatcher<AllocDescriptor>{}(partial_no_match_name)));
85 ASSERT_THAT(event, ::testing::Not(PartialMatcher<AllocDescriptor>{}(partial_no_match_size)));
86}
87
90{
91 const BeginDeepCopyEvent event {
92 .dst = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-dst", .ptr = reinterpret_cast<void*>(0x7ffee2b9d8f0), .size = 128},
93 .src = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-src", .ptr = reinterpret_cast<void*>(0x7ffee2b9d8f0), .size = 128}
94 };
95
96 const BeginDeepCopyEvent partial_match {
97 .dst = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-dst", .size = 128},
98 .src = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-src", .size = 128}
99 };
100
101 const BeginDeepCopyEvent partial_no_match_dst {
102 .dst = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-xxx", .size = 128},
103 .src = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-src", .size = 128}
104 };
105
106 const BeginDeepCopyEvent partial_no_match_src {
107 .dst = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-dst", .size = 128},
108 .src = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-xxx", .size = 128}
109 };
110
111 ASSERT_THAT(event, PartialMatcher<BeginDeepCopyEvent>{}(partial_match));
112 ASSERT_THAT(event, ::testing::Not(PartialMatcher<BeginDeepCopyEvent>{}(partial_no_match_dst)));
113 ASSERT_THAT(event, ::testing::Not(PartialMatcher<BeginDeepCopyEvent>{}(partial_no_match_src)));
114}
115
116} // namespace Kokkos::utils::tests::callbacks
auto ElementAt(const size_t index, ElementMatcher &&matcher)
Check that an element at a given index matches.
Definition Helpers.hpp:188
auto ABeginParallelForEventWithName(Matcher &&matcher)
Definition Helpers.hpp:59
auto ContainsInOrder(Matchers &&... matchers)
Definition Helpers.hpp:176
TEST(EventTest, BeginEvent)
Helper struct to hold descriptors of a data allocation.
Definition Events.hpp:109
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:136
Kokkos::DefaultExecutionSpace execution_space