tests: logging: log_backend_uart: Fix stack overflow

Put the buffer data in a static buffer to reduce the needed stack size.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
This commit is contained in:
Pieter De Gendt 2024-12-11 12:08:40 +01:00 committed by Fabio Baltieri
parent 8f07784e9f
commit 1e6f919999

View file

@ -55,19 +55,22 @@ static void uart_emul_before(void *f)
ZTEST_F(log_backend_uart, test_log_backend_uart_multi_instance)
{
/* Prevent stack overflow by making it static */
static uint8_t tx_content[SAMPLE_DATA_SIZE];
size_t tx_len;
zassert_equal(log_backend_count_get(), EMUL_UART_NUM, "Unexpected number of instance(s)");
LOG_RAW(TEST_DATA);
for (size_t i = 0; i < EMUL_UART_NUM; i++) {
uint8_t tx_content[SAMPLE_DATA_SIZE] = {0};
size_t tx_len;
memset(tx_content, 0, sizeof(tx_content));
tx_len = uart_emul_get_tx_data(fixture->dev[i], tx_content, sizeof(tx_content));
zassert_equal(tx_len, strlen(TEST_DATA),
"%d: TX buffer length does not match. Expected %d, got %d",
i, strlen(TEST_DATA), tx_len);
zassert_mem_equal(tx_content, TEST_DATA, strlen(tx_content));
zassert_mem_equal(tx_content, TEST_DATA, strlen(TEST_DATA));
}
}