Skip to content

Commit bec7ff3

Browse files
committed
[nrf fromtree] tests: drivers: uart: uart_async_api: Tweak test_read_abort test
Test was staring a TX transfer and aborting it after 300 us from the timer handler. Test was assuming that ongoing transfer will not finish in those 300 us. This might not be true for higher baudrates. Instead of using fixed timeout, a value is calculated from the baudrate and targets to abort the transfer after approx. 20 bytes of 95 byte long transfer. Signed-off-by: Krzysztof Chruściński <[email protected]> (cherry picked from commit 38c129d)
1 parent 1789986 commit bec7ff3

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

tests/drivers/uart/uart_async_api/src/test_uart_async.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,9 @@ static void *read_abort_setup(void)
592592

593593
ZTEST_USER(uart_async_read_abort, test_read_abort)
594594
{
595+
struct uart_config cfg;
596+
int err;
597+
uint32_t t_us;
595598
#if NOCACHE_MEM
596599
static __aligned(32) uint8_t rx_buf[100] __used __NOCACHE;
597600
static __aligned(32) uint8_t tx_buf[100] __used __NOCACHE;
@@ -603,17 +606,26 @@ ZTEST_USER(uart_async_read_abort, test_read_abort)
603606
memset(rx_buf, 0, sizeof(rx_buf));
604607
memset(tx_buf, 1, sizeof(tx_buf));
605608

606-
uart_rx_enable(uart_dev, rx_buf, sizeof(rx_buf), 50 * USEC_PER_MSEC);
609+
err = uart_config_get(uart_dev, &cfg);
610+
zassert_equal(err, 0);
611+
612+
/* Lets aim to abort after transmitting ~20 bytes (200 bauds) */
613+
t_us = (20 * 10 * 1000000) / cfg.baudrate;
614+
615+
err = uart_rx_enable(uart_dev, rx_buf, sizeof(rx_buf), 50 * USEC_PER_MSEC);
616+
zassert_equal(err, 0);
607617
k_sem_give(&rx_buf_coherency);
608618

609-
uart_tx(uart_dev, tx_buf, 5, 100 * USEC_PER_MSEC);
619+
err = uart_tx(uart_dev, tx_buf, 5, 100 * USEC_PER_MSEC);
620+
zassert_equal(err, 0);
610621
zassert_equal(k_sem_take(&tx_done, K_MSEC(100)), 0, "TX_DONE timeout");
611622
zassert_equal(k_sem_take(&rx_rdy, K_MSEC(100)), 0, "RX_RDY timeout");
612623
zassert_equal(memcmp(tx_buf, rx_buf, 5), 0, "Buffers not equal");
613624

614-
uart_tx(uart_dev, tx_buf, 95, 100 * USEC_PER_MSEC);
625+
err = uart_tx(uart_dev, tx_buf, 95, 100 * USEC_PER_MSEC);
626+
zassert_equal(err, 0);
615627

616-
k_timer_start(&read_abort_timer, K_USEC(300), K_NO_WAIT);
628+
k_timer_start(&read_abort_timer, K_USEC(t_us), K_NO_WAIT);
617629

618630
/* RX will be aborted from k_timer timeout */
619631

0 commit comments

Comments
 (0)