All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/6] log: syslog logging driver
@ 2020-02-15 10:14 Heinrich Schuchardt
  2020-02-15 10:14 ` [PATCH v3 1/6] log: correct CONFIG_LOG_TEST prerequisites Heinrich Schuchardt
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Heinrich Schuchardt @ 2020-02-15 10:14 UTC (permalink / raw)
  To: u-boot

This patch series provides a logging driver to send syslog messages via
UDP port 514 to a syslog server and a unit test for the syslog driver.
For testing LOG_SYSLOG is enabled on the sandbox.

For CONFIG_LOG=n a patch enables printf() or debug() output for log_*
functions. A unit test for this use case is provided.

Heinrich Schuchardt (6):
  log: correct CONFIG_LOG_TEST prerequisites
  log: syslog driver
  log: output for CONFIG_LOG=n
  test: log functions with CONFIG_LOG=n
  test: log: test syslog logging driver
  configs: sandbox: enable LOG_SYSLOG

 MAINTAINERS                        |   4 +-
 common/Kconfig                     |   9 +-
 common/Makefile                    |   1 +
 common/log_syslog.c                | 117 ++++++++++++++++++
 configs/sandbox64_defconfig        |   1 +
 configs/sandbox_defconfig          |   1 +
 configs/sandbox_flattree_defconfig |   1 +
 doc/README.log                     |   3 +
 include/log.h                      |  10 +-
 include/test/log.h                 |  16 +++
 include/test/suites.h              |   1 +
 test/Kconfig                       |   9 ++
 test/Makefile                      |   2 +-
 test/cmd_ut.c                      |   6 +
 test/log/Makefile                  |  14 +++
 test/log/nolog_test.c              | 135 +++++++++++++++++++++
 test/log/syslog_test.c             | 186 +++++++++++++++++++++++++++++
 test/log/test-main.c               |  20 ++++
 18 files changed, 527 insertions(+), 9 deletions(-)
 create mode 100644 common/log_syslog.c
 create mode 100644 include/test/log.h
 create mode 100644 test/log/nolog_test.c
 create mode 100644 test/log/syslog_test.c
 create mode 100644 test/log/test-main.c

--
2.25.0

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/6] log: correct CONFIG_LOG_TEST prerequisites
  2020-02-15 10:14 [PATCH v3 0/6] log: syslog logging driver Heinrich Schuchardt
@ 2020-02-15 10:14 ` Heinrich Schuchardt
  2020-02-15 10:14 ` [PATCH v3 2/6] log: syslog driver Heinrich Schuchardt
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Heinrich Schuchardt @ 2020-02-15 10:14 UTC (permalink / raw)
  To: u-boot

An error

	undefined reference to `do_log_test'

occurs for CONFIG_CMD_LOG=y, CONFIG_LOG_TEST=y, CONGIG_UNIT_TEST=n

Make CONFIG_UNIT_TEST a prerequisite.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v3:
	no change
---
 common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index 4bc3df4e1b..cfeb6ea648 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -775,7 +775,7 @@ config TPL_LOG_CONSOLE

 config LOG_TEST
 	bool "Provide a test for logging"
-	depends on LOG
+	depends on LOG && UNIT_TEST
 	default y if SANDBOX
 	help
 	  This enables a 'log test' command to test logging. It is normally
--
2.25.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 2/6] log: syslog driver
  2020-02-15 10:14 [PATCH v3 0/6] log: syslog logging driver Heinrich Schuchardt
  2020-02-15 10:14 ` [PATCH v3 1/6] log: correct CONFIG_LOG_TEST prerequisites Heinrich Schuchardt
@ 2020-02-15 10:14 ` Heinrich Schuchardt
  2020-02-16 19:02   ` Simon Glass
  2020-02-15 10:14 ` [PATCH v3 3/6] log: output for CONFIG_LOG=n Heinrich Schuchardt
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Heinrich Schuchardt @ 2020-02-15 10:14 UTC (permalink / raw)
  To: u-boot

Provide a log driver that broadcasts RFC 3164 messages to syslog servers.
rsyslog is one implementation of such a server.

The messages are sent to the local broadcast address 255.255.255.255 on
port 514.

The environment variable log_hostname can be used to provide the HOSTNAME
field for the messages. The optional TIMESTAMP field of RFC 3164 is not
provided.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v3:
	remove superfluous process ID field in syslog messages
