kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
test_upon_stopped.cpp
Go to the documentation of this file.
1
#include "gtest/gtest.h"
2
3
#include "
kokkos-execution/utils/ignore_warnings.hpp
"
4
PRAGMA_DIAGNOSTIC_PUSH
5
KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
6
#include "exec/single_thread_context.hpp"
7
#include "exec/static_thread_pool.hpp"
8
PRAGMA_DIAGNOSTIC_POP
9
10
#include "
kokkos-execution/stdexec.hpp
"
11
22
23
namespace
Tests
{
24
26
using
env_with_stop_token_t
= stdexec::env<stdexec::prop<stdexec::get_stop_token_t, stdexec::inplace_stop_token>>;
27
29
template
<
typename
Sndr>
30
consteval
bool
test_stopped_advertised_iff_stop_token
() {
31
static_assert
(!stdexec::sends_stopped<Sndr, stdexec::env<>>);
32
static_assert
(stdexec::sends_stopped<Sndr, env_with_stop_token_t>);
33
34
return
true
;
35
}
36
38
template
<
bool
Stop, stdexec::sender SchdSndr>
39
void
test_stop_before_start
(SchdSndr&& schd_sndr) {
40
stdexec::inplace_stop_source iss;
// NOLINT(misc-const-correctness)
41
42
if
constexpr
(Stop)
43
iss.request_stop();
44
45
unsigned
int
value = 0;
46
47
auto
sndr_then = std::forward<SchdSndr>(schd_sndr) | stdexec::then([&value]()
noexcept
{
48
value += 12;
49
return
666;
50
});
51
52
static_assert
(
test_stopped_advertised_iff_stop_token<decltype(sndr_then)>
());
53
54
static_assert
(
55
stdexec::get_completion_signatures<
decltype
(sndr_then), stdexec::env<>>()
56
== stdexec::completion_signatures<stdexec::set_value_t(
int
)>{});
57
58
auto
sndr_upon_stopped = std::move(sndr_then) | stdexec::upon_stopped([&value]()
noexcept
{
59
value += 56;
60
return
42;
61
});
62
63
static_assert
(
64
stdexec::get_completion_signatures<
decltype
(sndr_then), stdexec::env<>>()
65
== stdexec::completion_signatures<stdexec::set_value_t(
int
)>{});
66
68
static_assert
(STDEXEC::__never_sends<stdexec::set_stopped_t,
decltype
(sndr_upon_stopped),
env_with_stop_token_t
>);
69
70
auto
sndr = std::move(sndr_upon_stopped)
71
| stdexec::write_env(stdexec::prop{stdexec::get_stop_token, iss.get_token()});
72
73
const
auto
res = stdexec::sync_wait(std::move(sndr));
74
75
ASSERT_TRUE(res.has_value());
76
EXPECT_EQ(std::get<0>(*res), Stop ? 42 : 666);
77
ASSERT_EQ(value, Stop ? 56 : 12);
78
}
79
80
template
<
typename
T>
81
requires
requires
(T& arg) {
82
{ arg.get_scheduler() } -> stdexec::scheduler;
83
}
84
class
UponStoppedTest
:
public
testing::Test { };
85
86
TYPED_TEST_SUITE_P(
UponStoppedTest
);
87
88
TYPED_TEST_P(
UponStoppedTest
,
stop_before_start
) {
89
static_assert
(
test_stopped_advertised_iff_stop_token
<
decltype
(stdexec::schedule(
90
std::declval<TypeParam>().get_scheduler()))>());
91
92
TypeParam
scheduler_provider{};
93
94
test_stop_before_start<true>
(stdexec::schedule(scheduler_provider.get_scheduler()));
95
test_stop_before_start<false>
(stdexec::schedule(scheduler_provider.get_scheduler()));
96
}
97
98
REGISTER_TYPED_TEST_SUITE_P(
UponStoppedTest
,
stop_before_start
);
99
100
using
UponStoppedTestTypes
= testing::Types<exec::static_thread_pool, exec::single_thread_context>;
101
102
INSTANTIATE_TYPED_TEST_SUITE_P(UponStoppedTestInstantiation,
UponStoppedTest
,
UponStoppedTestTypes
);
103
104
}
// namespace Tests
Tests::UponStoppedTest
Definition
test_upon_stopped.cpp:84
Tests::gtest_suite_UponStoppedTest_::stop_before_start
Definition
test_upon_stopped.cpp:88
Tests::gtest_suite_UponStoppedTest_::stop_before_start::TypeParam
gtest_TypeParam_ TypeParam
Definition
test_upon_stopped.cpp:88
ignore_warnings.hpp
KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
#define KOKKOS_EXECUTION_STDEXEC_PRAGMA_DIAGNOSTIC_IGNORED
Basic list of ignored diagnostics when including anything from stdexec.
Definition
ignore_warnings.hpp:44
stdexec.hpp
Tests
Definition
test_any_sender.cpp:39
Tests::test_stop_before_start
void test_stop_before_start(SchdSndr &&schd_sndr)
Definition
test_upon_stopped.cpp:39
Tests::env_with_stop_token_t
stdexec::env< stdexec::prop< stdexec::get_stop_token_t, stdexec::inplace_stop_token > > env_with_stop_token_t
An environment queryable for stdexec::get_stop_token_t.
Definition
test_upon_stopped.cpp:26
Tests::UponStoppedTestTypes
testing::Types< exec::static_thread_pool, exec::single_thread_context > UponStoppedTestTypes
Definition
test_upon_stopped.cpp:100
Tests::test_stopped_advertised_iff_stop_token
consteval bool test_stopped_advertised_iff_stop_token()
Definition
test_upon_stopped.cpp:30
tests
stdexec
test_upon_stopped.cpp
Generated on
for kokkos-execution by
1.18.0