tests: uart: Add long tranfer test to UART_ASYNC_API.

Add test where transfer time is longer than rx timeout.

Signed-off-by: Mieszko Mierunski <mieszko.mierunski@nordicsemi.no>
This commit is contained in:
Mieszko Mierunski 2019-05-15 11:43:54 +02:00 committed by Carles Cufí
parent 7b0576243a
commit c4d90aabba
3 changed files with 85 additions and 0 deletions

View file

@ -21,6 +21,7 @@ void test_main(void)
ztest_unit_test(test_double_buffer),
ztest_unit_test(test_read_abort),
ztest_unit_test(test_chained_write),
ztest_unit_test(test_long_buffers),
ztest_unit_test(test_write_abort));
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_long_buffers(void);
void test_chained_write(void);
#endif /* __TEST_UART_H__ */

View file

@ -378,3 +378,86 @@ void test_chained_write(void)
"RX_BUF_RELEASED timeout");
zassert_equal(k_sem_take(&rx_disabled, 100), 0, "RX_DISABLED timeout");
}
u8_t long_rx_buf[1024];
u8_t long_rx_buf2[1024];
u8_t long_tx_buf[1000];
volatile u8_t evt_num;
size_t long_received[2];
void test_long_buffers_callback(struct uart_event *evt, void *user_data)
{
struct device *uart_dev = (struct device *) user_data;
static bool next_buf = true;
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:
long_received[evt_num] = evt->data.rx.len;
evt_num++;
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;
case UART_RX_BUF_REQUEST:
if (next_buf) {
uart_rx_buf_rsp(uart_dev, long_rx_buf2, 1024);
next_buf = false;
}
k_sem_give(&rx_disabled);
break;
default:
break;
}
}
void test_long_buffers(void)
{
struct device *uart_dev = device_get_binding(UART_DEVICE_NAME);
memset(long_rx_buf, 0, sizeof(long_rx_buf));
memset(long_tx_buf, 1, sizeof(long_tx_buf));
uart_callback_set(uart_dev, test_long_buffers_callback, uart_dev);
uart_rx_enable(uart_dev, long_rx_buf, sizeof(long_rx_buf), 10);
uart_tx(uart_dev, long_tx_buf, 500, 200);
zassert_equal(k_sem_take(&tx_done, 200), 0, "TX_DONE timeout");
zassert_equal(k_sem_take(&rx_rdy, 200), 0, "RX_RDY timeout");
zassert_equal(long_received[0], 500, "Wrong number of bytes received.");
zassert_equal(memcmp(long_tx_buf, long_rx_buf, 500),
0,
"Buffers not equal");
evt_num = 0;
uart_tx(uart_dev, long_tx_buf, 1000, 200);
zassert_equal(k_sem_take(&tx_done, 200), 0, "TX_DONE timeout");
zassert_equal(k_sem_take(&rx_rdy, 200), 0, "RX_RDY timeout");
zassert_equal(k_sem_take(&rx_rdy, 200), 0, "RX_RDY timeout");
zassert_equal(long_received[0], 524, "Wrong number of bytes received.");
zassert_equal(long_received[1], 476, "Wrong number of bytes received.");
zassert_equal(memcmp(long_tx_buf, long_rx_buf + 500, long_received[0]),
0,
"Buffers not equal");
zassert_equal(memcmp(long_tx_buf, long_rx_buf2, long_received[1]),
0,
"Buffers not equal");
uart_rx_disable(uart_dev);
zassert_equal(k_sem_take(&rx_buf_released, 100),
0,
"RX_BUF_RELEASED timeout");
zassert_equal(k_sem_take(&rx_disabled, 100), 0, "RX_DISABLED timeout");
}