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,16 +110,8 @@ def render():
|
||||
'+exec', 'rendertest.script'],
|
||||
env=env, check=True)
|
||||
|
||||
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'
|
||||
|
||||
compare = subprocess.run([f'{ROOT}/imagecompare', image_gold, image_test, image_diff])
|
||||
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
|
||||
@ -126,7 +122,21 @@ def compare():
|
||||
case _:
|
||||
raise Exception(f'Unexpected imagecompare return code {compare.returncode}')
|
||||
|
||||
subprocess.run(['convert',
|
||||
def compare():
|
||||
screenshot_base = f'{args.xash_dir}/valve/rendertest'
|
||||
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'
|
||||
|
||||
diffs.append(executor.submit(compare_one, imagecompare, image_base, image_gold, image_test, image_diff))
|
||||
|
||||
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)
|
||||
@ -134,6 +144,20 @@ def compare():
|
||||
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