All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/6] log: syslog logging driver
@ 2020-02-26 20:48 Heinrich Schuchardt
  2020-02-26 20:48 ` [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites Heinrich Schuchardt
                   ` (9 more replies)
  0 siblings, 10 replies; 19+ messages in thread
From: Heinrich Schuchardt @ 2020-02-26 20:48 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.

v5:
	do not build syslog driver in SPL
v4:
	correct syslog test (expect 'uboot:' not 'uboot[1]:')
	provide more comments for syslog test

*** BLURB HERE ***

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             | 280 +++++++++++++++++++++++++++++
 test/log/test-main.c               |  20 +++
 18 files changed, 621 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] 19+ messages in thread

* [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
@ 2020-02-26 20:48 ` Heinrich Schuchardt
  2020-02-26 20:48 ` [PATCH v5 2/6] log: syslog driver Heinrich Schuchardt
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Heinrich Schuchardt @ 2020-02-26 20:48 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>
---
v5:
	no change
v4:
	no change
---
 common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/Kconfig b/common/Kconfig
index 46e4193fc8..cedd353e89 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -776,7 +776,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] 19+ messages in thread

* [PATCH v5 2/6] log: syslog driver
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
  2020-02-26 20:48 ` [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites Heinrich Schuchardt
@ 2020-02-26 20:48 ` Heinrich Schuchardt
  2020-02-27 23:40   ` Simon Glass
  2020-03-03  2:46   ` sjg at google.com
  2020-02-26 20:48 ` [PATCH v5 3/6] log: output for CONFIG_LOG=n Heinrich Schuchardt
                   ` (7 subsequent siblings)
  9 siblings, 2 replies; 19+ messages in thread
From: Heinrich Schuchardt @ 2020-02-26 20:48 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>
---
v5:
	do not build syslog driver in SPL
v4:
	no change
---
 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 1842569f24..c1ff620c4a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -631,7 +631,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 cedd353e89..af0a009a8e 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -774,6 +774,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..dd54118091 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_$(SPL_TPL_)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] 19+ messages in thread

* [PATCH v5 3/6] log: output for CONFIG_LOG=n
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
  2020-02-26 20:48 ` [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites Heinrich Schuchardt
  2020-02-26 20:48 ` [PATCH v5 2/6] log: syslog driver Heinrich Schuchardt
@ 2020-02-26 20:48 ` Heinrich Schuchardt
  2020-04-22 19:00   ` Marek Vasut
  2020-02-26 20:48 ` [PATCH v5 4/6] test: log functions with CONFIG_LOG=n Heinrich Schuchardt
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Heinrich Schuchardt @ 2020-02-26 20:48 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>
---
v5:
	no change
v4:
	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] 19+ messages in thread

* [PATCH v5 4/6] test: log functions with CONFIG_LOG=n
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (2 preceding siblings ...)
  2020-02-26 20:48 ` [PATCH v5 3/6] log: output for CONFIG_LOG=n Heinrich Schuchardt
@ 2020-02-26 20:48 ` Heinrich Schuchardt
  2020-02-26 20:48 ` [PATCH v5 5/6] test: log: test syslog logging driver Heinrich Schuchardt
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Heinrich Schuchardt @ 2020-02-26 20:48 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>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v5:
	no change
v4:
	no change
---
 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 c1ff620c4a..9c2b7bf4c2 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -633,7 +633,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] 19+ messages in thread

* [PATCH v5 5/6] test: log: test syslog logging driver
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (3 preceding siblings ...)
  2020-02-26 20:48 ` [PATCH v5 4/6] test: log functions with CONFIG_LOG=n Heinrich Schuchardt
@ 2020-02-26 20:48 ` Heinrich Schuchardt
  2020-02-27 23:40   ` Simon Glass
  2020-03-03  2:45   ` sjg at google.com
  2020-02-26 20:48 ` [PATCH v5 6/6] configs: sandbox: enable LOG_SYSLOG Heinrich Schuchardt
                   ` (4 subsequent siblings)
  9 siblings, 2 replies; 19+ messages in thread
