Lines Matching refs:fixture

40 	static struct uart_emul_fixture fixture = {.dev = DEVICE_DT_GET(EMUL_UART_NODE)};  in uart_emul_setup()  local
43 fixture.sample_data[i] = i; in uart_emul_setup()
47 k_sem_init(&fixture.tx_done_sem, 0, 1); in uart_emul_setup()
48 k_sem_init(&fixture.rx_done_sem, 0, 1); in uart_emul_setup()
52 k_event_init(&fixture.async_events); in uart_emul_setup()
55 zassert_not_null(fixture.dev); in uart_emul_setup()
56 return &fixture; in uart_emul_setup()
61 struct uart_emul_fixture *fixture = f; in uart_emul_before() local
63 uart_emul_flush_rx_data(fixture->dev); in uart_emul_before()
64 uart_emul_flush_tx_data(fixture->dev); in uart_emul_before()
66 uart_err_check(fixture->dev); in uart_emul_before()
68 memset(fixture->tx_content, 0, sizeof(fixture->tx_content)); in uart_emul_before()
69 memset(fixture->rx_content, 0, sizeof(fixture->rx_content)); in uart_emul_before()
72 uart_irq_tx_disable(fixture->dev); in uart_emul_before()
73 uart_irq_rx_disable(fixture->dev); in uart_emul_before()
75 k_sem_reset(&fixture->tx_done_sem); in uart_emul_before()
76 k_sem_reset(&fixture->rx_done_sem); in uart_emul_before()
78 fixture->tx_remaining = SAMPLE_DATA_SIZE; in uart_emul_before()
79 fixture->rx_remaining = SAMPLE_DATA_SIZE; in uart_emul_before()
83 uart_tx_abort(fixture->dev); in uart_emul_before()
84 uart_rx_disable(fixture->dev); in uart_emul_before()
86 k_event_set(&fixture->async_events, 0); in uart_emul_before()
96 uart_poll_out(fixture->dev, fixture->sample_data[i]); in ZTEST_F()
99 tx_len = uart_emul_get_tx_data(fixture->dev, tx_content, sizeof(tx_content)); in ZTEST_F()
101 zassert_mem_equal(tx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
104 tx_len = uart_emul_get_tx_data(fixture->dev, tx_content, sizeof(tx_content)); in ZTEST_F()
112 uart_emul_put_rx_data(fixture->dev, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
115 rc = uart_poll_in(fixture->dev, &fixture->rx_content[i]); in ZTEST_F()
118 zassert_mem_equal(fixture->rx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
121 rc = uart_poll_in(fixture->dev, &fixture->rx_content[0]); in ZTEST_F()
129 uart_emul_set_errors(fixture->dev, (UART_ERROR_PARITY | UART_ERROR_FRAMING)); in ZTEST_F()
130 errors = uart_err_check(fixture->dev); in ZTEST_F()
134 errors = uart_err_check(fixture->dev); in ZTEST_F()
138 uart_emul_put_rx_data(fixture->dev, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
139 errors = uart_err_check(fixture->dev); in ZTEST_F()
141 uart_emul_put_rx_data(fixture->dev, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
142 errors = uart_err_check(fixture->dev); in ZTEST_F()
147 static void uart_emul_isr_handle_tx_ready(struct uart_emul_fixture *fixture) in uart_emul_isr_handle_tx_ready() argument
152 if (fixture->tx_remaining) { in uart_emul_isr_handle_tx_ready()
153 sample_data_it = sizeof(fixture->sample_data) - fixture->tx_remaining; in uart_emul_isr_handle_tx_ready()
154 ret = uart_fifo_fill(fixture->dev, &fixture->sample_data[sample_data_it], in uart_emul_isr_handle_tx_ready()
155 fixture->tx_remaining); in uart_emul_isr_handle_tx_ready()
156 fixture->tx_remaining -= (size_t)ret; in uart_emul_isr_handle_tx_ready()
159 if (fixture->tx_remaining == 0) { in uart_emul_isr_handle_tx_ready()
160 uart_irq_tx_disable(fixture->dev); in uart_emul_isr_handle_tx_ready()
161 k_sem_give(&fixture->tx_done_sem); in uart_emul_isr_handle_tx_ready()
165 static void uart_emul_isr_handle_rx_ready(struct uart_emul_fixture *fixture) in uart_emul_isr_handle_rx_ready() argument
170 if (fixture->rx_remaining) { in uart_emul_isr_handle_rx_ready()
171 rx_content_it = sizeof(fixture->rx_content) - fixture->rx_remaining; in uart_emul_isr_handle_rx_ready()
172 ret = uart_fifo_read(fixture->dev, &fixture->rx_content[rx_content_it], in uart_emul_isr_handle_rx_ready()
173 fixture->rx_remaining); in uart_emul_isr_handle_rx_ready()
174 fixture->rx_remaining -= (size_t)ret; in uart_emul_isr_handle_rx_ready()
177 if (fixture->rx_remaining == 0) { in uart_emul_isr_handle_rx_ready()
178 k_sem_give(&fixture->rx_done_sem); in uart_emul_isr_handle_rx_ready()
184 struct uart_emul_fixture *fixture = user_data; in uart_emul_isr() local
187 if (uart_irq_tx_ready(fixture->dev)) { in uart_emul_isr()
188 uart_emul_isr_handle_tx_ready(fixture); in uart_emul_isr()
190 if (uart_irq_rx_ready(fixture->dev)) { in uart_emul_isr()
191 uart_emul_isr_handle_rx_ready(fixture); in uart_emul_isr()
200 uart_irq_callback_user_data_set(fixture->dev, uart_emul_isr, fixture); in ZTEST_F()
202 uart_irq_tx_enable(fixture->dev); in ZTEST_F()
204 zassert_equal(k_sem_take(&fixture->tx_done_sem, K_SECONDS(1)), 0, in ZTEST_F()
207 tx_len = uart_emul_get_tx_data(fixture->dev, fixture->tx_content, SAMPLE_DATA_SIZE); in ZTEST_F()
209 zassert_mem_equal(fixture->tx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
212 tx_len = uart_emul_get_tx_data(fixture->dev, fixture->tx_content, in ZTEST_F()
213 sizeof(fixture->tx_content)); in ZTEST_F()
221 uart_irq_callback_user_data_set(fixture->dev, uart_emul_isr, fixture); in ZTEST_F()
222 uart_irq_rx_enable(fixture->dev); in ZTEST_F()
225 uart_emul_put_rx_data(fixture->dev, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
228 zassert_equal(k_sem_take(&fixture->rx_done_sem, K_SECONDS(1)), 0, in ZTEST_F()
231 zassert_mem_equal(fixture->rx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
234 rc = uart_poll_in(fixture->dev, &fixture->rx_content[0]); in ZTEST_F()
237 uart_irq_rx_disable(fixture->dev); in ZTEST_F()
244 struct uart_emul_fixture *fixture = user_data; in uart_emul_callback() local
247 k_event_post(&fixture->async_events, ((uint32_t)1 << evt->type)); in uart_emul_callback()
251 zassert_equal(evt->data.tx.len, sizeof(fixture->sample_data)); in uart_emul_callback()
252 zassert_equal(evt->data.tx.buf, fixture->sample_data); in uart_emul_callback()
255 zassert_equal(evt->data.rx.len, sizeof(fixture->sample_data)); in uart_emul_callback()
256 zassert_mem_equal(&evt->data.rx.buf[evt->data.rx.offset], fixture->sample_data, in uart_emul_callback()
257 sizeof(fixture->sample_data)); in uart_emul_callback()
260 zassert_equal(evt->data.rx_buf.buf, fixture->rx_content); in uart_emul_callback()
270 bool uart_emul_wait_for_event(struct uart_emul_fixture *fixture, enum uart_event_type event) in uart_emul_wait_for_event() argument
272 return k_event_wait(&fixture->async_events, ((uint32_t)1 << event), false, K_SECONDS(1)) != in uart_emul_wait_for_event()
280 uart_emul_set_release_buffer_on_timeout(fixture->dev, true); in ZTEST_F()
282 zassert_equal(uart_callback_set(fixture->dev, uart_emul_callback, fixture), 0); in ZTEST_F()
283 zassert_equal(uart_tx(fixture->dev, fixture->sample_data, sizeof(fixture->sample_data), in ZTEST_F()
288 zexpect_true(uart_emul_wait_for_event(fixture, UART_TX_DONE), in ZTEST_F()
291 tx_len = uart_emul_get_tx_data(fixture->dev, fixture->tx_content, SAMPLE_DATA_SIZE); in ZTEST_F()
293 zassert_mem_equal(fixture->tx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
296 tx_len = uart_emul_get_tx_data(fixture->dev, fixture->tx_content, in ZTEST_F()
297 sizeof(fixture->tx_content)); in ZTEST_F()
303 zassert_equal(uart_callback_set(fixture->dev, uart_emul_callback, fixture), 0); in ZTEST_F()
304 zassert_equal(uart_rx_enable(fixture->dev, fixture->rx_content, sizeof(fixture->rx_content), in ZTEST_F()
307 uart_emul_put_rx_data(fixture->dev, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
308 zexpect_true(uart_emul_wait_for_event(fixture, UART_RX_BUF_REQUEST), in ZTEST_F()
310 zexpect_true(uart_emul_wait_for_event(fixture, UART_RX_RDY), "UART_RX_RDY event expected"); in ZTEST_F()
311 zassert_mem_equal(fixture->rx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
312 zexpect_true(uart_emul_wait_for_event(fixture, UART_RX_BUF_RELEASED), in ZTEST_F()
314 zexpect_true(uart_emul_wait_for_event(fixture, UART_RX_DISABLED), in ZTEST_F()
321 struct uart_emul_fixture *fixture = user_data; in uart_emul_callback_rx_timeout() local
324 k_event_post(&fixture->async_events, ((uint32_t)1 << evt->type)); in uart_emul_callback_rx_timeout()
329 zassert_equal(uart_callback_set(fixture->dev, uart_emul_callback_rx_timeout, fixture), 0); in ZTEST_F()
337 uart_rx_enable(fixture->dev, rx_buffer, sizeof(rx_buffer), 100 * USEC_PER_MSEC), 0); in ZTEST_F()
339 uart_emul_set_release_buffer_on_timeout(fixture->dev, false); in ZTEST_F()
340 uart_emul_put_rx_data(fixture->dev, rx_data, sizeof(rx_data)); in ZTEST_F()
341 zexpect_false(uart_emul_wait_for_event(fixture, UART_RX_BUF_RELEASED), in ZTEST_F()
343 zexpect_true(uart_emul_wait_for_event(fixture, UART_RX_RDY)); in ZTEST_F()
345 k_event_set(&fixture->async_events, 0); in ZTEST_F()
347 uart_emul_set_release_buffer_on_timeout(fixture->dev, true); in ZTEST_F()
348 uart_emul_put_rx_data(fixture->dev, rx_data, sizeof(rx_data)); in ZTEST_F()
349 zexpect_true(uart_emul_wait_for_event(fixture, UART_RX_BUF_RELEASED), in ZTEST_F()
351 zexpect_true(uart_emul_wait_for_event(fixture, UART_RX_RDY)); in ZTEST_F()
352 zexpect_true(uart_emul_wait_for_event(fixture, UART_RX_DISABLED), in ZTEST_F()