| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #!/usr/bin/env python3
- """Independent V3 UART/SSR/diagnostic real-top regression with hashed inputs."""
- from __future__ import annotations
- import argparse
- import hashlib
- import json
- from pathlib import Path
- import shutil
- import subprocess
- import time
- def main():
- parser = argparse.ArgumentParser(description=__doc__)
- parser.add_argument('--repo', type=Path, required=True)
- parser.add_argument('--tests', type=Path)
- parser.add_argument('--out', type=Path, required=True)
- args = parser.parse_args()
- repo, out = args.repo.resolve(), args.out.resolve()
- tests = (args.tests or repo / 'tests/sim').resolve()
- closure_path = repo / 'products/6400-v2/source-closure.json'
- closure = json.loads(closure_path.read_text())
- sources = [repo / name for name in closure['sources'] if name.endswith('.v')]
- fixtures = [tests / 'prod2u_v3_protocol_tb.v', repo / 'tests/sim/ct7428_normal_slave_bfm.v']
- inputs = [closure_path, Path(__file__).resolve(), *fixtures, *[repo / n for n in closure['sources']]]
- for path in inputs:
- if not path.is_file():
- parser.error('Missing input: ' + str(path))
- for tool in ('iverilog', 'vvp'):
- if not shutil.which(tool):
- parser.error('Missing executable: ' + tool)
- out.mkdir(parents=True, exist_ok=False)
- receipt = {'test': 'prod2u_v3_protocol_tb', 'status': 'NOT_RUN',
- 'scope': '25 MHz production top and nominal 921600 external UART; digital CT bus model; no hardware claim',
- 'timer_only_elaboration_overrides': {'WD_TIMEOUT_CLKS': 1400000,
- 'u_core.BEACON_PERIOD': 400000},
- 'hierarchical_force_or_ram_injection': False,
- 'source_sha256': {str(p): hashlib.sha256(p.read_bytes()).hexdigest() for p in inputs},
- 'commands': []}
- commands = [('compile', ['iverilog', '-g2012', '-I', str(repo), '-s', 'prod2u_v3_protocol_tb',
- '-o', str(out / 'protocol.vvp'), *map(str, fixtures), *map(str, sources)]),
- ('simulate', ['vvp', str(out / 'protocol.vvp')])]
- success = True
- for name, command in commands:
- started = time.monotonic()
- try:
- result = subprocess.run(command, cwd=repo, text=True, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT, timeout=600, check=False)
- output, code = result.stdout, result.returncode
- except subprocess.TimeoutExpired as exc:
- output = exc.stdout or ''
- if isinstance(output, bytes): output = output.decode(errors='replace')
- output += '\nTIMEOUT after 600 seconds\n'
- code = 124
- log = out / (name + '.log')
- log.write_text(output)
- print(output, end='' if output.endswith('\n') else '\n', flush=True)
- receipt['commands'].append({'argv': command, 'returncode': code,
- 'seconds': round(time.monotonic() - started, 3), 'log': str(log)})
- if code or (name == 'simulate' and 'PASS prod2u_v3_protocol_tb:' not in output):
- success = False
- break
- receipt['status'] = 'PASS' if success else 'FAIL'
- (out / 'receipt.json').write_text(json.dumps(receipt, indent=2) + '\n')
- print(receipt['status'] + ': ' + str(out / 'receipt.json'))
- return 0 if success else 1
- if __name__ == '__main__':
- raise SystemExit(main())
|