From: Heinrich Schuchardt @ 2020-02-26 20:48 UTC (permalink / raw)
  To: u-boot

Provide unit tests for the syslog logging driver.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v5:
	no change
v4:
	provide more comments
	move uts and expected to a common structure
	expect 'uboot:' not 'uboot[1]:' in syslog message
v3:
	new patch
---
 test/log/Makefile      |   4 +
 test/log/syslog_test.c | 280 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 284 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..6ca5760eac
--- /dev/null
+++ b/test/log/syslog_test.c
@@ -0,0 +1,280 @@
+// 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;
+
+/**
+ * struct sb_log_env - private data for sandbox ethernet driver
+ *
+ * This structure is used for the private data of the sandbox ethernet
+ * driver.
+ *
+ * @expected:	string expected to be written by the syslog driver
+ * @uts:	unit test state
+ */
+struct sb_log_env {
+	const char *expected;
+	struct unit_test_state *uts;
+};
+
+/**
+ * sb_log_tx_handler() - transmit callback function
+ *
+ * This callback function is invoked when a network package is sent using the
+ * sandbox Ethernet driver. The private data of the driver holds a sb_log_env
+ * structure with the unit test state and the expected UDP payload.
+ *
+ * The following checks are executed:
+ *
+ * * the Ethernet packet indicates a IP broadcast message
+ * * the IP header is for a local UDP broadcast message to port 514
+ * * the UDP payload matches the expected string
+ *
+ * After testing the pointer to the expected string is set to NULL to signal
+ * that the callback function has been called.
+ *
+ * @dev:	sandbox ethernet device
+ * @packet:	Ethernet packet
+ * @len:	length of Ethernet packet
+ * Return:	0 = success
+ */
+static int sb_log_tx_handler(struct udevice *dev, void *packet,
+			     unsigned int len)
+{
+	struct eth_sandbox_priv *priv = dev_get_priv(dev);
+	struct sb_log_env *env = priv->priv;
+	/* uts is updated by the ut_assert* macros */
+	struct unit_test_state *uts = env->uts;
+	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(env->expected) + 1,
+		    ntohs(ip_udp_hdr->udp_len));
+
+	/* Check payload */
+	buf += sizeof(struct ip_udp_hdr);
+	ut_asserteq_mem(env->expected, buf,
+			ntohs(ip_udp_hdr->udp_len) - UDP_HDR_SIZE);
+
+	/* Signal that the callback function has been executed */
+	env->expected = NULL;
+
+	return 0;
+}
+
+/**
+ * syslog_test_log_err() - test log_err() function
+ *
+ * @uts:	unit test state
+ * Return:	0 = success
+ */
+static int syslog_test_log_err(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+	struct sb_log_env env;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	env.expected = "<3>sandbox uboot: syslog_test_log_err() "
+		       "testing log_err\n";
+	env.uts = uts;
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, &env);
+	log_err("testing %s\n", "log_err");
+	/* Check that the callback function was called */
+	sandbox_eth_set_tx_handler(0, NULL);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_err);
+
+/**
+ * syslog_test_log_warning() - test log_warning() function
+ *
+ * @uts:	unit test state
+ * Return:	0 = success
+ */
+static int syslog_test_log_warning(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+	struct sb_log_env env;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	env.expected = "<4>sandbox uboot: syslog_test_log_warning() "
+		       "testing log_warning\n";
+	env.uts = uts;
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, &env);
+	log_warning("testing %s\n", "log_warning");
+	sandbox_eth_set_tx_handler(0, NULL);
+	/* Check that the callback function was called */
+	ut_assertnull(env.expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_warning);
+
+/**
+ * syslog_test_log_notice() - test log_notice() function
+ *
+ * @uts:	unit test state
+ * Return:	0 = success
+ */
+static int syslog_test_log_notice(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+	struct sb_log_env env;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	env.expected = "<5>sandbox uboot: syslog_test_log_notice() "
+		       "testing log_notice\n";
+	env.uts = uts;
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, &env);
+	log_notice("testing %s\n", "log_notice");
+	sandbox_eth_set_tx_handler(0, NULL);
+	/* Check that the callback function was called */
+	ut_assertnull(env.expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_notice);
+
+/**
+ * syslog_test_log_info() - test log_info() function
+ *
+ * @uts:	unit test state
+ * Return:	0 = success
+ */
+static int syslog_test_log_info(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+	struct sb_log_env env;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	env.expected = "<6>sandbox uboot: syslog_test_log_info() "
+		       "testing log_info\n";
+	env.uts = uts;
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, &env);
+	log_info("testing %s\n", "log_info");
+	sandbox_eth_set_tx_handler(0, NULL);
+	/* Check that the callback function was called */
+	ut_assertnull(env.expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_info);
+
+/**
+ * syslog_test_log_debug() - test log_debug() function
+ *
+ * @uts:	unit test state
+ * Return:	0 = success
+ */
+static int syslog_test_log_debug(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+	struct sb_log_env env;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_DEBUG;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	env.expected = "<7>sandbox uboot: syslog_test_log_debug() "
+		       "testing log_debug\n";
+	env.uts = uts;
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, &env);
+	log_debug("testing %s\n", "log_debug");
+	sandbox_eth_set_tx_handler(0, NULL);
+	/* Check that the callback function was called */
+	ut_assertnull(env.expected);
+	gd->default_log_level = old_log_level;
+
+	return 0;
+}
+LOG_TEST(syslog_test_log_debug);
+
+/**
+ * syslog_test_log_nodebug() - test logging level filter
+ *
+ * Verify that log_debug() does not lead to a log message if the logging level
+ * is set to LOGL_INFO.
+ *
+ * @uts:	unit test state
+ * Return:	0 = success
+ */
+static int syslog_test_log_nodebug(struct unit_test_state *uts)
+{
+	int old_log_level = gd->default_log_level;
+	struct sb_log_env env;
+
+	gd->log_fmt = LOGF_DEFAULT;
+	gd->default_log_level = LOGL_INFO;
+	env_set("ethact", "eth at 10002000");
+	env_set("log_hostname", "sandbox");
+	env.expected = "<7>sandbox uboot: syslog_test_log_nodebug() "
+		       "testing log_debug\n";
+	env.uts = uts;
+	sandbox_eth_set_tx_handler(0, sb_log_tx_handler);
+	/* Used by ut_assert macros in the tx_handler */
+	sandbox_eth_set_priv(0, &env);
+	log_debug("testing %s\n", "log_debug");
+	sandbox_eth_set_tx_handler(0, NULL);
+	/* Check that the callback function was not called */
+	ut_assertnonnull(env.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] 19+ messages in thread

* [PATCH v5 6/6] configs: sandbox: enable LOG_SYSLOG
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (4 preceding siblings ...)
  2020-02-26 20:48 ` [PATCH v5 5/6] test: log: test syslog logging driver Heinrich Schuchardt
@ 2020-02-26 20:48 ` Heinrich Schuchardt
  2020-03-03  2:45 ` sjg at google.com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Heinrich Schuchardt @ 2020-02-26 20:48 UTC (permalink / raw)
  To: u-boot

For testing purposes enable the syslog logging driver.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v5:
	no change
v4:
	no change
---
 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] 19+ messages in thread

* [PATCH v5 2/6] log: syslog driver
  2020-02-26 20:48 ` [PATCH v5 2/6] log: syslog driver Heinrich Schuchardt
@ 2020-02-27 23:40   ` Simon Glass
  2020-03-03  2:46   ` sjg at google.com
  1 sibling, 0 replies; 19+ messages in thread
From: Simon Glass @ 2020-02-27 23:40 UTC (permalink / raw)
  To: u-boot

On Wed, 26 Feb 2020 at 12:48, 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>
> ---
> v5:
>         do not build syslog driver in SPL
> v4:
>         no change
> ---
>  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] 19+ messages in thread