---
 MAINTAINERS         |   2 +-
 common/Kconfig      |   7 +++
 common/Makefile     |   1 +
 common/log_syslog.c | 117 ++++++++++++++++++++++++++++++++++++++++++++
 doc/README.log      |   3 ++
 5 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 common/log_syslog.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 82e4159bec..d630176e33 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -630,7 +630,7 @@ LOGGING
 M:	Simon Glass <sjg@chromium.org>
 S:	Maintained
 T:	git https://gitlab.denx.de/u-boot/u-boot.git
-F:	common/log.c
+F:	common/log*
 F:	cmd/log.c
 F:	test/log/log_test.c
 F:	test/py/tests/test_log.py
diff --git a/common/Kconfig b/common/Kconfig
index cfeb6ea648..a2f60c010f 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -773,6 +773,13 @@ config TPL_LOG_CONSOLE
 	  log message is shown - other details like level, category, file and
 	  line number are omitted.

+config LOG_SYSLOG
+	bool "Log output to syslog server"
+	depends on LOG && NET
+	help
+	  Enables a log driver which broadcasts log records via UDP port 514
+	  to syslog servers.
+
 config LOG_TEST
 	bool "Provide a test for logging"
 	depends on LOG && UNIT_TEST
diff --git a/common/Makefile b/common/Makefile
index 896e4af91d..bde3f024bd 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -131,6 +131,7 @@ obj-$(CONFIG_DFU_OVER_USB) += dfu.o
 obj-y += command.o
 obj-$(CONFIG_$(SPL_TPL_)LOG) += log.o
 obj-$(CONFIG_$(SPL_TPL_)LOG_CONSOLE) += log_console.o
+obj-$(CONFIG_LOG_SYSLOG) += log_syslog.o
 obj-y += s_record.o
 obj-$(CONFIG_CMD_LOADB) += xyzModem.o
 obj-$(CONFIG_$(SPL_TPL_)YMODEM_SUPPORT) += xyzModem.o
diff --git a/common/log_syslog.c b/common/log_syslog.c
new file mode 100644
index 0000000000..5e3e20e8a4
--- /dev/null
+++ b/common/log_syslog.c
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Log to syslog.
+ *
+ * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
+ */
+
+#include <common.h>
+#include <log.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define BUFFER_SIZE 480
+
+static void append(char **buf, char *buf_end, const char *fmt, ...)
+{
+	va_list args;
+	size_t size = buf_end - *buf;
+
+	va_start(args, fmt);
+	vsnprintf(*buf, size, fmt, args);
+	va_end(args);
+	*buf += strlen(*buf);
+}
+
+static int log_syslog_emit(struct log_device *ldev, struct log_rec *rec)
+{
+	int ret;
+	int fmt = gd->log_fmt;
+	char msg[BUFFER_SIZE];
+	char *msg_end = msg + BUFFER_SIZE;
+	char *ptr = msg;
+	char *iphdr;
+	char *log_msg;
+	int eth_hdr_size;
+	struct in_addr bcast_ip;
+	static int processing_msg;
+	unsigned int log_level;
+	char *log_hostname;
+
+	/* Fend off messages from the network stack while writing a message */
+	if (processing_msg)
+		return 0;
+
+	processing_msg = 1;
+
+	/* Setup packet buffers */
+	net_init();
+	/* Disable hardware and put it into the reset state */
+	eth_halt();
+	/* Set current device according to environment variables */
+	eth_set_current();
+	/* Get hardware ready for send and receive operations */
+	ret = eth_init();
+	if (ret < 0) {
+		eth_halt();
+		goto out;
+	}
+
+	memset(msg, 0, BUFFER_SIZE);
+
+	/* Set ethernet header */
+	eth_hdr_size = net_set_ether((uchar *)ptr, net_bcast_ethaddr, PROT_IP);
+	ptr += eth_hdr_size;
+	iphdr = ptr;
+	ptr += IP_UDP_HDR_SIZE;
+	log_msg = ptr;
+
+	/*
+	 * The syslog log levels defined in RFC 5424 match the U-Boot ones up to
+	 * level 7 (debug).
+	 */
+	log_level = rec->level;
+	if (log_level > 7)
+		log_level = 7;
+	/* Leave high bits as 0 to write a 'kernel message' */
+
+	/* Write log message to buffer */
+	append(&ptr, msg_end, "<%u>", log_level);
+	log_hostname = env_get("log_hostname");
+	if (log_hostname)
+		append(&ptr, msg_end, "%s ", log_hostname);
+	append(&ptr, msg_end, "uboot: ");
+	if (fmt & (1 << LOGF_LEVEL))
+		append(&ptr, msg_end, "%s.",
+		       log_get_level_name(rec->level));
+	if (fmt & (1 << LOGF_CAT))
+		append(&ptr, msg_end, "%s,",
+		       log_get_cat_name(rec->cat));
+	if (fmt & (1 << LOGF_FILE))
+		append(&ptr, msg_end, "%s:", rec->file);
+	if (fmt & (1 << LOGF_LINE))
+		append(&ptr, msg_end, "%d-", rec->line);
+	if (fmt & (1 << LOGF_FUNC))
+		append(&ptr, msg_end, "%s()", rec->func);
+	if (fmt & (1 << LOGF_MSG))
+		append(&ptr, msg_end, "%s%s",
+		       fmt != (1 << LOGF_MSG) ? " " : "", rec->msg);
+	/* Consider trailing 0x00 */
+	ptr++;
+
+	debug("log message: '%s'\n", log_msg);
+
+	/* Broadcast message */
+	bcast_ip.s_addr = 0xFFFFFFFFL;
+	net_set_udp_header((uchar *)iphdr, bcast_ip, 514, 514, ptr - log_msg);
+	net_send_packet((uchar *)msg, ptr - msg);
+
+out:
+	processing_msg = 0;
+	return ret;
+}
+
+LOG_DRIVER(syslog) = {
+	.name	= "syslog",
+	.emit	= log_syslog_emit,
+};
diff --git a/doc/README.log b/doc/README.log
index 19856d43da..1057981f45 100644
--- a/doc/README.log
+++ b/doc/README.log
@@ -147,7 +147,10 @@ several possible determinations for logging information, all of which can be
 enabled or disabled independently:

    console - goes to stdout
