test_fw_6400_v1_entrypoint.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from pathlib import Path
  2. from unittest import mock
  3. import json
  4. import pytest
  5. from tools import fw_cli
  6. @pytest.mark.parametrize('target,unit_code,rtl_code,expected',[
  7. ('6400',0,0,0),('6400',0,7,7),('all',5,0,5),('all',0,7,7)])
  8. def test_current_regression_routes_and_retains_failures(tmp_path,target,unit_code,rtl_code,expected):
  9. calls=[]
  10. def process(command,**kwargs):
  11. calls.append(command)
  12. xml=Path(next(x.split('=',1)[1] for x in command if x.startswith('--junitxml=')))
  13. xml.write_text(f'<testsuites><testsuite tests="1" failures="{int(unit_code!=0)}" errors="0"/></testsuites>')
  14. fake=mock.Mock();fake.wait.return_value=unit_code;return fake
  15. with mock.patch.object(fw_cli.sys,'platform','linux'),mock.patch.object(fw_cli,'_generate_one'),\
  16. mock.patch.object(fw_cli,'source_identity',return_value={'source_kind':'fixture'}),\
  17. mock.patch.object(fw_cli.subprocess,'Popen',side_effect=process),\
  18. mock.patch.object(fw_cli,'cmd_diagnose',return_value=rtl_code) as rtl:
  19. assert fw_cli.main(['test',target,'--run-root',str(tmp_path/'run')])==expected
  20. assert '-m' in calls[0] and 'pytest' in calls[0]
  21. assert not any('run_6400_v1.py' in x or 'run_verification_matrix.py' in x for x in calls[0])
  22. assert rtl.call_args.args[0].target==('all' if target=='all' else '6400-front-rear')
  23. report=json.loads((tmp_path/'run/RESULT.json').read_text())
  24. assert report['status']==('PASS' if expected==0 else 'FAIL')
  25. assert report['complete'] is True
  26. def test_reuse_rejection_finishes_combined_receipt_as_failure(tmp_path):
  27. def process(command,**kwargs):
  28. xml=Path(next(x.split('=',1)[1] for x in command if x.startswith('--junitxml=')))
  29. xml.write_text('<testsuites><testsuite tests="1" failures="0" errors="0"/></testsuites>')
  30. fake=mock.Mock();fake.wait.return_value=0;return fake
  31. with mock.patch.object(fw_cli.sys,'platform','linux'),mock.patch.object(fw_cli,'_generate_one'),\
  32. mock.patch.object(fw_cli,'source_identity',return_value={'source_kind':'fixture'}),\
  33. mock.patch.object(fw_cli.subprocess,'Popen',side_effect=process),\
  34. mock.patch.object(fw_cli,'cmd_diagnose',side_effect=ValueError('RTL_REUSE_REJECTED')):
  35. assert fw_cli.main(['test','all','--run-root',str(tmp_path/'run'),'--reuse-rtl',str(tmp_path/'cache.json')])==2
  36. result=json.loads((tmp_path/'run/RESULT.json').read_text())
  37. assert result['status']=='FAIL' and result['complete'] and result['rtl_result'] is None
  38. assert result['unit']['status']=='PASS' and result['rtl_error']=='RTL_REUSE_REJECTED'