Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: core log unit tests #6017

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/core/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,13 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level,
if (msg_len < 0)
goto end;

if (errnum != NO_ERRNO) {
if ((size_t)msg_len < buf_len - 1 && errnum != NO_ERRNO) {
/*
* Ask for the error string right after the already printed
* message.
*/
char *msg_ptr = buf + msg_len;
size_t buf_len_left = buf_len - (size_t)msg_len;

/* Check if the longest possible error string can fit */
if (buf_len_left < _CORE_LOG_MAX_ERRNO_MSG) {
goto end;
}

/* Ask for the error string */
/*
* If it fails, the best thing to do is to at least pass
* the log message as is.
Expand All @@ -236,13 +233,11 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level,
* the CORE_LOG() macro it has to be done here again since it is not
* performed in the case of the CORE_LOG_TO_LAST macro. Sorry.
*/
if (level > Core_log_threshold[CORE_LOG_THRESHOLD]) {
if (level > Core_log_threshold[CORE_LOG_THRESHOLD])
goto end;
}

if (0 == Core_log_function) {
if (0 == Core_log_function)
goto end;
}

((core_log_function *)Core_log_function)(Core_log_function_context,
level, file_name, line_no, function_name, buf);
Expand All @@ -257,8 +252,8 @@ core_log(enum core_log_level level, int errnum, const char *file_name,
int line_no, const char *function_name, const char *message_format, ...)
{
char message[_CORE_LOG_MSG_MAXPRINT] = "";
va_list arg;

va_list arg;
va_start(arg, message_format);
core_log_va(message, sizeof(message), level, errnum, file_name,
line_no, function_name, message_format, arg);
Expand Down
1 change: 1 addition & 0 deletions src/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ OBJ_TESTS = \
OTHER_TESTS = \
arch_flags\
core_log_max\
core_log\
checksum\
compat_incompat_features\
ctl_prefault\
Expand Down
1 change: 1 addition & 0 deletions src/test/core_log/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
core_log
14 changes: 14 additions & 0 deletions src/test/core_log/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024, Intel Corporation

TARGET = core_log
OBJS = core_log.o

BUILD_STATIC_DEBUG=n
BUILD_STATIC_NONDEBUG=n

LIBPMEMCORE=internal-debug
EXTRA_CFLAGS=-Dnoreturn="/* noreturn */"

include ../Makefile.inc
LDFLAGS += $(call extract_funcs, core_log.c)
53 changes: 53 additions & 0 deletions src/test/core_log/TESTS.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!../env.py
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2024, Intel Corporation
#


import testframework as t
from testframework import granularity as g


@g.require_granularity(g.ANY)
# @t.require_build('nondebug')
class CORE_LOG(t.BaseTest):
test_type = t.Short

def run(self, ctx):
ctx.exec('core_log', self.test_case)


class TEST0(CORE_LOG):
test_case = 'test_CORE_LOG_BASIC'


class TEST1(CORE_LOG):
test_case = 'test_CORE_LOG_BASIC_W_ERRNO'


class TEST2(CORE_LOG):
test_case = 'test_CORE_LOG_BASIC_W_ERRNO_BAD'


class TEST3(CORE_LOG):
test_case = 'test_CORE_LOG_BASIC_LONG'


class TEST4(CORE_LOG):
test_case = 'test_CORE_LOG_BASIC_TOO_LONG'


class TEST5(CORE_LOG):
test_case = 'test_CORE_LOG_BASIC_TOO_LONG_W_ERRNO'


class TEST6(CORE_LOG):
test_case = 'test_CORE_LOG_LAST_BASIC_LONG'


class TEST7(CORE_LOG):
test_case = 'test_CORE_LOG_LAST_BASIC_TOO_LONG'


class TEST8(CORE_LOG):
test_case = 'test_CORE_LOG_TRESHOLD'
Loading
Loading