Skip to content

Commit

Permalink
tests: uart_async_api: update test for dma usage
Browse files Browse the repository at this point in the history
1. ensure the two dma buffers all aligned with 32 bits
2. clean the rx_data_idx at test begin

Signed-off-by: Hake Huang <[email protected]>
  • Loading branch information
hakehuang authored and nashif committed Oct 15, 2024
1 parent fb1ffff commit 193bfab
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tests/drivers/uart/uart_async_api/src/test_uart_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,24 @@ ZTEST_USER(uart_async_multi_rx, test_multiple_rx_enable)
}

#if NOCACHE_MEM
static __aligned(32) uint8_t chained_read_buf[2][8] __used __NOCACHE;
/* To ensure 32-bit alignment of the buffer array,
* the two arrays are defined instead using an array of arrays
*/
static __aligned(32) uint8_t chained_read_buf_0[8] __used __NOCACHE;
static __aligned(32) uint8_t chained_read_buf_1[8] __used __NOCACHE;
static __aligned(32) uint8_t chained_cpy_buf[10] __used __NOCACHE;
#else
ZTEST_BMEM uint8_t chained_read_buf[2][8];
ZTEST_BMEM uint8_t chained_read_buf_0[8];
ZTEST_BMEM uint8_t chained_read_buf_1[8];
ZTEST_BMEM uint8_t chained_cpy_buf[10];
#endif /* NOCACHE_MEM */
ZTEST_BMEM volatile uint8_t rx_data_idx;
ZTEST_BMEM uint8_t rx_buf_idx;

ZTEST_BMEM uint8_t *read_ptr;

static uint8_t *chained_read_buf[2] = {chained_read_buf_0, chained_read_buf_1};

static void test_chained_read_callback(const struct device *dev,
struct uart_event *evt, void *user_data)
{
Expand All @@ -352,9 +359,8 @@ static void test_chained_read_callback(const struct device *dev,
rx_data_idx += evt->data.rx.len;
break;
case UART_RX_BUF_REQUEST:
err = uart_rx_buf_rsp(dev,
chained_read_buf[rx_buf_idx],
sizeof(chained_read_buf[0]));
err = uart_rx_buf_rsp(dev, chained_read_buf[rx_buf_idx],
sizeof(chained_read_buf_0));
zassert_equal(err, 0);
rx_buf_idx = !rx_buf_idx ? 1 : 0;
break;
Expand Down Expand Up @@ -387,11 +393,10 @@ ZTEST_USER(uart_async_chain_read, test_chained_read)
uint32_t rx_timeout_ms = 50;
int err;

err = uart_rx_enable(uart_dev,
chained_read_buf[rx_buf_idx++],
sizeof(chained_read_buf[0]),
err = uart_rx_enable(uart_dev, chained_read_buf[rx_buf_idx++], sizeof(chained_read_buf_0),
rx_timeout_ms * USEC_PER_MSEC);
zassert_equal(err, 0);
rx_data_idx = 0;

for (int i = 0; i < iter; i++) {
zassert_not_equal(k_sem_take(&rx_disabled, K_MSEC(10)),
Expand All @@ -406,7 +411,7 @@ ZTEST_USER(uart_async_chain_read, test_chained_read)
"Unexpected amount of data received %d exp:%d",
rx_data_idx, sizeof(tx_buf));
zassert_equal(memcmp(tx_buf, chained_cpy_buf, sizeof(tx_buf)), 0,
"Buffers not equal");
"Buffers not equal exp %s, real %s", tx_buf, chained_cpy_buf);
rx_data_idx = 0;
}
uart_rx_disable(uart_dev);
Expand Down

0 comments on commit 193bfab

Please sign in to comment.