diff options
Diffstat (limited to 'tests')
27 files changed, 347 insertions, 208 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 966572b23e7..80d749c7040 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -14,15 +14,27 @@ endif() # Path to Blender and Python executables for all platforms. if(MSVC) set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender.exe) - set(TEST_PYTHON_EXE "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>") + set(_default_test_python_exe "${TEST_INSTALL_DIR}/${BLENDER_VERSION_MAJOR}.${BLENDER_VERSION_MINOR}/python/bin/python$<$<CONFIG:Debug>:_d>") elseif(APPLE) set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/Blender.app/Contents/MacOS/Blender) - set(TEST_PYTHON_EXE) + set(_default_test_python_exe ${PYTHON_EXECUTABLE}) else() set(TEST_BLENDER_EXE ${TEST_INSTALL_DIR}/blender) - set(TEST_PYTHON_EXE) + set(_default_test_python_exe ${PYTHON_EXECUTABLE}) endif() +# The installation directory's Python is the best one to use. However, it can only be there after the install step, +# which means that Python will never be there on a fresh system. To suit different needs, the user can pass +# -DTEST_PYTHON_EXE=/path/to/python to CMake. +if (NOT TEST_PYTHON_EXE) + set(TEST_PYTHON_EXE ${_default_test_python_exe}) + message(STATUS "Tests: Using Python executable: ${TEST_PYTHON_EXE}") +elseif(NOT EXISTS ${TEST_PYTHON_EXE}) + message(FATAL_ERROR "Tests: TEST_PYTHON_EXE ${TEST_PYTHON_EXE} does not exist") +endif() +unset(_default_test_python_exe) + + # For testing with Valgrind # set(TEST_BLENDER_EXE valgrind --track-origins=yes --error-limit=no ${TEST_BLENDER_EXE}) diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt index bcf77fb6de7..c02bad471ff 100644 --- a/tests/gtests/CMakeLists.txt +++ b/tests/gtests/CMakeLists.txt @@ -12,6 +12,7 @@ if(WITH_GTESTS) remove_strict_flags() add_subdirectory(testing) + add_subdirectory(blenkernel) add_subdirectory(blenlib) add_subdirectory(blenloader) add_subdirectory(guardedalloc) diff --git a/tests/gtests/blenkernel/BKE_armature_test.cc b/tests/gtests/blenkernel/BKE_armature_test.cc new file mode 100644 index 00000000000..0f390a471d7 --- /dev/null +++ b/tests/gtests/blenkernel/BKE_armature_test.cc @@ -0,0 +1,89 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2020 Blender Foundation + * All rights reserved. + */ + +#include "BKE_armature.h" + +#include "BLI_math.h" + +#include "testing/testing.h" + +static const float FLOAT_EPSILON = 1e-7; + +TEST(mat3_vec_to_roll, UnitMatrix) +{ + float unit_matrix[3][3]; + float roll; + + unit_m3(unit_matrix); + + // Any vector with a unit matrix should return zero roll. + mat3_vec_to_roll(unit_matrix, unit_matrix[0], &roll); + EXPECT_FLOAT_EQ(0.0f, roll); + + mat3_vec_to_roll(unit_matrix, unit_matrix[1], &roll); + EXPECT_FLOAT_EQ(0.0f, roll); + + mat3_vec_to_roll(unit_matrix, unit_matrix[2], &roll); + EXPECT_FLOAT_EQ(0.0f, roll); + + { + // Non-unit vector. + float vector[3] = {1.0f, 1.0f, 1.0f}; + mat3_vec_to_roll(unit_matrix, vector, &roll); + EXPECT_NEAR(0.0f, roll, FLOAT_EPSILON); + + // Normalized version of the above vector. + normalize_v3(vector); + mat3_vec_to_roll(unit_matrix, vector, &roll); + EXPECT_NEAR(0.0f, roll, FLOAT_EPSILON); + } +} + +TEST(mat3_vec_to_roll, Rotationmatrix) +{ + float rotation_matrix[3][3]; + float roll; + + const float rot_around_x[3] = {1.234f, 0.0f, 0.0f}; + eul_to_mat3(rotation_matrix, rot_around_x); + + { + const float unit_axis_x[3] = {1.0f, 0.0f, 0.0f}; + mat3_vec_to_roll(rotation_matrix, unit_axis_x, &roll); + EXPECT_NEAR(1.234f, roll, FLOAT_EPSILON); + } + + { + const float unit_axis_y[3] = {0.0f, 1.0f, 0.0f}; + mat3_vec_to_roll(rotation_matrix, unit_axis_y, &roll); + EXPECT_NEAR(0, roll, FLOAT_EPSILON); + } + + { + const float unit_axis_z[3] = {0.0f, 0.0f, 1.0f}; + mat3_vec_to_roll(rotation_matrix, unit_axis_z, &roll); + EXPECT_NEAR(0, roll, FLOAT_EPSILON); + } + + { + const float between_x_and_y[3] = {1.0f, 1.0f, 0.0f}; + mat3_vec_to_roll(rotation_matrix, between_x_and_y, &roll); + EXPECT_NEAR(0.57158958f, roll, FLOAT_EPSILON); + } +} diff --git a/tests/gtests/blenkernel/CMakeLists.txt b/tests/gtests/blenkernel/CMakeLists.txt new file mode 100644 index 00000000000..bbc274c5ddb --- /dev/null +++ b/tests/gtests/blenkernel/CMakeLists.txt @@ -0,0 +1,41 @@ +# ***** BEGIN GPL LICENSE BLOCK ***** +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# The Original Code is Copyright (C) 2020, Blender Foundation +# All rights reserved. +# ***** END GPL LICENSE BLOCK ***** + +set(INC + . + .. + ../../../source/blender/blenkernel + ../../../source/blender/blenlib + ../../../source/blender/makesdna + ../../../intern/guardedalloc + ../../../intern/atomic +) + +setup_libdirs() +include_directories(${INC}) + +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${PLATFORM_LINKFLAGS}") +set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${PLATFORM_LINKFLAGS_DEBUG}") + +if(WITH_BUILDINFO) + set(BUILDINFO buildinfoobj) +endif() + +BLENDER_TEST(BKE_armature "bf_blenloader;bf_blenkernel;bf_blenlib;${BUILDINFO}") diff --git a/tests/gtests/blenlib/BLI_array_ref_test.cc b/tests/gtests/blenlib/BLI_array_ref_test.cc index aacd6113161..7a1f54e7458 100644 --- a/tests/gtests/blenlib/BLI_array_ref_test.cc +++ b/tests/gtests/blenlib/BLI_array_ref_test.cc @@ -1,5 +1,5 @@ -#include "BLI_array_ref.h" -#include "BLI_vector.h" +#include "BLI_array_ref.hh" +#include "BLI_vector.hh" #include "testing/testing.h" using namespace BLI; diff --git a/tests/gtests/blenlib/BLI_array_test.cc b/tests/gtests/blenlib/BLI_array_test.cc index dd09c2d20f8..b1aa24aa808 100644 --- a/tests/gtests/blenlib/BLI_array_test.cc +++ b/tests/gtests/blenlib/BLI_array_test.cc @@ -1,4 +1,4 @@ -#include "BLI_array_cxx.h" +#include "BLI_array.hh" #include "testing/testing.h" using namespace BLI; diff --git a/tests/gtests/blenlib/BLI_index_range_test.cc b/tests/gtests/blenlib/BLI_index_range_test.cc index 60da18b6baf..b12502f0d97 100644 --- a/tests/gtests/blenlib/BLI_index_range_test.cc +++ b/tests/gtests/blenlib/BLI_index_range_test.cc @@ -1,5 +1,5 @@ -#include "BLI_index_range.h" -#include "BLI_vector.h" +#include "BLI_index_range.hh" +#include "BLI_vector.hh" #include "testing/testing.h" using BLI::ArrayRef; diff --git a/tests/gtests/blenlib/BLI_linear_allocator_test.cc b/tests/gtests/blenlib/BLI_linear_allocator_test.cc new file mode 100644 index 00000000000..0c67d1e76c9 --- /dev/null +++ b/tests/gtests/blenlib/BLI_linear_allocator_test.cc @@ -0,0 +1,113 @@ +#include "BLI_linear_allocator.hh" +#include "testing/testing.h" + +using namespace BLI; + +static bool is_aligned(void *ptr, uint alignment) +{ + BLI_assert(is_power_of_2_i(alignment)); + return (POINTER_AS_UINT(ptr) & (alignment - 1)) == 0; +} + +TEST(linear_allocator, AllocationAlignment) +{ + LinearAllocator<> allocator; + + EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 8), 8)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 16), 16)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 4), 4)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 64), 64)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 64), 64)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 8), 8)); + EXPECT_TRUE(is_aligned(allocator.allocate(10, 128), 128)); +} + +TEST(linear_allocator, PackedAllocation) +{ + LinearAllocator<> allocator; + BLI::AlignedBuffer<256, 32> buffer; + allocator.provide_buffer(buffer); + + uintptr_t ptr1 = (uintptr_t)allocator.allocate(10, 4); /* 0 - 10 */ + uintptr_t ptr2 = (uintptr_t)allocator.allocate(10, 4); /* 12 - 22 */ + uintptr_t ptr3 = (uintptr_t)allocator.allocate(8, 32); /* 32 - 40 */ + uintptr_t ptr4 = (uintptr_t)allocator.allocate(16, 8); /* 40 - 56 */ + uintptr_t ptr5 = (uintptr_t)allocator.allocate(1, 8); /* 56 - 57 */ + uintptr_t ptr6 = (uintptr_t)allocator.allocate(1, 4); /* 60 - 61 */ + uintptr_t ptr7 = (uintptr_t)allocator.allocate(1, 1); /* 61 - 62 */ + + EXPECT_EQ(ptr2 - ptr1, 12); /* 12 - 0 = 12 */ + EXPECT_EQ(ptr3 - ptr2, 20); /* 32 - 12 = 20 */ + EXPECT_EQ(ptr4 - ptr3, 8); /* 40 - 32 = 8 */ + EXPECT_EQ(ptr5 - ptr4, 16); /* 56 - 40 = 16 */ + EXPECT_EQ(ptr6 - ptr5, 4); /* 60 - 56 = 4 */ + EXPECT_EQ(ptr7 - ptr6, 1); /* 61 - 60 = 1 */ +} + +TEST(linear_allocator, CopyString) +{ + LinearAllocator<> allocator; + BLI::AlignedBuffer<256, 1> buffer; + allocator.provide_buffer(buffer); + + StringRefNull ref1 = allocator.copy_string("Hello"); + StringRefNull ref2 = allocator.copy_string("World"); + + EXPECT_EQ(ref1, "Hello"); + EXPECT_EQ(ref2, "World"); + EXPECT_EQ(ref2.data() - ref1.data(), 6); +} + +TEST(linear_allocator, AllocateArray) +{ + LinearAllocator<> allocator; + + MutableArrayRef<int> array = allocator.allocate_array<int>(5); + EXPECT_EQ(array.size(), 5); +} + +TEST(linear_allocator, Construct) +{ + LinearAllocator<> allocator; + + std::array<int, 5> values = {1, 2, 3, 4, 5}; + Vector<int> *vector = allocator.construct<Vector<int>>(values); + EXPECT_EQ(vector->size(), 5); + EXPECT_EQ((*vector)[3], 4); + vector->~Vector(); +} + +TEST(linear_allocator, ConstructElementsAndPointerArray) +{ + LinearAllocator<> allocator; + + std::array<int, 7> values = {1, 2, 3, 4, 5, 6, 7}; + ArrayRef<Vector<int> *> vectors = allocator.construct_elements_and_pointer_array<Vector<int>>( + 5, values); + + EXPECT_EQ(vectors.size(), 5); + EXPECT_EQ(vectors[3]->size(), 7); + EXPECT_EQ((*vectors[2])[5], 6); + + for (Vector<int> *vector : vectors) { + vector->~Vector(); + } +} + +TEST(linear_allocator, ConstructArrayCopy) +{ + LinearAllocator<> allocator; + + Vector<int> values = {1, 2, 3}; + MutableArrayRef<int> array1 = allocator.construct_array_copy(values.as_ref()); + MutableArrayRef<int> array2 = allocator.construct_array_copy(values.as_ref()); + EXPECT_NE(array1.begin(), array2.begin()); + EXPECT_EQ(array1.size(), 3); + EXPECT_EQ(array2.size(), 3); + EXPECT_EQ(array1[1], 2); + EXPECT_EQ(array2[2], 3); +} diff --git a/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc b/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc index 9934d1a3337..d1176527cb5 100644 --- a/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc +++ b/tests/gtests/blenlib/BLI_linklist_lockfree_test.cc @@ -65,7 +65,7 @@ struct IndexedNode { void concurrent_insert(TaskPool *__restrict pool, void *taskdata, int /*threadid*/) { - LockfreeLinkList *list = (LockfreeLinkList *)BLI_task_pool_userdata(pool); + LockfreeLinkList *list = (LockfreeLinkList *)BLI_task_pool_user_data(pool); CHECK_NOTNULL(list); IndexedNode *node = (IndexedNode *)MEM_mallocN(sizeof(IndexedNode), "test node"); node->index = POINTER_AS_INT(taskdata); diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc index 7be23157e94..e9e4b1895ab 100644 --- a/tests/gtests/blenlib/BLI_map_test.cc +++ b/tests/gtests/blenlib/BLI_map_test.cc @@ -1,5 +1,5 @@ -#include "BLI_map.h" -#include "BLI_set.h" +#include "BLI_map.hh" +#include "BLI_set.hh" #include "testing/testing.h" using BLI::Map; @@ -9,16 +9,20 @@ TEST(map, DefaultConstructor) { IntFloatMap map; EXPECT_EQ(map.size(), 0); + EXPECT_TRUE(map.is_empty()); } TEST(map, AddIncreasesSize) { IntFloatMap map; EXPECT_EQ(map.size(), 0); + EXPECT_TRUE(map.is_empty()); map.add(2, 5.0f); EXPECT_EQ(map.size(), 1); + EXPECT_FALSE(map.is_empty()); map.add(6, 2.0f); EXPECT_EQ(map.size(), 2); + EXPECT_FALSE(map.is_empty()); } TEST(map, Contains) diff --git a/tests/gtests/blenlib/BLI_optional_test.cc b/tests/gtests/blenlib/BLI_optional_test.cc index a25a3cbd588..e0dec5681fe 100644 --- a/tests/gtests/blenlib/BLI_optional_test.cc +++ b/tests/gtests/blenlib/BLI_optional_test.cc @@ -1,4 +1,4 @@ -#include "BLI_optional.h" +#include "BLI_optional.hh" #include "testing/testing.h" #include <string> diff --git a/tests/gtests/blenlib/BLI_set_test.cc b/tests/gtests/blenlib/BLI_set_test.cc index 555140f805c..dc163e752d8 100644 --- a/tests/gtests/blenlib/BLI_set_test.cc +++ b/tests/gtests/blenlib/BLI_set_test.cc @@ -1,5 +1,5 @@ -#include "BLI_set.h" -#include "BLI_vector.h" +#include "BLI_set.hh" +#include "BLI_vector.hh" #include "testing/testing.h" using BLI::Set; @@ -155,16 +155,6 @@ TEST(set, AddMultipleNew) EXPECT_TRUE(a.contains(6)); } -TEST(set, ToSmallVector) -{ - IntSet a = {5, 2, 8}; - BLI::Vector<int> vec = a.to_small_vector(); - EXPECT_EQ(vec.size(), 3); - EXPECT_TRUE(vec.contains(5)); - EXPECT_TRUE(vec.contains(2)); - EXPECT_TRUE(vec.contains(8)); -} - TEST(set, Iterator) { IntSet set = {1, 3, 2, 5, 4}; diff --git a/tests/gtests/blenlib/BLI_stack_cxx_test.cc b/tests/gtests/blenlib/BLI_stack_cxx_test.cc index 6376259927b..e49872f8643 100644 --- a/tests/gtests/blenlib/BLI_stack_cxx_test.cc +++ b/tests/gtests/blenlib/BLI_stack_cxx_test.cc @@ -1,4 +1,4 @@ -#include "BLI_stack_cxx.h" +#include "BLI_stack.hh" #include "testing/testing.h" using BLI::Stack; diff --git a/tests/gtests/blenlib/BLI_string_map_test.cc b/tests/gtests/blenlib/BLI_string_map_test.cc index 4cb67d5fbac..41cda920a89 100644 --- a/tests/gtests/blenlib/BLI_string_map_test.cc +++ b/tests/gtests/blenlib/BLI_string_map_test.cc @@ -1,5 +1,5 @@ -#include "BLI_string_map.h" -#include "BLI_vector.h" +#include "BLI_string_map.hh" +#include "BLI_vector.hh" #include "testing/testing.h" using namespace BLI; @@ -232,3 +232,20 @@ TEST(string_map, UniquePtrValues) std::unique_ptr<int> *b = map.lookup_ptr("A"); EXPECT_EQ(a.get(), b->get()); } + +TEST(string_map, AddOrModify) +{ + StringMap<int> map; + auto create_func = [](int *value) { + *value = 10; + return true; + }; + auto modify_func = [](int *value) { + *value += 5; + return false; + }; + EXPECT_TRUE(map.add_or_modify("Hello", create_func, modify_func)); + EXPECT_EQ(map.lookup("Hello"), 10); + EXPECT_FALSE(map.add_or_modify("Hello", create_func, modify_func)); + EXPECT_EQ(map.lookup("Hello"), 15); +} diff --git a/tests/gtests/blenlib/BLI_string_ref_test.cc b/tests/gtests/blenlib/BLI_string_ref_test.cc index a268bf3215a..393f28d4fc1 100644 --- a/tests/gtests/blenlib/BLI_string_ref_test.cc +++ b/tests/gtests/blenlib/BLI_string_ref_test.cc @@ -1,5 +1,5 @@ -#include "BLI_string_ref.h" -#include "BLI_vector.h" +#include "BLI_string_ref.hh" +#include "BLI_vector.hh" #include "testing/testing.h" using BLI::StringRef; @@ -237,3 +237,14 @@ TEST(string_ref, Substr) EXPECT_EQ(ref.substr(3, 4), "lo w"); EXPECT_EQ(ref.substr(6, 5), "world"); } + +TEST(string_ref, Copy) +{ + StringRef ref("hello"); + char dst[10]; + memset(dst, 0xFF, 10); + ref.copy(dst); + EXPECT_EQ(dst[5], '\0'); + EXPECT_EQ(dst[6], 0xFF); + EXPECT_EQ(ref, dst); +} diff --git a/tests/gtests/blenlib/BLI_task_performance_test.cc b/tests/gtests/blenlib/BLI_task_performance_test.cc index db596340464..06e832bdb5e 100644 --- a/tests/gtests/blenlib/BLI_task_performance_test.cc +++ b/tests/gtests/blenlib/BLI_task_performance_test.cc @@ -36,92 +36,6 @@ static uint gen_pseudo_random_number(uint num) return ((num & 255) << 6) + 1; } -/* *** Parallel iterations over range of indices. *** */ - -static void task_parallel_range_func(void *UNUSED(userdata), - int index, - const TaskParallelTLS *__restrict UNUSED(tls)) -{ - const uint limit = gen_pseudo_random_number((uint)index); - for (uint i = (uint)index; i < limit;) { - i += gen_pseudo_random_number(i); - } -} - -static void task_parallel_range_test_do(const char *id, - const int num_items, - const bool use_threads) -{ - TaskParallelSettings settings; - BLI_parallel_range_settings_defaults(&settings); - settings.use_threading = use_threads; - - double averaged_timing = 0.0; - for (int i = 0; i < NUM_RUN_AVERAGED; i++) { - const double init_time = PIL_check_seconds_timer(); - for (int j = 0; j < 10; j++) { - BLI_task_parallel_range(i + j, i + j + num_items, NULL, task_parallel_range_func, &settings); - } - averaged_timing += PIL_check_seconds_timer() - init_time; - } - - printf("\t%s: non-pooled done in %fs on average over %d runs\n", - id, - averaged_timing / NUM_RUN_AVERAGED, - NUM_RUN_AVERAGED); - - averaged_timing = 0.0; - for (int i = 0; i < NUM_RUN_AVERAGED; i++) { - const double init_time = PIL_check_seconds_timer(); - TaskParallelRangePool *range_pool = BLI_task_parallel_range_pool_init(&settings); - for (int j = 0; j < 10; j++) { - BLI_task_parallel_range_pool_push( - range_pool, i + j, i + j + num_items, NULL, task_parallel_range_func, &settings); - } - BLI_task_parallel_range_pool_work_and_wait(range_pool); - BLI_task_parallel_range_pool_free(range_pool); - averaged_timing += PIL_check_seconds_timer() - init_time; - } - - printf("\t%s: pooled done in %fs on average over %d runs\n", - id, - averaged_timing / NUM_RUN_AVERAGED, - NUM_RUN_AVERAGED); -} - -TEST(task, RangeIter10KNoThread) -{ - task_parallel_range_test_do( - "Range parallel iteration - Single thread - 10K items", 10000, false); -} - -TEST(task, RangeIter10k) -{ - task_parallel_range_test_do("Range parallel iteration - Threaded - 10K items", 10000, true); -} - -TEST(task, RangeIter100KNoThread) -{ - task_parallel_range_test_do( - "Range parallel iteration - Single thread - 100K items", 100000, false); -} - -TEST(task, RangeIter100k) -{ - task_parallel_range_test_do("Range parallel iteration - Threaded - 100K items", 100000, true); -} - -TEST(task, RangeIter1000KNoThread) -{ - task_parallel_range_test_do( - "Range parallel iteration - Single thread - 1000K items", 1000000, false); -} - -TEST(task, RangeIter1000k) -{ - task_parallel_range_test_do("Range parallel iteration - Threaded - 1000K items", 1000000, true); -} - /* *** Parallel iterations over double-linked list items. *** */ static void task_listbase_light_iter_func(void *UNUSED(userdata), diff --git a/tests/gtests/blenlib/BLI_task_test.cc b/tests/gtests/blenlib/BLI_task_test.cc index d4ab9de13c4..fe0f481d469 100644 --- a/tests/gtests/blenlib/BLI_task_test.cc +++ b/tests/gtests/blenlib/BLI_task_test.cc @@ -27,17 +27,19 @@ static void task_range_iter_func(void *userdata, int index, const TaskParallelTL // printf("%d, %d, %d\n", index, data[index], *((int *)tls->userdata_chunk)); } -static void task_range_iter_finalize_func(void *__restrict userdata, - void *__restrict userdata_chunk) +static void task_range_iter_reduce_func(const void *__restrict UNUSED(userdata), + void *__restrict join_v, + void *__restrict userdata_chunk) { - int *data = (int *)userdata; - data[NUM_ITEMS] += *(int *)userdata_chunk; + int *join = (int *)join_v; + int *chunk = (int *)userdata_chunk; + *join += *chunk; // printf("%d, %d\n", data[NUM_ITEMS], *((int *)userdata_chunk)); } TEST(task, RangeIter) { - int data[NUM_ITEMS + 1] = {0}; + int data[NUM_ITEMS] = {0}; int sum = 0; BLI_threadapi_init(); @@ -48,7 +50,7 @@ TEST(task, RangeIter) settings.userdata_chunk = ∑ settings.userdata_chunk_size = sizeof(sum); - settings.func_finalize = task_range_iter_finalize_func; + settings.func_reduce = task_range_iter_reduce_func; BLI_task_parallel_range(0, NUM_ITEMS, data, task_range_iter_func, &settings); @@ -60,79 +62,7 @@ TEST(task, RangeIter) EXPECT_EQ(data[i], i); expected_sum += i; } - EXPECT_EQ(data[NUM_ITEMS], expected_sum); - - BLI_threadapi_exit(); -} - -TEST(task, RangeIterPool) -{ - const int num_tasks = 10; - int data[num_tasks][NUM_ITEMS + 1] = {{0}}; - int sum = 0; - - BLI_threadapi_init(); - - TaskParallelSettings settings; - BLI_parallel_range_settings_defaults(&settings); - settings.min_iter_per_thread = 1; - - TaskParallelRangePool *range_pool = BLI_task_parallel_range_pool_init(&settings); - - for (int j = 0; j < num_tasks; j++) { - settings.userdata_chunk = ∑ - settings.userdata_chunk_size = sizeof(sum); - settings.func_finalize = task_range_iter_finalize_func; - - BLI_task_parallel_range_pool_push( - range_pool, 0, NUM_ITEMS, data[j], task_range_iter_func, &settings); - } - - BLI_task_parallel_range_pool_work_and_wait(range_pool); - - /* Those checks should ensure us all items of the listbase were processed once, and only once - - * as expected. */ - - for (int j = 0; j < num_tasks; j++) { - int expected_sum = 0; - for (int i = 0; i < NUM_ITEMS; i++) { - // EXPECT_EQ(data[j][i], i); - expected_sum += i; - } - EXPECT_EQ(data[j][NUM_ITEMS], expected_sum); - } - - /* A pool can be re-used untill it is freed. */ - - for (int j = 0; j < num_tasks; j++) { - memset(data[j], 0, sizeof(data[j])); - } - sum = 0; - - for (int j = 0; j < num_tasks; j++) { - settings.userdata_chunk = ∑ - settings.userdata_chunk_size = sizeof(sum); - settings.func_finalize = task_range_iter_finalize_func; - - BLI_task_parallel_range_pool_push( - range_pool, 0, NUM_ITEMS, data[j], task_range_iter_func, &settings); - } - - BLI_task_parallel_range_pool_work_and_wait(range_pool); - - BLI_task_parallel_range_pool_free(range_pool); - - /* Those checks should ensure us all items of the listbase were processed once, and only once - - * as expected. */ - - for (int j = 0; j < num_tasks; j++) { - int expected_sum = 0; - for (int i = 0; i < NUM_ITEMS; i++) { - // EXPECT_EQ(data[j][i], i); - expected_sum += i; - } - EXPECT_EQ(data[j][NUM_ITEMS], expected_sum); - } + EXPECT_EQ(sum, expected_sum); BLI_threadapi_exit(); } diff --git a/tests/gtests/blenlib/BLI_vector_set_test.cc b/tests/gtests/blenlib/BLI_vector_set_test.cc index 5ec51337aa7..816d5d653a5 100644 --- a/tests/gtests/blenlib/BLI_vector_set_test.cc +++ b/tests/gtests/blenlib/BLI_vector_set_test.cc @@ -1,4 +1,4 @@ -#include "BLI_vector_set.h" +#include "BLI_vector_set.hh" #include "testing/testing.h" using BLI::VectorSet; @@ -39,6 +39,17 @@ TEST(vector_set, Copy) EXPECT_EQ(set2.index(2), 1); } +TEST(vector_set, CopyAssignment) +{ + IntVectorSet set1 = {1, 2, 3}; + IntVectorSet set2 = {}; + set2 = set1; + EXPECT_EQ(set1.size(), 3); + EXPECT_EQ(set2.size(), 3); + EXPECT_EQ(set1.index(2), 1); + EXPECT_EQ(set2.index(2), 1); +} + TEST(vector_set, Move) { IntVectorSet set1 = {1, 2, 3}; @@ -47,6 +58,15 @@ TEST(vector_set, Move) EXPECT_EQ(set2.size(), 3); } +TEST(vector_set, MoveAssignment) +{ + IntVectorSet set1 = {1, 2, 3}; + IntVectorSet set2 = {}; + set2 = std::move(set1); + EXPECT_EQ(set1.size(), 0); + EXPECT_EQ(set2.size(), 3); +} + TEST(vector_set, AddNewIncreasesSize) { IntVectorSet set; diff --git a/tests/gtests/blenlib/BLI_vector_test.cc b/tests/gtests/blenlib/BLI_vector_test.cc index 2402ee9627f..1585b77675b 100644 --- a/tests/gtests/blenlib/BLI_vector_test.cc +++ b/tests/gtests/blenlib/BLI_vector_test.cc @@ -1,4 +1,4 @@ -#include "BLI_vector.h" +#include "BLI_vector.hh" #include "testing/testing.h" #include <forward_list> @@ -45,7 +45,7 @@ struct TestListValue { int value; }; -TEST(vector, IntrusiveListBaseConstructor) +TEST(vector, ListBaseConstructor) { TestListValue *value1 = new TestListValue{0, 0, 4}; TestListValue *value2 = new TestListValue{0, 0, 5}; @@ -55,7 +55,7 @@ TEST(vector, IntrusiveListBaseConstructor) BLI_addtail(&list, value1); BLI_addtail(&list, value2); BLI_addtail(&list, value3); - Vector<TestListValue *> vec(list, true); + Vector<TestListValue *> vec(list); EXPECT_EQ(vec.size(), 3); EXPECT_EQ(vec[0]->value, 4); diff --git a/tests/gtests/blenlib/CMakeLists.txt b/tests/gtests/blenlib/CMakeLists.txt index 119b54fa0d4..a0621448630 100644 --- a/tests/gtests/blenlib/CMakeLists.txt +++ b/tests/gtests/blenlib/CMakeLists.txt @@ -52,6 +52,7 @@ BLENDER_TEST(BLI_heap "bf_blenlib") BLENDER_TEST(BLI_heap_simple "bf_blenlib") BLENDER_TEST(BLI_index_range "bf_blenlib") BLENDER_TEST(BLI_kdopbvh "bf_blenlib;bf_intern_numaapi") +BLENDER_TEST(BLI_linear_allocator "bf_blenlib") BLENDER_TEST(BLI_linklist_lockfree "bf_blenlib;bf_intern_numaapi") BLENDER_TEST(BLI_listbase "bf_blenlib") BLENDER_TEST(BLI_map "bf_blenlib") diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index 2d6dc4af40e..a3df01fdbe2 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -48,18 +48,14 @@ endfunction() # Run Python script outside Blender. function(add_python_test testname testscript) - if(MSVC) - add_test( - NAME ${testname} - COMMAND ${TEST_PYTHON_EXE} ${testscript} ${ARGN} - ) - else() - add_test( - NAME ${testname} - COMMAND ${testscript} ${ARGN} - ) + if(NOT TEST_PYTHON_EXE) + message(FATAL_ERROR "No Python configured for running tests, set TEST_PYTHON_EXE.") endif() + add_test( + NAME ${testname} + COMMAND ${TEST_PYTHON_EXE} ${testscript} ${ARGN} + ) set_tests_properties(${testname} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0) endfunction() diff --git a/tests/python/alembic_tests.py b/tests/python/alembic_tests.py index 9de1bc06d84..9de1bc06d84 100755..100644 --- a/tests/python/alembic_tests.py +++ b/tests/python/alembic_tests.py diff --git a/tests/python/cycles_render_tests.py b/tests/python/cycles_render_tests.py index 79ba11fdd44..79ba11fdd44 100755..100644 --- a/tests/python/cycles_render_tests.py +++ b/tests/python/cycles_render_tests.py diff --git a/tests/python/eevee_render_tests.py b/tests/python/eevee_render_tests.py index a7130136d0a..a7130136d0a 100755..100644 --- a/tests/python/eevee_render_tests.py +++ b/tests/python/eevee_render_tests.py diff --git a/tests/python/ffmpeg_tests.py b/tests/python/ffmpeg_tests.py index 92734b5bc7d..92734b5bc7d 100755..100644 --- a/tests/python/ffmpeg_tests.py +++ b/tests/python/ffmpeg_tests.py diff --git a/tests/python/opengl_draw_tests.py b/tests/python/opengl_draw_tests.py index ab4df63afd9..ab4df63afd9 100755..100644 --- a/tests/python/opengl_draw_tests.py +++ b/tests/python/opengl_draw_tests.py diff --git a/tests/python/workbench_render_tests.py b/tests/python/workbench_render_tests.py index 155b54098a8..155b54098a8 100755..100644 --- a/tests/python/workbench_render_tests.py +++ b/tests/python/workbench_render_tests.py |