parallelize diffing and conversion; add command for to png conversion

This commit is contained in:
Ivan Avdeev 2023-11-27 12:31:41 -05:00
parent 8d67f409bc
commit e064d3d8d6

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse import argparse
import concurrent.futures
import os import os
import pathlib import pathlib
import shutil import shutil
@ -84,6 +85,9 @@ rt_debug_fixed_random_seed 31337
# print(f'Generating script {args.script.name}') # print(f'Generating script {args.script.name}')
# make_script(args.script, args.tests) # make_script(args.script, args.tests)
def mkdir_p(path: str):
pathlib.Path(path).mkdir(parents=True, exist_ok=True)
def compile(): def compile():
subprocess.run(['make', 'imagecompare'], cwd=ROOT, check=True) subprocess.run(['make', 'imagecompare'], cwd=ROOT, check=True)
with open(f'{args.xash_dir}/rendertest.script', 'w') as script: with open(f'{args.xash_dir}/rendertest.script', 'w') as script:
@ -96,7 +100,7 @@ def copy_assets():
def render(): def render():
print('Running xash3d') 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 = os.environ.copy()
env['RADV_PERFTEST'] = 'rt' env['RADV_PERFTEST'] = 'rt'
env['LD_LIBRARY_PATH'] = '.' env['LD_LIBRARY_PATH'] = '.'
@ -106,16 +110,8 @@ def render():
'+exec', 'rendertest.script'], '+exec', 'rendertest.script'],
env=env, check=True) env=env, check=True)
def compare(): def compare_one(imagecompare: str, image_base: str, image_gold: str, image_test: str, image_diff: str):
screenshot_base = f'{args.xash_dir}/valve/rendertest' compare = subprocess.run([imagecompare, image_gold, image_test, image_diff])
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: match compare.returncode:
case 0: case 0:
pass pass
@ -126,7 +122,21 @@ def compare():
case _: case _:
raise Exception(f'Unexpected imagecompare return code {compare.returncode}') 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_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', ')', '(', 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) '-loop', '0', '-set', 'delay', '25', f'{ROOT}/work/{image_base}_flip.gif'], check=True)
@ -134,6 +144,20 @@ def compare():
def command_compare(): def command_compare():
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(): def command_run():
compile() compile()
copy_assets() copy_assets()
@ -147,9 +171,10 @@ match args.command:
command_run() command_run()
case 'compare': case 'compare':
command_compare() command_compare()
case 'png':
command_png()
case _: case _:
raise Exception(f'Unknown command {args.command}') raise Exception(f'Unknown command {args.command}')
# TODO: # TODO:
# - parallel processing
# - HTML report # - HTML report