test_vendor_models.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import hashlib
  2. import pytest
  3. from tools.verify_motor_arithmetic import plaintext_vendor_model
  4. from tools import verify_motor_arithmetic as verification
  5. def test_selects_unchanged_complete_plaintext_and_binds_full_file(tmp_path):
  6. prefix=b'// Vendor header\n`timescale 1ns/1ps\nmodule EXAMPLE(input a,output y);\nassign y=a;\nendmodule\n\n'
  7. raw=prefix+b'`pragma protect begin_protected\nopaque trailer\n'
  8. path=tmp_path/'vendor.v';path.write_bytes(raw)
  9. selected,identity=plaintext_vendor_model(path,'EXAMPLE')
  10. assert selected==prefix and path.read_bytes()==raw
  11. assert identity['sha256']==hashlib.sha256(raw).hexdigest()
  12. assert identity['plaintext_sha256']==hashlib.sha256(prefix).hexdigest()
  13. @pytest.mark.parametrize('raw',[
  14. b'`pragma protect begin_protected\nopaque model',
  15. b'module EXAMPLE(input a);\n',
  16. b'module WRONG;\nendmodule\n',
  17. b'module EXAMPLE;\nendmodule\nmodule OTHER;\nendmodule\n',
  18. b'module EXAMPLE;\nendmodule\nassign outside=1;\n'])
  19. def test_missing_incomplete_or_ambiguous_plaintext_never_becomes_a_model(tmp_path,raw):
  20. path=tmp_path/'vendor.v';path.write_bytes(raw)
  21. with pytest.raises(ValueError,match='plaintext vendor module unavailable'):
  22. plaintext_vendor_model(path,'EXAMPLE')
  23. @pytest.mark.parametrize('options',[
  24. ['--state-delay','--vendor-state-delay'],
  25. ['--vendor-state-proof','--vendor-state-delay'],
  26. ['--state-delay','--vendor-library-root','/model']])
  27. def test_conflicting_or_unused_model_options_reject_before_creating_run(tmp_path,monkeypatch,options):
  28. out=tmp_path/'not-created'
  29. monkeypatch.setattr(verification.sys,'argv',['verify','--run-root',str(out),*options])
  30. with pytest.raises(SystemExit) as error:verification.main()
  31. assert error.value.code==2 and not out.exists()