summaryrefslogtreecommitdiff
path: root/test/log
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-05-08 13:46:54 -0600
committerTom Rini <trini@konsulko.com>2021-06-08 11:39:09 -0400
commite1cbd916c86cbfdb87a7b2219624057428c285d4 (patch)
tree338db8b14138d67a2969b677258873c30aa8f03e /test/log
parent8d9bb98f8649222777193c6c161361e1ebd5e3fa (diff)
log: Convert log values to printf() if not enabled
At present if logging not enabled, log_info() becomes a nop. But we want log output at the 'info' level to be akin to printf(). Update the macro to pass the output straight to printf() in this case. This mimics the behaviour for the log_...() macros like log_debug() and log_info(), so we can drop the special case for these. Add new tests to cover this case. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test/log')
-rw-r--r--test/log/Makefile1
-rw-r--r--test/log/nolog_ndebug.c39
-rw-r--r--test/log/nolog_test.c3
3 files changed, 43 insertions, 0 deletions
diff --git a/test/log/Makefile b/test/log/Makefile
index 09f8689d07..08eea70e34 100644
--- a/test/log/Makefile
+++ b/test/log/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_CONSOLE_RECORD) += cont_test.o
obj-y += pr_cont_test.o
else
obj-$(CONFIG_CONSOLE_RECORD) += nolog_test.o
+obj-$(CONFIG_CONSOLE_RECORD) += nolog_ndebug.o
endif
endif # CONFIG_UT_LOG
diff --git a/test/log/nolog_ndebug.c b/test/log/nolog_ndebug.c
new file mode 100644
index 0000000000..bd9a4f408e
--- /dev/null
+++ b/test/log/nolog_ndebug.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Logging function tests for CONFIG_LOG=n without #define DEBUG
+ */
+
+#include <common.h>
+#include <console.h>
+#include <log.h>
+#include <asm/global_data.h>
+#include <test/log.h>
+#include <test/ut.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define BUFFSIZE 32
+
+static int log_test_log_disabled_ndebug(struct unit_test_state *uts)
+{
+ char buf[BUFFSIZE];
+ int i;
+
+ memset(buf, 0, BUFFSIZE);
+ console_record_reset_enable();
+
+ /* Output a log record at every level */
+ for (i = LOGL_EMERG; i < LOGL_COUNT; i++)
+ log(LOGC_NONE, i, "testing level %i\n", i);
+ gd->flags &= ~GD_FLG_RECORD;
+
+ /* Since DEBUG is not defined, we expect to not get debug output */
+ for (i = LOGL_EMERG; i < LOGL_DEBUG; i++)
+ ut_assertok(ut_check_console_line(uts, "testing level %d", i));
+ ut_assertok(ut_check_console_end(uts));
+
+ return 0;
+}
+LOG_TEST(log_test_log_disabled_ndebug);
diff --git a/test/log/nolog_test.c b/test/log/nolog_test.c
index cb4fb3db9a..4e52e5bed8 100644
--- a/test/log/nolog_test.c
+++ b/test/log/nolog_test.c
@@ -10,6 +10,7 @@
#include <common.h>
#include <console.h>
+#include <log.h>
#include <asm/global_data.h>
#include <test/log.h>
#include <test/test.h>
@@ -128,8 +129,10 @@ static int log_test_nolog_debug(struct unit_test_state *uts)
memset(buf, 0, BUFFSIZE);
console_record_reset_enable();
log_debug("testing %s\n", "log_debug");
+ log(LOGC_NONE, LOGL_DEBUG, "more %s\n", "log_debug");
gd->flags &= ~GD_FLG_RECORD;
ut_assertok(ut_check_console_line(uts, "testing log_debug"));
+ ut_assertok(ut_check_console_line(uts, "more log_debug"));
ut_assertok(ut_check_console_end(uts));
return 0;
}