Commit: 18627a337793f8d57fa6561afecf3abc9bc38159 Author: Sergey Sharybin Date: Tue Jan 20 23:00:51 2015 +0500 Branches: cycles_ctests https://developer.blender.org/rB18627a337793f8d57fa6561afecf3abc9bc38159
Tests: Add render tests for Cycles The idea is to use the set of really small images from the lib folder and run Cycles render on them comparing render output to reference images in the tests repository. For sure same thing could become more generic for BI or Freestyle render engines. This is not totally easy to use at this moment, basically because of a bit of voodoo mango jambo black magic happening around how we are dealing with addons for ctests. Main issue is that blender loads all the scripts from the source directory, meaning it can't pick cycles up. Once this is figured out in a clean fashion the branch will be merged to master. For until then all the tweaks are gonna to be done here. For now it's possible to set BLENDER_USER_SCRIPTS to the directory with Cycles addon so it is picked up nicely. Reviewers: campbellbarton Differential Revision: https://developer.blender.org/D1011 =================================================================== M tests/python/CMakeLists.txt A tests/python/cycles_render_tests.py =================================================================== diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index 85c6869..e0b0b1b 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -358,3 +358,11 @@ add_test(export_fbx_all_objects ${TEST_BLENDER_EXE} --md5_source=${TEST_OUT_DIR}/export_fbx_all_objects.fbx --md5=b35eb2a9d0e73762ecae2278c25a38ac --md5_method=FILE ) + +if(WITH_CYCLES) + add_test(cycles_shaders_test + ${CMAKE_CURRENT_LIST_DIR}/cycles_render_tests.py + ${TEST_BLENDER_EXE} + ${TEST_SRC_DIR}/cycles/ctests/shader + ) +endif() diff --git a/tests/python/cycles_render_tests.py b/tests/python/cycles_render_tests.py new file mode 100755 index 0000000..cc887e0 --- /dev/null +++ b/tests/python/cycles_render_tests.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python3 + +import os +import tempfile +import subprocess +import sys + +BLENDER = sys.argv[1:-1] +ROOT = sys.argv[-1] + +TEMP = tempfile.mkdtemp() +TEMP_FILE_MASK = os.path.join(TEMP, "test") +TEMP_FILE = TEMP_FILE_MASK + '0001.png' + + +def render_file(filepath): + command = BLENDER + [ + '-b', + filepath, + '-o', + TEMP_FILE_MASK, + '-f', '1', + ] + try: + subprocess.check_output(command) + return os.path.exists(TEMP_FILE) + except: + if os.path.exists(TEMP_FILE): + os.remove(TEMP_FILE) + return False + + +def test_get_name(filepath): + filename = os.path.basename(filepath) + return os.path.splitext(filename)[0] + + +def verify_output(filepath): + testname = test_get_name(filepath) + dirpath = os.path.dirname(filepath) + reference_dirpath = os.path.join(dirpath, 'reference_renders') + reference_image = os.path.join(reference_dirpath, testname + '.png') + if not os.path.exists(reference_image): + return False + command = ['idiff', + '-fail', '0.01', + '-failpercent', '1', + reference_image, + TEMP_FILE, + ] + try: + subprocess.check_output(command) + return True + except subprocess.CalledProcessError as grepexc: + return grepexc.returncode == 1 + + +def run_test(filepath): + testname = test_get_name(filepath) + spacer = "." * (32 - len(testname)) + print(testname, spacer, end='') + sys.stdout.flush() + if render_file(filepath): + ok = verify_output(filepath) + os.remove(TEMP_FILE) + print("PASS" if ok else "FAIL (VERIFY)") + return ok + else: + print("FAIL (RENDER)") + return False + +def blend_list(path): + for dirpath, dirnames, filenames in os.walk(path): + for filename in filenames: + if filename.lower().endswith(".blend"): + filepath = os.path.join(dirpath, filename) + yield filepath + + +def run_all_tests(dirpath): + failed_tests = [] + all_files = list(blend_list(dirpath)) + all_files.sort() + for filepath in all_files: + if not run_test(filepath): + testname = test_get_name(filepath) + failed_tests.append(testname) + if failed_tests: + failed_tests.sort() + print("\n\nFAILED tests:") + for test in failed_tests: + print(" " + test) + return False + return True + +ok = run_all_tests(ROOT) + +# Cleanup temp files and folders +if os.path.exists(TEMP_FILE): + os.remove(TEMP_FILE) +os.rmdir(TEMP) + +sys.exit(0 if ok else 1) _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs