Files
test/tests/python/bl_blendfile_versioning.py
Bastien Montagne 3c14067ecd Unittests: 'versioning' py test: generate multiple instances to parallelize it.
The `io_blendfile_versioning` test is currently one of the slowest
(excluding Cycles ones) in debug builds, it can easily take several
minutes to complete.

This commit split it into several instances, each processing a subset of
all the blendfiles.

This gives a strong speed-up when only running that specific test.
As expected, speedup is neglectable when running the whole test suite
though.

| instances | debug  | release | debug all* | release all |
| --------- | ------ | ------- | ---------- | ----------- |
|         1 | 190.95 |   19.39 |     439.54 |       63.51 |
|         4 |  61.80 |    6.81 |        N/A |         N/A |
|         8 |  38.33 |    5.14 |     435.00 |       58.93 |
|        16 |  33.97 |    4.16 |        N/A |         N/A |
|        32 |  46.54 |    5.14 |        N/A |         N/A |

Times are in seconds.
`instances` are the number of tests generated (1 is same as before this
commit).
The first two columns are timings for running the versioning test only,
the last two are timings for the full test suite (excluding Cycles tests
in the debug build case).
2024-05-10 16:00:30 +02:00

139 lines
5.0 KiB
Python

# SPDX-FileCopyrightText: 2023 Blender Authors
#
# SPDX-License-Identifier: Apache-2.0
# ./blender.bin --background --python tests/python/bl_blendfile_versioning.py ..
import bpy
import os
import sys
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
from bl_blendfile_utils import TestHelper
class TestBlendFileOpenAllTestFiles(TestHelper):
def __init__(self, args):
self.args = args
# Some files are known broken currently.
# Each file in this list should either be the source of a bug report,
# or removed from tests repo.
self.excluded_paths = {
# tests/modifier_stack/explode_modifier.blend
# BLI_assert failed: source/blender/blenlib/BLI_ordered_edge.hh:41, operator==(), at 'e1.v_low < e1.v_high'
"explode_modifier.blend",
# tests/depsgraph/deg_anim_camera_dof_driving_material.blend
# ERROR (bke.fcurve):
# source/blender/blenkernel/intern/fcurve_driver.cc:188 dtar_get_prop_val:
# Driver Evaluation Error: cannot resolve target for OBCamera ->
# data.dof_distance
"deg_anim_camera_dof_driving_material.blend",
# tests/depsgraph/deg_driver_shapekey_same_datablock.blend
# Error: Not freed memory blocks: 4, total unfreed memory 0.000427 MB
"deg_driver_shapekey_same_datablock.blend",
# tests/physics/fluidsim.blend
# Error: Not freed memory blocks: 3, total unfreed memory 0.003548 MB
"fluidsim.blend",
# tests/opengl/ram_glsl.blend
# Error: Not freed memory blocks: 4, total unfreed memory 0.000427 MB
"ram_glsl.blend",
}
# Generate the slice of blendfile paths that this instance of the test should process.
blendfile_paths = [p for p in self.iter_blendfiles_from_directory(self.args.src_test_dir)]
# `os.scandir()` used by `iter_blendfiles_from_directory` does not
# guarantee any form of order.
blendfile_paths.sort()
slice_indices = self.generate_slice_indices(len(blendfile_paths), self.args.slice_range, self.args.slice_index)
self.blendfile_paths = blendfile_paths[slice_indices[0]:slice_indices[1]]
@classmethod
def iter_blendfiles_from_directory(cls, root_path):
for dir_entry in os.scandir(root_path):
if dir_entry.is_dir(follow_symlinks=False):
yield from cls.iter_blendfiles_from_directory(dir_entry.path)
elif dir_entry.is_file(follow_symlinks=False):
if os.path.splitext(dir_entry.path)[1] == ".blend":
yield dir_entry.path
@staticmethod
def generate_slice_indices(total_len, slice_range, slice_index):
slice_stride_base = total_len // slice_range
slice_stride_remain = total_len % slice_range
gen_indices = lambda i: (
(i * (slice_stride_base + 1))
if i < slice_stride_remain else
(slice_stride_remain * (slice_stride_base + 1)) + ((i - slice_stride_remain) * slice_stride_base)
)
slice_indices = [(gen_indices(i), gen_indices(i + 1)) for i in range(slice_range)]
return slice_indices[slice_index]
def test_open(self):
for bfp in self.blendfile_paths:
if os.path.basename(bfp) in self.excluded_paths:
continue
bpy.ops.wm.read_homefile(use_empty=True, use_factory_startup=True)
bpy.ops.wm.open_mainfile(filepath=bfp, load_ui=False)
TESTS = (
TestBlendFileOpenAllTestFiles,
)
def argparse_create():
import argparse
# When --help or no args are given, print this help
description = ("Test basic versioning code by opening all blend files "
"in `tests/data` directory.")
parser = argparse.ArgumentParser(description=description)
parser.add_argument(
"--src-test-dir",
dest="src_test_dir",
default="..",
help="Root tests directory to search for blendfiles",
required=False,
)
parser.add_argument(
"--slice-range",
dest="slice_range",
type=int,
default=1,
help="How many instances of this test are launched in parallel, the list of available blendfiles is then sliced "
"and each instance only processes the part matching its given `--slice-index`.",
required=False,
)
parser.add_argument(
"--slice-index",
dest="slice_index",
type=int,
default=0,
help="The index of the slice in blendfiles that this instance should process."
"Should always be specified when `--slice-range` > 1",
required=False,
)
return parser
def main():
args = argparse_create().parse_args()
assert(args.slice_range > 0)
assert(0 <= args.slice_index < args.slice_range)
for Test in TESTS:
Test(args).run_all_tests()
if __name__ == '__main__':
import sys
sys.argv = [__file__] + (sys.argv[sys.argv.index("--") + 1:] if "--" in sys.argv else [])
main()