Skip to contentSkip to conversation

sandbox: test: activate tests for the command LOG

PATCH In review Patrick Delaunay 2 participants 7 messages Jan 17, 2022 – Jan 27, 2022

lore
Share & tools
lore
#0 lore raw

v2 cover sandbox: test: activate tests for the command LOG

This patches activate the command LOG and the associated tests in sandbox with CONFIG_CMD_LOG=y and solve the associated issues when these tests are executed.

Patrick

Changes in v2:
- update commit message "sandox" => "sandbox"

Patrick Delaunay (3):
dm: fix up documentation for uclass_get_by_name_len
dm: compare full name in uclass_get_by_name
sandbox: test: activate tests for the command LOG

 configs/sandbox_defconfig |  2 +-
 drivers/core/uclass.c     | 11 ++++++++++-
 include/dm/uclass.h       |  4 ++--
 test/py/tests/test_log.py |  8 ++++----
 4 files changed, 17 insertions(+), 8 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/3 dm: fix up documentation for uclass_get_by_name_len

Fix up the comment for uclass_get_by_name_len() to avoid confusion.

Fixes 4b030177b660 ("dm: core: Allow finding children / uclasses by partial name")

---

(no changes since v1)

 include/dm/uclass.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/dm/uclass.h +2 -2
index f1fd2ba246..a606b6a20b 100644
@@ -173,10 +173,10 @@ int uclass_get(enum uclass_id key, struct uclass **ucp);
 const char *uclass_get_name(enum uclass_id id);
 
 /**
- * uclass_get_by_name() - Look up a uclass by its driver name
+ * uclass_get_by_name_len() - Look up a uclass by its partial driver name
  *
  * @name: Name to look up
- * @len: Length of name
+ * @len: Length of the partial name
  * @returns the associated uclass ID, or UCLASS_INVALID if not found
  */
 enum uclass_id uclass_get_by_name_len(const char *name, int len);
Signature · 1 line
2.25.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] dm: fix up documentation for uclass_get_by_name_len

Quoted 11 lines · Patrick Delaunay

Fix up the comment for uclass_get_by_name_len() to avoid confusion.

Fixes 4b030177b660 ("dm: core: Allow finding children / uclasses by partial name")

---

(no changes since v1)

 include/dm/uclass.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
#3 lore raw

PATCH v2 2/3 dm: compare full name in uclass_get_by_name

In reply to Patrick Delaunay

Change uclass_get_by_name to use a strict string compare function "strcmp" with the parameter 'name'.

This patch avoids issues when strlen(name)<strlen(uc_drv->name) as the function uclass_get_by_name() no more use uclass_get_by_name_len(), which limit the check with "strncmp" and length of name.

This problem is detected by the sandbox test for log filter:
in log_get_cat_by_name(), uclass_get_by_name("spi") = UCLASS_SPI_EMUL for "spi_emul", it is not the expected result = UCLASS_SPI for a search by name.
But it is the expected result for search with partial name uclass_get_by_name_len("spi", 3).

---

(no changes since v1)

 drivers/core/uclass.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/core/uclass.c +10 -1
index 336ea8d243..32b6cef167 100644
@@ -196,7 +196,16 @@ enum uclass_id uclass_get_by_name_len(const char *name, int len)
 
 enum uclass_id uclass_get_by_name(const char *name)
 {
-	return uclass_get_by_name_len(name, strlen(name));
+	int i;
+
+	for (i = 0; i < UCLASS_COUNT; i++) {
+		struct uclass_driver *uc_drv = lists_uclass_lookup(i);
+
+		if (uc_drv && !strcmp(uc_drv->name, name))
+			return i;
+	}
+
+	return UCLASS_INVALID;
 }
 
 int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH v2 2/3] dm: compare full name in uclass_get_by_name

Hi Patrick,

Quoted 15 lines · Patrick Delaunay

Change uclass_get_by_name to use a strict string compare function "strcmp" with the parameter 'name'.

This patch avoids issues when strlen(name)<strlen(uc_drv->name) as the function uclass_get_by_name() no more use uclass_get_by_name_len(), which limit the check with "strncmp" and length of name.

