tests: logging: log_api: Minor cleanups in the test
Fixing minor issues in the test. Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
653cda5029
commit
476033e81f
4 changed files with 18 additions and 12 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(log_core)
|
||||
project(log_api)
|
||||
|
||||
target_sources(app PRIVATE src/main.c src/mock_frontend.c
|
||||
src/mock_backend.c src/test_module.c)
|
||||
|
|
|
@ -149,6 +149,11 @@ static void process_and_validate(bool backend2_enable, bool panic)
|
|||
}
|
||||
}
|
||||
|
||||
static bool dbg_enabled(void)
|
||||
{
|
||||
return IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG) || (CONFIG_LOG_OVERRIDE_LEVEL == 4);
|
||||
}
|
||||
|
||||
ZTEST(test_log_api, test_log_various_messages)
|
||||
{
|
||||
char str[128];
|
||||
|
@ -166,7 +171,7 @@ ZTEST(test_log_api, test_log_various_messages)
|
|||
#define TEST_MSG_0_PREFIX "%s: %lld %llu %hhd"
|
||||
#define TEST_MSG_1 "%f %d %f"
|
||||
|
||||
if (IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG)) {
|
||||
if (dbg_enabled()) {
|
||||
/* If prefix is enabled, add function name prefix */
|
||||
if (IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_DBG)) {
|
||||
snprintk(str, sizeof(str),
|
||||
|
@ -201,7 +206,7 @@ ZTEST(test_log_api, test_log_various_messages)
|
|||
#define TEST_MSG_0 "%hhd"
|
||||
#define TEST_MSG_0_PREFIX "%s: %hhd"
|
||||
#define TEST_MSG_1 "%p"
|
||||
if (IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG)) {
|
||||
if (dbg_enabled()) {
|
||||
/* If prefix is enabled, add function name prefix */
|
||||
if (IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_DBG)) {
|
||||
snprintk(str, sizeof(str),
|
||||
|
@ -263,7 +268,7 @@ ZTEST(test_log_api, test_log_backend_runtime_filtering)
|
|||
|
||||
log_setup(true);
|
||||
|
||||
if (IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG)) {
|
||||
if (dbg_enabled()) {
|
||||
char str[128];
|
||||
|
||||
/* If prefix is enabled, add function name prefix */
|
||||
|
@ -546,7 +551,7 @@ ZTEST(test_log_api, test_log_from_declared_module)
|
|||
log_setup(false);
|
||||
|
||||
/* See test module for log message content. */
|
||||
if (IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG)) {
|
||||
if (dbg_enabled()) {
|
||||
char str[128];
|
||||
|
||||
/* If prefix is enabled, add function name prefix */
|
||||
|
@ -570,7 +575,7 @@ ZTEST(test_log_api, test_log_from_declared_module)
|
|||
|
||||
test_func();
|
||||
|
||||
if (IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG)) {
|
||||
if (dbg_enabled()) {
|
||||
char str[128];
|
||||
|
||||
/* If prefix is enabled, add function name prefix */
|
||||
|
@ -754,7 +759,7 @@ ZTEST(test_log_api, test_log_arg_evaluation)
|
|||
|
||||
log_setup(false);
|
||||
|
||||
if (IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG)) {
|
||||
if (dbg_enabled()) {
|
||||
/* Debug message arguments are only evaluated when this level
|
||||
* is enabled.
|
||||
*/
|
||||
|
@ -766,7 +771,7 @@ ZTEST(test_log_api, test_log_arg_evaluation)
|
|||
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
|
||||
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
|
||||
exp_timestamp++, "0 0");
|
||||
if (IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG)) {
|
||||
if (dbg_enabled()) {
|
||||
/* If prefix is enabled, add function name prefix */
|
||||
if (IS_ENABLED(CONFIG_LOG_FUNC_NAME_PREFIX_DBG)) {
|
||||
snprintk(str, sizeof(str),
|
||||
|
|
|
@ -308,8 +308,8 @@ static void process(const struct log_backend *const backend,
|
|||
log_const_source_id((const struct log_source_const_data *)source);
|
||||
}
|
||||
|
||||
zassert_equal(source_id, exp->source_id, "sourc_id:%p (exp: %d)",
|
||||
msg->log.hdr.source, exp->source_id);
|
||||
zassert_equal(source_id, exp->source_id, "source_id:%p (exp: %d)",
|
||||
source_id, exp->source_id);
|
||||
|
||||
size_t len;
|
||||
uint8_t *data;
|
||||
|
|
|
@ -10,12 +10,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include "test_module.h"
|
||||
#include <logging/log.h>
|
||||
|
||||
LOG_MODULE_DECLARE(test, CONFIG_SAMPLE_MODULE_LOG_LEVEL);
|
||||
|
||||
void test_func(void)
|
||||
{
|
||||
LOG_DBG("debug");
|
||||
LOG_ERR("test");
|
||||
LOG_DBG(TEST_DBG_MSG);
|
||||
LOG_ERR(TEST_ERR_MSG);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue