renderdiff: add a filter option for local testing (#9257)
This option will allow for rendering and comparing a single image or files that match a wildcard-style string. README.md has been updated
This commit is contained in:
@@ -3,13 +3,19 @@ import os
|
||||
import sys
|
||||
import pprint
|
||||
import json
|
||||
import fnmatch
|
||||
|
||||
from utils import execute, ArgParseImpl, important_print, mkdir_p
|
||||
from image_diff import same_image, output_image_diff
|
||||
from results import RESULT_OK, RESULT_FAILED, RESULT_MISSING, GOLDEN_MISSING
|
||||
|
||||
def _compare_goldens(base_dir, comparison_dir, out_dir=None):
|
||||
def _compare_goldens(base_dir, comparison_dir, out_dir=None, test_filter=None):
|
||||
def test_name(p):
|
||||
return p.replace('.tif', '')
|
||||
|
||||
all_files = glob.glob(os.path.join(base_dir, "./**/*.tif"), recursive=True)
|
||||
all_files = [os.path.abspath(f) for f in all_files \
|
||||
if not test_filter or fnmatch.fnmatch(test_name(os.path.basename(f)), test_filter)]
|
||||
test_dirs = set(os.path.abspath(os.path.dirname(f)).replace(os.path.abspath(base_dir) + '/', '') \
|
||||
for f in all_files)
|
||||
all_results = []
|
||||
@@ -43,13 +49,17 @@ def _compare_goldens(base_dir, comparison_dir, out_dir=None):
|
||||
comp_test_dir = os.path.abspath(os.path.join(comparison_dir, test_dir))
|
||||
results = [
|
||||
single_test(base_test_dir, comp_test_dir, golden_file) \
|
||||
for golden_file in glob.glob(os.path.join(base_test_dir, "*.tif"))
|
||||
for golden_file in all_files if os.path.dirname(golden_file) == base_test_dir
|
||||
]
|
||||
seen_test_cases = set([r['name'] for r in results])
|
||||
|
||||
# For files that are rendered but not in the golden directory
|
||||
for base_file in \
|
||||
glob.glob(os.path.join(comp_test_dir, "*.tif")):
|
||||
comparison_files = glob.glob(os.path.join(comp_test_dir, "*.tif"))
|
||||
if test_filter:
|
||||
comparison_files = [f for f in comparison_files \
|
||||
if fnmatch.fnmatch(test_name(os.path.basename(f)), test_filter)]
|
||||
|
||||
for base_file in comparison_files:
|
||||
src_fname = os.path.abspath(base_file)
|
||||
test_case = base_file.replace(f'{comp_test_dir}/', '')
|
||||
if test_case not in seen_test_cases:
|
||||
@@ -76,6 +86,7 @@ if __name__ == '__main__':
|
||||
parser.add_argument('--src', help='Directory of the base of the diff.', required=True)
|
||||
parser.add_argument('--dest', help='Directory of the comparison of the diff.')
|
||||
parser.add_argument('--out', help='Directory of output for the result of the diff.')
|
||||
parser.add_argument('--test_filter', help='Filter for the tests to run')
|
||||
|
||||
args, _ = parser.parse_known_args(sys.argv[1:])
|
||||
|
||||
@@ -85,7 +96,7 @@ if __name__ == '__main__':
|
||||
dest = os.path.join(os.getcwd(), './out/renderdiff')
|
||||
assert os.path.exists(dest), f"Destination folder={dest} does not exist."
|
||||
|
||||
results = _compare_goldens(args.src, dest, out_dir=args.out)
|
||||
results = _compare_goldens(args.src, dest, out_dir=args.out, test_filter=args.test_filter)
|
||||
|
||||
failed = [f" {k['name']} ({k['result']})" for k in results if k['result'] != RESULT_OK]
|
||||
success_count = len(results) - len(failed)
|
||||
|
||||
@@ -18,6 +18,8 @@ import json
|
||||
import glob
|
||||
import shutil
|
||||
import concurrent.futures
|
||||
import fnmatch
|
||||
|
||||
|
||||
from utils import execute, ArgParseImpl, mkdir_p, mv_f, important_print
|
||||
|
||||
@@ -80,7 +82,8 @@ def _render_test_config(gltf_viewer,
|
||||
output_dir,
|
||||
local_only=False,
|
||||
opengl_lib=None,
|
||||
vk_icd=None):
|
||||
vk_icd=None,
|
||||
test_filter=None):
|
||||
assert os.path.isdir(output_dir), f"output directory {output_dir} does not exist"
|
||||
assert os.access(gltf_viewer, os.X_OK)
|
||||
|
||||
@@ -103,6 +106,10 @@ def _render_test_config(gltf_viewer,
|
||||
if backend == 'vulkan':
|
||||
assert vk_icd, "VK ICD must be specified when testing vulkan backend"
|
||||
for model in test.models:
|
||||
test_name = f'{test.name}.{backend}.{model}'
|
||||
if test_filter and not fnmatch.fnmatch(test_name, test_filter):
|
||||
print(f'Skipping {test_name} because it does not match filter')
|
||||
continue
|
||||
model_path = os.path.abspath(test_config.models[model])
|
||||
futures.append(
|
||||
executor.submit(_render_single_model, gltf_viewer_abs,
|
||||
@@ -122,6 +129,7 @@ if __name__ == "__main__":
|
||||
parser.add_argument('--output_dir', help='Output Directory', required=True)
|
||||
parser.add_argument('--opengl_lib', help='Path to the folder containing OpenGL driver lib (for LD_LIBRARY_PATH)')
|
||||
parser.add_argument('--vk_icd', help='Path to VK ICD file')
|
||||
parser.add_argument('--test_filter', help='Filter for the tests to run')
|
||||
|
||||
args, _ = parser.parse_known_args(sys.argv[1:])
|
||||
test = test_config.parse_from_path(args.test)
|
||||
@@ -131,7 +139,8 @@ if __name__ == "__main__":
|
||||
test,
|
||||
args.output_dir,
|
||||
opengl_lib=args.opengl_lib,
|
||||
vk_icd=args.vk_icd)
|
||||
vk_icd=args.vk_icd,
|
||||
test_filter=args.test_filter)
|
||||
|
||||
with open(f'{output_dir}/render_results.json', 'w') as f:
|
||||
f.write(json.dumps(results, indent=2))
|
||||
|
||||
Reference in New Issue
Block a user