| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- from pathlib import Path
- from unittest import mock
- import json
- import pytest
- from tools import fw_cli
- @pytest.mark.parametrize('target,unit_code,rtl_code,expected',[
- ('6400',0,0,0),('6400',0,7,7),('all',5,0,5),('all',0,7,7)])
- def test_current_regression_routes_and_retains_failures(tmp_path,target,unit_code,rtl_code,expected):
- calls=[]
- def process(command,**kwargs):
- calls.append(command)
- xml=Path(next(x.split('=',1)[1] for x in command if x.startswith('--junitxml=')))
- xml.write_text(f'<testsuites><testsuite tests="1" failures="{int(unit_code!=0)}" errors="0"/></testsuites>')
- fake=mock.Mock();fake.wait.return_value=unit_code;return fake
- with mock.patch.object(fw_cli.sys,'platform','linux'),mock.patch.object(fw_cli,'_generate_one'),\
- mock.patch.object(fw_cli,'source_identity',return_value={'source_kind':'fixture'}),\
- mock.patch.object(fw_cli.subprocess,'Popen',side_effect=process),\
- mock.patch.object(fw_cli,'cmd_diagnose',return_value=rtl_code) as rtl:
- assert fw_cli.main(['test',target,'--run-root',str(tmp_path/'run')])==expected
- assert '-m' in calls[0] and 'pytest' in calls[0]
- assert not any('run_6400_v1.py' in x or 'run_verification_matrix.py' in x for x in calls[0])
- assert rtl.call_args.args[0].target==('all' if target=='all' else '6400-front-rear')
- report=json.loads((tmp_path/'run/RESULT.json').read_text())
- assert report['status']==('PASS' if expected==0 else 'FAIL')
- assert report['complete'] is True
- def test_reuse_rejection_finishes_combined_receipt_as_failure(tmp_path):
- def process(command,**kwargs):
- xml=Path(next(x.split('=',1)[1] for x in command if x.startswith('--junitxml=')))
- xml.write_text('<testsuites><testsuite tests="1" failures="0" errors="0"/></testsuites>')
- fake=mock.Mock();fake.wait.return_value=0;return fake
- with mock.patch.object(fw_cli.sys,'platform','linux'),mock.patch.object(fw_cli,'_generate_one'),\
- mock.patch.object(fw_cli,'source_identity',return_value={'source_kind':'fixture'}),\
- mock.patch.object(fw_cli.subprocess,'Popen',side_effect=process),\
- mock.patch.object(fw_cli,'cmd_diagnose',side_effect=ValueError('RTL_REUSE_REJECTED')):
- assert fw_cli.main(['test','all','--run-root',str(tmp_path/'run'),'--reuse-rtl',str(tmp_path/'cache.json')])==2
- result=json.loads((tmp_path/'run/RESULT.json').read_text())
- assert result['status']=='FAIL' and result['complete'] and result['rtl_result'] is None
- assert result['unit']['status']=='PASS' and result['rtl_error']=='RTL_REUSE_REJECTED'
|