mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-28 15:41:40 +00:00
test: log functions with CONFIG_LOG=n
If CONFIG_LOG=n, we still expect output for log_err(), log_warning(), log_notice(), log_info() and in case of DEBUG=1 also for log_debug(). Provide unit tests verifying this. The tests depend on: CONFIG_CONSOLE_RECORD=y CONFIG_LOG=n CONFIG_UT_LOG=y It may be necessary to increase the value of CONFIG_SYS_MALLOC_F_LEN to accommodate CONFIG_CONSOLE_RECORD=y. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
20fd256deb
commit
395041b2fd
9 changed files with 199 additions and 2 deletions
|
@ -656,7 +656,7 @@ S: Maintained
|
|||
T: git https://gitlab.denx.de/u-boot/u-boot.git
|
||||
F: common/log*
|
||||
F: cmd/log.c
|
||||
F: test/log/log_test.c
|
||||
F: test/log/
|
||||
F: test/py/tests/test_log.py
|
||||
|
||||
MALI DISPLAY PROCESSORS
|
||||
|
|
16
include/test/log.h
Normal file
16
include/test/log.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
|
||||
*
|
||||
* Tests for logging functions
|
||||
*/
|
||||
|
||||
#ifndef __TEST_LOG_H__
|
||||
#define __TEST_LOG_H__
|
||||
|
||||
#include <test/test.h>
|
||||
|
||||
/* Declare a new logging test */
|
||||
#define LOG_TEST(_name) UNIT_TEST(_name, 0, log_test)
|
||||
|
||||
#endif /* __TEST_LOG_H__ */
|
|
@ -30,6 +30,7 @@ int do_ut_compression(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
|
|||
int do_ut_dm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||
int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||
int do_ut_lib(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||
int do_ut_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||
int do_ut_optee(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||
int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||
int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
|
||||
|
|
|
@ -40,6 +40,15 @@ config UT_LIB_RSA
|
|||
|
||||
endif
|
||||
|
||||
config UT_LOG
|
||||
bool "Unit tests for logging functions"
|
||||
depends on UNIT_TEST
|
||||
default y
|
||||
help
|
||||
Enables the 'ut log' command which tests logging functions like
|
||||
log_err().
|
||||
See also CONFIG_LOG_TEST which provides the 'log test' command.
|
||||
|
||||
config UT_TIME
|
||||
bool "Unit tests for time functions"
|
||||
depends on UNIT_TEST
|
||||
|
|
|
@ -10,5 +10,5 @@ obj-$(CONFIG_SANDBOX) += compression.o
|
|||
obj-$(CONFIG_SANDBOX) += print_ut.o
|
||||
obj-$(CONFIG_UT_TIME) += time_ut.o
|
||||
obj-$(CONFIG_UT_UNICODE) += unicode_ut.o
|
||||
obj-$(CONFIG_$(SPL_)LOG) += log/
|
||||
obj-y += log/
|
||||
obj-$(CONFIG_UNIT_TEST) += lib/
|
||||
|
|
|
@ -60,6 +60,9 @@ static cmd_tbl_t cmd_ut_sub[] = {
|
|||
#ifdef CONFIG_UT_LIB
|
||||
U_BOOT_CMD_MKENT(lib, CONFIG_SYS_MAXARGS, 1, do_ut_lib, "", ""),
|
||||
#endif
|
||||
#ifdef CONFIG_UT_LOG
|
||||
U_BOOT_CMD_MKENT(log, CONFIG_SYS_MAXARGS, 1, do_ut_log, "", ""),
|
||||
#endif
|
||||
#ifdef CONFIG_UT_TIME
|
||||
U_BOOT_CMD_MKENT(time, CONFIG_SYS_MAXARGS, 1, do_ut_time, "", ""),
|
||||
#endif
|
||||
|
@ -125,6 +128,9 @@ static char ut_help_text[] =
|
|||
#ifdef CONFIG_UT_LIB
|
||||
"ut lib [test-name] - test library functions\n"
|
||||
#endif
|
||||
#ifdef CONFIG_UT_LOG
|
||||
"ut log [test-name] - test logging functions\n"
|
||||
#endif
|
||||
#ifdef CONFIG_UT_OPTEE
|
||||
"ut optee [test-name]\n"
|
||||
#endif
|
||||
|
|
|
@ -3,3 +3,13 @@
|
|||
# Copyright (c) 2017 Google, Inc
|
||||
|
||||
obj-$(CONFIG_LOG_TEST) += log_test.o
|
||||
|
||||
ifdef CONFIG_UT_LOG
|
||||
|
||||
obj-y += test-main.o
|
||||
|
||||
ifndef CONFIG_LOG
|
||||
obj-$(CONFIG_CONSOLE_RECORD) += nolog_test.o
|
||||
endif
|
||||
|
||||
endif # CONFIG_UT_LOG
|
||||
|
|
135
test/log/nolog_test.c
Normal file
135
test/log/nolog_test.c
Normal file
|
@ -0,0 +1,135 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
|
||||
*
|
||||
* Logging function tests for CONFIG_LOG=n.
|
||||
*/
|
||||
|
||||
/* Needed for testing log_debug() */
|
||||
#define DEBUG 1
|
||||
|
||||
#include <common.h>
|
||||
#include <console.h>
|
||||
#include <test/log.h>
|
||||
#include <test/test.h>
|
||||
#include <test/suites.h>
|
||||
#include <test/ut.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
#define BUFFSIZE 32
|
||||
|
||||
static int nolog_test_log_err(struct unit_test_state *uts)
|
||||
{
|
||||
char buf[BUFFSIZE];
|
||||
|
||||
memset(buf, 0, BUFFSIZE);
|
||||
console_record_reset_enable();
|
||||
log_err("testing %s\n", "log_err");
|
||||
gd->flags &= ~GD_FLG_RECORD;
|
||||
ut_assertok(ut_check_console_line(uts, "testing log_err"));
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
LOG_TEST(nolog_test_log_err);
|
||||
|
||||
static int nolog_test_log_warning(struct unit_test_state *uts)
|
||||
{
|
||||
char buf[BUFFSIZE];
|
||||
|
||||
memset(buf, 0, BUFFSIZE);
|
||||
console_record_reset_enable();
|
||||
log_warning("testing %s\n", "log_warning");
|
||||
gd->flags &= ~GD_FLG_RECORD;
|
||||
ut_assertok(ut_check_console_line(uts, "testing log_warning"));
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
LOG_TEST(nolog_test_log_warning);
|
||||
|
||||
static int nolog_test_log_notice(struct unit_test_state *uts)
|
||||
{
|
||||
char buf[BUFFSIZE];
|
||||
|
||||
memset(buf, 0, BUFFSIZE);
|
||||
console_record_reset_enable();
|
||||
log_notice("testing %s\n", "log_notice");
|
||||
gd->flags &= ~GD_FLG_RECORD;
|
||||
ut_assertok(ut_check_console_line(uts, "testing log_notice"));
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
LOG_TEST(nolog_test_log_notice);
|
||||
|
||||
static int nolog_test_log_info(struct unit_test_state *uts)
|
||||
{
|
||||
char buf[BUFFSIZE];
|
||||
|
||||
memset(buf, 0, BUFFSIZE);
|
||||
console_record_reset_enable();
|
||||
log_err("testing %s\n", "log_info");
|
||||
gd->flags &= ~GD_FLG_RECORD;
|
||||
ut_assertok(ut_check_console_line(uts, "testing log_info"));
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
LOG_TEST(nolog_test_log_info);
|
||||
|
||||
#undef _DEBUG
|
||||
#define _DEBUG 0
|
||||
static int nolog_test_nodebug(struct unit_test_state *uts)
|
||||
{
|
||||
char buf[BUFFSIZE];
|
||||
|
||||
memset(buf, 0, BUFFSIZE);
|
||||
console_record_reset_enable();
|
||||
debug("testing %s\n", "debug");
|
||||
gd->flags &= ~GD_FLG_RECORD;
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
LOG_TEST(nolog_test_nodebug);
|
||||
|
||||
static int nolog_test_log_nodebug(struct unit_test_state *uts)
|
||||
{
|
||||
char buf[BUFFSIZE];
|
||||
|
||||
memset(buf, 0, BUFFSIZE);
|
||||
console_record_reset_enable();
|
||||
log_debug("testing %s\n", "log_debug");
|
||||
gd->flags &= ~GD_FLG_RECORD;
|
||||
ut_assert(!strcmp(buf, ""));
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
LOG_TEST(nolog_test_log_nodebug);
|
||||
|
||||
#undef _DEBUG
|
||||
#define _DEBUG 1
|
||||
static int nolog_test_debug(struct unit_test_state *uts)
|
||||
{
|
||||
char buf[BUFFSIZE];
|
||||
|
||||
memset(buf, 0, BUFFSIZE);
|
||||
console_record_reset_enable();
|
||||
debug("testing %s\n", "debug");
|
||||
gd->flags &= ~GD_FLG_RECORD;
|
||||
ut_assertok(ut_check_console_line(uts, "testing debug"));
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
LOG_TEST(nolog_test_debug);
|
||||
|
||||
static int nolog_test_log_debug(struct unit_test_state *uts)
|
||||
{
|
||||
char buf[BUFFSIZE];
|
||||
|
||||
memset(buf, 0, BUFFSIZE);
|
||||
console_record_reset_enable();
|
||||
log_debug("testing %s\n", "log_debug");
|
||||
gd->flags &= ~GD_FLG_RECORD;
|
||||
ut_assertok(ut_check_console_line(uts, "testing log_debug"));
|
||||
ut_assertok(ut_check_console_end(uts));
|
||||
return 0;
|
||||
}
|
||||
LOG_TEST(nolog_test_log_debug);
|
20
test/log/test-main.c
Normal file
20
test/log/test-main.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
|
||||
*
|
||||
* Logging function tests.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <console.h>
|
||||
#include <test/log.h>
|
||||
#include <test/suites.h>
|
||||
|
||||
int do_ut_log(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||
{
|
||||
struct unit_test *tests = ll_entry_start(struct unit_test, log_test);
|
||||
const int n_ents = ll_entry_count(struct unit_test, log_test);
|
||||
|
||||
return cmd_ut_category("log", "log_test_",
|
||||
tests, n_ents, argc, argv);
|
||||
}
|
Loading…
Reference in a new issue