ynl.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # SPDX-License-Identifier: GPL-2.0
  2. import sys
  3. from pathlib import Path
  4. from .consts import KSRC, KSFT_DIR
  5. from .ksft import ksft_pr, ktap_result
  6. # Resolve paths
  7. try:
  8. if (KSFT_DIR / "kselftest-list.txt").exists():
  9. # Running in "installed" selftests
  10. tools_full_path = KSFT_DIR
  11. SPEC_PATH = KSFT_DIR / "net/lib/specs"
  12. sys.path.append(tools_full_path.as_posix())
  13. from net.lib.ynl.pyynl.lib import YnlFamily, NlError
  14. else:
  15. # Running in tree
  16. tools_full_path = KSRC / "tools"
  17. SPEC_PATH = KSRC / "Documentation/netlink/specs"
  18. sys.path.append(tools_full_path.as_posix())
  19. from net.ynl.pyynl.lib import YnlFamily, NlError
  20. except ModuleNotFoundError as e:
  21. ksft_pr("Failed importing `ynl` library from kernel sources")
  22. ksft_pr(str(e))
  23. ktap_result(True, comment="SKIP")
  24. sys.exit(4)
  25. #
  26. # Wrapper classes, loading the right specs
  27. # Set schema='' to avoid jsonschema validation, it's slow
  28. #
  29. class EthtoolFamily(YnlFamily):
  30. def __init__(self, recv_size=0):
  31. super().__init__((SPEC_PATH / Path('ethtool.yaml')).as_posix(),
  32. schema='', recv_size=recv_size)
  33. class RtnlFamily(YnlFamily):
  34. def __init__(self, recv_size=0):
  35. super().__init__((SPEC_PATH / Path('rt-link.yaml')).as_posix(),
  36. schema='', recv_size=recv_size)
  37. class RtnlAddrFamily(YnlFamily):
  38. def __init__(self, recv_size=0):
  39. super().__init__((SPEC_PATH / Path('rt-addr.yaml')).as_posix(),
  40. schema='', recv_size=recv_size)
  41. class NetdevFamily(YnlFamily):
  42. def __init__(self, recv_size=0):
  43. super().__init__((SPEC_PATH / Path('netdev.yaml')).as_posix(),
  44. schema='', recv_size=recv_size)
  45. class NetshaperFamily(YnlFamily):
  46. def __init__(self, recv_size=0):
  47. super().__init__((SPEC_PATH / Path('net_shaper.yaml')).as_posix(),
  48. schema='', recv_size=recv_size)
  49. class DevlinkFamily(YnlFamily):
  50. def __init__(self, recv_size=0):
  51. super().__init__((SPEC_PATH / Path('devlink.yaml')).as_posix(),
  52. schema='', recv_size=recv_size)
  53. class PSPFamily(YnlFamily):
  54. def __init__(self, recv_size=0):
  55. super().__init__((SPEC_PATH / Path('psp.yaml')).as_posix(),
  56. schema='', recv_size=recv_size)