+   syslog - broadcast RFC 3164 messages to syslog servers on UDP port 514

+The syslog driver sends the value of environmental variable 'log_hostname' as
+HOSTNAME if available.

 Log format
 ----------
--
2.25.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 3/6] log: output for CONFIG_LOG=n
  2020-02-15 10:14 [PATCH v3 0/6] log: syslog logging driver Heinrich Schuchardt
  2020-02-15 10:14 ` [PATCH v3 1/6] log: correct CONFIG_LOG_TEST prerequisites Heinrich Schuchardt
  2020-02-15 10:14 ` [PATCH v3 2/6] log: syslog driver Heinrich Schuchardt
@ 2020-02-15 10:14 ` Heinrich Schuchardt
  2020-02-15 10:14 ` [PATCH v3 4/6] test: log functions with CONFIG_LOG=n Heinrich Schuchardt
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Heinrich Schuchardt @ 2020-02-15 10:14 UTC (permalink / raw)
  To: u-boot

If CONFIG_LOG=n, we should still output errors, warnings, notices, infos,
and for DEBUG=1 also debug messages.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v3:
	no change
---
 include/log.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/include/log.h b/include/log.h
index 62fb8afbd0..0453876001 100644
--- a/include/log.h
+++ b/include/log.h
@@ -115,11 +115,11 @@ static inline int _log_nop(enum log_category_t cat, enum log_level_t level,
 #define log_io(_fmt...)		log(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt)
 #else
 #define _LOG_MAX_LEVEL LOGL_INFO
-#define log_err(_fmt...)	log_nop(LOG_CATEGORY, LOGL_ERR, ##_fmt)
-#define log_warning(_fmt...)	log_nop(LOG_CATEGORY, LOGL_WARNING, ##_fmt)
-#define log_notice(_fmt...)	log_nop(LOG_CATEGORY, LOGL_NOTICE, ##_fmt)
-#define log_info(_fmt...)	log_nop(LOG_CATEGORY, LOGL_INFO, ##_fmt)
-#define log_debug(_fmt...)	log_nop(LOG_CATEGORY, LOGL_DEBUG, ##_fmt)
+#define log_err(_fmt, ...)	printf(_fmt, ##__VA_ARGS__)
+#define log_warning(_fmt, ...)	printf(_fmt, ##__VA_ARGS__)
+#define log_notice(_fmt, ...)	printf(_fmt, ##__VA_ARGS__)
+#define log_info(_fmt, ...)	printf(_fmt, ##__VA_ARGS__)
+#define log_debug(_fmt, ...)	debug(_fmt, ##__VA_ARGS__)
 #define log_content(_fmt...)	log_nop(LOG_CATEGORY, \
 					LOGL_DEBUG_CONTENT, ##_fmt)
 #define log_io(_fmt...)		log_nop(LOG_CATEGORY, LOGL_DEBUG_IO, ##_fmt)
--
2.25.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 4/6] test: log functions with CONFIG_LOG=n
  2020-02-15 10:14 [PATCH v3 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (2 preceding siblings ...)
  2020-02-15 10:14 ` [PATCH v3 3/6] log: output for CONFIG_LOG=n Heinrich Schuchardt
@ 2020-02-15 10:14 ` Heinrich Schuchardt
  2020-02-16 19:02   ` Simon Glass
  2020-02-15 10:14 ` [PATCH v3 5/6] test: log: test syslog logging driver Heinrich Schuchardt
  2020-02-15 10:14 ` [PATCH v3 6/6] configs: sandbox: enable LOG_SYSLOG Heinrich Schuchardt
  5 siblings, 1 reply; 11+ messages in thread
From: Heinrich Schuchardt @ 2020-02-15 10:14 UTC (permalink / raw)
  To: u-boot

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>
---
v3:
	correctly consider CONFIG_UT_LOG in test/cmd_ut.c
v2:
	use ut_check_console_line()
	move do_ut_log() to test/log/test-main.c to accomodate further
	tests
	provide CONFIG_UT_LOG configuration option
---
 MAINTAINERS           |   2 +-
 include/test/log.h    |  16 +++++
 include/test/suites.h |   1 +
 test/Kconfig          |   9 +++
 test/Makefile         |   2 +-
 test/cmd_ut.c         |   6 ++
 test/log/Makefile     |  10 ++++
 test/log/nolog_test.c | 135 ++++++++++++++++++++++++++++++++++++++++++
 test/log/test-main.c  |  20 +++++++
 9 files changed, 199 insertions(+), 2 deletions(-)
 create mode 100644 include/test/log.h
 create mode 100644 test/log/nolog_test.c
 create mode 100644 test/log/test-main.c

diff --git a/MAINTAINERS b/MAINTAINERS
index d630176e33..ee80460fd7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -632,7 +632,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
diff --git a/include/test/log.h b/include/test/log.h
new file mode 100644
index 0000000000..c661cde75a
--- /dev/null
+++ b/include/test/log.h
@@ -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__ */
diff --git a/include/test/suites.h b/include/test/suites.h
index 0748185eaf..39ad81a90f 100644
--- a/include/test/suites.h
+++ b/include/test/suites.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[]);
diff --git a/test/Kconfig b/test/Kconfig
index cb51b46721..32e6197dca 100644
--- a/test/Kconfig
+++ b/test/Kconfig
@@ -30,6 +30,15 @@ config UT_LIB_ASN1

 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
diff --git a/test/Makefile b/test/Makefile
index 2fe41f489c..2971d0d87f 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -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/
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index a3a9d49f7e..7fdcdbb1a6 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -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
diff --git a/test/log/Makefile b/test/log/Makefile
index e0d0a4745f..98178f5e2b 100644
--- a/test/log/Makefile
+++ b/test/log/Makefile
@@ -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
diff --git a/test/log/nolog_test.c b/test/log/nolog_test.c
new file mode 100644
index 0000000000..84619521c9
--- /dev/null
+++ b/test/log/nolog_test.c
@@ -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);
diff --git a/test/log/test-main.c b/test/log/test-main.c
new file mode 100644
index 0000000000..855de47f33
--- /dev/null
+++ b/test/log/test-main.c
@@ -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);
+}
--
2.25.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 5/6] test: log: test syslog logging driver
  2020-02-15 10:14 [PATCH v3 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (3 preceding siblings ...)
  2020-02-15 10:14 ` [PATCH v3 4/6] test: log functions with CONFIG_LOG=n Heinrich Schuchardt
@ 2020-02-15 10:14 ` Heinrich Schuchardt
  2020-02-16 19:02   ` Simon Glass
  2020-02-15 10:14 ` [PATCH v3 6/6] configs: sandbox: enable LOG_SYSLOG Heinrich Schuchardt
  5 siblings, 1 reply; 11+ messages in thread
From: Heinrich Schuchardt @ 2020-02-15 10:14 UTC (permalink / raw)
  To: u-boot

Provide unit tests for the syslog logging driver.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v3:
	new patch
---
 test/log/Makefile      |   4 +
 test/log/syslog_test.c | 186 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 190 insertions(+)
 create mode 100644 test/log/syslog_test.c

diff --git a/test/log/Makefile b/test/log/Makefile
index 98178f5e2b..4c92550f6e 100644
--- a/test/log/Makefile
+++ b/test/log/Makefile
@@ -8,6 +8,10 @@ ifdef CONFIG_UT_LOG

 obj-y += test-main.o

+ifdef CONFIG_SANDBOX
+obj-$(CONFIG_LOG_SYSLOG) += syslog_test.o
+endif
+
 ifndef CONFIG_LOG
 obj-$(CONFIG_CONSOLE_RECORD) += nolog_test.o
 endif
diff --git a/test/log/syslog_test.c b/test/log/syslog_test.c
new file mode 100644
index 0000000000..7f3321f680
--- /dev/null
+++ b/test/log/syslog_test.c
@@ -0,0 +1,186 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
+ *
+ * Logging function tests for CONFIG_LOG_SYSLOG=y.
+ *
+ * Invoke the test with: ./u-boot -d arch/sandbox/dts/test.dtb
+ */
+
+/* Override CONFIG_LOG_MAX_LEVEL */
+#define LOG_DEBUG
+
+#include <common.h>
+#include <dm/device.h>
+#include <hexdump.h>
+#include <test/log.h>
+#include <test/test.h>
+#include <test/suites.h>
+#include <test/ut.h>
+#include <asm/eth.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+const char *expected;
+
+static int sb_log_tx_handler(struct udevice *dev, void *packet,
+			     unsigned int len)
+{
+	struct eth_sandbox_priv *priv = dev_get_priv(dev);
+	struct unit_test_state *uts = priv->priv;
+	char *buf = packet;
+	struct ethernet_hdr *eth_hdr = packet;
+	struct ip_udp_hdr *ip_udp_hdr;
+
+	/* Check Ethernet header */
+	ut_asserteq_mem(&eth_hdr->et_dest, net_bcast_ethaddr, ARP_HLEN);
+	ut_asserteq(ntohs(eth_hdr->et_protlen), PROT_IP);
+
+	/* Check IP header */
+	buf += sizeof(struct ethernet_hdr);
+	ip_udp_hdr = (struct ip_udp_hdr *)buf;
+	ut_asserteq(ip_udp_hdr->ip_p, IPPROTO_UDP);
+	ut_asserteq(ip_udp_hdr->ip_dst.s_addr, 0xffffffff);
+	ut_asserteq(ntohs(ip_udp_hdr->udp_dst), 514);
+	ut_asserteq(UDP_HDR_SIZE + strlen(expected) + 1,
+		    ntohs(ip_udp_hdr->udp_len));
+
+	/* Check payload */
+	buf += sizeof(struct ip_udp_hdr);
+	ut_asserteq_mem(expected, buf,
+			ntohs(ip_udp_hdr->udp_len) - UDP_HDR_SIZE);
+	expected = NULL;
+
+	return 0;
+}
+
+static int syslog_test_log_err(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	expected = "<3>sandbox uboot[1]: syslog_test_log_err() "
+		   "testing log_err\n";
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, uts);
+	log_err("testing %s\n", "log_err");
+	sandbox_eth_set_tx_handler(0, NULL);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_err);
+
+static int syslog_test_log_warning(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	expected = "<4>sandbox uboot[1]: syslog_test_log_warning() "
+		   "testing log_warning\n";
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, uts);
+	log_warning("testing %s\n", "log_warning");
+	sandbox_eth_set_tx_handler(0, NULL);
+	ut_assertnull(expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_warning);
+
+static int syslog_test_log_notice(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	expected = "<5>sandbox uboot[1]: syslog_test_log_notice() "
+		   "testing log_notice\n";
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, uts);
+	log_notice("testing %s\n", "log_notice");
+	sandbox_eth_set_tx_handler(0, NULL);
+	ut_assertnull(expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_notice);
+
+static int syslog_test_log_info(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	expected = "<6>sandbox uboot[1]: syslog_test_log_info() "
+		   "testing log_info\n";
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, uts);
+	log_info("testing %s\n", "log_info");
+	sandbox_eth_set_tx_handler(0, NULL);
+	ut_assertnull(expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_info);
+
+static int syslog_test_log_debug(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_DEBUG;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	expected = "<7>sandbox uboot[1]: syslog_test_log_debug() "
+		   "testing log_debug\n";
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, uts);
+	log_debug("testing %s\n", "log_debug");
+	sandbox_eth_set_tx_handler(0, NULL);
+	ut_assertnull(expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_debug);
+
+static int syslog_test_log_nodebug(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	expected = "<7>sandbox uboot[1]: syslog_test_log_nodebug() "
+		   "testing log_debug\n";
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, uts);
+	log_debug("testing %s\n", "log_debug");
+	sandbox_eth_set_tx_handler(0, NULL);
+	ut_assertnonnull(expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_nodebug);
--
2.25.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 6/6] configs: sandbox: enable LOG_SYSLOG
  2020-02-15 10:14 [PATCH v3 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (4 preceding siblings ...)
  2020-02-15 10:14 ` [PATCH v3 5/6] test: log: test syslog logging driver Heinrich Schuchardt
@ 2020-02-15 10:14 ` Heinrich Schuchardt
  2020-02-16 19:02   ` Simon Glass
  5 siblings, 1 reply; 11+ messages in thread
From: Heinrich Schuchardt @ 2020-02-15 10:14 UTC (permalink / raw)
  To: u-boot

For testing purposes enable the syslog logging driver.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v3:
	new patch
---
 configs/sandbox64_defconfig        | 1 +
 configs/sandbox_defconfig          | 1 +
 configs/sandbox_flattree_defconfig | 1 +
 3 files changed, 3 insertions(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index 941b1fd2c7..035900eb42 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -18,6 +18,7 @@ CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
 CONFIG_SILENT_CONSOLE=y
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_LOG_MAX_LEVEL=6
+CONFIG_LOG_SYSLOG=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 7b02b8de7c..49610a2f76 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -19,6 +19,7 @@ CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
 CONFIG_SILENT_CONSOLE=y
 CONFIG_PRE_CONSOLE_BUFFER=y
 CONFIG_LOG_MAX_LEVEL=6
+CONFIG_LOG_SYSLOG=y
 CONFIG_LOG_ERROR_RETURN=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_ANDROID_AB=y
diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig
index 0049da3d48..22d54678e0 100644
--- a/configs/sandbox_flattree_defconfig
+++ b/configs/sandbox_flattree_defconfig
@@ -15,6 +15,7 @@ CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
 CONFIG_SILENT_CONSOLE=y
 CONFIG_LOG_MAX_LEVEL=6
+CONFIG_LOG_SYSLOG=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
--
2.25.0

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 2/6] log: syslog driver
  2020-02-15 10:14 ` [PATCH v3 2/6] log: syslog driver Heinrich Schuchardt
@ 2020-02-16 19:02   ` Simon Glass
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2020-02-16 19:02 UTC (permalink / raw)
  To: u-boot

On Sat, 15 Feb 2020 at 03:14, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Provide a log driver that broadcasts RFC 3164 messages to syslog servers.
> rsyslog is one implementation of such a server.
>
> The messages are sent to the local broadcast address 255.255.255.255 on
> port 514.
>
> The environment variable log_hostname can be used to provide the HOSTNAME
> field for the messages. The optional TIMESTAMP field of RFC 3164 is not
> provided.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v3:
>         remove superfluous process ID field in syslog messages
> ---
>  MAINTAINERS         |   2 +-
>  common/Kconfig      |   7 +++
>  common/Makefile     |   1 +
>  common/log_syslog.c | 117 ++++++++++++++++++++++++++++++++++++++++++++
>  doc/README.log      |   3 ++
>  5 files changed, 129 insertions(+), 1 deletion(-)
>  create mode 100644 common/log_syslog.c

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 4/6] test: log functions with CONFIG_LOG=n
  2020-02-15 10:14 ` [PATCH v3 4/6] test: log functions with CONFIG_LOG=n Heinrich Schuchardt
@ 2020-02-16 19:02   ` Simon Glass
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2020-02-16 19:02 UTC (permalink / raw)
  To: u-boot

