From 3424c7af7f6fb4fa541969ceaa5edab29aec53a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Mon, 8 Apr 2024 17:36:41 +0200 Subject: [PATCH] tests: drivers: uart: uart_pm: Minor adjustments in the test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modifying arbitrary delay to cover for receivers with timeout. Adding a delay between polling and asynchronous checking to cover for cases when CPU processing is fast enough so that both checks may overlap. Allow error code for uart_rx_disable call. Signed-off-by: Krzysztof Chruściński --- tests/drivers/uart/uart_pm/src/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/drivers/uart/uart_pm/src/main.c b/tests/drivers/uart/uart_pm/src/main.c index 6b640853b90..07e75ec8dd6 100644 --- a/tests/drivers/uart/uart_pm/src/main.c +++ b/tests/drivers/uart/uart_pm/src/main.c @@ -34,7 +34,10 @@ static void polling_verify(const struct device *dev, bool is_async, bool active) for (int i = 0; i < ARRAY_SIZE(outs); i++) { uart_poll_out(dev, outs[i]); - k_busy_wait(1000); + /* We need to wait until receiver gets the data. Receiver may have + * RX timeout so data is not received instantly. + */ + k_busy_wait(5000); if (active) { err = uart_poll_in(dev, &c); @@ -78,6 +81,12 @@ static bool async_verify(const struct device *dev, bool active) zassert_equal(err, 0, "Unexpected err: %d", err); + /* Wait a bit to ensure that polling transfer is already finished otherwise + * receiver might be enabled when there is an ongoing transfer and bytes + * will get corrupted. + */ + k_busy_wait(1000); + if (!DISABLED_RX) { err = uart_rx_enable(dev, rxbuf, sizeof(rxbuf), 1 * USEC_PER_MSEC); zassert_equal(err, 0, "Unexpected err: %d", err); @@ -90,7 +99,7 @@ static bool async_verify(const struct device *dev, bool active) if (!DISABLED_RX) { err = uart_rx_disable(dev); - zassert_equal(err, 0, "Unexpected err: %d", err); + zassert_true((err == 0) || (err == -EFAULT)); k_busy_wait(10000);