You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 satır
1.9KB

  1. #!/usr/bin/env python3
  2. import argparse
  3. from pathlib import Path
  4. from typing import List, NamedTuple
  5. import shutil
  6. import subprocess
  7. import sys
  8. ROOT = Path(__file__).parent.parent.absolute()
  9. class TestOptions(NamedTuple):
  10. exe: Path
  11. toolchain: str
  12. def run_test_dir(dir: Path, opts: TestOptions) -> bool:
  13. print(f'Running test: {dir.stem} ', end='')
  14. out_dir = dir / '_build'
  15. if out_dir.exists():
  16. shutil.rmtree(out_dir)
  17. res = subprocess.run(
  18. [
  19. str(opts.exe),
  20. 'build',
  21. '--export',
  22. '--warnings',
  23. '--tests',
  24. f'--toolchain={opts.toolchain}',
  25. f'--out-dir={out_dir}',
  26. f'--export-name={dir.stem}',
  27. ],
  28. cwd=dir,
  29. stdout=subprocess.PIPE,
  30. stderr=subprocess.STDOUT,
  31. )
  32. if res.returncode != 0:
  33. print('- FAILED')
  34. print(f'Test failed with exit code [{res.returncode}]:\n{res.stdout.decode()}')
  35. else:
  36. print('- PASSED')
  37. return res.returncode == 0
  38. def run_tests(opts: TestOptions) -> int:
  39. print('Sanity check...')
  40. subprocess.check_output([str(opts.exe), '--help'])
  41. tests_subdir = ROOT / 'tests'
  42. test_dirs = tests_subdir.glob('*.test')
  43. ret = 0
  44. for td in test_dirs:
  45. if not run_test_dir(td, opts):
  46. ret = 1
  47. return ret
  48. def main(argv: List[str]) -> int:
  49. parser = argparse.ArgumentParser()
  50. parser.add_argument(
  51. '--exe',
  52. '-e',
  53. help='Path to the ddslim executable to test',
  54. required=True)
  55. parser.add_argument(
  56. '--toolchain',
  57. '-T',
  58. help='The ddslim toolchain to use while testing',
  59. required=True,
  60. )
  61. args = parser.parse_args(argv)
  62. opts = TestOptions(exe=Path(args.exe).absolute(), toolchain=args.toolchain)
  63. return run_tests(opts)
  64. if __name__ == "__main__":
  65. sys.exit(main(sys.argv[1:]))