tests: uart: Add forever timeout test for UART Async API.

Check for proper driver behaviour if timeout for uart_rx_enable or
uart_tx is set to K_FOREVER.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
This commit is contained in:
Mieszko Mierunski 2020-01-24 16:14:54 +01:00 committed by Carles Cufí
commit 3fff2e7291
3 changed files with 76 additions and 1 deletions

View file

@ -33,6 +33,8 @@ void test_main(void)
ztest_unit_test(test_long_buffers_setup),
ztest_user_unit_test(test_long_buffers),
ztest_unit_test(test_write_abort_setup),
ztest_user_unit_test(test_write_abort));
ztest_user_unit_test(test_write_abort),
ztest_unit_test(test_forever_timeout_setup),
ztest_user_unit_test(test_forever_timeout));
ztest_run_test_suite(uart_async_test);
}

View file

@ -32,6 +32,7 @@ void test_chained_read(void);
void test_double_buffer(void);
void test_read_abort(void);
void test_write_abort(void);
void test_forever_timeout(void);
void test_long_buffers(void);
void test_chained_write(void);
@ -40,6 +41,7 @@ void test_chained_read_setup(void);
void test_double_buffer_setup(void);
void test_read_abort_setup(void);
void test_write_abort_setup(void);
void test_forever_timeout_setup(void);
void test_long_buffers_setup(void);
void test_chained_write_setup(void);

View file

@ -360,6 +360,77 @@ void test_write_abort(void)
"RX_DISABLED timeout");
}
void test_forever_timeout_callback(struct uart_event *evt, void *user_data)
{
switch (evt->type) {
case UART_TX_DONE:
k_sem_give(&tx_done);
break;
case UART_TX_ABORTED:
sent = evt->data.tx.len;
k_sem_give(&tx_aborted);
break;
case UART_RX_RDY:
received = evt->data.rx.len;
k_sem_give(&rx_rdy);
break;
case UART_RX_BUF_RELEASED:
k_sem_give(&rx_buf_released);
break;
case UART_RX_DISABLED:
k_sem_give(&rx_disabled);
break;
default:
break;
}
}
void test_forever_timeout_setup(void)
{
struct device *uart_dev = device_get_binding(UART_DEVICE_NAME);
uart_callback_set(uart_dev, test_forever_timeout_callback, NULL);
}
void test_forever_timeout(void)
{
struct device *uart_dev = device_get_binding(UART_DEVICE_NAME);
u8_t rx_buf[100];
u8_t tx_buf[100];
memset(rx_buf, 0, sizeof(rx_buf));
memset(tx_buf, 1, sizeof(tx_buf));
uart_rx_enable(uart_dev, rx_buf, sizeof(rx_buf), K_FOREVER);
uart_tx(uart_dev, tx_buf, 5, K_FOREVER);
zassert_not_equal(k_sem_take(&tx_aborted, K_MSEC(1000)), 0,
"TX_ABORTED timeout");
zassert_equal(k_sem_take(&tx_done, K_MSEC(100)), 0, "TX_DONE timeout");
zassert_not_equal(k_sem_take(&rx_rdy, K_MSEC(1000)), 0,
"RX_RDY timeout");
uart_tx(uart_dev, tx_buf, 95, K_FOREVER);
zassert_not_equal(k_sem_take(&tx_aborted, K_MSEC(1000)), 0,
"TX_ABORTED timeout");
zassert_equal(k_sem_take(&tx_done, K_MSEC(100)), 0, "TX_DONE timeout");
zassert_equal(k_sem_take(&rx_rdy, K_MSEC(100)), 0, "RX_RDY timeout");
zassert_equal(memcmp(tx_buf, rx_buf, 100), 0, "Buffers not equal");
uart_rx_disable(uart_dev);
zassert_equal(k_sem_take(&rx_buf_released, K_MSEC(100)),
0,
"RX_BUF_RELEASED timeout");
zassert_equal(k_sem_take(&rx_disabled, K_MSEC(100)), 0,
"RX_DISABLED timeout");
}
ZTEST_DMEM u8_t chained_write_tx_bufs[2][10] = {"Message 1", "Message 2"};
ZTEST_DMEM bool chained_write_next_buf = true;
ZTEST_BMEM volatile u8_t tx_sent;