Skip to contentSkip to conversation

log: Fix the syslog spam when running tests

PATCH New Simon Glass 3 participants 18 messages Sep 12, 2020 – Oct 12, 2020

lore
Share & tools
lore
#0 lore raw

cover log: Fix the syslog spam when running tests

At present running some sandbox tests produces unwanted ethernet errors from the syslog driver, e.g.:

$ ./u-boot -c "ut bloblist"

Running 5 bloblist tests
Test: bloblist_test_bad_blob
Test: bloblist_test_blob
Test: bloblist_test_blob_ensure
Failed to allocate e0 bytes size=100, need size=130 No ethernet found.
bloblist add: returning err=-28
No ethernet found.
Test: bloblist_test_checksum
Checksum f3129fae != 338fbdc
No ethernet found.
Bad checksum: returning err=-5
No ethernet found.
...

This series fixes this by making the syslog driver disabled by default. It can be enabled with a function call.

Simon Glass (4):
log: Add a flag to enable log drivers
log: Drop #ifdef in log_test
log: Add a way to enable/disable a log device
log: Disable the syslog driver by default

 common/log.c                  | 42 ++++++++++++++++++++++++++++++++++-
 common/log_console.c          |  1 +
 include/log.h                 | 28 ++++++++++++++++++++++-
 test/log/log_test.c           |  9 ++++++--
 test/log/syslog_test.c        | 24 ++++++++++++++++++++
 test/log/syslog_test.h        | 16 +++++++++++++
 test/log/syslog_test_ndebug.c |  2 ++
 test/py/tests/test_log.py     |  8 +++++++
 8 files changed, 126 insertions(+), 4 deletions(-)
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
#1 lore raw

PATCH 1/4 log: Add a flag to enable log drivers

At present there is no way to disable a log driver. But the syslog driver causes (attempted) network traffic in sandbox every time a log message is printed, which is often.

Add a flag to enable a log driver. Adjust struct log_device to use a short for next_filter_num so that no more memory is used for devices. Also fix a missing line in the struct log_driver comment while here.

To maintain compatibility, enable it for all drivers for now.

---

 common/log.c         |  4 +++-
 common/log_console.c |  1 +
 common/log_syslog.c  |  1 +
 include/log.h        | 11 ++++++++++-
 4 files changed, 15 insertions(+), 2 deletions(-)
common/log.c +3 -1
index f44f15743ff..ce528fe4535 100644
@@ -196,7 +196,8 @@ static int log_dispatch(struct log_rec *rec)
 	struct log_device *ldev;
 
 	list_for_each_entry(ldev, &gd->log_head, sibling_node) {
-		if (log_passes_filters(ldev, rec))
+		if ((ldev->flags & LOGDF_ENABLE) &&
+		    log_passes_filters(ldev, rec))
 			ldev->drv->emit(ldev, rec);
 	}
 
@@ -318,6 +319,7 @@ int log_init(void)
 		}
 		INIT_LIST_HEAD(&ldev->filter_head);
 		ldev->drv = drv;
+		ldev->flags = drv->flags;
 		list_add_tail(&ldev->sibling_node,
 			      (struct list_head *)&gd->log_head);
 		drv++;
common/log_console.c +1 -0
index bb3f8464b98..8776fd47039 100644
@@ -44,4 +44,5 @@ static int log_console_emit(struct log_device *ldev, struct log_rec *rec)
 LOG_DRIVER(console) = {
 	.name	= "console",
 	.emit	= log_console_emit,
+	.flags	= LOGDF_ENABLE,
 };
common/log_syslog.c +1 -0
index 149ff5af310..cf0dbba9bf5 100644
@@ -115,4 +115,5 @@ out:
 LOG_DRIVER(syslog) = {
 	.name	= "syslog",
 	.emit	= log_syslog_emit,
+	.flags	= LOGDF_ENABLE,
 };