On Sat, 15 Feb 2020 at 03:14, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> 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>
> ---
> v3:
>         correctly consider CONFIG_UT_LOG in test/cmd_ut.c
> v2:
>         use ut_check_console_line()
>         move do_ut_log() to test/log/test-main.c to accomodate further
>         tests
>         provide CONFIG_UT_LOG configuration option
> ---
>  MAINTAINERS           |   2 +-
>  include/test/log.h    |  16 +++++
>  include/test/suites.h |   1 +
>  test/Kconfig          |   9 +++
>  test/Makefile         |   2 +-
>  test/cmd_ut.c         |   6 ++
>  test/log/Makefile     |  10 ++++
>  test/log/nolog_test.c | 135 ++++++++++++++++++++++++++++++++++++++++++
>  test/log/test-main.c  |  20 +++++++
>  9 files changed, 199 insertions(+), 2 deletions(-)
>  create mode 100644 include/test/log.h
>  create mode 100644 test/log/nolog_test.c
>  create mode 100644 test/log/test-main.c
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 5/6] test: log: test syslog logging driver
  2020-02-15 10:14 ` [PATCH v3 5/6] test: log: test syslog logging driver Heinrich Schuchardt
@ 2020-02-16 19:02   ` Simon Glass
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2020-02-16 19:02 UTC (permalink / raw)
  To: u-boot

