Skip to content

Commit cd89942

Browse files
JvanDoorenheinwessels
authored andcommitted
tests: drivers: uart: Adding wide data async tests
Extending async tests with wide data support. Signed-off-by: Jeroen van Dooren <[email protected]>
1 parent cad43aa commit cd89942

File tree

3 files changed

+139
-0
lines changed

3 files changed

+139
-0
lines changed

tests/drivers/uart/uart_async_api/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ project(uart_high_level_api)
88
target_sources(app PRIVATE
99
src/test_uart_async.c
1010
)
11+
target_sources_ifdef(CONFIG_UART_WIDE_DATA app PRIVATE src/test_uart_wide.c)
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Copyright (c) 2023 Jeroen van Dooren
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "test_uart.h"
8+
9+
K_SEM_DEFINE(tx_wide_done, 0, 1);
10+
K_SEM_DEFINE(tx_wide_aborted, 0, 1);
11+
K_SEM_DEFINE(rx_wide_rdy, 0, 1);
12+
K_SEM_DEFINE(rx_wide_buf_released, 0, 1);
13+
K_SEM_DEFINE(rx_wide_disabled, 0, 1);
14+
15+
static ZTEST_BMEM const struct device *const uart_dev =
16+
DEVICE_DT_GET(UART_NODE);
17+
18+
static void init_test(void)
19+
{
20+
__ASSERT_NO_MSG(device_is_ready(uart_dev));
21+
uart_rx_disable(uart_dev);
22+
uart_tx_abort(uart_dev);
23+
k_sem_reset(&tx_wide_done);
24+
k_sem_reset(&tx_wide_aborted);
25+
k_sem_reset(&rx_wide_rdy);
26+
k_sem_reset(&rx_wide_buf_released);
27+
k_sem_reset(&rx_wide_disabled);
28+
}
29+
30+
#ifdef CONFIG_USERSPACE
31+
static void set_permissions(void)
32+
{
33+
k_thread_access_grant(k_current_get(), &tx_wide_done, &tx_wide_aborted,
34+
&rx_wide_rdy, &rx_wide_buf_released, &rx_wide_disabled,
35+
uart_dev);
36+
}
37+
#endif
38+
39+
static void uart_async_test_init(void)
40+
{
41+
init_test();
42+
43+
#ifdef CONFIG_USERSPACE
44+
set_permissions();
45+
#endif
46+
}
47+
48+
static void test_single_read_callback(const struct device *dev,
49+
struct uart_event *evt, void *user_data)
50+
{
51+
ARG_UNUSED(dev);
52+
53+
switch (evt->type) {
54+
case UART_TX_DONE:
55+
k_sem_give(&tx_wide_done);
56+
break;
57+
case UART_TX_ABORTED:
58+
(*(uint32_t *)user_data)++;
59+
break;
60+
case UART_RX_RDY:
61+
k_sem_give(&rx_wide_rdy);
62+
break;
63+
case UART_RX_BUF_RELEASED:
64+
k_sem_give(&rx_wide_buf_released);
65+
break;
66+
case UART_RX_DISABLED:
67+
k_sem_give(&rx_wide_disabled);
68+
break;
69+
default:
70+
break;
71+
}
72+
}
73+
74+
ZTEST_BMEM volatile uint32_t tx_wide_aborted_count;
75+
76+
static void *single_read_setup_wide(void)
77+
{
78+
uart_async_test_init();
79+
80+
uart_callback_set(uart_dev,
81+
test_single_read_callback,
82+
(void *) &tx_wide_aborted_count);
83+
84+
return NULL;
85+
}
86+
87+
ZTEST_USER(uart_async_single_read_wide, test_single_read_wide)
88+
{
89+
uint16_t rx_buf[10] = {0};
90+
91+
/* Check also if sending from read only memory (e.g. flash) works. */
92+
static const uint16_t tx_buf[5] = {0x74, 0x65, 0x73, 0x74, 0x0D};
93+
94+
zassert_not_equal(memcmp(tx_buf, rx_buf, 5), 0,
95+
"Initial buffer check failed");
96+
97+
uart_rx_enable_u16(uart_dev, rx_buf, 10, 50 * USEC_PER_MSEC);
98+
zassert_equal(k_sem_take(&rx_wide_rdy, K_MSEC(100)), -EAGAIN,
99+
"RX_RDY not expected at this point");
100+
101+
uart_tx_u16(uart_dev, tx_buf, sizeof(tx_buf)/sizeof(uint16_t), 100 * USEC_PER_MSEC);
102+
zassert_equal(k_sem_take(&tx_wide_done, K_MSEC(100)), 0, "TX_DONE timeout");
103+
zassert_equal(k_sem_take(&rx_wide_rdy, K_MSEC(100)), 0, "RX_RDY timeout");
104+
zassert_equal(k_sem_take(&rx_wide_rdy, K_MSEC(100)), -EAGAIN,
105+
"Extra RX_RDY received");
106+
107+
zassert_equal(memcmp(tx_buf, rx_buf, 5), 0, "Buffers not equal");
108+
zassert_not_equal(memcmp(tx_buf, rx_buf+5, 5), 0, "Buffers not equal");
109+
110+
uart_tx_u16(uart_dev, tx_buf, sizeof(tx_buf)/sizeof(uint16_t), 100 * USEC_PER_MSEC);
111+
zassert_equal(k_sem_take(&tx_wide_done, K_MSEC(100)), 0, "TX_DONE timeout");
112+
zassert_equal(k_sem_take(&rx_wide_rdy, K_MSEC(100)), 0, "RX_RDY timeout");
113+
zassert_equal(k_sem_take(&rx_wide_buf_released, K_MSEC(100)),
114+
0,
115+
"RX_BUF_RELEASED timeout");
116+
zassert_equal(k_sem_take(&rx_wide_disabled, K_MSEC(1000)), 0,
117+
"RX_DISABLED timeout");
118+
zassert_equal(k_sem_take(&rx_wide_rdy, K_MSEC(100)), -EAGAIN,
119+
"Extra RX_RDY received");
120+
121+
zassert_equal(memcmp(tx_buf, rx_buf+5, 5), 0, "Buffers not equal");
122+
zassert_equal(tx_wide_aborted_count, 0, "TX aborted triggered");
123+
}
124+
125+
ZTEST_SUITE(uart_async_single_read_wide, NULL, single_read_setup_wide,
126+
NULL, NULL, NULL);

tests/drivers/uart/uart_async_api/testcase.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ tests:
3131
harness_config:
3232
fixture: gpio_loopback
3333
depends_on: gpio
34+
drivers.uart.wide:
35+
filter: CONFIG_UART_CONSOLE and CONFIG_SERIAL_SUPPORT_ASYNC and not CONFIG_UART_MCUX_LPUART
36+
harness: ztest
37+
harness_config:
38+
fixture: gpio_loopback
39+
depends_on: gpio
40+
extra_configs:
41+
- CONFIG_UART_WIDE_DATA=y
42+
arch_allow: arm
43+
platform_allow: nucleo_h743zi
44+
integration_platforms:
45+
- nucleo_h743zi
3446
drivers.uart.async_api.nrf_uart:
3547
filter: CONFIG_UART_CONSOLE and CONFIG_SERIAL_SUPPORT_ASYNC
3648
harness: ztest

0 commit comments

Comments
 (0)