8 #include <zephyr/ztest.h>
10 #include <zephyr/kernel.h>
21 #define SIGNAL_RESULT 0x1ee7d00d
22 #define FIFO_MSG_VALUE 0xdeadbeef
29 void* fifo_reserved{};
48 ZTEST(zpp_poll_tests, test_poll_wait)
50 using namespace std::chrono;
68 auto poll_helper = [](
bool do_fifo) noexcept {
74 wait_fifo.push_back(&wait_msg);
80 auto t =
zpp::thread(test_thread, test_thread_stack(), attr, poll_helper,
true);
82 auto rc = wait_events.try_poll_for(1s);
86 zassert_equal(rc,
true,
"");
88 zassert_equal(wait_events[0].is_ready(),
true,
"");
89 zassert_equal(wait_sem.try_take(),
true,
"");
91 zassert_equal(wait_events[1].is_ready(),
true,
"");
92 auto msg_ptr = wait_fifo.try_pop_front();
93 zassert_not_null(msg_ptr,
"");
94 zassert_equal(msg_ptr, &wait_msg,
"");
97 zassert_equal(wait_events[2].is_ready(),
true,
"");
98 zassert_equal(wait_signal.check().value_or(-1),
SIGNAL_RESULT,
"");
100 zassert_equal(wait_events[3].is_ready(),
false,
"");
105 wait_events[0].reset();
106 wait_events[1].reset();
107 wait_events[2].reset();
108 wait_events[3].reset();
111 zassert_equal(wait_events.try_poll_for(1s),
false,
"");
113 zassert_equal(wait_events[0].is_ready(),
false,
"");
114 zassert_equal(wait_events[1].is_ready(),
false,
"");
115 zassert_equal(wait_events[2].is_ready(),
false,
"");
116 zassert_equal(wait_events[3].is_ready(),
false,
"");
124 attr.
set(old_prio + 1);
125 t =
zpp::thread(test_thread, test_thread_stack(), attr, poll_helper,
false);
127 rc = wait_events.try_poll_for(1s);
131 zassert_equal(rc,
true,
"");
133 zassert_equal(wait_events[0].is_ready(),
true,
"");
134 zassert_equal(wait_sem.try_take(),
true,
"");
136 zassert_equal(wait_events[1].is_ready(),
false,
"");
137 msg_ptr = wait_fifo.try_pop_front();
138 zassert_is_null(msg_ptr,
"");
140 zassert_equal(wait_events[2].is_ready(),
true,
"");
141 zassert_equal(wait_signal.check().value_or(-1),
SIGNAL_RESULT,
"");
143 zassert_equal(wait_events[3].is_ready(),
false,
"");
150 wait_events[0].reset();
151 wait_events[1].reset();
152 wait_events[2].reset();
153 wait_events[3].reset();
156 attr.
set(old_prio - 1);
157 t =
zpp::thread(test_thread, test_thread_stack(), attr, poll_helper,
true);
162 rc = wait_events.try_poll_for(1s);
164 zassert_equal(rc,
true,
"");
166 zassert_equal(wait_events[0].is_ready(),
true,
"");
167 zassert_equal(wait_sem.try_take(),
true,
"");
169 zassert_equal(wait_events[1].is_ready(),
false,
"");
170 msg_ptr = wait_fifo.try_pop_front();
171 zassert_is_null(msg_ptr,
"");
173 zassert_equal(wait_events[2].is_ready(),
false,
"");
175 wait_events[0].reset();
180 rc = wait_events.try_poll_for(1s);
182 zassert_equal(rc,
true,
"");
184 zassert_equal(wait_events[0].is_ready(),
false,
"");
185 zassert_equal(wait_sem.try_take(),
false,
"");
187 zassert_equal(wait_events[1].is_ready(),
true,
"");
188 msg_ptr = wait_fifo.try_pop_front();
189 zassert_not_null(msg_ptr,
"");
191 zassert_equal(wait_events[2].is_ready(),
false,
"");
193 wait_events[1].reset();
198 rc = wait_events.try_poll_for(1s);
200 zassert_equal(rc,
true,
"");
202 zassert_equal(wait_events[0].is_ready(),
false,
"");
203 zassert_equal(wait_sem.try_take(),
false,
"");
205 zassert_equal(wait_events[1].is_ready(),
false,
"");
206 msg_ptr = wait_fifo.try_pop_front();
207 zassert_is_null(msg_ptr,
"");
209 zassert_equal(wait_events[2].is_ready(),
true,
"");
210 zassert_equal(wait_signal.check().value_or(-1),
SIGNAL_RESULT,
"");
212 wait_events[2].reset();
fifo that manages a k_fifo object
class owning a k_poll_signal
A counting semaphore class.
Thread creation attributes.
constexpr void set(T_FirstArg &&first, T_Args &&... rest) noexcept
thread_data holds the stack and thread control block memory
The class thread repecents a single Zephyr thread.
void set_priority(thread_prio prio) noexcept
Set the current thread's priority.
auto sleep_for(const std::chrono::duration< T_Rep, T_Period > &sleep_duration)
Suspend the current thread for a specified time duration.
thread_prio get_priority() noexcept
Get the current thread's priority.
ZTEST(zpp_atomic_tests, test_atomic_bitset)
ZTEST_SUITE(zpp_atomic_tests, NULL, NULL, NULL, NULL, NULL)
#define ZPP_THREAD_STACK_DEFINE(sym, size)