test_ct_diagnostics.py 1.3 KB

12345678910111213141516171819202122232425262728
  1. """Passive CT diagnostics against actual I2C pins, at production bus timing."""
  2. import pytest
  3. from pathlib import Path
  4. import shutil
  5. import subprocess
  6. ROOT = Path(__file__).resolve().parents[2]
  7. @pytest.mark.parametrize("bench, marker", [("ct7428_diagnostics_tb", "36 external-pin reads"), ("ct7428_status_registers_tb", "28 external-pin reads")])
  8. def test_ct_diagnostics_success_nack_stuck_recovery(tmp_path, bench, marker):
  9. sources = [
  10. 'src/rtl/prod2u_p4_i2c_stop_start_read.v',
  11. 'src/modules/i2c_word_reader.v',
  12. 'src/acquisition/ct7428_scan.v',
  13. 'tests/sim/ct7428_normal_slave_bfm.v',
  14. f'tests/sim/{bench}.v',
  15. ]
  16. assert shutil.which('iverilog') and shutil.which('vvp'), 'Icarus tools required'
  17. executable = tmp_path / 'ct_diag.vvp'
  18. compile_result = subprocess.run(
  19. ['iverilog', '-g2012', '-Wall', '-s', bench, '-o', str(executable), *sources],
  20. cwd=ROOT, text=True, capture_output=True, timeout=30)
  21. assert compile_result.returncode == 0, compile_result.stdout + compile_result.stderr
  22. result = subprocess.run(['vvp', str(executable)], cwd=ROOT, text=True,
  23. capture_output=True, timeout=30)
  24. assert result.returncode == 0, result.stdout + result.stderr
  25. assert f'PASS {bench}: {marker}' in result.stdout