run_v3_protocol.py 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env python3
  2. """Independent V3 UART/SSR/diagnostic real-top regression with hashed inputs."""
  3. from __future__ import annotations
  4. import argparse
  5. import hashlib
  6. import json
  7. from pathlib import Path
  8. import shutil
  9. import subprocess
  10. import time
  11. def main():
  12. parser = argparse.ArgumentParser(description=__doc__)
  13. parser.add_argument('--repo', type=Path, required=True)
  14. parser.add_argument('--tests', type=Path)
  15. parser.add_argument('--out', type=Path, required=True)
  16. args = parser.parse_args()
  17. repo, out = args.repo.resolve(), args.out.resolve()
  18. tests = (args.tests or repo / 'tests/sim').resolve()
  19. closure_path = repo / 'products/6400-v2/source-closure.json'
  20. closure = json.loads(closure_path.read_text())
  21. sources = [repo / name for name in closure['sources'] if name.endswith('.v')]
  22. fixtures = [tests / 'prod2u_v3_protocol_tb.v', repo / 'tests/sim/ct7428_normal_slave_bfm.v']
  23. inputs = [closure_path, Path(__file__).resolve(), *fixtures, *[repo / n for n in closure['sources']]]
  24. for path in inputs:
  25. if not path.is_file():
  26. parser.error('Missing input: ' + str(path))
  27. for tool in ('iverilog', 'vvp'):
  28. if not shutil.which(tool):
  29. parser.error('Missing executable: ' + tool)
  30. out.mkdir(parents=True, exist_ok=False)
  31. receipt = {'test': 'prod2u_v3_protocol_tb', 'status': 'NOT_RUN',
  32. 'scope': '25 MHz production top and nominal 921600 external UART; digital CT bus model; no hardware claim',
  33. 'timer_only_elaboration_overrides': {'WD_TIMEOUT_CLKS': 1400000,
  34. 'u_core.BEACON_PERIOD': 400000},
  35. 'hierarchical_force_or_ram_injection': False,
  36. 'source_sha256': {str(p): hashlib.sha256(p.read_bytes()).hexdigest() for p in inputs},
  37. 'commands': []}
  38. commands = [('compile', ['iverilog', '-g2012', '-I', str(repo), '-s', 'prod2u_v3_protocol_tb',
  39. '-o', str(out / 'protocol.vvp'), *map(str, fixtures), *map(str, sources)]),
  40. ('simulate', ['vvp', str(out / 'protocol.vvp')])]
  41. success = True
  42. for name, command in commands:
  43. started = time.monotonic()
  44. try:
  45. result = subprocess.run(command, cwd=repo, text=True, stdout=subprocess.PIPE,
  46. stderr=subprocess.STDOUT, timeout=600, check=False)
  47. output, code = result.stdout, result.returncode
  48. except subprocess.TimeoutExpired as exc:
  49. output = exc.stdout or ''
  50. if isinstance(output, bytes): output = output.decode(errors='replace')
  51. output += '\nTIMEOUT after 600 seconds\n'
  52. code = 124
  53. log = out / (name + '.log')
  54. log.write_text(output)
  55. print(output, end='' if output.endswith('\n') else '\n', flush=True)
  56. receipt['commands'].append({'argv': command, 'returncode': code,
  57. 'seconds': round(time.monotonic() - started, 3), 'log': str(log)})
  58. if code or (name == 'simulate' and 'PASS prod2u_v3_protocol_tb:' not in output):
  59. success = False
  60. break
  61. receipt['status'] = 'PASS' if success else 'FAIL'
  62. (out / 'receipt.json').write_text(json.dumps(receipt, indent=2) + '\n')
  63. print(receipt['status'] + ': ' + str(out / 'receipt.json'))
  64. return 0 if success else 1
  65. if __name__ == '__main__':
  66. raise SystemExit(main())