parallelize diffing and conversion; add command for to png conversion
This commit is contained in:
parent
8d67f409bc
commit
e064d3d8d6
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import concurrent.futures
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
@ -84,6 +85,9 @@ rt_debug_fixed_random_seed 31337
|
||||
# print(f'Generating script {args.script.name}')
|
||||
# make_script(args.script, args.tests)
|
||||
|
||||
def mkdir_p(path: str):
|
||||
pathlib.Path(path).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def compile():
|
||||
subprocess.run(['make', 'imagecompare'], cwd=ROOT, check=True)
|
||||
with open(f'{args.xash_dir}/rendertest.script', 'w') as script:
|
||||
@ -96,7 +100,7 @@ def copy_assets():
|
||||
|
||||
def render():
|
||||
print('Running xash3d')
|
||||
pathlib.Path(f'{args.xash_dir}/valve/rendertest').mkdir(parents=True, exist_ok=True)
|
||||
mkdir_p(f'{args.xash_dir}/valve/rendertest')
|
||||
env = os.environ.copy()
|
||||
env['RADV_PERFTEST'] = 'rt'
|
||||
env['LD_LIBRARY_PATH'] = '.'
|
||||
@ -106,34 +110,54 @@ def render():
|
||||
'+exec', 'rendertest.script'],
|
||||
env=env, check=True)
|
||||
|
||||
def compare_one(imagecompare: str, image_base: str, image_gold: str, image_test: str, image_diff: str):
|
||||
compare = subprocess.run([imagecompare, image_gold, image_test, image_diff])
|
||||
match compare.returncode:
|
||||
case 0:
|
||||
pass
|
||||
case 1:
|
||||
raise Exception(f'FATAL imagecompare error: TBD')
|
||||
case 2:
|
||||
print(f'ERROR: {image_base} differ by more than threshold')
|
||||
case _:
|
||||
raise Exception(f'Unexpected imagecompare return code {compare.returncode}')
|
||||
|
||||
def compare():
|
||||
screenshot_base = f'{args.xash_dir}/valve/rendertest'
|
||||
for test in args.tests:
|
||||
for name, display in displays.items():
|
||||
image_base = f'{test}_{name}'
|
||||
image_test = f'{screenshot_base}/{image_base}.tga'
|
||||
image_gold = f'{ROOT}/gold/{image_base}.png'
|
||||
image_diff = f'{ROOT}/work/{image_base}_diff.tga'
|
||||
imagecompare = f'{ROOT}/imagecompare'
|
||||
diffs = []
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
for test in args.tests:
|
||||
for name, display in displays.items():
|
||||
image_base = f'{test}_{name}'
|
||||
image_test = f'{screenshot_base}/{image_base}.tga'
|
||||
image_gold = f'{ROOT}/gold/{image_base}.png'
|
||||
image_diff = f'{ROOT}/work/{image_base}_diff.tga'
|
||||
|
||||
compare = subprocess.run([f'{ROOT}/imagecompare', image_gold, image_test, image_diff])
|
||||
match compare.returncode:
|
||||
case 0:
|
||||
pass
|
||||
case 1:
|
||||
raise Exception(f'FATAL imagecompare error: TBD')
|
||||
case 2:
|
||||
print(f'ERROR: {image_base} differ by more than threshold')
|
||||
case _:
|
||||
raise Exception(f'Unexpected imagecompare return code {compare.returncode}')
|
||||
diffs.append(executor.submit(compare_one, imagecompare, image_base, image_gold, image_test, image_diff))
|
||||
|
||||
subprocess.run(['convert',
|
||||
'(', image_gold, '-bordercolor', 'gold', '-border', '2x2', '-gravity', 'SouthWest', '-font', 'Impact', '-pointsize', '24', '-fill', 'gold', '-stroke', 'black', '-annotate', '0', 'GOLD', ')',
|
||||
'(', image_test, '-bordercolor', 'white', '-border', '2x2', '-fill', 'white', '-annotate', '0', 'TEST', ')',
|
||||
'-loop', '0', '-set', 'delay', '25', f'{ROOT}/work/{image_base}_flip.gif'], check=True)
|
||||
executor.submit(subprocess.run, ['convert',
|
||||
'(', image_gold, '-bordercolor', 'gold', '-border', '2x2', '-gravity', 'SouthWest', '-font', 'Impact', '-pointsize', '24', '-fill', 'gold', '-stroke', 'black', '-annotate', '0', 'GOLD', ')',
|
||||
'(', image_test, '-bordercolor', 'white', '-border', '2x2', '-fill', 'white', '-annotate', '0', 'TEST', ')',
|
||||
'-loop', '0', '-set', 'delay', '25', f'{ROOT}/work/{image_base}_flip.gif'], check=True)
|
||||
|
||||
def command_compare():
|
||||
compare()
|
||||
|
||||
def command_png():
|
||||
screenshot_base = f'{args.xash_dir}/valve/rendertest'
|
||||
new_gold_base = f'{ROOT}/work/gold'
|
||||
mkdir_p(new_gold_base)
|
||||
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||
for test in args.tests:
|
||||
for name, display in displays.items():
|
||||
image_base = f'{test}_{name}'
|
||||
image_test = f'{screenshot_base}/{image_base}.tga'
|
||||
image_new_gold = f'{new_gold_base}/{image_base}.png'
|
||||
|
||||
print(f'{image_new_gold}')
|
||||
executor.submit(subprocess.run, ['convert', image_test, image_new_gold], check=True)
|
||||
|
||||
def command_run():
|
||||
compile()
|
||||
copy_assets()
|
||||
@ -147,9 +171,10 @@ match args.command:
|
||||
command_run()
|
||||
case 'compare':
|
||||
command_compare()
|
||||
case 'png':
|
||||
command_png()
|
||||
case _:
|
||||
raise Exception(f'Unknown command {args.command}')
|
||||
|
||||
# TODO:
|
||||
# - parallel processing
|
||||
# - HTML report
|
||||
|
Loading…
Reference in New Issue
Block a user