kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
test_tracking_allocator.cpp
Go to the documentation of this file.
1
#include "gtest/gtest.h"
2
3
#include "
kokkos-execution/stdexec.hpp
"
4
5
#include "
tests/utils/tracking_allocator.hpp
"
6
17
18
namespace
Tests
{
19
21
TEST(TrackingAllocatorTest, write_read_env) {
22
std::atomic<size_t> count = 0;
23
24
stdexec::sender
auto
sndr =
25
stdexec::read_env(stdexec::get_allocator) | stdexec::then([](
auto
allocator) {
26
int
value = 42;
27
return
Tests::Utils::round_trip_allocate
(allocator,
static_cast<
int
&
>
(value));
28
})
29
| stdexec::write_env(stdexec::prop{stdexec::get_allocator,
Tests::Utils::TrackingAllocator<int>
{&count}});
30
31
const
auto
[val] = stdexec::sync_wait(std::move(sndr)).value();
// NOLINT(performance-move-const-arg)
32
33
ASSERT_EQ(val, 42);
34
ASSERT_EQ(count, 1);
35
}
36
38
TEST(TrackingAllocatorTest, forwarded_through_then) {
39
static_assert
(stdexec::forwarding_query(stdexec::get_allocator));
40
41
std::atomic<size_t> count = 0;
42
43
stdexec::sender
auto
sndr =
44
stdexec::read_env(stdexec::get_allocator)
45
| stdexec::then([](
auto
allocator) {
return
Tests::Utils::round_trip_allocate
(allocator, 42); })
46
| stdexec::then([](
auto
&& value) {
return
value; })
47
| stdexec::write_env(stdexec::prop{stdexec::get_allocator,
Tests::Utils::TrackingAllocator<int>
{&count}});
48
49
const
auto
[val] = stdexec::sync_wait(std::move(sndr)).value();
// NOLINT(performance-move-const-arg)
50
51
ASSERT_EQ(val, 42);
52
ASSERT_EQ(count, 1);
53
}
54
55
}
// namespace Tests
stdexec.hpp
Tests::Utils::round_trip_allocate
auto round_trip_allocate(Allocator &allocator, T &&value)
Definition
tracking_allocator.hpp:39
Tests
Definition
test_any_sender.cpp:39
Tests::Utils::TrackingAllocator
A minimal tracking allocator.
Definition
tracking_allocator.hpp:16
tracking_allocator.hpp
tests
utils
test_tracking_allocator.cpp
Generated on
for kokkos-execution by
1.18.0