Fix T92252: User after free when opening file after Blender starts
[blender.git] / tests / python / cycles_render_tests.py
1 #!/usr/bin/env python3
2 # Apache License, Version 2.0
3
4 import argparse
5 import os
6 import shlex
7 import shutil
8 import subprocess
9 import sys
10 from pathlib import Path
11
12 # List of .blend files that are known to be failing and are not ready to be
13 # tested, or that only make sense on some devices. Accepts regular expressions.
14 BLACKLIST_OSL = [
15     # OSL only supported on CPU.
16     '.*_osl.blend',
17     'osl_.*.blend',
18 ]
19
20 BLACKLIST_OPTIX = [
21     # No branched path on Optix.
22     'T53854.blend',
23     'T50164.blend',
24     'portal.blend',
25     'denoise_sss.blend',
26     'denoise_passes.blend',
27     'distant_light.blend',
28     'aov_position.blend',
29     'subsurface_branched_path.blend',
30     'T43865.blend',
31 ]
32
33 BLACKLIST_GPU = [
34     # Missing equiangular sampling on GPU.
35     'area_light.blend',
36     'denoise_hair.blend',
37     'point_density_.*.blend',
38     'point_light.blend',
39     'shadow_catcher_bpt_.*.blend',
40     'sphere_light.blend',
41     'spot_light.blend',
42     'T48346.blend',
43     'world_volume.blend',
44     # Uninvestigated differences with GPU.
45     'image_log.blend',
46     'subsurface_behind_glass_branched.blend',
47     'T40964.blend',
48     'T45609.blend',
49     'T48860.blend',
50     'smoke_color.blend',
51     'bevel_mblur.blend',
52     # Inconsistency between Embree and Hair primitive on GPU.
53     'hair_basemesh_intercept.blend',
54     'hair_instancer_uv.blend',
55     'hair_particle_random.blend',
56     'principled_hair_.*.blend',
57     'transparent_shadow_hair.*.blend',
58 ]
59
60
61 def get_arguments(filepath, output_filepath):
62     dirname = os.path.dirname(filepath)
63     basedir = os.path.dirname(dirname)
64     subject = os.path.basename(dirname)
65
66     args = [
67         "--background",
68         "-noaudio",
69         "--factory-startup",
70         "--enable-autoexec",
71         "--debug-memory",
72         "--debug-exit-on-error",
73         filepath,
74         "-E", "CYCLES",
75         "-o", output_filepath,
76         "-F", "PNG"]
77
78     # OSL and GPU examples
79     # custom_args += ["--python-expr", "import bpy; bpy.context.scene.cycles.shading_system = True"]
80     # custom_args += ["--python-expr", "import bpy; bpy.context.scene.cycles.device = 'GPU'"]
81     custom_args = os.getenv('CYCLESTEST_ARGS')
82     if custom_args:
83         args.extend(shlex.split(custom_args))
84
85     if subject == 'bake':
86         args.extend(['--python', os.path.join(basedir, "util", "render_bake.py")])
87     elif subject == 'denoise_animation':
88         args.extend(['--python', os.path.join(basedir, "util", "render_denoise.py")])
89     else:
90         args.extend(["-f", "1"])
91
92     return args
93
94
95 def create_argparse():
96     parser = argparse.ArgumentParser()
97     parser.add_argument("-blender", nargs="+")
98     parser.add_argument("-testdir", nargs=1)
99     parser.add_argument("-outdir", nargs=1)
100     parser.add_argument("-idiff", nargs=1)
101     parser.add_argument("-device", nargs=1)
102     parser.add_argument("-blacklist", nargs="*")
103     return parser
104
105
106 def main():
107     parser = create_argparse()
108     args = parser.parse_args()
109
110     blender = args.blender[0]
111     test_dir = args.testdir[0]
112     idiff = args.idiff[0]
113     output_dir = args.outdir[0]
114     device = args.device[0]
115
116     blacklist = []
117     if device != 'CPU':
118         blacklist += BLACKLIST_GPU
119     if device != 'CPU' or 'OSL' in args.blacklist:
120         blacklist += BLACKLIST_OSL
121     if device == 'OPTIX':
122         blacklist += BLACKLIST_OPTIX
123
124     from modules import render_report
125     report = render_report.Report('Cycles', output_dir, idiff, device, blacklist)
126     report.set_pixelated(True)
127     report.set_reference_dir("cycles_renders")
128     if device == 'CPU':
129         report.set_compare_engine('eevee')
130     else:
131         report.set_compare_engine('cycles', 'CPU')
132
133     # Increase threshold for motion blur, see T78777.
134     test_dir_name = Path(test_dir).name
135     if test_dir_name == 'motion_blur':
136         report.set_fail_threshold(0.032)
137
138     ok = report.run(test_dir, blender, get_arguments, batch=True)
139
140     sys.exit(not ok)
141
142
143 if __name__ == "__main__":
144     main()