[Bf-blender-cvs] [f445f72ecad] master: Tests: Blendfile-loading test class

Sybren A. Stüvel noreply at git.blender.org
Thu Nov 28 17:41:50 CET 2019


Commit: f445f72ecadf21857a36b52b187620df158ef698
Author: Sybren A. Stüvel
Date:   Thu Nov 28 17:37:27 2019 +0100
Branches: master
https://developer.blender.org/rBf445f72ecadf21857a36b52b187620df158ef698

Tests: Blendfile-loading test class

This new test class minimally sets up Blender so that it can load blend
files and construct a depsgraph without crashing.

Note that it hasn't been tested on very complex blend files, so it may
still crash when the loaded blend file references/requires uninitialised
data structures.

The test will certainly crash with Blend files created with Blender
older than 2.80, as the versioning code requires space types to be
registered. This is normally done by initialising the window manager,
which is not done in this test. The WM requires Python to run, which in
turn requires that Blender finds the release directory in the same
directory that contains the running executable, which is not the case
for GTest tests (they are written to `bin/tests/executablename`.

Reviewed By: sergey, mont29

Differential Revision: https://developer.blender.org/D6246

===================================================================

M	build_files/cmake/Modules/GTestTesting.cmake
M	tests/gtests/CMakeLists.txt
A	tests/gtests/blenloader/CMakeLists.txt
A	tests/gtests/blenloader/blendfile_load_test.cc
A	tests/gtests/blenloader/blendfile_loading_base_test.cc
A	tests/gtests/blenloader/blendfile_loading_base_test.h

===================================================================

diff --git a/build_files/cmake/Modules/GTestTesting.cmake b/build_files/cmake/Modules/GTestTesting.cmake
index a93e829e6b0..2a05b92ba3f 100644
--- a/build_files/cmake/Modules/GTestTesting.cmake
+++ b/build_files/cmake/Modules/GTestTesting.cmake
@@ -12,9 +12,14 @@
 #
 #=============================================================================
 
-macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
+macro(BLENDER_SRC_GTEST_EX)
   if(WITH_GTESTS)
-    set(TARGET_NAME ${NAME}_test)
+    set(options SKIP_ADD_TEST)
+    set(oneValueArgs NAME)
+    set(multiValueArgs SRC EXTRA_LIBS COMMAND_ARGS)
+    cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
+
+    set(TARGET_NAME ${ARG_NAME}_test)
     get_property(_current_include_directories
                  DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
                  PROPERTY INCLUDE_DIRECTORIES)
@@ -30,11 +35,11 @@ macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
     )
     unset(_current_include_directories)
 
-    add_executable(${TARGET_NAME} ${SRC})
+    add_executable(${TARGET_NAME} ${ARG_SRC})
     target_include_directories(${TARGET_NAME} PUBLIC "${TEST_INC}")
     target_include_directories(${TARGET_NAME} SYSTEM PUBLIC "${TEST_INC_SYS}")
     target_link_libraries(${TARGET_NAME}
-                          ${EXTRA_LIBS}
+                          ${ARG_EXTRA_LIBS}
                           ${PLATFORM_LINKLIBS}
                           bf_testing_main
                           bf_intern_eigen
@@ -60,8 +65,11 @@ macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
                           RUNTIME_OUTPUT_DIRECTORY         "${TESTS_OUTPUT_DIR}"
                           RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"
                           RUNTIME_OUTPUT_DIRECTORY_DEBUG   "${TESTS_OUTPUT_DIR}")
-    if(${DO_ADD_TEST})
-      add_test(NAME ${TARGET_NAME} COMMAND ${TESTS_OUTPUT_DIR}/${TARGET_NAME} WORKING_DIRECTORY ${TEST_INSTALL_DIR})
+    if(NOT ARG_SKIP_ADD_TEST)
+      add_test(
+        NAME ${TARGET_NAME}
+        COMMAND ${TESTS_OUTPUT_DIR}/${TARGET_NAME} ${ARG_COMMAND_ARGS}
+        WORKING_DIRECTORY ${TEST_INSTALL_DIR})
 
       # Don't fail tests on leaks since these often happen in external libraries
       # that we can't fix.
@@ -74,13 +82,23 @@ macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
 endmacro()
 
 macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS)
-  BLENDER_SRC_GTEST_EX("${NAME}" "${SRC}" "${EXTRA_LIBS}" "TRUE")
+  BLENDER_SRC_GTEST_EX(
+    NAME "${NAME}"
+    SRC "${SRC}"
+    EXTRA_LIBS "${EXTRA_LIBS}")
 endmacro()
 
 macro(BLENDER_TEST NAME EXTRA_LIBS)
-  BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "TRUE")
+  BLENDER_SRC_GTEST_EX(
+    NAME "${NAME}"
+    SRC "${NAME}_test.cc"
+    EXTRA_LIBS "${EXTRA_LIBS}")
 endmacro()
 
 macro(BLENDER_TEST_PERFORMANCE NAME EXTRA_LIBS)
-  BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "FALSE")
+  BLENDER_SRC_GTEST_EX(
+    NAME "${NAME}"
+    SRC "${NAME}_test.cc"
+    EXTRA_LIBS "${EXTRA_LIBS}"
+    SKIP_ADD_TEST)
 endmacro()
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
index 285b414e997..54a1ee41198 100644
--- a/tests/gtests/CMakeLists.txt
+++ b/tests/gtests/CMakeLists.txt
@@ -13,6 +13,7 @@ if(WITH_GTESTS)
 
   add_subdirectory(testing)
   add_subdirectory(blenlib)
