import hashlib import pytest from tools.verify_motor_arithmetic import plaintext_vendor_model from tools import verify_motor_arithmetic as verification def test_selects_unchanged_complete_plaintext_and_binds_full_file(tmp_path): prefix=b'// Vendor header\n`timescale 1ns/1ps\nmodule EXAMPLE(input a,output y);\nassign y=a;\nendmodule\n\n' raw=prefix+b'`pragma protect begin_protected\nopaque trailer\n' path=tmp_path/'vendor.v';path.write_bytes(raw) selected,identity=plaintext_vendor_model(path,'EXAMPLE') assert selected==prefix and path.read_bytes()==raw assert identity['sha256']==hashlib.sha256(raw).hexdigest() assert identity['plaintext_sha256']==hashlib.sha256(prefix).hexdigest() @pytest.mark.parametrize('raw',[ b'`pragma protect begin_protected\nopaque model', b'module EXAMPLE(input a);\n', b'module WRONG;\nendmodule\n', b'module EXAMPLE;\nendmodule\nmodule OTHER;\nendmodule\n', b'module EXAMPLE;\nendmodule\nassign outside=1;\n']) def test_missing_incomplete_or_ambiguous_plaintext_never_becomes_a_model(tmp_path,raw): path=tmp_path/'vendor.v';path.write_bytes(raw) with pytest.raises(ValueError,match='plaintext vendor module unavailable'): plaintext_vendor_model(path,'EXAMPLE') @pytest.mark.parametrize('options',[ ['--state-delay','--vendor-state-delay'], ['--vendor-state-proof','--vendor-state-delay'], ['--state-delay','--vendor-library-root','/model']]) def test_conflicting_or_unused_model_options_reject_before_creating_run(tmp_path,monkeypatch,options): out=tmp_path/'not-created' monkeypatch.setattr(verification.sys,'argv',['verify','--run-root',str(out),*options]) with pytest.raises(SystemExit) as error:verification.main() assert error.value.code==2 and not out.exists()