On Sat, 15 Feb 2020 at 03:14, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Provide unit tests for the syslog logging driver.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v3:
>         new patch
> ---
>  test/log/Makefile      |   4 +
>  test/log/syslog_test.c | 186 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 190 insertions(+)
>  create mode 100644 test/log/syslog_test.c
>

Reviewed-by: Simon Glass <sjg@chromium.org>

This is a great set of tests.

But please see below.

> diff --git a/test/log/Makefile b/test/log/Makefile
> index 98178f5e2b..4c92550f6e 100644
> --- a/test/log/Makefile
> +++ b/test/log/Makefile
> @@ -8,6 +8,10 @@ ifdef CONFIG_UT_LOG
>
>  obj-y += test-main.o
>
> +ifdef CONFIG_SANDBOX
> +obj-$(CONFIG_LOG_SYSLOG) += syslog_test.o
> +endif
> +
>  ifndef CONFIG_LOG
>  obj-$(CONFIG_CONSOLE_RECORD) += nolog_test.o
>  endif
> diff --git a/test/log/syslog_test.c b/test/log/syslog_test.c
> new file mode 100644
> index 0000000000..7f3321f680
> --- /dev/null
> +++ b/test/log/syslog_test.c
> @@ -0,0 +1,186 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
> + *
> + * Logging function tests for CONFIG_LOG_SYSLOG=y.
> + *
> + * Invoke the test with: ./u-boot -d arch/sandbox/dts/test.dtb
> + */
> +
> +/* Override CONFIG_LOG_MAX_LEVEL */
> +#define LOG_DEBUG
> +
> +#include <common.h>
> +#include <dm/device.h>
> +#include <hexdump.h>
> +#include <test/log.h>
> +#include <test/test.h>
> +#include <test/suites.h>
> +#include <test/ut.h>
> +#include <asm/eth.h>
> +
> +DECLARE_GLOBAL_DATA_PTR;
> +
> +const char *expected;

