mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-21 04:14:34 +00:00
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. Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
dfd5321bec
commit
97c7ac214e
3 changed files with 21 additions and 3 deletions
2
cmd/dm.c
2
cmd/dm.c
|
@ -94,5 +94,5 @@ U_BOOT_CMD(
|
||||||
"tree Dump driver model tree ('*' = activated)\n"
|
"tree Dump driver model tree ('*' = activated)\n"
|
||||||
"dm uclass Dump list of instances for each uclass\n"
|
"dm uclass Dump list of instances for each uclass\n"
|
||||||
"dm devres Dump list of device resources for each device\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"
|
||||||
);
|
);
|
||||||
|
|
|
@ -107,7 +107,8 @@ void dm_dump_drivers(void)
|
||||||
puts("Driver Compatible\n");
|
puts("Driver Compatible\n");
|
||||||
puts("--------------------------------\n");
|
puts("--------------------------------\n");
|
||||||
for (entry = d; entry < d + n_ents; entry++) {
|
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",
|
printf("%-20.20s %s\n",
|
||||||
match == entry->of_match ? entry->name : "",
|
match == entry->of_match ? entry->name : "",
|
||||||
match->compatible);
|
match->compatible);
|
||||||
|
|
17
test/py/tests/test_dm.py
Normal file
17
test/py/tests/test_dm.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
# SPDX-License-Identifier: GPL-2.0
|
||||||
|
# Copyright (C) 2020 Sean Anderson
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@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
|
Loading…
Add table
Reference in a new issue