Skip to content

Commit

Permalink
[nrf fromlist] tests: subsys: logging: Test with CONFIG_LOG disabled
Browse files Browse the repository at this point in the history
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.

Upstream PR #: 85383

Signed-off-by: Sebastian Głąb <[email protected]>
  • Loading branch information
nordic-segl committed Feb 10, 2025
1 parent 693769a commit 400b96d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/subsys/logging/log_disabled/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions tests/subsys/logging/log_disabled/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_PRINTK=y
CONFIG_LOG=n
43 changes: 43 additions & 0 deletions tests/subsys/logging/log_disabled/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>

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;
}
17 changes: 17 additions & 0 deletions tests/subsys/logging/log_disabled/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
common:
tags:
- logging
build_only: true
harness: console
harness_config:
type: one_line
regex:
- "All done."

tests:
logging.log_disable:
platform_allow:
- nrf5340dk/nrf5340/cpunet
- nrf54l15dk/nrf54l15/cpuapp
integration_platforms:
- nrf5340dk/nrf5340/cpunet

0 comments on commit 400b96d

Please sign in to comment.