Lines Matching refs:fixture
46 static struct uart_emul_device_fixture fixture = {.dev = DEVICE_DT_GET(EMUL_UART_NODE)}; in uart_emul_device_setup() local
49 fixture.sample_data[i] = i; in uart_emul_device_setup()
53 k_sem_init(&fixture.tx_done_sem, 0, 1); in uart_emul_device_setup()
54 k_sem_init(&fixture.rx_done_sem, 0, 1); in uart_emul_device_setup()
58 k_event_init(&fixture.async_events); in uart_emul_device_setup()
61 zassert_not_null(fixture.dev); in uart_emul_device_setup()
62 return &fixture; in uart_emul_device_setup()
67 struct uart_emul_device_fixture *fixture = f; in uart_emul_device_before() local
69 uart_emul_flush_rx_data(fixture->dev); in uart_emul_device_before()
70 uart_emul_flush_tx_data(fixture->dev); in uart_emul_device_before()
72 uart_err_check(fixture->dev); in uart_emul_device_before()
74 memset(fixture->rx_content, 0, sizeof(fixture->rx_content)); in uart_emul_device_before()
77 uart_irq_tx_disable(fixture->dev); in uart_emul_device_before()
78 uart_irq_rx_disable(fixture->dev); in uart_emul_device_before()
80 k_sem_reset(&fixture->tx_done_sem); in uart_emul_device_before()
81 k_sem_reset(&fixture->rx_done_sem); in uart_emul_device_before()
83 fixture->tx_remaining = SAMPLE_DATA_SIZE; in uart_emul_device_before()
84 fixture->rx_remaining = SAMPLE_DATA_SIZE; in uart_emul_device_before()
88 uart_tx_abort(fixture->dev); in uart_emul_device_before()
89 uart_rx_disable(fixture->dev); in uart_emul_device_before()
91 k_event_set(&fixture->async_events, 0); in uart_emul_device_before()
102 uart_poll_out(fixture->dev, i); in ZTEST_F()
105 len = uart_emul_get_tx_data(fixture->dev, NULL, UINT32_MAX); in ZTEST_F()
109 ret = uart_poll_in(fixture->dev, &byte); in ZTEST_F()
114 ret = uart_poll_in(fixture->dev, &byte); in ZTEST_F()
119 static void uart_emul_device_isr_handle_tx_ready(struct uart_emul_device_fixture *fixture) in uart_emul_device_isr_handle_tx_ready() argument
124 if (fixture->tx_remaining) { in uart_emul_device_isr_handle_tx_ready()
125 sample_data_it = sizeof(fixture->sample_data) - fixture->tx_remaining; in uart_emul_device_isr_handle_tx_ready()
126 ret = uart_fifo_fill(fixture->dev, &fixture->sample_data[sample_data_it], in uart_emul_device_isr_handle_tx_ready()
127 fixture->tx_remaining); in uart_emul_device_isr_handle_tx_ready()
128 fixture->tx_remaining -= (size_t)ret; in uart_emul_device_isr_handle_tx_ready()
131 if (fixture->tx_remaining == 0) { in uart_emul_device_isr_handle_tx_ready()
132 uart_irq_tx_disable(fixture->dev); in uart_emul_device_isr_handle_tx_ready()
133 k_sem_give(&fixture->tx_done_sem); in uart_emul_device_isr_handle_tx_ready()
137 static void uart_emul_device_isr_handle_rx_ready(struct uart_emul_device_fixture *fixture) in uart_emul_device_isr_handle_rx_ready() argument
142 if (fixture->rx_remaining) { in uart_emul_device_isr_handle_rx_ready()
143 rx_content_it = sizeof(fixture->rx_content) - fixture->rx_remaining; in uart_emul_device_isr_handle_rx_ready()
144 ret = uart_fifo_read(fixture->dev, &fixture->rx_content[rx_content_it], in uart_emul_device_isr_handle_rx_ready()
145 fixture->rx_remaining); in uart_emul_device_isr_handle_rx_ready()
146 fixture->rx_remaining -= (size_t)ret; in uart_emul_device_isr_handle_rx_ready()
149 if (fixture->rx_remaining == 0) { in uart_emul_device_isr_handle_rx_ready()
150 k_sem_give(&fixture->rx_done_sem); in uart_emul_device_isr_handle_rx_ready()
156 struct uart_emul_device_fixture *fixture = user_data; in uart_emul_device_isr() local
159 if (uart_irq_tx_ready(fixture->dev)) { in uart_emul_device_isr()
160 uart_emul_device_isr_handle_tx_ready(fixture); in uart_emul_device_isr()
162 if (uart_irq_rx_ready(fixture->dev)) { in uart_emul_device_isr()
163 uart_emul_device_isr_handle_rx_ready(fixture); in uart_emul_device_isr()
173 uart_irq_callback_user_data_set(fixture->dev, uart_emul_device_isr, fixture); in ZTEST_F()
175 uart_irq_rx_enable(fixture->dev); in ZTEST_F()
177 uart_irq_tx_enable(fixture->dev); in ZTEST_F()
180 zassert_ok(k_sem_take(&fixture->tx_done_sem, K_SECONDS(1)), in ZTEST_F()
183 tx_len = uart_emul_get_tx_data(fixture->dev, NULL, SAMPLE_DATA_SIZE); in ZTEST_F()
186 zassert_ok(k_sem_take(&fixture->rx_done_sem, K_SECONDS(1)), in ZTEST_F()
188 zassert_mem_equal(fixture->rx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
191 rc = uart_poll_in(fixture->dev, &fixture->rx_content[0]); in ZTEST_F()
194 uart_irq_rx_disable(fixture->dev); in ZTEST_F()
201 struct uart_emul_device_fixture *fixture = user_data; in uart_emul_callback() local
204 k_event_post(&fixture->async_events, ((uint32_t)1 << evt->type)); in uart_emul_callback()
208 zassert_equal(evt->data.tx.len, sizeof(fixture->sample_data)); in uart_emul_callback()
209 zassert_equal(evt->data.tx.buf, fixture->sample_data); in uart_emul_callback()
212 zassert_equal(evt->data.rx.len, sizeof(fixture->sample_data)); in uart_emul_callback()
213 zassert_mem_equal(&evt->data.rx.buf[evt->data.rx.offset], fixture->sample_data, in uart_emul_callback()
214 sizeof(fixture->sample_data)); in uart_emul_callback()
217 zassert_equal(evt->data.rx_buf.buf, fixture->rx_content); in uart_emul_callback()
227 static bool uart_emul_device_wait_for_event(struct uart_emul_device_fixture *fixture, in uart_emul_device_wait_for_event() argument
230 return k_event_wait(&fixture->async_events, ((uint32_t)1 << event), false, K_SECONDS(1)) != in uart_emul_device_wait_for_event()
238 uart_emul_set_release_buffer_on_timeout(fixture->dev, true); in ZTEST_F()
240 zassert_ok(uart_callback_set(fixture->dev, uart_emul_callback, fixture)); in ZTEST_F()
241 zassert_ok(uart_tx(fixture->dev, fixture->sample_data, sizeof(fixture->sample_data), in ZTEST_F()
243 zassert_ok(uart_rx_enable(fixture->dev, fixture->rx_content, sizeof(fixture->rx_content), in ZTEST_F()
247 zexpect_true(uart_emul_device_wait_for_event(fixture, UART_TX_DONE), in ZTEST_F()
250 tx_len = uart_emul_get_tx_data(fixture->dev, NULL, SAMPLE_DATA_SIZE); in ZTEST_F()
253 zexpect_true(uart_emul_device_wait_for_event(fixture, UART_RX_BUF_REQUEST), in ZTEST_F()
255 zexpect_true(uart_emul_device_wait_for_event(fixture, UART_RX_RDY), in ZTEST_F()
257 zassert_mem_equal(fixture->rx_content, fixture->sample_data, SAMPLE_DATA_SIZE); in ZTEST_F()
258 zexpect_true(uart_emul_device_wait_for_event(fixture, UART_RX_BUF_RELEASED), in ZTEST_F()
260 zexpect_true(uart_emul_device_wait_for_event(fixture, UART_RX_DISABLED), in ZTEST_F()