kokkos-utils 0.0.1
 
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
52{
53 const AllocDescriptor event{.kpsh = {.name = "Cuda"}, .name = "my-label", .ptr = reinterpret_cast<void*>(0x7ffee2b9d8f0), .size = 128};
54
55 const AllocDescriptor partial_match {.kpsh = {.name = "Cuda"}, .name = "my-label", .size = 128};
56 const AllocDescriptor partial_no_match_kpsh_name {.kpsh = {.name = "osef"}, .name = "my-label", .size = 128};
57 const AllocDescriptor partial_no_match_name {.kpsh = {.name = "Cuda"}, .name = "my-xxxxx", .size = 128};
58 const AllocDescriptor partial_no_match_size {.kpsh = {.name = "Cuda"}, .name = "my-label", .size = 129};
59
60 ASSERT_THAT(event, PartialMatcher<AllocDescriptor>{}(partial_match));
61 ASSERT_THAT(event, ::testing::Not(PartialMatcher<AllocDescriptor>{}(partial_no_match_kpsh_name)));
62 ASSERT_THAT(event, ::testing::Not(PartialMatcher<AllocDescriptor>{}(partial_no_match_name)));
63 ASSERT_THAT(event, ::testing::Not(PartialMatcher<AllocDescriptor>{}(partial_no_match_size)));
64}
65
68{
69 const BeginDeepCopyEvent event {
70 .dst = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-dst", .ptr = reinterpret_cast<void*>(0x7ffee2b9d8f0), .size = 128},
71 .src = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-src", .ptr = reinterpret_cast<void*>(0x7ffee2b9d8f0), .size = 128}
72 };
73
74 const BeginDeepCopyEvent partial_match {
75 .dst = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-dst", .size = 128},
76 .src = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-src", .size = 128}
77 };
78
79 const BeginDeepCopyEvent partial_no_match_dst {
80 .dst = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-xxx", .size = 128},
81 .src = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-src", .size = 128}
82 };
83
84 const BeginDeepCopyEvent partial_no_match_src {
85 .dst = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-dst", .size = 128},
86 .src = AllocDescriptor{.kpsh = {.name = "Cuda"}, .name = "my-xxx", .size = 128}
87 };
88
89 ASSERT_THAT(event, PartialMatcher<BeginDeepCopyEvent>{}(partial_match));
90 ASSERT_THAT(event, ::testing::Not(PartialMatcher<BeginDeepCopyEvent>{}(partial_no_match_dst)));
91 ASSERT_THAT(event, ::testing::Not(PartialMatcher<BeginDeepCopyEvent>{}(partial_no_match_src)));
92}
93
94} // namespace Kokkos::utils::tests::callbacks
auto ABeginParallelForEventWithName(Matcher &&matcher)
Definition Helpers.hpp:55
auto ContainsInOrder(Matchers &&... matchers)
Definition Helpers.hpp:138
TEST(EventTest, BeginEvent)
Helper struct to hold descriptors of a data allocation.
Definition Events.hpp:102
Begin-deep-copy event associated with Kokkos::Tools::Experimental::EventSet::begin_deep_copy.
Definition Events.hpp:129
Kokkos::DefaultExecutionSpace execution_space