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
|
#!/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,34 +110,54 @@ def render():
|
|||||||
'+exec', 'rendertest.script'],
|
'+exec', 'rendertest.script'],
|
||||||
env=env, check=True)
|
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():
|
def compare():
|
||||||
screenshot_base = f'{args.xash_dir}/valve/rendertest'
|
screenshot_base = f'{args.xash_dir}/valve/rendertest'
|
||||||
for test in args.tests:
|
imagecompare = f'{ROOT}/imagecompare'
|
||||||
for name, display in displays.items():
|
diffs = []
|
||||||
image_base = f'{test}_{name}'
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
||||||
image_test = f'{screenshot_base}/{image_base}.tga'
|
for test in args.tests:
|
||||||
image_gold = f'{ROOT}/gold/{image_base}.png'
|
for name, display in displays.items():
|
||||||
image_diff = f'{ROOT}/work/{image_base}_diff.tga'
|
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])
|
diffs.append(executor.submit(compare_one, imagecompare, image_base, 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}')
|
|
||||||
|
|
||||||
subprocess.run(['convert',
|
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)
|
||||||
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user