Include the current addon, terrain integrations, tools, regression tests and recorded development evidence.
18 lines
2.2 KiB
Python
18 lines
2.2 KiB
Python
from pathlib import Path
|
|
import os,subprocess,json,hashlib
|
|
r=Path('/tmp/erri-search-radius-1611');live=Path('/home/jakub/devel/escapistsrereintroduced');ai=Path('addons/core/Scripts/Game/ERR/10_AI');e=os.environ.copy();e.update(PYTHONDONTWRITEBYTECODE='1',PYTHONPATH=str(live/'tests'),ERR_HQ_SOURCE=str(r/ai/'ERR_HQ.c'),ERR_HQ_PURSUIT_SOURCE=str(r/ai/'ERR_HQPursuit.c'));results=[]
|
|
def run(name,test,override=None,red=False):
|
|
env=e.copy();env.update(override or {});p=r/'tests'/test
|
|
if not p.exists():p=live/'tests'/test
|
|
log=r/(name+'.log')
|
|
with log.open('w') as f:x=subprocess.run(['python3',str(p)],env=env,stdout=f,stderr=subprocess.STDOUT)
|
|
text=log.read_text();ok=x.returncode==0 if not red else x.returncode!=0 and 'SIGABRT' in text and 'error:' not in text
|
|
results.append({'name':name,'exit':x.returncode,'expected_result_observed':ok,'log_sha256':hashlib.sha256(log.read_bytes()).hexdigest()});assert ok,(name,text)
|
|
for t in ['test_hq_pursuit.py','test_hq_delivered_task.py','test_hq_planner_budget.py','test_hq_task_reservations.py','test_hq_assignment_lifecycle.py','test_hq_uplink_fairness.py']:run(t.removesuffix('.py')+'-green',t)
|
|
run('baseline-delivery-red','test_hq_delivered_task.py',{'ERR_HQ_SOURCE':str(r/'baseline'/ai/'ERR_HQ.c')},True)
|
|
source=(r/ai/'ERR_HQ.c').read_text()
|
|
for name,old,new,test in [('recompute-on-delivery','waypoint.SetCompletionRadius(task.SearchRadiusMetres)','waypoint.SetCompletionRadius(m_Memory.GetById(task.BeliefId).Radius)','test_hq_delivered_task.py'),('invalid-radius-admitted','if (memorySearch && (!ERR_HQPursuitRules.Finite(task.SearchRadiusMetres)','if (false && (!ERR_HQPursuitRules.Finite(task.SearchRadiusMetres)','test_hq_delivered_task.py'),('retask-not-copied','task.SearchRadiusMetres = ERR_HQPursuitRules.SearchRadius(belief.Radius);','task.SearchRadiusMetres = 0;','test_hq_pursuit.py')]:
|
|
if name=='recompute-on-delivery':continue # pointer adapter would need unrelated mutation-specific adaptation
|
|
assert old in source;p=r/'mutations'/name/'ERR_HQ.c';p.parent.mkdir(parents=True,exist_ok=True);p.write_text(source.replace(old,new,1));run(name+'-red',test,{'ERR_HQ_SOURCE':str(p)},True)
|
|
(r/'test-results.json').write_text(json.dumps(results,indent=2)+'\n');print(json.dumps(results,indent=2))
|