blob: f4c2ccd110159c59d69ed86dfb1d68f2e391d58b [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')
Simon Glassddba5202025-02-09 09:07:14 -07007def test_dm_compat(ubman):
Niel Fourie39832fb2020-03-24 16:17:05 +01008 """Test that each driver in `dm tree` is also listed in `dm compat`."""
Simon Glassddba5202025-02-09 09:07:14 -07009 response = ubman.run_command('dm tree')
Sean Anderson439f1c62020-04-06 10:23:09 -040010 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
Simon Glassddba5202025-02-09 09:07:14 -070015 response = ubman.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
Simon Glassddba5202025-02-09 09:07:14 -070032 response = ubman.run_command('dm tree -s')
Simon Glasse5314c12023-01-17 10:47:12 -070033 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')
Simon Glassddba5202025-02-09 09:07:14 -070061def test_dm_drivers(ubman):
Niel Fourie39832fb2020-03-24 16:17:05 +010062 """Test that each driver in `dm compat` is also listed in `dm drivers`."""
Simon Glassddba5202025-02-09 09:07:14 -070063 response = ubman.run_command('dm compat')
Niel Fourie39832fb2020-03-24 16:17:05 +010064 drivers = (line[:20].rstrip() for line in response[:-1].split('\n')[2:])
Simon Glassddba5202025-02-09 09:07:14 -070065 response = ubman.run_command('dm drivers')
Niel Fourie39832fb2020-03-24 16:17:05 +010066 for driver in drivers:
67 assert driver in response
68
69@pytest.mark.buildconfigspec('cmd_dm')
Simon Glassddba5202025-02-09 09:07:14 -070070def test_dm_static(ubman):
Niel Fourie39832fb2020-03-24 16:17:05 +010071 """Test that each driver in `dm static` is also listed in `dm drivers`."""
Simon Glassddba5202025-02-09 09:07:14 -070072 response = ubman.run_command('dm static')
Niel Fourie39832fb2020-03-24 16:17:05 +010073 drivers = (line[:25].rstrip() for line in response[:-1].split('\n')[2:])
Simon Glassddba5202025-02-09 09:07:14 -070074 response = ubman.run_command('dm drivers')
Sean Anderson439f1c62020-04-06 10:23:09 -040075 for driver in drivers:
76 assert driver in response
Michal Simeka5980732022-07-07 12:59:42 +020077
78@pytest.mark.buildconfigspec("cmd_dm")
Simon Glassddba5202025-02-09 09:07:14 -070079def test_dm_uclass(ubman):
80 response = ubman.run_command("dm uclass")
Michal Simeka5980732022-07-07 12:59:42 +020081
82@pytest.mark.buildconfigspec("cmd_dm")
Simon Glassddba5202025-02-09 09:07:14 -070083def test_dm_devres(ubman):
84 response = ubman.run_command("dm devres")