test_dm.py 3.0 KB

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