All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] cmd: Add command to dump drivers and compatible strings
@ 2020-02-06 17:03 Sean Anderson
  2020-02-06 17:46 ` Simon Glass
  0 siblings, 1 reply; 5+ messages in thread
From: Sean Anderson @ 2020-02-06 17:03 UTC (permalink / raw)
  To: u-boot

This adds a subcommand to dm to dump out what drivers are installed, and their
compatible strings. I have found this useful in ensuring that I have the correct
drivers compiled, and that I have put in the correct compatible strings.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

---

Changes in v3:
- Add python test

Changes in v2:
- Check if entry->of_match is NULL before accessing it
- Remove trailing newline in help message

 cmd/dm.c                 | 12 +++++++++++-
 drivers/core/dump.c      | 20 ++++++++++++++++++++
 include/dm/util.h        |  3 +++
 test/py/tests/test_dm.py | 17 +++++++++++++++++
 4 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 test/py/tests/test_dm.py

diff --git a/cmd/dm.c b/cmd/dm.c
index 7b271db0bb..7a90685f8b 100644
--- a/cmd/dm.c
+++ b/cmd/dm.c
@@ -40,10 +40,19 @@ static int do_dm_dump_devres(cmd_tbl_t *cmdtp, int flag, int argc,
 	return 0;
 }
 
+static int do_dm_dump_drivers(cmd_tbl_t *cmdtp, int flag, int argc,
+			      char * const argv[])
+{
+	dm_dump_drivers();
+
+	return 0;
+}
+
 static cmd_tbl_t test_commands[] = {
 	U_BOOT_CMD_MKENT(tree, 0, 1, do_dm_dump_all, "", ""),
 	U_BOOT_CMD_MKENT(uclass, 1, 1, do_dm_dump_uclass, "", ""),
 	U_BOOT_CMD_MKENT(devres, 1, 1, do_dm_dump_devres, "", ""),
+	U_BOOT_CMD_MKENT(drivers, 1, 1, do_dm_dump_drivers, "", ""),
 };
 
 static __maybe_unused void dm_reloc(void)
@@ -84,5 +93,6 @@ U_BOOT_CMD(
 	"Driver model low level access",
 	"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"
+	"dm devres        Dump list of device resources for each device\n"
+	"dm drivers       Dump list of drivers and their compatible strings"
 );
diff --git a/drivers/core/dump.c b/drivers/core/dump.c
index 4704049aee..b5046398d4 100644
--- a/drivers/core/dump.c
+++ b/drivers/core/dump.c
@@ -96,3 +96,23 @@ void dm_dump_uclass(void)
 		puts("\n");
 	}
 }
+
+void dm_dump_drivers(void)
+{
+	struct driver *d = ll_entry_start(struct driver, driver);
+	const int n_ents = ll_entry_count(struct driver, driver);
+	struct driver *entry;
+	const struct udevice_id *match;
+
+	puts("Driver                Compatible\n");
+	puts("--------------------------------\n");
+	for (entry = d; entry < d + n_ents; entry++) {
+		for (match = entry->of_match;
+		     match && match->compatible; match++)
+			printf("%-20.20s  %s\n",
+			       match == entry->of_match ? entry->name : "",
+			       match->compatible);
+		if (match == entry->of_match)
+			printf("%-20.20s\n", entry->name);
+	}
+}
diff --git a/include/dm/util.h b/include/dm/util.h
index 348c2ace3c..0ccb3fbadf 100644
--- a/include/dm/util.h
+++ b/include/dm/util.h
@@ -39,6 +39,9 @@ static inline void dm_dump_devres(void)
 }
 #endif
 
+/* Dump out a list of drivers */
+void dm_dump_drivers(void);
+
 /**
  * Check if an of node should be or was bound before relocation.
  *
diff --git a/test/py/tests/test_dm.py b/test/py/tests/test_dm.py
new file mode 100644
index 0000000000..f6fbf8ba4c
--- /dev/null
+++ b/test/py/tests/test_dm.py
@@ -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.25.0

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

* [PATCH v3] cmd: Add command to dump drivers and compatible strings
  2020-02-06 17:03 [PATCH v3] cmd: Add command to dump drivers and compatible strings Sean Anderson
@ 2020-02-06 17:46 ` Simon Glass
  2020-02-19 15:45   ` Bin Meng
  0 siblings, 1 reply; 5+ messages in thread
From: Simon Glass @ 2020-02-06 17:46 UTC (permalink / raw)
  To: u-boot

On Thu, 6 Feb 2020 at 10:03, Sean Anderson <seanga2@gmail.com> wrote:
>
> This adds a subcommand to dm to dump out what drivers are installed, and their
> compatible strings. I have found this useful in ensuring that I have the correct
> drivers compiled, and that I have put in the correct compatible strings.
>
> Signed-off-by: Sean Anderson <seanga2@gmail.com>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> Tested-by: Bin Meng <bmeng.cn@gmail.com>
>
> ---
>
> Changes in v3:
> - Add python test
>
> Changes in v2:
> - Check if entry->of_match is NULL before accessing it
> - Remove trailing newline in help message
>
>  cmd/dm.c                 | 12 +++++++++++-
>  drivers/core/dump.c      | 20 ++++++++++++++++++++
>  include/dm/util.h        |  3 +++
>  test/py/tests/test_dm.py | 17 +++++++++++++++++
>  4 files changed, 51 insertions(+), 1 deletion(-)
>  create mode 100644 test/py/tests/test_dm.py

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

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

* [PATCH v3] cmd: Add command to dump drivers and compatible strings
  2020-02-06 17:46 ` Simon Glass
