Skip to content

Commit 930edd8

Browse files
JvanDoorencarlescufi
authored andcommitted
tests: drivers: uart: Resetting uart state
Resetting uart state before every testcase. Signed-off-by: Jeroen van Dooren <[email protected]>
1 parent c3a1730 commit 930edd8

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ K_SEM_DEFINE(rx_buf_released, 0, 1);
1414
K_SEM_DEFINE(rx_disabled, 0, 1);
1515

1616
ZTEST_BMEM volatile bool failed_in_isr;
17-
ZTEST_BMEM static const struct device *const uart_dev =
17+
static ZTEST_BMEM const struct device *const uart_dev =
1818
DEVICE_DT_GET(UART_NODE);
1919

2020
static void read_abort_timeout(struct k_timer *timer);
@@ -24,6 +24,13 @@ K_TIMER_DEFINE(read_abort_timer, read_abort_timeout, NULL);
2424
static void init_test(void)
2525
{
2626
__ASSERT_NO_MSG(device_is_ready(uart_dev));
27+
uart_rx_disable(uart_dev);
28+
uart_tx_abort(uart_dev);
29+
k_sem_reset(&tx_done);
30+
k_sem_reset(&tx_aborted);
31+
k_sem_reset(&rx_rdy);
32+
k_sem_reset(&rx_buf_released);
33+
k_sem_reset(&rx_disabled);
2734
}
2835

2936
#ifdef CONFIG_USERSPACE
@@ -39,21 +46,35 @@ static void uart_async_test_init(void)
3946
{
4047
static bool initialized;
4148

49+
__ASSERT_NO_MSG(device_is_ready(uart_dev));
50+
uart_rx_disable(uart_dev);
51+
uart_tx_abort(uart_dev);
4252
k_sem_reset(&tx_done);
4353
k_sem_reset(&tx_aborted);
4454
k_sem_reset(&rx_rdy);
4555
k_sem_reset(&rx_buf_coherency);
4656
k_sem_reset(&rx_buf_released);
4757
k_sem_reset(&rx_disabled);
4858

59+
#ifdef CONFIG_UART_WIDE_DATA
60+
const struct uart_config uart_cfg = {
61+
.baudrate = 115200,
62+
.parity = UART_CFG_PARITY_NONE,
63+
.stop_bits = UART_CFG_STOP_BITS_1,
64+
.data_bits = UART_CFG_DATA_BITS_9,
65+
.flow_ctrl = UART_CFG_FLOW_CTRL_NONE
66+
};
67+
__ASSERT_NO_MSG(uart_configure(uart_dev, &uart_cfg) == 0);
68+
#endif
69+
4970
if (!initialized) {
5071
init_test();
5172
initialized = true;
52-
5373
#ifdef CONFIG_USERSPACE
5474
set_permissions();
5575
#endif
5676
}
77+
5778
}
5879

5980
struct test_data {
@@ -99,7 +120,6 @@ static void test_single_read_callback(const struct device *dev,
99120
default:
100121
break;
101122
}
102-
103123
}
104124

105125
ZTEST_BMEM volatile uint32_t tx_aborted_count;
@@ -122,7 +142,7 @@ ZTEST_USER(uart_async_single_read, test_single_read)
122142
uint8_t rx_buf[10] = {0};
123143

124144
/* Check also if sending from read only memory (e.g. flash) works. */
125-
static const uint8_t tx_buf[5] = "test";
145+
static const uint8_t tx_buf[5] = "test\0";
126146

127147
zassert_not_equal(memcmp(tx_buf, rx_buf, 5), 0,
128148
"Initial buffer check failed");

0 commit comments

Comments
 (0)