+  add_subdirectory(blenloader)
   add_subdirectory(guardedalloc)
   add_subdirectory(bmesh)
   if(WITH_ALEMBIC)
diff --git a/tests/gtests/blenloader/CMakeLists.txt b/tests/gtests/blenloader/CMakeLists.txt
new file mode 100644
index 00000000000..f8457e0164b
--- /dev/null
+++ b/tests/gtests/blenloader/CMakeLists.txt
@@ -0,0 +1,90 @@
+# ***** 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) 2019 by Blender Foundation.
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+    .
+    ..
+    ../../../source/blender/blenkernel
+    ../../../source/blender/blenlib
+    ../../../source/blender/blenloader
+    ../../../source/blender/depsgraph
+    ../../../source/blender/imbuf
+    ../../../source/blender/makesdna
+    ../../../source/blender/makesrna
+    ../../../source/blender/windowmanager
+    ../../../intern/guardedalloc
+    ${GLOG_INCLUDE_DIRS}
+    ${GFLAGS_INCLUDE_DIRS}
+    ../../../extern/gtest/include
+)
+
+set(SRC
+  blendfile_loading_base_test.cc
+  blendfile_loading_base_test.h
+)
+
+set(LIB
+)
+
+blender_add_lib(bf_blenloader_test "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
+
+
+set(INC
+    .
+    ..
+    ../../../source/blender/blenlib
+    ../../../source/blender/blenloader
+    ../../../source/blender/blenkernel
+    ../../../source/blender/makesdna
+    ../../../source/blender/makesrna
+    ../../../source/blender/depsgraph
+    ../../../intern/guardedalloc
+)
+
+set(LIB
+    bf_blenloader_test
+    bf_blenloader
+
+    # Should not be needed but gives windows linker errors if the ocio libs are linked before this:
+    bf_intern_opencolorio
+    bf_gpu
+)
+
+include_directories(${INC})
+
+setup_libdirs()
+get_property(BLENDER_SORTED_LIBS GLOBAL PROPERTY BLENDER_SORTED_LIBS_PROP)
+
+
+set(SRC
+    blendfile_load_test.cc
+)
+if(WITH_BUILDINFO)
+  list(APPEND SRC "$<TARGET_OBJECTS:buildinfoobj>")
+endif()
+
+BLENDER_SRC_GTEST_EX(
+  NAME blenloader
+  SRC "${SRC}"
+  EXTRA_LIBS "${LIB}"
+  COMMAND_ARGS --test-assets-dir "${CMAKE_SOURCE_DIR}/../lib/tests")
+
+unset(_buildinfo_src)
+
+setup_liblinks(blenloader_test)
diff --git a/tests/gtests/blenloader/blendfile_load_test.cc b/tests/gtests/blenloader/blendfile_load_test.cc
new file mode 100644
index 00000000000..2ba3e3fcd88
--- /dev/null
+++ b/tests/gtests/blenloader/blendfile_load_test.cc
@@ -0,0 +1,31 @@
+/*
+ * 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) 2019 by Blender Foundation.
+ */
+#include "blendfile_loading_base_test.h"
+
+class BlendfileLoadingTest : public BlendfileLoadingBaseTest {
+};
+
+TEST_F(BlendfileLoadingTest, CanaryTest)
+{
+  /* Load the smallest blend file we have in the SVN lib/tests directory. */
+  if (!blendfile_load("modifier_stack/array_test.blend")) {
+    return;
+  }
+  depsgraph_create(DAG_EVAL_RENDER);
+  EXPECT_NE(nullptr, this->depsgraph);
+}
diff --git a/tests/gtests/blenloader/blendfile_loading_base_test.cc b/tests/gtests/blenloader/blendfile_loading_base_test.cc
new file mode 100644
index 00000000000..5a1a7f9aae5
--- /dev/null
+++ b/tests/gtests/blenloader/blendfile_loading_base_test.cc
@@ -0,0 +1,172 @@
+/*
+ * 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) 2019 by Blender Foundation.
+ */
+#include "blendfile_loading_base_test.h"
+
+extern "C" {
+#include "BKE_appdir.h"
+#include "BKE_blender.h"
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_image.h"
+#include "BKE_main.h"
+#include "BKE_modifier.h"
+#include "BKE_node.h"
+#include "BKE_scene.h"
+
+#include "BLI_threads.h"
+#include "BLI_path_util.h"
+
+#include "BLO_readfile.h"
+
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph.h"
+
+#include "DNA_genfile.h" /* for DNA_sdna_current_init() */
+#include "DNA_windowmanager_types.h"
+
+#include "IMB_imbuf.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "wm.h"
+}
+
+DEFINE_string(test_assets_dir, "", "lib/tests directory from SVN containing the test assets.");
+
+BlendfileLoadingBaseTest::~BlendfileLoadingBaseTest()
+{
+}
+
+void BlendfileLoadingBaseTest::SetUpTestCase()
+{
+  testing::Test::SetUpTestCase();
+
+  /* Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from
+   * main() in creator.c. */
+  BLI_threadapi_init();
+
+  DNA_sdna_current_init();
+  BKE_blender_globals_init();
+  IMB_init();
+  BKE_images_init();
+  BKE_modifier_init();
+  DEG_register_node_types();
+  RNA_init();
+  init_nodesystem();
+
+  G.background = true;
+  G.factory_startup = true;
+
+  /* Allocate a dummy window manager. The real window manager will try and load Python scripts from
+   * the release directory, which it won't be able to find. */
+  ASSERT_EQ(G.main->wm.first, nullptr);
+  G.main->w

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list