Skip to content

Commit e23b798

Browse files
nordic-krchnordic-piks
authored andcommitted
tests: drivers: lpuart: Fix TX timeout
Some test cases were using too short TX timeout (1 ms). Transfer setup (waiting for receiver being ready) can take more than 1ms and if timeout is too short then TX may expire before it is even started. Added a fixed timeout in the test. It is used for all test cases. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 813fe0b commit e23b798

File tree

1 file changed

+10
-4
lines changed
  • tests/drivers/lpuart/src

1 file changed

+10
-4
lines changed

tests/drivers/lpuart/src/main.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ static uint8_t rx_buf[5];
2525
static bool buf_released;
2626
static int test_time;
2727

28+
/* Timeout should be more than a millisecond as transfer setup with enabling
29+
* of HFXO can take more than a millisecond so if timeout is too short it can
30+
* expire before first byte is transferred.
31+
*/
32+
#define TX_TIMEOUT_US 10000
33+
2834
static void kill_timer_handler(struct k_timer *timer)
2935
{
3036
ARG_UNUSED(timer);
@@ -85,7 +91,7 @@ static void next_tx(const struct device *dev)
8591
}
8692

8793
tx_req_cnt++;
88-
int err = uart_tx(dev, tx_buf, tx_len, 100000);
94+
int err = uart_tx(dev, tx_buf, tx_len, TX_TIMEOUT_US);
8995

9096
if (err != 0) {
9197
TC_PRINT("uart_tx returned err:%d\n", err);
@@ -323,7 +329,7 @@ static void validate_lpuart(const struct device *lpuart)
323329

324330
k_timer_start(&wdt_timer, K_MSEC(200), K_NO_WAIT);
325331

326-
err = uart_tx(lpuart, tx_buf, sizeof(tx_buf), 10000);
332+
err = uart_tx(lpuart, tx_buf, sizeof(tx_buf), TX_TIMEOUT_US);
327333
zassert_equal(err, 0, NULL);
328334

329335
k_msleep(10);
@@ -479,7 +485,7 @@ ZTEST(test_lpuart_resilency, test_tx_abort_rx_not_enabled)
479485
zassert_true(device_is_ready(lpuart), NULL);
480486
uart_callback_set(lpuart, tx_abort_expected_callback, NULL);
481487

482-
err = uart_tx(lpuart, tx_buf, sizeof(tx_buf), 1000);
488+
err = uart_tx(lpuart, tx_buf, sizeof(tx_buf), TX_TIMEOUT_US);
483489
zassert_equal(err, 0, "uart_tx - unexpected err: %d", err);
484490
k_msleep(10);
485491
zassert_equal(tx_abort_cnt, 1, "tx_abort_cnt != 1: %d", tx_abort_cnt);
@@ -500,7 +506,7 @@ ZTEST(test_lpuart_resilency, test_tx_abort_from_api)
500506

501507
err = uart_rx_enable(lpuart, rx_buffer, sizeof(rx_buffer), 100);
502508
zassert_equal(err, 0, "uart_rx_enable - unexpected err:%d", err);
503-
err = uart_tx(lpuart, tx_buffer, sizeof(tx_buffer), 1000);
509+
err = uart_tx(lpuart, tx_buffer, sizeof(tx_buffer), TX_TIMEOUT_US);
504510
zassert_equal(err, 0, "uart_tx - unexpected err:%d", err);
505511
k_msleep(1);
506512
err = uart_tx_abort(lpuart);

0 commit comments

Comments
 (0)