comment? It seems to have strange behaviour.

> +
> +static int sb_log_tx_handler(struct udevice *dev, void *packet,
> +                            unsigned int len)

Add function comment

> +{
> +       struct eth_sandbox_priv *priv = dev_get_priv(dev);
> +       struct unit_test_state *uts = priv->priv;
> +       char *buf = packet;
> +       struct ethernet_hdr *eth_hdr = packet;
> +       struct ip_udp_hdr *ip_udp_hdr;
> +
> +       /* Check Ethernet header */
> +       ut_asserteq_mem(&eth_hdr->et_dest, net_bcast_ethaddr, ARP_HLEN);
> +       ut_asserteq(ntohs(eth_hdr->et_protlen), PROT_IP);
> +
> +       /* Check IP header */
> +       buf += sizeof(struct ethernet_hdr);
> +       ip_udp_hdr = (struct ip_udp_hdr *)buf;
> +       ut_asserteq(ip_udp_hdr->ip_p, IPPROTO_UDP);
> +       ut_asserteq(ip_udp_hdr->ip_dst.s_addr, 0xffffffff);
> +       ut_asserteq(ntohs(ip_udp_hdr->udp_dst), 514);
> +       ut_asserteq(UDP_HDR_SIZE + strlen(expected) + 1,
> +                   ntohs(ip_udp_hdr->udp_len));
> +
> +       /* Check payload */
> +       buf += sizeof(struct ip_udp_hdr);
> +       ut_asserteq_mem(expected, buf,
> +                       ntohs(ip_udp_hdr->udp_len) - UDP_HDR_SIZE);
> +       expected = NULL;
> +
> +       return 0;
> +}
> +
> +static int syslog_test_log_err(struct unit_test_state *uts)
> +{
> +       int old_log_level = gd->default_log_level;
> +
> +       gd->log_fmt = LOGF_DEFAULT;
> +       gd->default_log_level = LOGL_INFO;
> +       env_set("ethact", "eth at 10002000");
> +       env_set("log_hostname", "sandbox");
> +       expected = "<3>sandbox uboot[1]: syslog_test_log_err() "
> +                  "testing log_err\n";
> +       sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
> +       /* Used by ut_assert macros in the tx_handler */
> +       sandbox_eth_set_priv(0, uts);
> +       log_err("testing %s\n", "log_err");
> +       sandbox_eth_set_tx_handler(0, NULL);
> +       gd->default_log_level = old_log_level;
> +
> +       return 0;
> +}
> +LOG_TEST(syslog_test_log_err);
> +
> +static int syslog_test_log_warning(struct unit_test_state *uts)
> +{
> +       int old_log_level = gd->default_log_level;
> +
> +       gd->log_fmt = LOGF_DEFAULT;
> +       gd->default_log_level = LOGL_INFO;
> +       env_set("ethact", "eth at 10002000");
> +       env_set("log_hostname", "sandbox");
> +       expected = "<4>sandbox uboot[1]: syslog_test_log_warning() "
> +                  "testing log_warning\n";
> +       sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
> +       /* Used by ut_assert macros in the tx_handler */
> +       sandbox_eth_set_priv(0, uts);
> +       log_warning("testing %s\n", "log_warning");
> +       sandbox_eth_set_tx_handler(0, NULL);
> +       ut_assertnull(expected);

Comment here that expected is set to NULL in the tx handler

> +       gd->default_log_level = old_log_level;
> +
> +       return 0;
> +}
> +LOG_TEST(syslog_test_log_warning);
> +