* [PATCH v5 5/6] test: log: test syslog logging driver
  2020-02-26 20:48 ` [PATCH v5 5/6] test: log: test syslog logging driver Heinrich Schuchardt
@ 2020-02-27 23:40   ` Simon Glass
  2020-03-03  2:45   ` sjg at google.com
  1 sibling, 0 replies; 19+ messages in thread
From: Simon Glass @ 2020-02-27 23:40 UTC (permalink / raw)
  To: u-boot

On Wed, 26 Feb 2020 at 12:48, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Provide unit tests for the syslog logging driver.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v5:
>         no change
> v4:
>         provide more comments
>         move uts and expected to a common structure
>         expect 'uboot:' not 'uboot[1]:' in syslog message
> v3:
>         new patch
> ---
>  test/log/Makefile      |   4 +
>  test/log/syslog_test.c | 280 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 284 insertions(+)
>  create mode 100644 test/log/syslog_test.c

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


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..6ca5760eac
> --- /dev/null
> +++ b/test/log/syslog_test.c
> @@ -0,0 +1,280 @@
> +// 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>

That should be at the end


> +#include <hexdump.h>
> +#include <test/log.h>
> +#include <test/test.h>
> +#include <test/suites.h>
> +#include <test/ut.h>
> +#include <asm/eth.h>

test/ comes after asm/

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

* [PATCH v5 6/6] configs: sandbox: enable LOG_SYSLOG
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (5 preceding siblings ...)
  2020-02-26 20:48 ` [PATCH v5 6/6] configs: sandbox: enable LOG_SYSLOG Heinrich Schuchardt
