2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-12-04 20:48:27 +00:00
|
|
|
/*
|
|
|
|
* Logging support test program
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-10-27 23:55:27 +00:00
|
|
|
#include <test/log.h>
|
|
|
|
#include <test/ut.h>
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2017-12-04 20:48:27 +00:00
|
|
|
|
|
|
|
/* emit some sample log records in different ways, for testing */
|
2020-11-27 10:20:53 +00:00
|
|
|
static int do_log_run(struct unit_test_state *uts, int cat, const char *file)
|
2017-12-04 20:48:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
2020-11-27 10:20:53 +00:00
|
|
|
int ret, expected_ret;
|
|
|
|
|
|
|
|
if (gd->flags & GD_FLG_LOG_READY)
|
|
|
|
expected_ret = 0;
|
|
|
|
else
|
|
|
|
expected_ret = -ENOSYS;
|
2017-12-04 20:48:27 +00:00
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
gd->log_fmt = LOGF_TEST;
|
2017-12-04 20:48:27 +00:00
|
|
|
debug("debug\n");
|
|
|
|
for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
|
|
|
|
log(cat, i, "log %d\n", i);
|
2020-11-27 10:20:53 +00:00
|
|
|
ret = _log(log_uc_cat(cat), i, file, 100 + i,
|
|
|
|
"func", "_log %d\n", i);
|
|
|
|
ut_asserteq(ret, expected_ret);
|
2017-12-04 20:48:27 +00:00
|
|
|
}
|
2020-11-27 10:20:51 +00:00
|
|
|
/* test with LOGL_COUNT flag */
|
|
|
|
for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
|
2020-11-27 10:20:53 +00:00
|
|
|
ret = _log(log_uc_cat(cat), i | LOGL_FORCE_DEBUG, file, 100 + i,
|
|
|
|
"func", "_log force %d\n", i);
|
|
|
|
ut_asserteq(ret, expected_ret);
|
2020-11-27 10:20:51 +00:00
|
|
|
}
|
2017-12-04 20:48:27 +00:00
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
gd->log_fmt = log_get_default_format();
|
2017-12-04 20:48:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-11-27 10:20:53 +00:00
|
|
|
#define log_run_cat(cat) do_log_run(uts, cat, "file")
|
|
|
|
#define log_run_file(file) do_log_run(uts, UCLASS_SPI, file)
|
|
|
|
#define log_run() do_log_run(uts, UCLASS_SPI, "file")
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
#define EXPECT_LOG BIT(0)
|
|
|
|
#define EXPECT_DIRECT BIT(1)
|
|
|
|
#define EXPECT_EXTRA BIT(2)
|
2020-11-27 10:20:51 +00:00
|
|
|
#define EXPECT_FORCE BIT(3)
|
2020-11-27 10:20:58 +00:00
|
|
|
#define EXPECT_DEBUG BIT(4)
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
static int do_check_log_entries(struct unit_test_state *uts, int flags, int min,
|
|
|
|
int max)
|
2017-12-04 20:48:27 +00:00
|
|
|
{
|
2020-10-27 23:55:27 +00:00
|
|
|
int i;
|
2017-12-04 20:48:27 +00:00
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
for (i = min; i <= max; i++) {
|
|
|
|
if (flags & EXPECT_LOG)
|
|
|
|
ut_assert_nextline("do_log_run() log %d", i);
|
|
|
|
if (flags & EXPECT_DIRECT)
|
|
|
|
ut_assert_nextline("func() _log %d", i);
|
2020-11-27 10:20:58 +00:00
|
|
|
if (flags & EXPECT_DEBUG) {
|
|
|
|
ut_assert_nextline("log %d", i);
|
|
|
|
ut_assert_nextline("_log %d", i);
|
|
|
|
}
|
2017-12-04 20:48:27 +00:00
|
|
|
}
|
2020-10-27 23:55:27 +00:00
|
|
|
if (flags & EXPECT_EXTRA)
|
|
|
|
for (; i <= LOGL_MAX ; i++)
|
|
|
|
ut_assert_nextline("func() _log %d", i);
|
|
|
|
|
2020-11-27 10:20:51 +00:00
|
|
|
for (i = LOGL_FIRST; i < LOGL_COUNT; i++) {
|
|
|
|
if (flags & EXPECT_FORCE)
|
|
|
|
ut_assert_nextline("func() _log force %d", i);
|
2020-11-27 10:20:58 +00:00
|
|
|
if (flags & EXPECT_DEBUG)
|
|
|
|
ut_assert_nextline("_log force %d", i);
|
2020-11-27 10:20:51 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define check_log_entries_flags_levels(flags, min, max) do {\
|
|
|
|
int ret = do_check_log_entries(uts, flags, min, max); \
|
|
|
|
if (ret) \
|
|
|
|
return ret; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define check_log_entries_flags(flags) \
|
|
|
|
check_log_entries_flags_levels(flags, LOGL_FIRST, _LOG_MAX_LEVEL)
|
2020-11-27 10:20:51 +00:00
|
|
|
#define check_log_entries() check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE)
|
2020-10-27 23:55:27 +00:00
|
|
|
#define check_log_entries_extra() \
|
2020-11-27 10:20:51 +00:00
|
|
|
check_log_entries_flags(EXPECT_LOG | EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE)
|
|
|
|
#define check_log_entries_none() check_log_entries_flags(EXPECT_FORCE)
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
/* Check a category filter using the first category */
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_cat_allow(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
enum log_category_t cat_list[] = {
|
|
|
|
log_uc_cat(UCLASS_MMC), log_uc_cat(UCLASS_SPI),
|
|
|
|
LOGC_NONE, LOGC_END
|
|
|
|
};
|
|
|
|
int filt;
|
|
|
|
|
|
|
|
filt = log_add_filter("console", cat_list, LOGL_MAX, NULL);
|
|
|
|
ut_assert(filt >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_cat(UCLASS_MMC);
|
|
|
|
check_log_entries_extra();
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_cat(UCLASS_SPI);
|
|
|
|
check_log_entries_extra();
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt));
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_cat_allow, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
/* Check a category filter that should block log entries */
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_cat_deny_implicit(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
enum log_category_t cat_list[] = {
|
|
|
|
log_uc_cat(UCLASS_MMC), LOGC_NONE, LOGC_END
|
|
|
|
};
|
|
|
|
int filt;
|
|
|
|
|
|
|
|
filt = log_add_filter("console", cat_list, LOGL_MAX, NULL);
|
|
|
|
ut_assert(filt >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_cat(UCLASS_SPI);
|
|
|
|
check_log_entries_none();
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt));
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_cat_deny_implicit, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
/* Check passing and failing file filters */
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_file(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
int filt;
|
|
|
|
|
|
|
|
filt = log_add_filter("console", NULL, LOGL_MAX, "file");
|
|
|
|
ut_assert(filt >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_file("file");
|
2020-11-27 10:20:51 +00:00
|
|
|
check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_file("file2");
|
|
|
|
check_log_entries_none();
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt));
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_file, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
/* Check a passing file filter (second in list) */
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_file_second(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
int filt;
|
2017-12-04 20:48:27 +00:00
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
filt = log_add_filter("console", NULL, LOGL_MAX, "file,file2");
|
|
|
|
ut_assert(filt >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_file("file2");
|
2020-11-27 10:20:51 +00:00
|
|
|
check_log_entries_flags(EXPECT_DIRECT | EXPECT_EXTRA | EXPECT_FORCE);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt));
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_file_second, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
/* Check a passing file filter (middle of list) */
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_file_mid(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
int filt;
|
|
|
|
|
|
|
|
filt = log_add_filter("console", NULL, LOGL_MAX,
|
|
|
|
"file,file2,log/log_test.c");
|
|
|
|
ut_assert(filt >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_file("file2");
|
|
|
|
check_log_entries_extra();
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt));
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_file_mid, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
/* Check a log level filter */
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_level(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
int filt;
|
|
|
|
|
|
|
|
filt = log_add_filter("console", NULL, LOGL_WARNING, NULL);
|
|
|
|
ut_assert(filt >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run();
|
2020-11-27 10:20:51 +00:00
|
|
|
check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
|
|
|
|
LOGL_FIRST, LOGL_WARNING);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt));
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_level, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
|
|
|
/* Check two filters, one of which passes everything */
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_double(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
int filt1, filt2;
|
|
|
|
|
|
|
|
filt1 = log_add_filter("console", NULL, LOGL_WARNING, NULL);
|
|
|
|
ut_assert(filt1 >= 0);
|
|
|
|
filt2 = log_add_filter("console", NULL, LOGL_MAX, NULL);
|
|
|
|
ut_assert(filt2 >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run();
|
|
|
|
check_log_entries_extra();
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt1));
|
|
|
|
ut_assertok(log_remove_filter("console", filt2));
|
2017-12-04 20:48:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_double, UT_TESTF_CONSOLE_REC);
|
2017-12-04 20:48:27 +00:00
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
/* Check three filters, which together pass everything */
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_triple(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
int filt1, filt2, filt3;
|
|
|
|
|
|
|
|
filt1 = log_add_filter("console", NULL, LOGL_MAX, "file)");
|
|
|
|
ut_assert(filt1 >= 0);
|
|
|
|
filt2 = log_add_filter("console", NULL, LOGL_MAX, "file2");
|
|
|
|
ut_assert(filt2 >= 0);
|
|
|
|
filt3 = log_add_filter("console", NULL, LOGL_MAX, "log/log_test.c");
|
|
|
|
ut_assert(filt3 >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_file("file2");
|
|
|
|
check_log_entries_extra();
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt1));
|
|
|
|
ut_assertok(log_remove_filter("console", filt2));
|
|
|
|
ut_assertok(log_remove_filter("console", filt3));
|
|
|
|
return 0;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_triple, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
2020-10-27 23:55:28 +00:00
|
|
|
int do_log_test_helpers(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_err("level %d\n", LOGL_EMERG);
|
|
|
|
log_err("level %d\n", LOGL_ALERT);
|
|
|
|
log_err("level %d\n", LOGL_CRIT);
|
|
|
|
log_err("level %d\n", LOGL_ERR);
|
|
|
|
log_warning("level %d\n", LOGL_WARNING);
|
|
|
|
log_notice("level %d\n", LOGL_NOTICE);
|
|
|
|
log_info("level %d\n", LOGL_INFO);
|
|
|
|
log_debug("level %d\n", LOGL_DEBUG);
|
|
|
|
log_content("level %d\n", LOGL_DEBUG_CONTENT);
|
|
|
|
log_io("level %d\n", LOGL_DEBUG_IO);
|
|
|
|
|
|
|
|
for (i = LOGL_EMERG; i <= _LOG_MAX_LEVEL; i++)
|
|
|
|
ut_assert_nextline("%s() level %d", __func__, i);
|
|
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_helpers(struct unit_test_state *uts)
|
2017-12-04 20:48:27 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
gd->log_fmt = LOGF_TEST;
|
2020-10-27 23:55:28 +00:00
|
|
|
ret = do_log_test_helpers(uts);
|
2020-10-27 23:55:27 +00:00
|
|
|
gd->log_fmt = log_get_default_format();
|
|
|
|
return ret;
|
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_helpers, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:27 +00:00
|
|
|
|
2020-10-27 23:55:28 +00:00
|
|
|
int do_log_test_disable(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_err("default\n");
|
|
|
|
ut_assert_nextline("%s() default", __func__);
|
|
|
|
|
|
|
|
ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), false));
|
|
|
|
log_err("disabled\n");
|
2017-12-04 20:48:27 +00:00
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
ut_assertok(log_device_set_enable(LOG_GET_DRIVER(console), true));
|
|
|
|
log_err("enabled\n");
|
|
|
|
ut_assert_nextline("%s() enabled", __func__);
|
|
|
|
ut_assert_console_end();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-27 23:55:28 +00:00
|
|
|
int log_test_disable(struct unit_test_state *uts)
|
2020-10-27 23:55:27 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2017-12-04 20:48:27 +00:00
|
|
|
|
2020-10-27 23:55:27 +00:00
|
|
|
gd->log_fmt = LOGF_TEST;
|
2020-10-27 23:55:28 +00:00
|
|
|
ret = do_log_test_disable(uts);
|
2020-10-27 23:55:27 +00:00
|
|
|
gd->log_fmt = log_get_default_format();
|
|
|
|
return ret;
|
2017-12-04 20:48:27 +00:00
|
|
|
}
|
2020-10-27 23:55:28 +00:00
|
|
|
LOG_TEST_FLAGS(log_test_disable, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:29 +00:00
|
|
|
|
|
|
|
/* Check denying based on category */
|
|
|
|
int log_test_cat_deny(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
int filt1, filt2;
|
|
|
|
enum log_category_t cat_list[] = {
|
|
|
|
log_uc_cat(UCLASS_SPI), LOGC_END
|
|
|
|
};
|
|
|
|
|
|
|
|
filt1 = log_add_filter("console", cat_list, LOGL_MAX, NULL);
|
|
|
|
ut_assert(filt1 >= 0);
|
|
|
|
filt2 = log_add_filter_flags("console", cat_list, LOGL_MAX, NULL,
|
|
|
|
LOGFF_DENY);
|
|
|
|
ut_assert(filt2 >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_cat(UCLASS_SPI);
|
|
|
|
check_log_entries_none();
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt1));
|
|
|
|
ut_assertok(log_remove_filter("console", filt2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LOG_TEST_FLAGS(log_test_cat_deny, UT_TESTF_CONSOLE_REC);
|
|
|
|
|
|
|
|
/* Check denying based on file */
|
|
|
|
int log_test_file_deny(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
int filt1, filt2;
|
|
|
|
|
|
|
|
filt1 = log_add_filter("console", NULL, LOGL_MAX, "file");
|
|
|
|
ut_assert(filt1 >= 0);
|
|
|
|
filt2 = log_add_filter_flags("console", NULL, LOGL_MAX, "file",
|
|
|
|
LOGFF_DENY);
|
|
|
|
ut_assert(filt2 >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run_file("file");
|
|
|
|
check_log_entries_none();
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt1));
|
|
|
|
ut_assertok(log_remove_filter("console", filt2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LOG_TEST_FLAGS(log_test_file_deny, UT_TESTF_CONSOLE_REC);
|
|
|
|
|
|
|
|
/* Check denying based on level */
|
|
|
|
int log_test_level_deny(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
int filt1, filt2;
|
|
|
|
|
|
|
|
filt1 = log_add_filter("console", NULL, LOGL_INFO, NULL);
|
|
|
|
ut_assert(filt1 >= 0);
|
|
|
|
filt2 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
|
|
|
|
LOGFF_DENY);
|
|
|
|
ut_assert(filt2 >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run();
|
2020-11-27 10:20:51 +00:00
|
|
|
check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
|
2020-10-27 23:55:29 +00:00
|
|
|
LOGL_WARNING + 1, _LOG_MAX_LEVEL);
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt1));
|
|
|
|
ut_assertok(log_remove_filter("console", filt2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LOG_TEST_FLAGS(log_test_level_deny, UT_TESTF_CONSOLE_REC);
|
2020-10-27 23:55:31 +00:00
|
|
|
|
|
|
|
/* Check matching based on minimum level */
|
|
|
|
int log_test_min(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
int filt1, filt2;
|
|
|
|
|
|
|
|
filt1 = log_add_filter_flags("console", NULL, LOGL_WARNING, NULL,
|
|
|
|
LOGFF_LEVEL_MIN);
|
|
|
|
ut_assert(filt1 >= 0);
|
|
|
|
filt2 = log_add_filter_flags("console", NULL, LOGL_INFO, NULL,
|
|
|
|
LOGFF_DENY | LOGFF_LEVEL_MIN);
|
|
|
|
ut_assert(filt2 >= 0);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run();
|
2020-11-27 10:20:51 +00:00
|
|
|
check_log_entries_flags_levels(EXPECT_LOG | EXPECT_DIRECT | EXPECT_FORCE,
|
2020-10-27 23:55:31 +00:00
|
|
|
LOGL_WARNING, LOGL_INFO - 1);
|
|
|
|
|
|
|
|
ut_assertok(log_remove_filter("console", filt1));
|
|
|
|
ut_assertok(log_remove_filter("console", filt2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LOG_TEST_FLAGS(log_test_min, UT_TESTF_CONSOLE_REC);
|
2020-11-27 10:20:53 +00:00
|
|
|
|
|
|
|
/* Check dropped traces */
|
|
|
|
int log_test_dropped(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
/* force LOG not ready */
|
|
|
|
gd->flags &= ~(GD_FLG_LOG_READY);
|
|
|
|
gd->log_drop_count = 0;
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
log_run();
|
|
|
|
|
|
|
|
ut_asserteq(gd->log_drop_count, 3 * (LOGL_COUNT - LOGL_FIRST - 1));
|
2020-11-27 10:20:58 +00:00
|
|
|
check_log_entries_flags_levels(EXPECT_DEBUG, LOGL_FIRST, CONFIG_LOG_DEFAULT_LEVEL);
|
2020-11-27 10:20:53 +00:00
|
|
|
|
|
|
|
gd->flags |= GD_FLG_LOG_READY;
|
|
|
|
gd->log_drop_count = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
LOG_TEST_FLAGS(log_test_dropped, UT_TESTF_CONSOLE_REC);
|