Regards,
Simon

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 6/6] configs: sandbox: enable LOG_SYSLOG
  2020-02-15 10:14 ` [PATCH v3 6/6] configs: sandbox: enable LOG_SYSLOG Heinrich Schuchardt
@ 2020-02-16 19:02   ` Simon Glass
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2020-02-16 19:02 UTC (permalink / raw)
  To: u-boot

On Sat, 15 Feb 2020 at 03:14, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> For testing purposes enable the syslog logging driver.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v3:
>         new patch
> ---
>  configs/sandbox64_defconfig        | 1 +
>  configs/sandbox_defconfig          | 1 +
>  configs/sandbox_flattree_defconfig | 1 +
>  3 files changed, 3 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-02-16 19:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-15 10:14 [PATCH v3 0/6] log: syslog logging driver Heinrich Schuchardt
2020-02-15 10:14 ` [PATCH v3 1/6] log: correct CONFIG_LOG_TEST prerequisites Heinrich Schuchardt
2020-02-15 10:14 ` [PATCH v3 2/6] log: syslog driver Heinrich Schuchardt
2020-02-16 19:02   ` Simon Glass
2020-02-15 10:14 ` [PATCH v3 3/6] log: output for CONFIG_LOG=n Heinrich Schuchardt
2020-02-15 10:14 ` [PATCH v3 4/6] test: log functions with CONFIG_LOG=n Heinrich Schuchardt
2020-02-16 19:02   ` Simon Glass
2020-02-15 10:14 ` [PATCH v3 5/6] test: log: test syslog logging driver Heinrich Schuchardt
2020-02-16 19:02   ` Simon Glass
2020-02-15 10:14 ` [PATCH v3 6/6] configs: sandbox: enable LOG_SYSLOG Heinrich Schuchardt
2020-02-16 19:02   ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.