Skip to content

Commit 9e3e077

Browse files
committed
tests: drivers: uart: mix_fifo_poll: Rework to support multi-instance
Rework test to allow testing multiple UART instances in a single run. Signed-off-by: Krzysztof Chruściński <[email protected]>
1 parent 2cd2374 commit 9e3e077

File tree

1 file changed

+35
-4
lines changed
  • tests/drivers/uart/uart_mix_fifo_poll/src

1 file changed

+35
-4
lines changed

tests/drivers/uart/uart_mix_fifo_poll/src/main.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,18 @@ struct rx_source {
4242
uint8_t prev;
4343
};
4444

45+
struct dut_data {
46+
const struct device *dev;
47+
const char *name;
48+
};
49+
50+
static struct dut_data duts[] = {
51+
{
52+
.dev = DEVICE_DT_GET(UART_NODE),
53+
.name = DT_NODE_FULL_NAME(UART_NODE),
54+
},
55+
};
56+
4557
#define BUF_SIZE 16
4658

4759
/* Buffer used for polling. */
@@ -68,8 +80,7 @@ static struct test_data int_async_data;
6880

6981
static const struct device *const counter_dev =
7082
DEVICE_DT_GET(COUNTER_NODE);
71-
static const struct device *const uart_dev =
72-
DEVICE_DT_GET(UART_NODE);
83+
static const struct device *uart_dev;
7384

7485
static bool async;
7586
static bool int_driven;
@@ -112,8 +123,10 @@ static void process_byte(uint8_t b)
112123
src->prev = b;
113124
}
114125

126+
static volatile bool in_counter_isr;
115127
static void counter_top_handler(const struct device *dev, void *user_data)
116128
{
129+
in_counter_isr = true;
117130
static bool enable = true;
118131
static uint8_t async_rx_buf[4];
119132

@@ -139,9 +152,10 @@ static void counter_top_handler(const struct device *dev, void *user_data)
139152
process_byte(c);
140153
}
141154
}
155+
in_counter_isr = false;
142156
}
143157

144-
static void init_test(void)
158+
static void init_test(int idx)
145159
{
146160
int err;
147161
struct counter_top_cfg top_cfg = {
@@ -150,6 +164,12 @@ static void init_test(void)
150164
.flags = 0
151165
};
152166

167+
memset(source, 0, sizeof(source));
168+
error_found = false;
169+
async_rx_enabled = false;
170+
uart_dev = duts[idx].dev;
171+
TC_PRINT("UART instance:%s\n", duts[idx].name);
172+
153173
zassert_true(device_is_ready(uart_dev), "uart device is not ready");
154174

155175
if (uart_callback_set(uart_dev, async_callback, NULL) == 0) {
@@ -388,10 +408,21 @@ ZTEST(uart_mix_fifo_poll, test_mixed_uart_access)
388408

389409
void *uart_mix_setup(void)
390410
{
391-
init_test();
411+
static int idx;
412+
413+
init_test(idx++);
392414

393415
return NULL;
394416
}
395417

396418
ZTEST_SUITE(uart_mix_fifo_poll, NULL, uart_mix_setup,
397419
NULL, NULL, NULL);
420+
421+
void test_main(void)
422+
{
423+
/* Run all suites for each dut UART. Setup function for each suite is picking
424+
* next UART from the array.
425+
*/
426+
ztest_run_all(NULL, false, ARRAY_SIZE(duts), 1);
427+
ztest_verify_all_test_suites_ran();
428+
}

0 commit comments

Comments
 (0)