@ 2020-02-19 15:45   ` Bin Meng
  2020-02-19 20:12     ` Sean Anderson
  2020-02-20  2:23     ` Simon Glass
  0 siblings, 2 replies; 5+ messages in thread
From: Bin Meng @ 2020-02-19 15:45 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Fri, Feb 7, 2020 at 1:46 AM Simon Glass <sjg@chromium.org> wrote:
>
> On Thu, 6 Feb 2020 at 10:03, Sean Anderson <seanga2@gmail.com> wrote:
> >
> > This adds a subcommand to dm to dump out what drivers are installed, and their
> > compatible strings. I have found this useful in ensuring that I have the correct
> > drivers compiled, and that I have put in the correct compatible strings.
> >
> > Signed-off-by: Sean Anderson <seanga2@gmail.com>
> > Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> > Tested-by: Bin Meng <bmeng.cn@gmail.com>
> >
> > ---
> >
> > Changes in v3:
> > - Add python test
> >
> > Changes in v2:
> > - Check if entry->of_match is NULL before accessing it
> > - Remove trailing newline in help message
> >
> >  cmd/dm.c                 | 12 +++++++++++-
> >  drivers/core/dump.c      | 20 ++++++++++++++++++++
> >  include/dm/util.h        |  3 +++
> >  test/py/tests/test_dm.py | 17 +++++++++++++++++

Is this what you're looking for? I thought we need something in
test/dm C test cases instead?

> >  4 files changed, 51 insertions(+), 1 deletion(-)
> >  create mode 100644 test/py/tests/test_dm.py
>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Regards,
Bin

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

* [PATCH v3] cmd: Add command to dump drivers and compatible strings
  2020-02-19 15:45   ` Bin Meng
@ 2020-02-19 20:12     ` Sean Anderson
  2020-02-20  2:23     ` Simon Glass
  1 sibling, 0 replies; 5+ messages in thread
From: Sean Anderson @ 2020-02-19 20:12 UTC (permalink / raw)
  To: u-boot