include/log.h +10 -1
index 86c8d7be09d..d28bc1ef0e4 100644
@@ -307,10 +307,16 @@ struct log_rec {
 
 struct log_device;
 
+enum log_device_flags {
+	LOGDF_ENABLE		= BIT(0),	/* Device is enabled */
+};
+
 /**
  * struct log_driver - a driver which accepts and processes log records
  *
  * @name: Name of driver
+ * @emit: Method to call to emit a log record via this device
+ * @flags: Initial value for flags (use LOGDF_ENABLE to enable on start-up)
  */
 struct log_driver {
 	const char *name;
@@ -321,6 +327,7 @@ struct log_driver {
 	 * for processing. The filter is checked before calling this function.
 	 */
 	int (*emit)(struct log_device *ldev, struct log_rec *rec);
+	unsigned short flags;
 };
 
 /**
@@ -333,12 +340,14 @@ struct log_driver {
  * @next_filter_num: Seqence number of next filter filter added (0=no filters
  *	yet). This increments with each new filter on the device, but never
  *	decrements
+ * @flags: Flags for this filter (enum log_device_flags)
  * @drv: Pointer to driver for this device
  * @filter_head: List of filters for this device
  * @sibling_node: Next device in the list of all devices
  */
 struct log_device {
-	int next_filter_num;
+	unsigned short next_filter_num;
+	unsigned short flags;
 	struct log_driver *drv;
 	struct list_head filter_head;
 	struct list_head sibling_node;
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
#2 lore raw

PATCH 1/4 log: Add a flag to enable log drivers

Quoted 11 lines · Simon Glass

At present there is no way to disable a log driver. But the syslog driver causes (attempted) network traffic in sandbox every time a log message is printed, which is often.

Add a flag to enable a log driver. Adjust struct log_device to use a short for next_filter_num so that no more memory is used for devices. Also fix a missing line in the struct log_driver comment while here.

To maintain compatibility, enable it for all drivers for now.

Applied to u-boot/master, thanks!

Signature · 8 lines
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/20201011/d716825b/attachment.sig>
#3 lore raw

PATCH 2/4 log: Drop #ifdef in log_test

In reply to Simon Glass

This is not needed as the Makefile only builds the file if CONFIG_LOG_TEST is enabled. Drop it.

---

 test/log/log_test.c | 2 --
 1 file changed, 2 deletions(-)
test/log/log_test.c +0 -2
index 4245372d65f..fdee5e6757f 100644
@@ -201,7 +201,6 @@ static int log_test(int testnum)
 	return 0;
 }
 
-#ifdef CONFIG_LOG_TEST
 int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	int testnum = 0;
@@ -216,4 +215,3 @@ int do_log_test(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
 	return ret ? CMD_RET_FAILURE : 0;
 }
-#endif
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
#4 lore raw

PATCH 2/4 log: Drop #ifdef in log_test

Quoted 4 lines · Simon Glass

This is not needed as the Makefile only builds the file if CONFIG_LOG_TEST is enabled. Drop it.

Applied to u-boot/master, thanks!

Signature · 8 lines
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/20201011/ff7c3bc1/attachment.sig>
#5 lore raw

PATCH 3/4 log: Add a way to enable/disable a log device

In reply to Simon Glass

At present all log devices are enabled by default. Add a function to allow devices to be disabled or enabled at runtime.

---

 common/log.c              | 38 ++++++++++++++++++++++++++++++++++++++
 include/log.h             | 17 +++++++++++++++++
 test/log/log_test.c       |  7 +++++++
 test/py/tests/test_log.py |  8 ++++++++
 4 files changed, 70 insertions(+)
common/log.c +38 -0
index ce528fe4535..a9aacfaf354 100644
@@ -297,6 +297,44 @@ int log_remove_filter(const char *drv_name, int filter_num)
 	return -ENOENT;
 }
 
+/**
+ * log_find_device_by_drv() - Find a device by its driver
+ *
+ * @drv: Log driver
+ * @return Device associated with that driver, or NULL if not found
+ */
+static struct log_device *log_find_device_by_drv(struct log_driver *drv)
+{
+	struct log_device *ldev;
+
+	list_for_each_entry(ldev, &gd->log_head, sibling_node) {
+		if (ldev->drv == drv)
+			return ldev;
+	}
+	/*
+	 * It is quite hard to pass an invalid driver since passing an unknown
+	 * LOG_GET_DRIVER(xxx) would normally produce a compilation error. But
+	 * it is possible to pass NULL, for example, so this
+	 */
+
+	return NULL;
+}
+
+int log_device_set_enable(struct log_driver *drv, bool enable)
+{
+	struct log_device *ldev;
+
+	ldev = log_find_device_by_drv(drv);
+	if (!ldev)
+		return -ENOENT;
+	if (enable)
+		ldev->flags |= LOGDF_ENABLE;
+	else
+		ldev->flags &= ~LOGDF_ENABLE;
+
+	return 0;
+}
+
 int log_init(void)
 {
 	struct log_driver *drv = ll_entry_start(struct log_driver, log_driver);
include/log.h +17 -0
index d28bc1ef0e4..4acc087b2e9 100644
@@ -388,6 +388,10 @@ struct log_filter {
 #define LOG_DRIVER(_name) \
 	ll_entry_declare(struct log_driver, _name, log_driver)
 
+/* Get a pointer to a given driver */
+#define LOG_GET_DRIVER(__name)						\
+	ll_entry_get(struct log_driver, __name, log_driver)
+
 /**
  * log_get_cat_name() - Get the name of a category
  *
@@ -465,6 +469,19 @@ int log_add_filter(const char *drv_name, enum log_category_t cat_list[],
  */
 int log_remove_filter(const char *drv_name, int filter_num);
 
+/**
+ * log_device_set_enable() - Enable or disable a log device
+ *
+ * Devices are referenced by their driver, so use LOG_GET_DRIVER(name) to pass
+ * the driver to this function. For example if the driver is declared with
+ * LOG_DRIVER(wibble) then pass LOG_GET_DRIVER(wibble) here.
+ *
+ * @drv: Driver of device to enable
+ * @enable: true to enable, false to disable
+ * @return 0 if OK, -ENOENT if the driver was not found
+ */
+int log_device_set_enable(struct log_driver *drv, bool enable);
+
 #if CONFIG_IS_ENABLED(LOG)
 /**
  * log_init() - Set up the log system ready for use
test/log/log_test.c +7 -0
index fdee5e6757f..6a60ff6be3c 100644
@@ -196,6 +196,13 @@ static int log_test(int testnum)
 		log_io("level %d\n", LOGL_DEBUG_IO);
 		break;
 	}
+	case 11:
+		log_err("default\n");
+		ret = log_device_set_enable(LOG_GET_DRIVER(console), false);
+		log_err("disabled\n");
+		ret = log_device_set_enable(LOG_GET_DRIVER(console), true);
+		log_err("enabled\n");
+		break;
 	}
 
 	return 0;
test/py/tests/test_log.py +8 -0
index ddc28f19ee8..275f9382d2f 100644
@@ -92,6 +92,13 @@ def test_log(u_boot_console):
         for i in range(7):
             assert 'log_test() level %d' % i == next(lines)
 
+    def test11():
+        """Test use of log_device_set_enable()"""
+        lines = run_test(11)
+        assert 'log_test() default'
+        # disabled should not be displayed
+        assert 'log_test() enabled'
+
     # TODO(sjg at chromium.org): Consider structuring this as separate tests
     cons = u_boot_console
     test0()
@@ -105,6 +112,7 @@ def test_log(u_boot_console):
     test8()
     test9()
     test10()
+    test11()
 
 @pytest.mark.buildconfigspec('cmd_log')
 def test_log_format(u_boot_console):
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
#6 lore raw

PATCH 3/4 log: Add a way to enable/disable a log device

Am 12. September 2020 20:28:49 MESZ schrieb Simon Glass <[email protected]>:

Quoted 3 lines

At present all log devices are enabled by default. Add a function to allow
devices to be disabled or enabled at runtime.

Should this capability be added to the log command?

Regards

Heinrich

Quoted 146 lines

---

common/log.c              | 38 ++++++++++++++++++++++++++++++++++++++
include/log.h             | 17 +++++++++++++++++
test/log/log_test.c       |  7 +++++++
test/py/tests/test_log.py |  8 ++++++++
4 files changed, 70 insertions(+)
common/log.c +16 -0
index ce528fe4535..a9aacfaf354 100644
@@ -297,6 +297,44 @@ int log_remove_filter(const char *drv_name, int
 filter_num)
 	return -ENOENT;
 }
 
+/**
+ * log_find_device_by_drv() - Find a device by its driver
+ *
+ * @drv: Log driver
+ * @return Device associated with that driver, or NULL if not found
+ */
+static struct log_device *log_find_device_by_drv(struct log_driver
 *drv)
+{
+	struct log_device *ldev;
+
+	list_for_each_entry(ldev, &gd->log_head, sibling_node) {
+		if (ldev->drv == drv)
+			return ldev;
+	}
+	/*
+	 * It is quite hard to pass an invalid driver since passing an

unknown

common/log.c +1 -0
+	 * LOG_GET_DRIVER(xxx) would normally produce a compilation error.

But

common/log.c +21 -0
+	 * it is possible to pass NULL, for example, so this
+	 */
+
+	return NULL;
+}
+
+int log_device_set_enable(struct log_driver *drv, bool enable)
+{
+	struct log_device *ldev;
+
+	ldev = log_find_device_by_drv(drv);
+	if (!ldev)
+		return -ENOENT;
+	if (enable)
+		ldev->flags |= LOGDF_ENABLE;
+	else
+		ldev->flags &= ~LOGDF_ENABLE;
+
+	return 0;
+}
+

int log_init(void)
{
struct log_driver *drv = ll_entry_start(struct log_driver,
log_driver);

include/log.h +8 -0
index d28bc1ef0e4..4acc087b2e9 100644
@@ -388,6 +388,10 @@ struct log_filter {
 #define LOG_DRIVER(_name) \
 	ll_entry_declare(struct log_driver, _name, log_driver)
 
+/* Get a pointer to a given driver */
+#define LOG_GET_DRIVER(__name)						\
+	ll_entry_get(struct log_driver, __name, log_driver)
+
 /**
 * log_get_cat_name() - Get the name of a category
 *
@@ -465,6 +469,19 @@ int log_add_filter(const char *drv_name, enum
 log_category_t cat_list[],
 */
 int log_remove_filter(const char *drv_name, int filter_num);
 
+/**
+ * log_device_set_enable() - Enable or disable a log device
+ *
+ * Devices are referenced by their driver, so use LOG_GET_DRIVER(name)

to pass
+ * the driver to this function. For example if the driver is declared with
+ * LOG_DRIVER(wibble) then pass LOG_GET_DRIVER(wibble) here.
+ *
+ * @drv: Driver of device to enable
+ * @enable: true to enable, false to disable
+ * @return 0 if OK, -ENOENT if the driver was not found
+ */

include/log.h +2 -0
+int log_device_set_enable(struct log_driver *drv, bool enable);
+

#if CONFIG_IS_ENABLED(LOG)
/**
* log_init() - Set up the log system ready for use

test/log/log_test.c +7 -0
index fdee5e6757f..6a60ff6be3c 100644
@@ -196,6 +196,13 @@ static int log_test(int testnum)
 		log_io("level %d\n", LOGL_DEBUG_IO);
 		break;
 	}
+	case 11:
+		log_err("default\n");
+		ret = log_device_set_enable(LOG_GET_DRIVER(console), false);
+		log_err("disabled\n");
+		ret = log_device_set_enable(LOG_GET_DRIVER(console), true);
+		log_err("enabled\n");
+		break;
 	}
 
 	return 0;
test/py/tests/test_log.py +8 -0
index ddc28f19ee8..275f9382d2f 100644
@@ -92,6 +92,13 @@ def test_log(u_boot_console):
        for i in range(7):
            assert 'log_test() level %d' % i == next(lines)
 
+    def test11():
+        """Test use of log_device_set_enable()"""
+        lines = run_test(11)
+        assert 'log_test() default'
+        # disabled should not be displayed
+        assert 'log_test() enabled'
+
 # TODO(sjg at chromium.org): Consider structuring this as separate tests
    cons = u_boot_console
    test0()
@@ -105,6 +112,7 @@ def test_log(u_boot_console):
    test8()
    test9()
    test10()
+    test11()
 
 @pytest.mark.buildconfigspec('cmd_log')

def test_log_format(u_boot_console):

#7 lore raw

PATCH 3/4 log: Add a way to enable/disable a log device

Hi Heinrich,

Quoted 7 lines · Heinrich Schuchardt

Am 12. September 2020 20:28:49 MESZ schrieb Simon Glass <[email protected]>:

Quoted 3 lines

At present all log devices are enabled by default. Add a function to allow
devices to be disabled or enabled at runtime.

Should this capability be added to the log command?

It's probably not a bad idea. I'll take a look.

Regards,
Simon

#8 lore raw

PATCH 3/4 log: Add a way to enable/disable a log device

In reply to Simon Glass
Quoted 4 lines · Simon Glass

At present all log devices are enabled by default. Add a function to allow devices to be disabled or enabled at runtime.

Applied to u-boot/master, thanks!

Signature · 8 lines
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/20201011/7f9d01e4/attachment.sig>
#9 lore raw

PATCH 4/4 log: Disable the syslog driver by default

In reply to Simon Glass

This driver interferes with other sandbox tests since it causes log output to be interspersed with "No ethernet found." messages. Disable this driver by default.

Enable it for the syslog tests so that they still pass.

---

 common/log_syslog.c           |  1 -
 test/log/syslog_test.c        | 24 ++++++++++++++++++++++++
 test/log/syslog_test.h        | 16 ++++++++++++++++
 test/log/syslog_test_ndebug.c |  2 ++
 4 files changed, 42 insertions(+), 1 deletion(-)
common/log_syslog.c +0 -1
index cf0dbba9bf5..149ff5af310 100644
@@ -115,5 +115,4 @@ out:
 LOG_DRIVER(syslog) = {
 	.name	= "syslog",
 	.emit	= log_syslog_emit,
-	.flags	= LOGDF_ENABLE,
 };
test/log/syslog_test.c +24 -0
index abcb9ffd28b..febaca68e8d 100644
@@ -56,6 +56,20 @@ int sb_log_tx_handler(struct udevice *dev, void *packet, unsigned int len)
 	return 0;
 }
 
+int syslog_test_setup(struct unit_test_state *uts)
+{
+	ut_assertok(log_device_set_enable(LOG_GET_DRIVER(syslog), true));
+
+	return 0;
+}
+
+int syslog_test_finish(struct unit_test_state *uts)
+{
+	ut_assertok(log_device_set_enable(LOG_GET_DRIVER(syslog), false));
+
+	return 0;
+}
+
 /**
  * log_test_syslog_err() - test log_err() function
  *
@@ -67,6 +81,7 @@ static int log_test_syslog_err(struct unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
 	env_set("ethact", "eth at 10002000");
@@ -82,6 +97,7 @@ static int log_test_syslog_err(struct unit_test_state *uts)
 	sandbox_eth_set_tx_handler(0, NULL);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;
 }
@@ -98,6 +114,7 @@ static int log_test_syslog_warning(struct unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
 	env_set("ethact", "eth at 10002000");
@@ -114,6 +131,7 @@ static int log_test_syslog_warning(struct unit_test_state *uts)
 	ut_assertnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;
 }
@@ -130,6 +148,7 @@ static int log_test_syslog_notice(struct unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
 	env_set("ethact", "eth at 10002000");
@@ -146,6 +165,7 @@ static int log_test_syslog_notice(struct unit_test_state *uts)
 	ut_assertnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;
 }
@@ -162,6 +182,7 @@ static int log_test_syslog_info(struct unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
 	env_set("ethact", "eth at 10002000");
@@ -178,6 +199,7 @@ static int log_test_syslog_info(struct unit_test_state *uts)
 	ut_assertnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;
 }
@@ -194,6 +216,7 @@ static int log_test_syslog_debug(struct unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_DEBUG;
 	env_set("ethact", "eth at 10002000");
@@ -210,6 +233,7 @@ static int log_test_syslog_debug(struct unit_test_state *uts)
 	ut_assertnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;
 }
test/log/syslog_test.h +16 -0
index 75900f3aad3..1310257bfe1 100644
@@ -47,4 +47,20 @@ struct sb_log_env {
  */
 int sb_log_tx_handler(struct udevice *dev, void *packet, unsigned int len);
 
+/**
+ * syslog_test_setup() - Enable syslog logging ready for tests
+ *
+ * @uts: Test state
+ * @return 0 if OK, -ENOENT if the syslog log driver is not found
+ */
+int syslog_test_setup(struct unit_test_state *uts);
+
+/**
+ * syslog_test_finish() - Disable syslog logging after tests
+ *
+ * @uts: Test state
+ * @return 0 if OK, -ENOENT if the syslog log driver is not found
+ */
+int syslog_test_finish(struct unit_test_state *uts);
+
 #endif
test/log/syslog_test_ndebug.c +2 -0
index 7815977ea27..c7f5a60861f 100644
@@ -33,6 +33,7 @@ static int log_test_syslog_nodebug(struct unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
 	env_set("ethact", "eth at 10002000");
@@ -49,6 +50,7 @@ static int log_test_syslog_nodebug(struct unit_test_state *uts)
 	ut_assertnonnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;
 }
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
#10 lore raw

PATCH 4/4 log: Disable the syslog driver by default

Am 12. September 2020 20:28:50 MESZ schrieb Simon Glass <[email protected]>:

Quoted 22 lines

This driver interferes with other sandbox tests since it causes log output
to be interspersed with "No ethernet found." messages. Disable this driver
by default.

Enable it for the syslog tests so that they still pass.

---

common/log_syslog.c           |  1 -
test/log/syslog_test.c        | 24 ++++++++++++++++++++++++
test/log/syslog_test.h        | 16 ++++++++++++++++
test/log/syslog_test_ndebug.c |  2 ++
4 files changed, 42 insertions(+), 1 deletion(-)
common/log_syslog.c +0 -0
index cf0dbba9bf5..149ff5af310 100644

common/log_syslog.c out: · line 118

Quoted 4 lines
common/log_syslog.c +0 -1
@@ -115,5 +115,4 @@ out:
 LOG_DRIVER(syslog) = {
 	.name	= "syslog",
 	.emit	= log_syslog_emit,
-	.flags	= LOGDF_ENABLE,

What does the flag removal change outside Python testing?

Best regards

Heinrich

Quoted 166 lines
common/log_syslog.c +0 -0
 };
test/log/syslog_test.c +14 -0
index abcb9ffd28b..febaca68e8d 100644
@@ -56,6 +56,20 @@ int sb_log_tx_handler(struct udevice *dev, void
 *packet, unsigned int len)
 	return 0;
 }
 
+int syslog_test_setup(struct unit_test_state *uts)
+{
+	ut_assertok(log_device_set_enable(LOG_GET_DRIVER(syslog), true));
+
+	return 0;
+}
+
+int syslog_test_finish(struct unit_test_state *uts)
+{
+	ut_assertok(log_device_set_enable(LOG_GET_DRIVER(syslog), false));
+
+	return 0;
+}
+
 /**
 * log_test_syslog_err() - test log_err() function

*

test/log/syslog_test.c +1 -0
@@ -67,6 +81,7 @@ static int log_test_syslog_err(struct unit_test_state
 *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
	env_set("ethact", "eth at 10002000");
test/log/syslog_test.c +1 -0
@@ -82,6 +97,7 @@ static int log_test_syslog_err(struct unit_test_state
 *uts)
 	sandbox_eth_set_tx_handler(0, NULL);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;

}

test/log/syslog_test.c +1 -0
@@ -98,6 +114,7 @@ static int log_test_syslog_warning(struct
 unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
	env_set("ethact", "eth at 10002000");
test/log/syslog_test.c +1 -0
@@ -114,6 +131,7 @@ static int log_test_syslog_warning(struct
 unit_test_state *uts)
 	ut_assertnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;

}

test/log/syslog_test.c +1 -0
@@ -130,6 +148,7 @@ static int log_test_syslog_notice(struct
 unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
	env_set("ethact", "eth at 10002000");
test/log/syslog_test.c +1 -0
@@ -146,6 +165,7 @@ static int log_test_syslog_notice(struct
 unit_test_state *uts)
 	ut_assertnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;

}

test/log/syslog_test.c +1 -0
@@ -162,6 +182,7 @@ static int log_test_syslog_info(struct
 unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
	env_set("ethact", "eth at 10002000");
test/log/syslog_test.c +1 -0
@@ -178,6 +199,7 @@ static int log_test_syslog_info(struct
 unit_test_state *uts)
 	ut_assertnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;

}

test/log/syslog_test.c +1 -0
@@ -194,6 +216,7 @@ static int log_test_syslog_debug(struct
 unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_DEBUG;
	env_set("ethact", "eth at 10002000");
test/log/syslog_test.c +1 -0
@@ -210,6 +233,7 @@ static int log_test_syslog_debug(struct
 unit_test_state *uts)
 	ut_assertnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;

}

test/log/syslog_test.h +0 -0
index 75900f3aad3..1310257bfe1 100644
@@ -47,4 +47,20 @@ struct sb_log_env {
 */

int sb_log_tx_handler(struct udevice *dev, void *packet, unsigned int len);

test/log/syslog_test.h +16 -0
+/**
+ * syslog_test_setup() - Enable syslog logging ready for tests
+ *
+ * @uts: Test state
+ * @return 0 if OK, -ENOENT if the syslog log driver is not found
+ */
+int syslog_test_setup(struct unit_test_state *uts);
+
+/**
+ * syslog_test_finish() - Disable syslog logging after tests
+ *
+ * @uts: Test state
+ * @return 0 if OK, -ENOENT if the syslog log driver is not found
+ */
+int syslog_test_finish(struct unit_test_state *uts);
+

#endif

test/log/syslog_test_ndebug.c +1 -0
index 7815977ea27..c7f5a60861f 100644
@@ -33,6 +33,7 @@ static int log_test_syslog_nodebug(struct
 unit_test_state *uts)
 	int old_log_level = gd->default_log_level;
 	struct sb_log_env env;
 
+	ut_assertok(syslog_test_setup(uts));
 	gd->log_fmt = LOGF_TEST;
 	gd->default_log_level = LOGL_INFO;
	env_set("ethact", "eth at 10002000");
test/log/syslog_test_ndebug.c +1 -0
@@ -49,6 +50,7 @@ static int log_test_syslog_nodebug(struct
 unit_test_state *uts)
 	ut_assertnonnull(env.expected);
 	gd->default_log_level = old_log_level;
 	gd->log_fmt = log_get_default_format();
+	ut_assertok(syslog_test_finish(uts));
 
 	return 0;

}

#11 lore raw

PATCH 4/4 log: Disable the syslog driver by default

Hi Heinrich,

Quoted 19 lines · Heinrich Schuchardt

Am 12. September 2020 20:28:50 MESZ schrieb Simon Glass <[email protected]>:

Quoted 17 lines

This driver interferes with other sandbox tests since it causes log output
to be interspersed with "No ethernet found." messages. Disable this driver
by default.

Enable it for the syslog tests so that they still pass.

---

common/log_syslog.c           |  1 -
test/log/syslog_test.c        | 24 ++++++++++++++++++++++++
test/log/syslog_test.h        | 16 ++++++++++++++++
test/log/syslog_test_ndebug.c |  2 ++
4 files changed, 42 insertions(+), 1 deletion(-)
Quoted 11 lines

common/log_syslog.c out: · line 118

Quoted 9 lines
common/log_syslog.c +0 -1
index cf0dbba9bf5..149ff5af310 100644
@@ -115,5 +115,4 @@ out:
 LOG_DRIVER(syslog) = {
      .name   = "syslog",
      .emit   = log_syslog_emit,
-      .flags  = LOGDF_ENABLE,

What does the flag removal change outside Python testing?

If this driver is to be used on a board, you must call log_device_set_enable().

Regards,
Simon

#12 lore raw

PATCH 4/4 log: Disable the syslog driver by default

Am 12. September 2020 22:24:24 MESZ schrieb Simon Glass <[email protected]>:

Quoted 36 lines

Hi Heinrich,

Quoted 2 lines · Heinrich Schuchardt

Am 12. September 2020 20:28:50 MESZ schrieb Simon Glass

<[email protected]>:

Quoted 17 lines
Quoted 17 lines

This driver interferes with other sandbox tests since it causes log output
to be interspersed with "No ethernet found." messages. Disable this driver
by default.

Enable it for the syslog tests so that they still pass.

---

common/log_syslog.c           |  1 -
test/log/syslog_test.c        | 24 ++++++++++++++++++++++++
test/log/syslog_test.h        | 16 ++++++++++++++++
test/log/syslog_test_ndebug.c |  2 ++
4 files changed, 42 insertions(+), 1 deletion(-)
Quoted 11 lines

common/log_syslog.c out: · line 118

Quoted 9 lines
common/log_syslog.c +0 -1
index cf0dbba9bf5..149ff5af310 100644
@@ -115,5 +115,4 @@ out:
 LOG_DRIVER(syslog) = {
      .name   = "syslog",
      .emit   = log_syslog_emit,
-      .flags  = LOGDF_ENABLE,

What does the flag removal change outside Python testing?

Quoted 2 lines

If this driver is to be used on a board, you must call log_device_set_enable().

This would pervert the nice log driver system that you have provided. I definitively want syslog with vanilla code just by customizing.

If you want to mute the network stack, then move it to use log and filter on the network uclass.

Or simply adjust the test that has hickups.

Best regards

Heinrich

Quoted 3 lines

Regards,
Simon

#13 lore raw

PATCH 4/4 log: Disable the syslog driver by default

Hi Heinrich,

Quoted 38 lines · Heinrich Schuchardt

Am 12. September 2020 22:24:24 MESZ schrieb Simon Glass <[email protected]>:

Quoted 36 lines

Hi Heinrich,

Quoted 2 lines · Heinrich Schuchardt

Am 12. September 2020 20:28:50 MESZ schrieb Simon Glass

<[email protected]>:

Quoted 28 lines
Quoted 22 lines

This driver interferes with other sandbox tests since it causes log output
to be interspersed with "No ethernet found." messages. Disable this driver
by default.

Enable it for the syslog tests so that they still pass.

---

common/log_syslog.c           |  1 -
test/log/syslog_test.c        | 24 ++++++++++++++++++++++++
test/log/syslog_test.h        | 16 ++++++++++++++++
test/log/syslog_test_ndebug.c |  2 ++
4 files changed, 42 insertions(+), 1 deletion(-)
common/log_syslog.c +0 -0
index cf0dbba9bf5..149ff5af310 100644

common/log_syslog.c out: · line 118

Quoted 4 lines
common/log_syslog.c +0 -1
@@ -115,5 +115,4 @@ out:
 LOG_DRIVER(syslog) = {
      .name   = "syslog",
      .emit   = log_syslog_emit,
-      .flags  = LOGDF_ENABLE,

What does the flag removal change outside Python testing?

Quoted 6 lines
Quoted 2 lines

If this driver is to be used on a board, you must call log_device_set_enable().

This would pervert the nice log driver system that you have provided. I definitively want syslog with vanilla code just by customizing.

If you want to mute the network stack, then move it to use log and filter on the network uclass.

Well sandbox has a network but it fails to send syslog messages, which is probably a good thing, at least without someone saying they want it to happen.

Quoted 2 lines

Or simply adjust the test that has hickups.

I don't like that idea because any test can produce log output.

Another option would be to only disable the device with sandbox, e.g.

#ifndef CONFIG_SANDBOX
.flags = LOGDF_ENABLE,
#endif

Regards,
Simon

#14 lore raw

PATCH 4/4 log: Disable the syslog driver by default

Am 13. September 2020 03:24:02 MESZ schrieb Simon Glass <[email protected]>:

Quoted 62 lines

Hi Heinrich,

Quoted 2 lines · Heinrich Schuchardt

Am 12. September 2020 22:24:24 MESZ schrieb Simon Glass

<[email protected]>:

Quoted 3 lines
Quoted 3 lines

Hi Heinrich,

On Sat, 12 Sep 2020 at 14:16, Heinrich Schuchardt

<[email protected]>

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines · wrote:

Am 12. September 2020 20:28:50 MESZ schrieb Simon Glass

<[email protected]>:

Quoted 1 line
Quoted 1 line

This driver interferes with other sandbox tests since it causes

log

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

output
to be interspersed with "No ethernet found." messages. Disable

this

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 19 lines

driver
by default.

Enable it for the syslog tests so that they still pass.

---

common/log_syslog.c           |  1 -
test/log/syslog_test.c        | 24 ++++++++++++++++++++++++
test/log/syslog_test.h        | 16 ++++++++++++++++
test/log/syslog_test_ndebug.c |  2 ++
4 files changed, 42 insertions(+), 1 deletion(-)
common/log_syslog.c +0 -0
index cf0dbba9bf5..149ff5af310 100644

common/log_syslog.c out: · line 118

Quoted 4 lines
common/log_syslog.c +0 -1
@@ -115,5 +115,4 @@ out:
 LOG_DRIVER(syslog) = {
      .name   = "syslog",
      .emit   = log_syslog_emit,
-      .flags  = LOGDF_ENABLE,

What does the flag removal change outside Python testing?

Quoted 4 lines
Quoted 2 lines

If this driver is to be used on a board, you must call log_device_set_enable().

This would pervert the nice log driver system that you have provided.

I definitively want syslog with vanilla code just by customizing.

Quoted 2 lines

If you want to mute the network stack, then move it to use log and

filter on the network uclass.

Well sandbox has a network but it fails to send syslog messages, which is probably a good thing, at least without someone saying they want it to happen.

Quoted 2 lines

Or simply adjust the test that has hickups.

Quoted 7 lines

I don't like that idea because any test can produce log output.

Another option would be to only disable the device with sandbox, e.g.

#ifndef CONFIG_SANDBOX
.flags = LOGDF_ENABLE,
#endif

The decision to send syslog messages is not board specific but application specific. This is why I think it must be customizable. I would be fine if you would simply remove log_syslog from sandbox_defconfig.

What I am missing most in the log command is the possibility to set the verbosity per log area/uclass. This would allow to see debug messages only from the area of interest. Especially network does not work when debugging messages are shown per packet, while the user might be interested in debug messages from other areas e.g. EFI.

Concerning your problem such a change would allow to selectively mute network messages.

Would such a change make sense to you?

Best regards

Heinrich

Quoted 3 lines

Regards,
Simon

#15 lore raw

PATCH 4/4 log: Disable the syslog driver by default

Hi Heinrich,

Quoted 66 lines · Heinrich Schuchardt

Am 13. September 2020 03:24:02 MESZ schrieb Simon Glass <[email protected]>:

Quoted 64 lines

Hi Heinrich,

Quoted 2 lines · Heinrich Schuchardt

Am 12. September 2020 22:24:24 MESZ schrieb Simon Glass

<[email protected]>:

Quoted 3 lines
Quoted 3 lines

Hi Heinrich,

On Sat, 12 Sep 2020 at 14:16, Heinrich Schuchardt

<[email protected]>

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines · wrote:

Am 12. September 2020 20:28:50 MESZ schrieb Simon Glass

<[email protected]>:

Quoted 1 line
Quoted 1 line

This driver interferes with other sandbox tests since it causes

log

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

output
to be interspersed with "No ethernet found." messages. Disable

this

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 19 lines

driver
by default.

Enable it for the syslog tests so that they still pass.

---

common/log_syslog.c           |  1 -
test/log/syslog_test.c        | 24 ++++++++++++++++++++++++
test/log/syslog_test.h        | 16 ++++++++++++++++
test/log/syslog_test_ndebug.c |  2 ++
4 files changed, 42 insertions(+), 1 deletion(-)
common/log_syslog.c +0 -0
index cf0dbba9bf5..149ff5af310 100644

common/log_syslog.c out: · line 118

Quoted 4 lines
common/log_syslog.c +0 -1
@@ -115,5 +115,4 @@ out:
 LOG_DRIVER(syslog) = {
      .name   = "syslog",
      .emit   = log_syslog_emit,
-      .flags  = LOGDF_ENABLE,

What does the flag removal change outside Python testing?

Quoted 4 lines
Quoted 2 lines

If this driver is to be used on a board, you must call log_device_set_enable().

This would pervert the nice log driver system that you have provided.

I definitively want syslog with vanilla code just by customizing.

Quoted 2 lines

If you want to mute the network stack, then move it to use log and

filter on the network uclass.

Well sandbox has a network but it fails to send syslog messages, which is probably a good thing, at least without someone saying they want it to happen.

Quoted 2 lines

Or simply adjust the test that has hickups.

I don't like that idea because any test can produce log output.

Quoted 7 lines
Quoted 5 lines

Another option would be to only disable the device with sandbox, e.g.

#ifndef CONFIG_SANDBOX
.flags = LOGDF_ENABLE,
#endif

The decision to send syslog messages is not board specific but application specific. This is why I think it must be customizable. I would be fine if you would simply remove log_syslog from sandbox_defconfig.

But then we would lose test coverage for syslog. I agree that making it customisable is a good thing. But what do you think is the solution to the problem at hand? As above, the driver is disabled by default only on sandbox, since it must be enabled for testing, but is intrusive otherwise.

Quoted 6 lines

What I am missing most in the log command is the possibility to set the verbosity per log area/uclass. This would allow to see debug messages only from the area of interest. Especially network does not work when debugging messages are shown per packet, while the user might be interested in debug messages from other areas e.g. EFI.

Concerning your problem such a change would allow to selectively mute network messages.

Would such a change make sense to you?

Yes, but I feel these are separate issues:
- add a command enabling / disabling a log driver
- add a command to add/remove log filters based on category/level/file

Regards,
Simon

#16 lore raw

PATCH 4/4 log: Disable the syslog driver by default

In reply to Simon Glass
Quoted 7 lines · Simon Glass

This driver interferes with other sandbox tests since it causes log output to be interspersed with "No ethernet found." messages. Disable this driver by default.

Enable it for the syslog tests so that they still pass.

Applied to u-boot/master, thanks!

Signature · 8 lines
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/20201011/dd788e57/attachment.sig>
#17 lore raw

cover log: Fix the syslog spam when running tests

In reply to Simon Glass
Quoted 20 lines · Simon Glass

At present running some sandbox tests produces unwanted ethernet errors from the syslog driver, e.g.:

$ ./u-boot -c "ut bloblist"

Running 5 bloblist tests
Test: bloblist_test_bad_blob
Test: bloblist_test_blob
Test: bloblist_test_blob_ensure
Failed to allocate e0 bytes size=100, need size=130 No ethernet found.
bloblist add: returning err=-28
No ethernet found.
Test: bloblist_test_checksum
Checksum f3129fae != 338fbdc
No ethernet found.
Bad checksum: returning err=-5
No ethernet found.
...

Quoted 2 lines

This series fixes this by making the syslog driver disabled by default. It can be enabled with a function call.

Hello Simon,

in log_syslog_emit() I already set processing_msg = 1 to fend of messages from the network driver when writing messages to syslog.

The idea was right but not in the right place. This logic should be moved to log_dispatch() to securely avoid that writing messages creates new messages which even might lead to endless recursion.

See
[PATCH 1/1] log: mute messages generated by log drivers
https://lists.denx.de/pipermail/u-boot/2020-September/426418.html

Best regards

Heinrich

Quoted 18 lines

Simon Glass (4):
log: Add a flag to enable log drivers
log: Drop #ifdef in log_test
log: Add a way to enable/disable a log device
log: Disable the syslog driver by default

 common/log.c                  | 42 ++++++++++++++++++++++++++++++++++-
 common/log_console.c          |  1 +
 include/log.h                 | 28 ++++++++++++++++++++++-
 test/log/log_test.c           |  9 ++++++--
 test/log/syslog_test.c        | 24 ++++++++++++++++++++
 test/log/syslog_test.h        | 16 +++++++++++++
 test/log/syslog_test_ndebug.c |  2 ++
 test/py/tests/test_log.py     |  8 +++++++
 8 files changed, 126 insertions(+), 4 deletions(-)