kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_tracking_allocator.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2
4
6
17
18namespace Tests {
19
21TEST(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
38TEST(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
auto round_trip_allocate(Allocator &allocator, T &&value)
A minimal tracking allocator.