Skip to content
Permalink
Browse files

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>
  • Loading branch information...
Mierunski authored and carlescufi committed May 15, 2019
1 parent 7b05762 commit c4d90aabbae487fc04bbdb5bbce8b935ae89053b
@@ -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);
}
@@ -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__ */
@@ -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");
}

0 comments on commit c4d90aa

Please sign in to comment.
You can’t perform that action at this time.