On 2/19/20 10:45 AM, Bin Meng wrote:
> Hi Simon,
> 
> On Fri, Feb 7, 2020 at 1:46 AM Simon Glass <sjg@chromium.org> wrote:
>>
>> On Thu, 6 Feb 2020 at 10:03, Sean Anderson <seanga2@gmail.com> wrote:
>>>
>>> This adds a subcommand to dm to dump out what drivers are installed, and their
>>> compatible strings. I have found this useful in ensuring that I have the correct
>>> drivers compiled, and that I have put in the correct compatible strings.
>>>
>>> Signed-off-by: Sean Anderson <seanga2@gmail.com>
>>> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
>>> Tested-by: Bin Meng <bmeng.cn@gmail.com>
>>>
>>> ---
>>>
>>> Changes in v3:
>>> - Add python test
>>>
>>> Changes in v2:
>>> - Check if entry->of_match is NULL before accessing it
>>> - Remove trailing newline in help message
>>>
>>>  cmd/dm.c                 | 12 +++++++++++-
>>>  drivers/core/dump.c      | 20 ++++++++++++++++++++
>>>  include/dm/util.h        |  3 +++
>>>  test/py/tests/test_dm.py | 17 +++++++++++++++++
> 
> Is this what you're looking for? I thought we need something in
> test/dm C test cases instead?

Tests for commands seem to be python tests. I considered writing a dm
test, but afiak that seems to be for testing function calls. There does
not seem to be an easy way to grab the console output. Additionally,
where would the authoritative list of installed drivers come from? The
easiest way would be to just use the same api that the command is using,
but this doesn't really test anything. As it is, the current test does
an ok job at correlating different methods of accessing the DM system
from the associated commands. It will also catch null-dereference bugs
like the one I found during testing.

--Sean

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

* [PATCH v3] cmd: Add command to dump drivers and compatible strings
  2020-02-19 15:45   ` Bin Meng
  2020-02-19 20:12     ` Sean Anderson
@ 2020-02-20  2:23     ` Simon Glass
  1 sibling, 0 replies; 5+ messages in thread
From: Simon Glass @ 2020-02-20  2:23 UTC (permalink / raw)
  To: u-boot

Hi Bin,

On Wed, 19 Feb 2020 at 08:45, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> Hi Simon,
>
> On Fri, Feb 7, 2020 at 1:46 AM Simon Glass <sjg@chromium.org> wrote:
> >
> > On Thu, 6 Feb 2020 at 10:03, Sean Anderson <seanga2@gmail.com> wrote:
> > >
> > > This adds a subcommand to dm to dump out what drivers are installed, and their
> > > compatible strings. I have found this useful in ensuring that I have the correct
> > > drivers compiled, and that I have put in the correct compatible strings.
> > >
> > > Signed-off-by: Sean Anderson <seanga2@gmail.com>
> > > Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> > > Tested-by: Bin Meng <bmeng.cn@gmail.com>
> > >
> > > ---
> > >
> > > Changes in v3:
> > > - Add python test
> > >
> > > Changes in v2:
> > > - Check if entry->of_match is NULL before accessing it
> > > - Remove trailing newline in help message
> > >
> > >  cmd/dm.c                 | 12 +++++++++++-
> > >  drivers/core/dump.c      | 20 ++++++++++++++++++++
> > >  include/dm/util.h        |  3 +++
> > >  test/py/tests/test_dm.py | 17 +++++++++++++++++
>
> Is this what you're looking for? I thought we need something in
> test/dm C test cases instead?

I would prefer C but this test only runs two commands so is not too bad.

Regards,
Simon

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

end of thread, other threads:[~2020-02-20  2:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06 17:03 [PATCH v3] cmd: Add command to dump drivers and compatible strings Sean Anderson
2020-02-06 17:46 ` Simon Glass
2020-02-19 15:45   ` Bin Meng
2020-02-19 20:12     ` Sean Anderson
2020-02-20  2:23     ` Simon Glass

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