@ 2020-03-03  2:45 ` sjg at google.com
  2020-03-03  2:46 ` [PATCH v5 4/6] test: log functions with CONFIG_LOG=n sjg at google.com
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: sjg at google.com @ 2020-03-03  2:45 UTC (permalink / raw)
  To: u-boot

For testing purposes enable the syslog logging driver.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v5:
	no change
v4:
	no change
---
 configs/sandbox64_defconfig        | 1 +
 configs/sandbox_defconfig          | 1 +
 configs/sandbox_flattree_defconfig | 1 +
 3 files changed, 3 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH v5 5/6] test: log: test syslog logging driver
  2020-02-26 20:48 ` [PATCH v5 5/6] test: log: test syslog logging driver Heinrich Schuchardt
  2020-02-27 23:40   ` Simon Glass
@ 2020-03-03  2:45   ` sjg at google.com
  2020-05-06  3:42     ` Simon Glass
  1 sibling, 1 reply; 19+ messages in thread
From: sjg at google.com @ 2020-03-03  2:45 UTC (permalink / raw)
  To: u-boot

On Wed, 26 Feb 2020 at 12:48, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> Provide unit tests for the syslog logging driver.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> v5:
>         no change
> v4:
>         provide more comments
>         move uts and expected to a common structure
>         expect 'uboot:' not 'uboot[1]:' in syslog message
> v3:
>         new patch
> ---
>  test/log/Makefile      |   4 +
>  test/log/syslog_test.c | 280 +++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 284 insertions(+)
>  create mode 100644 test/log/syslog_test.c

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


See below

>
Applied to u-boot-dm, thanks!

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

* [PATCH v5 3/6] log: output for CONFIG_LOG=n
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (7 preceding siblings ...)
  2020-03-03  2:46 ` [PATCH v5 4/6] test: log functions with CONFIG_LOG=n sjg at google.com
@ 2020-03-03  2:46 ` sjg at google.com
  2020-03-03  2:46 ` [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites sjg at google.com
  9 siblings, 0 replies; 19+ messages in thread
From: sjg at google.com @ 2020-03-03  2:46 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>
---
v5:
	no change
v4:
	no change
---
 include/log.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Applied to u-boot-dm, thanks!

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

* [PATCH v5 4/6] test: log functions with CONFIG_LOG=n
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (6 preceding siblings ...)
  2020-03-03  2:45 ` sjg at google.com
