Skip to content

Commit c3a1730

Browse files
JvanDoorencarlescufi
authored andcommitted
tests: drivers: uart: Adding wide data cfg tests
Extending configuration tests with wide data support. Signed-off-by: Jeroen van Dooren <[email protected]>
1 parent 4133956 commit c3a1730

File tree

5 files changed

+140
-0
lines changed

5 files changed

+140
-0
lines changed

tests/drivers/uart/uart_basic_api/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ target_sources(app PRIVATE
1111
)
1212
target_sources_ifdef(CONFIG_UART_INTERRUPT_DRIVEN app PRIVATE src/test_uart_fifo.c)
1313
target_sources_ifdef(CONFIG_UART_INTERRUPT_DRIVEN app PRIVATE src/test_uart_pending.c)
14+
target_sources_ifdef(CONFIG_UART_WIDE_DATA app PRIVATE src/test_uart_config_wide.c)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
dut: &usart2 {
6+
pinctrl-0 = <&usart2_tx_pd5 &usart2_rx_pd6>;
7+
pinctrl-names = "default";
8+
current-speed = <115200>;
9+
status = "okay";
10+
};

tests/drivers/uart/uart_basic_api/src/test_uart.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ void test_uart_configure(void);
2323
void test_uart_config_get(void);
2424
void test_uart_poll_out(void);
2525
void test_uart_poll_in(void);
26+
#if CONFIG_UART_WIDE_DATA
27+
void test_uart_configure_wide(void);
28+
void test_uart_config_get_wide(void);
29+
#endif
2630
#if CONFIG_UART_INTERRUPT_DRIVEN
2731
void test_uart_fifo_fill(void);
2832
void test_uart_fifo_read(void);
2933
void test_uart_pending(void);
3034
#endif
35+
3136
#endif
3237

3338
#endif /* __TEST_UART_H__ */
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) 2023 Jeroen van Dooren
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* @addtogroup t_uart_basic
9+
* @{
10+
* @defgroup t_uart_config test_uart_config_wide
11+
* @brief TestPurpose: verify UART configure API settings for wide data support
12+
* @details
13+
* - Test Steps
14+
* - Configure: test_uart_configure_wide( )
15+
* - Configure Get: test_uart_config_get_wide( )
16+
* - Expected Results
17+
* -# When test UART CONFIG Configure, the value of configurations actually
18+
* set will be equal to the original configuration values (from device
19+
* tree or run-time configuration to modify those loaded initially from
20+
* device tree)
21+
* -# When test UART CONFIG Configure Get, the app will get/retrieve the
22+
* value of configurations stored at location and to be passed to UART
23+
* CONFIG Configure
24+
* @}
25+
*/
26+
27+
#include "test_uart.h"
28+
const struct uart_config uart_cfg_wide = {
29+
.baudrate = 115200,
30+
.parity = UART_CFG_PARITY_NONE,
31+
.stop_bits = UART_CFG_STOP_BITS_1,
32+
.data_bits = UART_CFG_DATA_BITS_9,
33+
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE
34+
};
35+
36+
static int test_configure_wide(void)
37+
{
38+
const struct device *const uart_dev = DEVICE_DT_GET(DT_NODELABEL(dut));
39+
40+
if (!device_is_ready(uart_dev)) {
41+
TC_PRINT("UART device not ready\n");
42+
return TC_FAIL;
43+
}
44+
45+
/* Verify configure() - set device configuration using data in cfg */
46+
int ret = uart_configure(uart_dev, &uart_cfg_wide);
47+
48+
if (ret == -ENOSYS) {
49+
return TC_SKIP;
50+
}
51+
52+
/* 0 if successful, - error code otherwise */
53+
return (ret == 0) ? TC_PASS : TC_FAIL;
54+
55+
}
56+
57+
/* test UART configure get (retrieve configuration) */
58+
static int test_config_get_wide(void)
59+
{
60+
struct uart_config uart_cfg_check;
61+
const struct device *const uart_dev = DEVICE_DT_GET(DT_NODELABEL(dut));
62+
63+
if (!device_is_ready(uart_dev)) {
64+
TC_PRINT("UART device not ready\n");
65+
return TC_FAIL;
66+
}
67+
68+
TC_PRINT("This is a configure_get_wide test.\n");
69+
70+
/* Verify configure() - set device configuration using data in cfg */
71+
/* 0 if successful, - error code otherwise */
72+
int ret = uart_configure(uart_dev, &uart_cfg_wide);
73+
74+
if (ret == -ENOSYS) {
75+
return TC_SKIP;
76+
}
77+
78+
zassert_true(ret == 0, "set config error");
79+
80+
/* Verify config_get() - get device configuration, put in cfg */
81+
/* 0 if successful, - error code otherwise */
82+
/* so get the configurations from the device and check */
83+
ret = uart_config_get(uart_dev, &uart_cfg_check);
84+
zassert_true(ret == 0, "get config error");
85+
86+
/* Confirm the values from device are the values put in cfg*/
87+
if (memcmp(&uart_cfg_wide, &uart_cfg_check, sizeof(uart_cfg_wide)) != 0) {
88+
return TC_FAIL;
89+
} else {
90+
return TC_PASS;
91+
}
92+
}
93+
94+
#if CONFIG_SHELL
95+
void test_uart_configure_wide(void)
96+
#else
97+
ZTEST(uart_basic_api, test_uart_configure_wide)
98+
#endif
99+
{
100+
int ret = test_configure_wide();
101+
102+
zassert_true((ret == TC_PASS) || (ret == TC_SKIP));
103+
}
104+
105+
#if CONFIG_SHELL
106+
void test_uart_config_get_wide(void)
107+
#else
108+
ZTEST(uart_basic_api, test_uart_config_get_wide)
109+
#endif
110+
{
111+
int ret = test_config_get_wide();
112+
113+
zassert_true((ret == TC_PASS) || (ret == TC_SKIP));
114+
}

tests/drivers/uart/uart_basic_api/testcase.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ tests:
77
harness: keyboard
88
integration_platforms:
99
- mps2_an385
10+
drivers.uart.basic_api.wide:
11+
extra_configs:
12+
- CONFIG_UART_WIDE_DATA=y
13+
tags: drivers uart
14+
filter: CONFIG_UART_CONSOLE
15+
arch_allow: arm
16+
platform_allow: nucleo_h743zi
17+
integration_platforms:
18+
- nucleo_h743zi
19+
extra_args: DTC_OVERLAY_FILE="boards/nucleo_h743zi.overlay"
1020
drivers.uart.basic_api.poll:
1121
extra_args: CONF_FILE=prj_poll.conf
1222
tags:

0 commit comments

Comments
 (0)