| 17 | #include "marl/ticket.h" |
| 18 | |
| 19 | void WithBoundSchedulerBase::TestTicket() |
| 20 | { |
| 21 | marl::Ticket::Queue queue; |
| 22 | |
| 23 | constexpr int count = 1000; |
| 24 | std::atomic<int> next = {0}; |
| 25 | int result[count] = {}; |
| 26 | |
| 27 | for (int i = 0; i < count; i++) { |
| 28 | auto ticket = queue.take(); |
| 29 | marl::schedule([ticket, i, &result, &next] { |
| 30 | ticket.wait(); |
| 31 | result[next++] = i; |
| 32 | ticket.done(); |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | queue.take().wait(); |
| 37 | |
| 38 | for (int i = 0; i < count; i++) { |
| 39 | ASSERT_EQ(result[i], i); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | TEST_CASE_METHOD(WithBoundScheduler<0>, "TestTicket-0") { TestTicket(); }; |
| 44 | TEST_CASE_METHOD(WithBoundScheduler<1>, "TestTicket-1") { TestTicket(); }; |