This problem is detected by the sandbox test for log filter:
in log_get_cat_by_name(), uclass_get_by_name("spi") = UCLASS_SPI_EMUL for "spi_emul", it is not the expected result = UCLASS_SPI for a search by name.
But it is the expected result for search with partial name uclass_get_by_name_len("spi", 3).

Quoted 7 lines

---

(no changes since v1)

 drivers/core/uclass.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

To save code space, could we avoid copying the function and instead use len == -1 to mean to check the whole thing?

Quoted 24 lines
drivers/core/uclass.c +10 -2
index 336ea8d243..32b6cef167 100644
@@ -196,7 +196,16 @@ enum uclass_id uclass_get_by_name_len(const char *name, int len)
 
 enum uclass_id uclass_get_by_name(const char *name)
 {
-       return uclass_get_by_name_len(name, strlen(name));
+       int i;
+
+       for (i = 0; i < UCLASS_COUNT; i++) {
+               struct uclass_driver *uc_drv = lists_uclass_lookup(i);
+
+               if (uc_drv && !strcmp(uc_drv->name, name))
+                       return i;
+       }
+
+       return UCLASS_INVALID;
 }
 
 int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
--
Quoted 2 lines

2.25.1

Regards,
Simon

#5 lore raw

PATCH v2 3/3 sandbox: test: activate tests for the command LOG

In reply to Patrick Delaunay

Activate the CONFIG_CMD_LOG in sandbox to execute the LOG tests by default and correct the test log format after 72fa1ad8d9 ("log: Allow padding of the function name").

---

Changes in v2:
- update commit message "sandox" => "sandbox"

 configs/sandbox_defconfig | 2 +-
 test/py/tests/test_log.py | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)
configs/sandbox_defconfig +1 -1
index 4f413582fb..a4aeee062f 100644
@@ -30,7 +30,6 @@ CONFIG_AUTOBOOT_STOP_STR_CRYPT="$5$rounds=640000$HrpE65IkB8CM5nCL$BKT3QdF98Bo8fJ
 CONFIG_CONSOLE_RECORD=y
 CONFIG_CONSOLE_RECORD_OUT_SIZE=0x1000
 CONFIG_PRE_CONSOLE_BUFFER=y
-CONFIG_LOG=y
 CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_MISC_INIT_F=y
 CONFIG_STACKPROTECTOR=y
@@ -108,6 +107,7 @@ CONFIG_CMD_CRAMFS=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_SQUASHFS=y
 CONFIG_CMD_MTDPARTS=y
+CONFIG_CMD_LOG=y
 CONFIG_CMD_STACKPROTECTOR_TEST=y
 CONFIG_MAC_PARTITION=y
 CONFIG_AMIGA_PARTITION=y
test/py/tests/test_log.py +4 -4
index 140dcb9aa2..20a3e56301 100644
@@ -27,13 +27,13 @@ def test_log_format(u_boot_console):
 
     cons = u_boot_console
     with cons.log.section('format'):
-        run_with_format('all', 'NOTICE.arch,file.c:123-func() msg')
+        run_with_format('all', 'NOTICE.arch,file.c:123-                func() msg')
         output = cons.run_command('log format')
         assert output == 'Log format: clFLfm'
 
-        run_with_format('fm', 'func() msg')
-        run_with_format('clfm', 'NOTICE.arch,func() msg')
-        run_with_format('FLfm', 'file.c:123-func() msg')
+        run_with_format('fm', '                func() msg')
+        run_with_format('clfm', 'NOTICE.arch,                func() msg')
+        run_with_format('FLfm', 'file.c:123-                func() msg')
         run_with_format('lm', 'NOTICE. msg')
         run_with_format('m', 'msg')
 
Signature · 1 line
2.25.1
Reviewed-by on v2 3/3
#6 lore raw
Quoted 6 lines · Patrick Delaunay

Activate the CONFIG_CMD_LOG in sandbox to execute the LOG tests by default and correct the test log format after 72fa1ad8d9 ("log: Allow padding of the function name").

Quoted 9 lines

---

Changes in v2:
- update commit message "sandox" => "sandbox"

 configs/sandbox_defconfig | 2 +-
 test/py/tests/test_log.py | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

activate tests for the command LOG