Sean Anderson | 439f1c6 | 2020-04-06 10:23:09 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # Copyright (C) 2020 Sean Anderson |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | @pytest.mark.buildconfigspec('cmd_dm') |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 7 | def test_dm_compat(u_boot_console): |
| 8 | """Test that each driver in `dm tree` is also listed in `dm compat`.""" |
Sean Anderson | 439f1c6 | 2020-04-06 10:23:09 -0400 | [diff] [blame] | 9 | 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 Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 15 | response = u_boot_console.run_command('dm compat') |
| 16 | for driver in drivers: |
| 17 | assert driver in response |
| 18 | |
Simon Glass | e5314c1 | 2023-01-17 10:47:12 -0700 | [diff] [blame] | 19 | # check sorting - output looks something like this: |
| 20 | # testacpi 0 [ ] testacpi_drv |-- acpi-test |
| 21 | # testacpi 1 [ ] testacpi_drv | `-- child |
| 22 | # pci_emul_p 1 [ ] pci_emul_parent_drv |-- pci-emul2 |
| 23 | # pci_emul 5 [ ] sandbox_swap_case_em | `-- emul2@1f,0 |
| 24 | |
| 25 | # The number of '| ' and '--' matches indicate the indent level. We start |
| 26 | # checking sorting only after UCLASS_AXI_EMUL after which the names should |
| 27 | # be sorted. |
| 28 | |
| 29 | response = u_boot_console.run_command('dm tree -s') |
| 30 | lines = response.split('\n')[2:] |
| 31 | stack = [] # holds where we were up to at the previous indent level |
| 32 | prev = '' # uclass name of previous line |
| 33 | start = False |
| 34 | for line in lines: |
| 35 | indent = line.count('| ') + ('--' in line) |
| 36 | cur = line.split()[0] |
| 37 | if not start: |
| 38 | if cur != 'axi_emul': |
| 39 | continue |
| 40 | start = True |
| 41 | |
| 42 | # Handle going up or down an indent level |
| 43 | if indent > len(stack): |
| 44 | stack.append(prev) |
| 45 | prev = '' |
| 46 | elif indent < len(stack): |
| 47 | prev = stack.pop() |
| 48 | |
| 49 | # Check that the current uclass name is not alphabetically before the |
| 50 | # previous one |
| 51 | if 'emul' not in cur and cur < prev: |
| 52 | print('indent', cur >= prev, indent, prev, cur, stack) |
| 53 | assert cur >= prev |
| 54 | prev = cur |
| 55 | |
| 56 | |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 57 | @pytest.mark.buildconfigspec('cmd_dm') |
| 58 | def test_dm_drivers(u_boot_console): |
| 59 | """Test that each driver in `dm compat` is also listed in `dm drivers`.""" |
| 60 | response = u_boot_console.run_command('dm compat') |
| 61 | drivers = (line[:20].rstrip() for line in response[:-1].split('\n')[2:]) |
| 62 | response = u_boot_console.run_command('dm drivers') |
| 63 | for driver in drivers: |
| 64 | assert driver in response |
| 65 | |
| 66 | @pytest.mark.buildconfigspec('cmd_dm') |
| 67 | def test_dm_static(u_boot_console): |
| 68 | """Test that each driver in `dm static` is also listed in `dm drivers`.""" |
| 69 | response = u_boot_console.run_command('dm static') |
| 70 | drivers = (line[:25].rstrip() for line in response[:-1].split('\n')[2:]) |
Sean Anderson | 439f1c6 | 2020-04-06 10:23:09 -0400 | [diff] [blame] | 71 | response = u_boot_console.run_command('dm drivers') |
| 72 | for driver in drivers: |
| 73 | assert driver in response |
Michal Simek | a598073 | 2022-07-07 12:59:42 +0200 | [diff] [blame] | 74 | |
| 75 | @pytest.mark.buildconfigspec("cmd_dm") |
| 76 | def test_dm_uclass(u_boot_console): |
| 77 | response = u_boot_console.run_command("dm uclass") |
| 78 | |
| 79 | @pytest.mark.buildconfigspec("cmd_dm") |
| 80 | def test_dm_devres(u_boot_console): |
| 81 | response = u_boot_console.run_command("dm devres") |