kokkos-execution 0.0.1
Loading...
Searching...
No Matches
check_sync_wait.hpp
Go to the documentation of this file.
1#ifndef KOKKOS_EXECUTION_TESTS_UTILS_CHECK_SYNC_WAIT_HPP
2#define KOKKOS_EXECUTION_TESTS_UTILS_CHECK_SYNC_WAIT_HPP
3
4#include "gtest/gtest.h"
5
6#include "Kokkos_Macros.hpp"
7#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
8import kokkos.core;
9#else
10# include "Kokkos_Core.hpp"
11#endif
12
16
18
26
27namespace Tests::Utils {
28
30template <typename Domain, stdexec::sender Sndr>
32 static_assert(stdexec::__never_sends<stdexec::set_error_t, Sndr>);
35 return true;
36}
37
38template <typename ContextType>
57
58TYPED_TEST_SUITE_P(TEST_CATEGORY(SyncWaitTest));
59
65 std::thread::id tid;
66
67 auto sndr = stdexec::read_env(stdexec::get_start_scheduler)
68 | stdexec::let_value([&](auto schd) { return stdexec::schedule(schd) | THEN_STORE_THREAD_ID(&tid); })
70 | stdexec::continues_on(this->ctx.get_scheduler());
71
72 stdexec::sync_wait(std::move(sndr)); // NOLINT(performance-move-const-arg)
73
74 ASSERT_EQ(tid, std::this_thread::get_id());
75}
76
82 std::thread::id tid;
83
84 auto sndr = stdexec::just() | THEN_STORE_THREAD_ID(&tid)
86 | stdexec::continues_on(this->ctx.get_scheduler());
87
88 stdexec::sync_wait(std::move(sndr)); // NOLINT(performance-move-const-arg)
89
90 ASSERT_EQ(tid, std::this_thread::get_id());
91}
92
95 auto sndr = stdexec::schedule(this->ctx.get_scheduler());
96
97 ASSERT_THAT(
98 TestFixture::recorder_listener_t::record(
99 [sndr = std::move(sndr)]() mutable { // NOLINT(performance-move-const-arg)
100 const auto value = stdexec::sync_wait(std::move(sndr)); // NOLINT(performance-move-const-arg)
101 static_assert(std::same_as<decltype(value), const std::optional<std::tuple<>>>);
102 ASSERT_TRUE(value.has_value());
103 }),
104 testing::IsEmpty());
105}
106
109 auto sndr = stdexec::schedule(Tests::Utils::Schedulers::Stopped{})
110 | stdexec::continues_on(this->ctx.get_scheduler());
111
112 ASSERT_THAT(
113 TestFixture::recorder_listener_t::record(
114 [sndr = std::move(sndr)]() mutable { // NOLINT(performance-move-const-arg)
115 const auto value = stdexec::sync_wait(std::move(sndr)); // NOLINT(performance-move-const-arg)
116 static_assert(std::same_as<decltype(value), const std::optional<std::tuple<>>>);
117 ASSERT_FALSE(value.has_value());
118 }),
119 testing::IsEmpty());
120}
121
124 auto sndr = stdexec::schedule(this->ctx.get_scheduler())
126
127 ASSERT_THAT(
128 Tests::Utils::Functors::MutableMoveToSyncWait{.sndr = std::move(sndr)},
129 testing::ThrowsMessage<std::runtime_error>(testing::StrEq("ThrowsWhenCopied: Throwing in copy constructor!")));
130}
131
132REGISTER_TYPED_TEST_SUITE_P(
135 just,
139
140} // namespace Tests::Utils
141
142#endif // KOKKOS_EXECUTION_TESTS_UTILS_CHECK_SYNC_WAIT_HPP
#define TEST_CATEGORY(_name_)
Definition category.hpp:10
Check that apply_sender is noexcept.
Definition stdexec.hpp:42
consteval bool check_nothrow_apply_sender()
constexpr check_completion_scheduler_type_t< Tag, Schd > check_completion_scheduler_type
#define THEN_STORE_THREAD_ID(__id__)
Add a stdexec::then calling Tests::Utils::Functors::StoreThreadID. // NOLINTNEXTLINE(cppcoreguideline...
Matcher to filter out events that are just noise for tests.
Event to be sent to Kokkos::utils::callbacks::dispatch when a Kokkos graph is created.
Definition events.hpp:28
Event to be sent to Kokkos::utils::callbacks::dispatch when calling record.
Definition event.hpp:59
This helper struct throws when copy constructed.
Scheduler that returns a sender that always completes on the stop channel.
Definition stopped.hpp:22
Kokkos::utils::callbacks::RecorderListener< EventDiscardMatcher< execution_space >, Kokkos::utils::callbacks::BeginFenceEvent, Kokkos::utils::callbacks::BeginSingleEvent, Kokkos::utils::callbacks::BeginParallelForEvent, Kokkos::utils::callbacks::BeginParallelReduceEvent, Kokkos::Execution::Impl::RecordEvent, Kokkos::Execution::GraphImpl::GraphCreateEvent > recorder_listener_t
typename ContextType::execution_space execution_space