collect-code-tests.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #
  2. # collect-code-tests.py
  3. # Convenience script to collect all code tests. Used by env:linux_native_test in native.ini.
  4. #
  5. import pioutil
  6. if pioutil.is_pio_build():
  7. import os, re
  8. env = pioutil.env
  9. os.environ['PATH'] = f"./buildroot/bin/:./buildroot/tests/:{os.environ['PATH']}"
  10. def collect_test_suites():
  11. """Get all the test suites"""
  12. from pathlib import Path
  13. return sorted(list(Path("./test").glob("*.ini")))
  14. def register_test_suites():
  15. """Register all the test suites"""
  16. targets = []
  17. test_suites = collect_test_suites()
  18. for path in test_suites:
  19. name = re.sub(r'^\d+-|\.ini$', '', path.name)
  20. targets += [name];
  21. env.AddCustomTarget(
  22. name = f"marlin_{name}",
  23. dependencies = None,
  24. actions = [
  25. f"echo ====== Configuring for marlin_{name} ======",
  26. "restore_configs",
  27. f"cp -f {path} ./Marlin/config.ini",
  28. "python ./buildroot/share/PlatformIO/scripts/configuration.py",
  29. f"platformio test -e linux_native_test -f {name}",
  30. "restore_configs",
  31. ],
  32. title = "Marlin: {}".format(name.lower().title().replace("_", " ")),
  33. description = (
  34. f"Run a Marlin test suite, with the appropriate configuration, "
  35. f"that sits in {path}"
  36. )
  37. )
  38. env.AddCustomTarget(
  39. name = "test-marlin",
  40. dependencies = None,
  41. actions = [
  42. f"platformio run -t marlin_{name} -e linux_native_test"
  43. for name in targets
  44. ],
  45. title = "Marlin: Test all code test suites",
  46. description = (
  47. f"Run all Marlin code test suites ({len(targets)} found)."
  48. ),
  49. )
  50. register_test_suites()