@ 2020-03-03  2:46 ` sjg at google.com
  2020-03-03  2:46 ` [PATCH v5 3/6] log: output for CONFIG_LOG=n sjg at google.com
  2020-03-03  2:46 ` [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites sjg at google.com
  9 siblings, 0 replies; 19+ messages in thread
From: sjg at google.com @ 2020-03-03  2:46 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>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
v5:
	no change
v4:
	no change
---
 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

Applied to u-boot-dm, thanks!

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

* [PATCH v5 2/6] log: syslog driver
  2020-02-26 20:48 ` [PATCH v5 2/6] log: syslog driver Heinrich Schuchardt
  2020-02-27 23:40   ` Simon Glass
@ 2020-03-03  2:46   ` sjg at google.com
  1 sibling, 0 replies; 19+ messages in thread
From: sjg at google.com @ 2020-03-03  2:46 UTC (permalink / raw)
  To: u-boot

On Wed, 26 Feb 2020 at 12:48, 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>
> ---
> v5:
>         do not build syslog driver in SPL
> v4:
>         no change
> ---
>  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>

Applied to u-boot-dm, thanks!

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

* [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites
  2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
                   ` (8 preceding siblings ...)
  2020-03-03  2:46 ` [PATCH v5 3/6] log: output for CONFIG_LOG=n sjg at google.com
@ 2020-03-03  2:46 ` sjg at google.com
  9 siblings, 0 replies; 19+ messages in thread
From: sjg at google.com @ 2020-03-03  2:46 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>
---
v5:
	no change
v4:
	no change
---
 common/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied to u-boot-dm, thanks!

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

* [PATCH v5 3/6] log: output for CONFIG_LOG=n
  2020-02-26 20:48 ` [PATCH v5 3/6] log: output for CONFIG_LOG=n Heinrich Schuchardt
@ 2020-04-22 19:00   ` Marek Vasut
  2020-04-22 19:01     ` Tom Rini
  0 siblings, 1 reply; 19+ messages in thread
From: Marek Vasut @ 2020-04-22 19:00 UTC (permalink / raw)
  To: u-boot

On 2/26/20 9:48 PM, Heinrich Schuchardt wrote:
> 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>

NAK

This patch grows SoCFPGA SPL size by more than 6 bytes, and considering
the recent discussion, I believe it was made very clear that any growth
in SPL size is not allowed. I am surprised that this was not caught earlier.

So, please revert this patch.

I see the following with socfpga_cyclone5_defconfig

   text    data     bss     dec     hex filename
- 52235    1916      16   54167    d397 spl/u-boot-spl
+ 52319    1916      16   54251    d3eb spl/u-boot-spl

> ---
> v5:
> 	no change
> v4:
> 	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	[flat|nested] 19+ messages in thread

* [PATCH v5 3/6] log: output for CONFIG_LOG=n
  2020-04-22 19:00   ` Marek Vasut
@ 2020-04-22 19:01     ` Tom Rini
  2020-04-22 19:10       ` Marek Vasut
  0 siblings, 1 reply; 19+ messages in thread
From: Tom Rini @ 2020-04-22 19:01 UTC (permalink / raw)
  To: u-boot

On Wed, Apr 22, 2020 at 09:00:02PM +0200, Marek Vasut wrote:
> On 2/26/20 9:48 PM, Heinrich Schuchardt wrote:
> > 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>
> 
> NAK
> 
> This patch grows SoCFPGA SPL size by more than 6 bytes, and considering
> the recent discussion, I believe it was made very clear that any growth
> in SPL size is not allowed. I am surprised that this was not caught earlier.
> 
> So, please revert this patch.
> 
> I see the following with socfpga_cyclone5_defconfig
> 
>    text    data     bss     dec     hex filename
> - 52235    1916      16   54167    d397 spl/u-boot-spl
> + 52319    1916      16   54251    d3eb spl/u-boot-spl

Bugfix of previously important prints being missing.  Fix your patch and
quit trolling please.

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200422/ee3409db/attachment.sig>

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

* [PATCH v5 3/6] log: output for CONFIG_LOG=n
  2020-04-22 19:01     ` Tom Rini
@ 2020-04-22 19:10       ` Marek Vasut
  0 siblings, 0 replies; 19+ messages in thread
From: Marek Vasut @ 2020-04-22 19:10 UTC (permalink / raw)
  To: u-boot

On 4/22/20 9:01 PM, Tom Rini wrote:
> On Wed, Apr 22, 2020 at 09:00:02PM +0200, Marek Vasut wrote:
>> On 2/26/20 9:48 PM, Heinrich Schuchardt wrote:
>>> 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>
>>
>> NAK
>>
>> This patch grows SoCFPGA SPL size by more than 6 bytes, and considering
>> the recent discussion, I believe it was made very clear that any growth
>> in SPL size is not allowed. I am surprised that this was not caught earlier.
>>
>> So, please revert this patch.
>>
>> I see the following with socfpga_cyclone5_defconfig
>>
>>    text    data     bss     dec     hex filename
>> - 52235    1916      16   54167    d397 spl/u-boot-spl
>> + 52319    1916      16   54251    d3eb spl/u-boot-spl
> 
> Bugfix of previously important prints being missing.
So, can you please clarify what the rule for acceptable SPL growth is?

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

* [PATCH v5 5/6] test: log: test syslog logging driver
  2020-03-03  2:45   ` sjg at google.com
@ 2020-05-06  3:42     ` Simon Glass
  0 siblings, 0 replies; 19+ messages in thread
From: Simon Glass @ 2020-05-06  3:42 UTC (permalink / raw)
  To: u-boot

Hi Heinrich,

On Mon, 2 Mar 2020 at 19:45, <sjg@google.com> wrote:
>
> On Wed, 26 Feb 2020 at 12:48, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
> >
> > Provide unit tests for the syslog logging driver.
> >
> > Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> > ---
> > v5:
> >         no change
> > v4:
> >         provide more comments
> >         move uts and expected to a common structure
> >         expect 'uboot:' not 'uboot[1]:' in syslog message
> > v3:
> >         new patch
> > ---
> >  test/log/Makefile      |   4 +
> >  test/log/syslog_test.c | 280 +++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 284 insertions(+)
> >  create mode 100644 test/log/syslog_test.c
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Unfortunately this test does not run automatically with pytest at
present. Can you please take a look?

Regards,
SImon

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

end of thread, other threads:[~2020-05-06  3:42 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 20:48 [PATCH v5 0/6] log: syslog logging driver Heinrich Schuchardt
2020-02-26 20:48 ` [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites Heinrich Schuchardt
2020-02-26 20:48 ` [PATCH v5 2/6] log: syslog driver Heinrich Schuchardt
2020-02-27 23:40   ` Simon Glass
2020-03-03  2:46   ` sjg at google.com
2020-02-26 20:48 ` [PATCH v5 3/6] log: output for CONFIG_LOG=n Heinrich Schuchardt
2020-04-22 19:00   ` Marek Vasut
2020-04-22 19:01     ` Tom Rini
2020-04-22 19:10       ` Marek Vasut
2020-02-26 20:48 ` [PATCH v5 4/6] test: log functions with CONFIG_LOG=n Heinrich Schuchardt
2020-02-26 20:48 ` [PATCH v5 5/6] test: log: test syslog logging driver Heinrich Schuchardt
2020-02-27 23:40   ` Simon Glass
2020-03-03  2:45   ` sjg at google.com
2020-05-06  3:42     ` Simon Glass
2020-02-26 20:48 ` [PATCH v5 6/6] configs: sandbox: enable LOG_SYSLOG Heinrich Schuchardt
2020-03-03  2:45 ` sjg at google.com
2020-03-03  2:46 ` [PATCH v5 4/6] test: log functions with CONFIG_LOG=n sjg at google.com
2020-03-03  2:46 ` [PATCH v5 3/6] log: output for CONFIG_LOG=n sjg at google.com
2020-03-03  2:46 ` [PATCH v5 1/6] log: correct CONFIG_LOG_TEST prerequisites sjg at google.com

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.