test: logging: add testcase for multi-instance log backend uart
Add testcase for the multi-instance log backend uart using emulated uart. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
parent
c0064f1de8
commit
6d9fcd83a9
9
tests/subsys/logging/log_backend_uart/CMakeLists.txt
Normal file
9
tests/subsys/logging/log_backend_uart/CMakeLists.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# Copyright (c) 2023 Meta
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(log_backend_uart_test)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
8
tests/subsys/logging/log_backend_uart/Kconfig
Normal file
8
tests/subsys/logging/log_backend_uart/Kconfig
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
# Copyright (c) 2021 Nordic Semiconductor ASA
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
module = SAMPLE_MODULE
|
||||||
|
module-str = Test logging API
|
||||||
|
source "subsys/logging/Kconfig.template.log_config"
|
||||||
|
|
||||||
|
source "Kconfig.zephyr"
|
32
tests/subsys/logging/log_backend_uart/multi.overlay
Normal file
32
tests/subsys/logging/log_backend_uart/multi.overlay
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Meta
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/ {
|
||||||
|
chosen {
|
||||||
|
zephyr,log-uart = &log_uarts;
|
||||||
|
};
|
||||||
|
|
||||||
|
log_uarts: log_uarts {
|
||||||
|
compatible = "zephyr,log-uart";
|
||||||
|
uarts = <&euart0 &euart1>;
|
||||||
|
};
|
||||||
|
|
||||||
|
euart0: uart-emul0 {
|
||||||
|
compatible = "zephyr,uart-emul";
|
||||||
|
status = "okay";
|
||||||
|
current-speed = <0>;
|
||||||
|
rx-fifo-size = <256>;
|
||||||
|
tx-fifo-size = <256>;
|
||||||
|
};
|
||||||
|
|
||||||
|
euart1: uart-emul1 {
|
||||||
|
compatible = "zephyr,uart-emul";
|
||||||
|
status = "okay";
|
||||||
|
current-speed = <0>;
|
||||||
|
rx-fifo-size = <256>;
|
||||||
|
tx-fifo-size = <256>;
|
||||||
|
};
|
||||||
|
};
|
11
tests/subsys/logging/log_backend_uart/prj.conf
Normal file
11
tests/subsys/logging/log_backend_uart/prj.conf
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Copyright (c) 2023 Meta
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
CONFIG_ZTEST=y
|
||||||
|
CONFIG_ASSERT=y
|
||||||
|
CONFIG_TEST_LOGGING_DEFAULTS=n
|
||||||
|
|
||||||
|
CONFIG_LOG=y
|
||||||
|
CONFIG_LOG_BACKEND_UART=y
|
||||||
|
CONFIG_LOG_MODE_IMMEDIATE=y
|
||||||
|
CONFIG_LOG_PRINTK=n
|
24
tests/subsys/logging/log_backend_uart/single.overlay
Normal file
24
tests/subsys/logging/log_backend_uart/single.overlay
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Meta
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/ {
|
||||||
|
chosen {
|
||||||
|
zephyr,log-uart = &log_uarts;
|
||||||
|
};
|
||||||
|
|
||||||
|
log_uarts: log_uarts {
|
||||||
|
compatible = "zephyr,log-uart";
|
||||||
|
uarts = <&euart0>;
|
||||||
|
};
|
||||||
|
|
||||||
|
euart0: uart-emul0 {
|
||||||
|
compatible = "zephyr,uart-emul";
|
||||||
|
status = "okay";
|
||||||
|
current-speed = <0>;
|
||||||
|
rx-fifo-size = <256>;
|
||||||
|
tx-fifo-size = <256>;
|
||||||
|
};
|
||||||
|
};
|
73
tests/subsys/logging/log_backend_uart/src/main.c
Normal file
73
tests/subsys/logging/log_backend_uart/src/main.c
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Meta
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
#include <zephyr/logging/log.h>
|
||||||
|
#include <zephyr/logging/log_backend.h>
|
||||||
|
#include <zephyr/drivers/uart.h>
|
||||||
|
#include <zephyr/drivers/serial/uart_emul.h>
|
||||||
|
|
||||||
|
LOG_MODULE_REGISTER(test, CONFIG_SAMPLE_MODULE_LOG_LEVEL);
|
||||||
|
|
||||||
|
#define EMUL_UART_NUM DT_NUM_INST_STATUS_OKAY(zephyr_uart_emul)
|
||||||
|
#define EMUL_UART_NODE(i) DT_NODELABEL(euart##i)
|
||||||
|
#define EMUL_UART_DEV_INIT(i, _) DEVICE_DT_GET(EMUL_UART_NODE(i))
|
||||||
|
#define EMUL_UART_TX_FIFO_SIZE(i) DT_PROP(EMUL_UART_NODE(i), tx_fifo_size)
|
||||||
|
#define SAMPLE_DATA_SIZE EMUL_UART_TX_FIFO_SIZE(0)
|
||||||
|
|
||||||
|
#define TEST_DATA "0123456789ABCDEF"
|
||||||
|
BUILD_ASSERT(strlen(TEST_DATA) < SAMPLE_DATA_SIZE);
|
||||||
|
|
||||||
|
struct log_backend_uart_fixture {
|
||||||
|
const struct device *dev[EMUL_UART_NUM];
|
||||||
|
};
|
||||||
|
|
||||||
|
static void *uart_emul_setup(void)
|
||||||
|
{
|
||||||
|
static struct log_backend_uart_fixture fixture = {
|
||||||
|
.dev = {LISTIFY(EMUL_UART_NUM, EMUL_UART_DEV_INIT, (,))}};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < EMUL_UART_NUM; i++) {
|
||||||
|
zassert_not_null(fixture.dev[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return &fixture;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uart_emul_before(void *f)
|
||||||
|
{
|
||||||
|
struct log_backend_uart_fixture *fixture = f;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < EMUL_UART_NUM; i++) {
|
||||||
|
uart_irq_tx_disable(fixture->dev[i]);
|
||||||
|
uart_irq_rx_disable(fixture->dev[i]);
|
||||||
|
|
||||||
|
uart_emul_flush_rx_data(fixture->dev[i]);
|
||||||
|
uart_emul_flush_tx_data(fixture->dev[i]);
|
||||||
|
|
||||||
|
uart_err_check(fixture->dev[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST_F(log_backend_uart, test_log_backend_uart_multi_instance)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST_SUITE(log_backend_uart, NULL, uart_emul_setup, uart_emul_before, NULL, NULL);
|
14
tests/subsys/logging/log_backend_uart/testcase.yaml
Normal file
14
tests/subsys/logging/log_backend_uart/testcase.yaml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
# Copyright (c) 2023 Meta
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
common:
|
||||||
|
tags:
|
||||||
|
- logging
|
||||||
|
- backend
|
||||||
|
- uart
|
||||||
|
platform_allow: qemu_x86
|
||||||
|
tests:
|
||||||
|
logging.backend.uart.single:
|
||||||
|
extra_args: DTC_OVERLAY_FILE="./single.overlay"
|
||||||
|
logging.backend.uart.multi:
|
||||||
|
extra_args: DTC_OVERLAY_FILE="./multi.overlay"
|
Loading…
Reference in a new issue