blob: be94971e455bd19d0c449c350b7459dd52e8fe4b [file] [log] [blame]
Sean Anderson439f1c62020-04-06 10:23:09 -04001# SPDX-License-Identifier: GPL-2.0
2# Copyright (C) 2020 Sean Anderson
3
4import pytest
5
6@pytest.mark.buildconfigspec('cmd_dm')
Niel Fourie39832fb2020-03-24 16:17:05 +01007def test_dm_compat(u_boot_console):
8 """Test that each driver in `dm tree` is also listed in `dm compat`."""
Sean Anderson439f1c62020-04-06 10:23:09 -04009 response = u_boot_console.run_command('dm tree')
10 driver_index = response.find('Driver')
11 assert driver_index != -1
12 drivers = (line[driver_index:].split()[0]
13 for line in response[:-1].split('\n')[2:])
14
Niel Fourie39832fb2020-03-24 16:17:05 +010015 response = u_boot_console.run_command('dm compat')
Simon Glassbcdcba02024-06-23 14:30:29 -060016 bad_drivers = set()
Niel Fourie39832fb2020-03-24 16:17:05 +010017 for driver in drivers:
Simon Glassbcdcba02024-06-23 14:30:29 -060018 if not driver in response:
19 bad_drivers.add(driver)
20 assert not bad_drivers
Niel Fourie39832fb2020-03-24 16:17:05 +010021
Simon Glasse5314c12023-01-17 10:47:12 -070022 # check sorting - output looks something like this:
23 # testacpi 0 [ ] testacpi_drv |-- acpi-test
24 # testacpi 1 [ ] testacpi_drv | `-- child
25 # pci_emul_p 1 [ ] pci_emul_parent_drv |-- pci-emul2
26 # pci_emul 5 [ ] sandbox_swap_case_em | `-- emul2@1f,0
27
28 # The number of '| ' and '--' matches indicate the indent level. We start
29 # checking sorting only after UCLASS_AXI_EMUL after which the names should
30 # be sorted.
31
32 response = u_boot_console.run_command('dm tree -s')
33 lines = response.split('\n')[2:]
34 stack = [] # holds where we were up to at the previous indent level
35 prev = '' # uclass name of previous line
36 start = False
37 for line in lines:
38 indent = line.count('| ') + ('--' in line)
39 cur = line.split()[0]
40 if not start:
41 if cur != 'axi_emul':
42 continue
43 start = True
44
45 # Handle going up or down an indent level
46 if indent > len(stack):
47 stack.append(prev)
48 prev = ''
49 elif indent < len(stack):
50 prev = stack.pop()
51
52 # Check that the current uclass name is not alphabetically before the
53 # previous one
54 if 'emul' not in cur and cur < prev:
55 print('indent', cur >= prev, indent, prev, cur, stack)
56 assert cur >= prev
57 prev = cur
58
59
Niel Fourie39832fb2020-03-24 16:17:05 +010060@pytest.mark.buildconfigspec('cmd_dm')
61def test_dm_drivers(u_boot_console):
62 """Test that each driver in `dm compat` is also listed in `dm drivers`."""
63 response = u_boot_console.run_command('dm compat')
64 drivers = (line[:20].rstrip() for line in response[:-1].split('\n')[2:])
65 response = u_boot_console.run_command('dm drivers')
66 for driver in drivers:
67 assert driver in response
68
69@pytest.mark.buildconfigspec('cmd_dm')
70def test_dm_static(u_boot_console):
71 """Test that each driver in `dm static` is also listed in `dm drivers`."""
72 response = u_boot_console.run_command('dm static')
73 drivers = (line[:25].rstrip() for line in response[:-1].split('\n')[2:])
Sean Anderson439f1c62020-04-06 10:23:09 -040074 response = u_boot_console.run_command('dm drivers')
75 for driver in drivers:
76 assert driver in response
Michal Simeka5980732022-07-07 12:59:42 +020077
78@pytest.mark.buildconfigspec("cmd_dm")
79def test_dm_uclass(u_boot_console):
80 response = u_boot_console.run_command("dm uclass")
81
82@pytest.mark.buildconfigspec("cmd_dm")
83def test_dm_devres(u_boot_console):
84 response = u_boot_console.run_command("dm devres")