ynl.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.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.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):
  31. super().__init__((SPEC_PATH / Path('ethtool.yaml')).as_posix(),
  32. schema='')
  33. class RtnlFamily(YnlFamily):
  34. def __init__(self):
  35. super().__init__((SPEC_PATH / Path('rt_link.yaml')).as_posix(),
  36. schema='')
  37. class NetdevFamily(YnlFamily):
  38. def __init__(self):
  39. super().__init__((SPEC_PATH / Path('netdev.yaml')).as_posix(),
  40. schema='')