From 5eff0c1cd7bfb40b930bacf3a200fd93f9668c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20G=C5=82=C4=85b?= Date: Fri, 7 Feb 2025 13:56:51 +0100 Subject: [PATCH] tests: subsys: logging: Test with CONFIG_LOG disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Developer reports build error when he uses LOG_RAW in his code and disables logging in prj.conf using CONFIG_LOG=n. Add test case for above described scenario. Signed-off-by: Sebastian Głąb --- .../logging/log_disabled/CMakeLists.txt | 13 ++++++ tests/subsys/logging/log_disabled/prj.conf | 2 + tests/subsys/logging/log_disabled/src/main.c | 43 +++++++++++++++++++ .../subsys/logging/log_disabled/testcase.yaml | 16 +++++++ 4 files changed, 74 insertions(+) create mode 100644 tests/subsys/logging/log_disabled/CMakeLists.txt create mode 100644 tests/subsys/logging/log_disabled/prj.conf create mode 100644 tests/subsys/logging/log_disabled/src/main.c create mode 100644 tests/subsys/logging/log_disabled/testcase.yaml diff --git a/tests/subsys/logging/log_disabled/CMakeLists.txt b/tests/subsys/logging/log_disabled/CMakeLists.txt new file mode 100644 index 000000000000..b656ca6b4a2a --- /dev/null +++ b/tests/subsys/logging/log_disabled/CMakeLists.txt @@ -0,0 +1,13 @@ +# +# Copyright (c) 2025 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +project(log_disable) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/subsys/logging/log_disabled/prj.conf b/tests/subsys/logging/log_disabled/prj.conf new file mode 100644 index 000000000000..9717b5ec67eb --- /dev/null +++ b/tests/subsys/logging/log_disabled/prj.conf @@ -0,0 +1,2 @@ +CONFIG_PRINTK=y +CONFIG_LOG=n diff --git a/tests/subsys/logging/log_disabled/src/main.c b/tests/subsys/logging/log_disabled/src/main.c new file mode 100644 index 000000000000..100681de358b --- /dev/null +++ b/tests/subsys/logging/log_disabled/src/main.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2025 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +LOG_MODULE_REGISTER(app, LOG_LEVEL_DBG); + +int main(void) +{ + uint8_t data[] = {0, 1, 2, 3}; + uint32_t dummy_1 = 1; + uint32_t dummy_2 = 2; + uint32_t dummy_3 = 3; + uint32_t dummy_4 = 4; + uint32_t dummy_5 = 5; + uint32_t dummy_6 = 6; + uint32_t dummy_7 = 7; + + LOG_DBG("Debug log %u", dummy_1); + LOG_INF("Info log %u", dummy_2); + LOG_WRN("Warning log %u", dummy_3); + LOG_ERR("Error log %u", dummy_4); + + for (int i = 0; i < 10; i++) { + LOG_WRN_ONCE("Warning on the first execution only %u", dummy_5); + } + + LOG_PRINTK("Printk log %u\n", dummy_6); + + LOG_RAW("Raw log %u\n", dummy_7); + + LOG_HEXDUMP_DBG(data, sizeof(data), "Debug data"); + LOG_HEXDUMP_INF(data, sizeof(data), "Info data"); + LOG_HEXDUMP_WRN(data, sizeof(data), "Warning data"); + LOG_HEXDUMP_ERR(data, sizeof(data), "Error data"); + + printk("All done.\n"); + return 0; +} diff --git a/tests/subsys/logging/log_disabled/testcase.yaml b/tests/subsys/logging/log_disabled/testcase.yaml new file mode 100644 index 000000000000..06a327988c9c --- /dev/null +++ b/tests/subsys/logging/log_disabled/testcase.yaml @@ -0,0 +1,16 @@ +common: + tags: + - logging + build_only: true + platform_allow: + - native_sim + integration_platforms: + - native_sim + +tests: + logging.log_disable: + harness: console + harness_config: + type: one_line + regex: + - "All done."