Skip to contentSkip to conversation

cmd: Add test and fix bugs for dm drivers

PATCH New Sean Anderson 3 participants 4 messages Apr 6, 2020 – Apr 9, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cmd: Add test and fix bugs for dm drivers

Add a test for the dm drivers command. Also fix a null pointer dereference revealed by said test.

---
The changes in this patch were originally submitted as v3 of 7b9d60fc1ff "cmd: Add command to dump drivers and compatible strings" [1]. I have retained the Reviewed-by and Tested-by tags since no other changes besides rebasing on v1 have been made.

[1] https://patchwork.ozlabs.org/patch/1234460/

 cmd/dm.c                 |  4 ++--
 drivers/core/dump.c      |  3 ++-
 test/py/tests/test_dm.py | 17 +++++++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 test/py/tests/test_dm.py
cmd/dm.c +2 -2
index 108707c298..7a90685f8b 100644
@@ -41,7 +41,7 @@ static int do_dm_dump_devres(cmd_tbl_t *cmdtp, int flag, int argc,
 }
 
 static int do_dm_dump_drivers(cmd_tbl_t *cmdtp, int flag, int argc,
-			       char * const argv[])
+			      char * const argv[])
 {
 	dm_dump_drivers();
 
@@ -94,5 +94,5 @@ U_BOOT_CMD(
 	"tree          Dump driver model tree ('*' = activated)\n"
 	"dm uclass        Dump list of instances for each uclass\n"
 	"dm devres        Dump list of device resources for each device\n"
-	"dm drivers       Dump list of drivers and their compatible strings\n"
+	"dm drivers       Dump list of drivers and their compatible strings"
 );
drivers/core/dump.c +2 -1
index e73ebeabcc..b5046398d4 100644
@@ -107,7 +107,8 @@ void dm_dump_drivers(void)
 	puts("Driver                Compatible\n");
 	puts("--------------------------------\n");
 	for (entry = d; entry < d + n_ents; entry++) {
-		for (match = entry->of_match; match->compatible; match++)
+		for (match = entry->of_match;
+		     match && match->compatible; match++)
 			printf("%-20.20s  %s\n",
 			       match == entry->of_match ? entry->name : "",
 			       match->compatible);
test/py/tests/test_dm.py new file +17 -0
new file mode 100644
index 0000000000..f6fbf8ba4c
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 Sean Anderson
+
+import pytest
+
+ at pytest.mark.buildconfigspec('cmd_dm')
+def test_dm_drivers(u_boot_console):
+    """Test that each driver in `dm tree` is also listed in `dm drivers`."""
+    response = u_boot_console.run_command('dm tree')
+    driver_index = response.find('Driver')
+    assert driver_index != -1
+    drivers = (line[driver_index:].split()[0]
+               for line in response[:-1].split('\n')[2:])
+
+    response = u_boot_console.run_command('dm drivers')
+    for driver in drivers:
+        assert driver in response
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 cmd: Add test and fix bugs for dm drivers

Also CC Ovidiu and Niel, since I believe they were both working on patches related to this.

Quoted 79 lines · Sean Anderson

Add a test for the dm drivers command. Also fix a null pointer dereference revealed by said test.

---
The changes in this patch were originally submitted as v3 of 7b9d60fc1ff "cmd: Add command to dump drivers and compatible strings" [1]. I have retained the Reviewed-by and Tested-by tags since no other changes besides rebasing on v1 have been made.

[1] https://patchwork.ozlabs.org/patch/1234460/

 cmd/dm.c                 |  4 ++--
 drivers/core/dump.c      |  3 ++-
 test/py/tests/test_dm.py | 17 +++++++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 test/py/tests/test_dm.py
cmd/dm.c +2 -2
index 108707c298..7a90685f8b 100644
@@ -41,7 +41,7 @@ static int do_dm_dump_devres(cmd_tbl_t *cmdtp, int flag, int argc,
 }
 
 static int do_dm_dump_drivers(cmd_tbl_t *cmdtp, int flag, int argc,
-			       char * const argv[])
+			      char * const argv[])
 {
 	dm_dump_drivers();
 
@@ -94,5 +94,5 @@ U_BOOT_CMD(
 	"tree          Dump driver model tree ('*' = activated)\n"
 	"dm uclass        Dump list of instances for each uclass\n"
 	"dm devres        Dump list of device resources for each device\n"
-	"dm drivers       Dump list of drivers and their compatible strings\n"
+	"dm drivers       Dump list of drivers and their compatible strings"
 );
drivers/core/dump.c +2 -1
index e73ebeabcc..b5046398d4 100644
@@ -107,7 +107,8 @@ void dm_dump_drivers(void)
 	puts("Driver                Compatible\n");
 	puts("--------------------------------\n");
 	for (entry = d; entry < d + n_ents; entry++) {
-		for (match = entry->of_match; match->compatible; match++)
+		for (match = entry->of_match;
+		     match && match->compatible; match++)
 			printf("%-20.20s  %s\n",
 			       match == entry->of_match ? entry->name : "",
 			       match->compatible);
test/py/tests/test_dm.py new file +17 -0
new file mode 100644
index 0000000000..f6fbf8ba4c
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 Sean Anderson
+
+import pytest
+
+ at pytest.mark.buildconfigspec('cmd_dm')
+def test_dm_drivers(u_boot_console):
+    """Test that each driver in `dm tree` is also listed in `dm drivers`."""
+    response = u_boot_console.run_command('dm tree')
+    driver_index = response.find('Driver')
+    assert driver_index != -1
+    drivers = (line[driver_index:].split()[0]
+               for line in response[:-1].split('\n')[2:])
+
+    response = u_boot_console.run_command('dm drivers')
+    for driver in drivers:
+        assert driver in response
#2 lore raw

PATCH 1/1 cmd: Add test and fix bugs for dm drivers

Quoted 2 lines · Sean Anderson

Also CC Ovidiu and Niel, since I believe they were both working on patches related to this.

+Tom for consideration for the release if there is time

Quoted 82 lines · Sean Anderson
Quoted 79 lines

Add a test for the dm drivers command. Also fix a null pointer dereference revealed by said test.

---
The changes in this patch were originally submitted as v3 of 7b9d60fc1ff "cmd: Add command to dump drivers and compatible strings" [1]. I have retained the Reviewed-by and Tested-by tags since no other changes besides rebasing on v1 have been made.

[1] https://patchwork.ozlabs.org/patch/1234460/

 cmd/dm.c                 |  4 ++--
 drivers/core/dump.c      |  3 ++-
 test/py/tests/test_dm.py | 17 +++++++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 test/py/tests/test_dm.py
cmd/dm.c +2 -2
index 108707c298..7a90685f8b 100644
@@ -41,7 +41,7 @@ static int do_dm_dump_devres(cmd_tbl_t *cmdtp, int flag, int argc,
 }
 
 static int do_dm_dump_drivers(cmd_tbl_t *cmdtp, int flag, int argc,
-                            char * const argv[])
+                           char * const argv[])
 {
      dm_dump_drivers();
 
@@ -94,5 +94,5 @@ U_BOOT_CMD(
      "tree          Dump driver model tree ('*' = activated)\n"
      "dm uclass        Dump list of instances for each uclass\n"
      "dm devres        Dump list of device resources for each device\n"
-     "dm drivers       Dump list of drivers and their compatible strings\n"
+     "dm drivers       Dump list of drivers and their compatible strings"
 );
drivers/core/dump.c +2 -1
index e73ebeabcc..b5046398d4 100644
@@ -107,7 +107,8 @@ void dm_dump_drivers(void)
      puts("Driver                Compatible\n");
      puts("--------------------------------\n");
      for (entry = d; entry < d + n_ents; entry++) {
-             for (match = entry->of_match; match->compatible; match++)
+             for (match = entry->of_match;
+                  match && match->compatible; match++)
                      printf("%-20.20s  %s\n",
                             match == entry->of_match ? entry->name : "",
                             match->compatible);
test/py/tests/test_dm.py new file +17 -0
new file mode 100644
index 0000000000..f6fbf8ba4c
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2020 Sean Anderson
+
+import pytest
+
+ at pytest.mark.buildconfigspec('cmd_dm')
+def test_dm_drivers(u_boot_console):
+    """Test that each driver in `dm tree` is also listed in `dm drivers`."""
+    response = u_boot_console.run_command('dm tree')
+    driver_index = response.find('Driver')
+    assert driver_index != -1
+    drivers = (line[driver_index:].split()[0]
+               for line in response[:-1].split('\n')[2:])
+
+    response = u_boot_console.run_command('dm drivers')
+    for driver in drivers:
+        assert driver in response
#3 lore raw

PATCH 1/1 cmd: Add test and fix bugs for dm drivers

In reply to Sean Anderson
Quoted 7 lines · Sean Anderson

Add a test for the dm drivers command. Also fix a null pointer dereference revealed by said test.

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/20200409/46ad0917/attachment.sig>