[Bf-blender-cvs] [476202026cf] sybren-usd: USD: Created abstract Blendfile-loading test class
Sybren A. Stüvel
noreply at git.blender.org
Tue Nov 12 16:14:22 CET 2019
Commit: 476202026cf7238d6727d42967e38840bc4dbb9a
Author: Sybren A. Stüvel
Date: Tue Nov 12 15:58:14 2019 +0100
Branches: sybren-usd
https://developer.blender.org/rB476202026cf7238d6727d42967e38840bc4dbb9a
USD: Created abstract Blendfile-loading test class
This test class minimally sets up Blender so that it can load blend files
and construct a depsgraph without crashing. Note that I haven't tested this
on very complex blend files, so it may still crash when the loaded blend
file references/requires uninitialised data structures.
I also changed the USD Export Hierarchy Iterator Test to use the new test
class, and renamed it to Abstract Hierarchy Iterator Test as it doesn't
test anything USD-specific.
===================================================================
M tests/gtests/usd/CMakeLists.txt
R070 tests/gtests/usd/usd_export_hierarchy_iterator_test.cc tests/gtests/usd/abstract_hierarchy_iterator_test.cc
A tests/gtests/usd/blendfile_loading_test.cc
A tests/gtests/usd/blendfile_loading_test.h
===================================================================
diff --git a/tests/gtests/usd/CMakeLists.txt b/tests/gtests/usd/CMakeLists.txt
index 8f5897d551f..5c17674219c 100644
--- a/tests/gtests/usd/CMakeLists.txt
+++ b/tests/gtests/usd/CMakeLists.txt
@@ -53,8 +53,12 @@ else()
set(_buildinfo_src "")
endif()
-# For motivation on doubling BLENDER_SORTED_LIBS, see ../bmesh/CMakeLists.txt
-BLENDER_SRC_GTEST(usd "usd_export_hierarchy_iterator_test.cc;${_buildinfo_src}" "${LIB}")
+BLENDER_SRC_GTEST_EX(usd "blendfile_loading_test.cc;abstract_hierarchy_iterator_test.cc;${_buildinfo_src}" "${LIB}" "FALSE")
+add_test(
+ NAME usd_test
+ COMMAND ${TESTS_OUTPUT_DIR}/usd_test --test-assets-dir ${CMAKE_SOURCE_DIR}/../lib/tests
+ WORKING_DIRECTORY ${TEST_INSTALL_DIR})
+
unset(_buildinfo_src)
diff --git a/tests/gtests/usd/usd_export_hierarchy_iterator_test.cc b/tests/gtests/usd/abstract_hierarchy_iterator_test.cc
similarity index 70%
rename from tests/gtests/usd/usd_export_hierarchy_iterator_test.cc
rename to tests/gtests/usd/abstract_hierarchy_iterator_test.cc
index c8f34c0fad9..27666803ce9 100644
--- a/tests/gtests/usd/usd_export_hierarchy_iterator_test.cc
+++ b/tests/gtests/usd/abstract_hierarchy_iterator_test.cc
@@ -1,30 +1,10 @@
-#include "testing/testing.h"
-
-// Keep first since utildefines defines AT which conflicts with STL
+#include "blendfile_loading_test.h"
#include "intern/abstract_hierarchy_iterator.h"
extern "C" {
-#include "BKE_blender.h"
-#include "BKE_main.h"
-#include "BKE_modifier.h"
-#include "BKE_node.h"
-#include "BKE_scene.h"
-
-#include "BLI_utildefines.h"
#include "BLI_math.h"
-
-#include "BLO_readfile.h"
-
-#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph.h"
-
-#include "DNA_genfile.h"
-#include "DNA_scene_types.h"
-#include "DNA_windowmanager_types.h"
-
-#include "RNA_define.h"
-
-#include "MEM_guardedalloc.h"
+#include "DNA_object_types.h"
}
#include <map>
@@ -102,76 +82,20 @@ class TestingHierarchyIterator : public AbstractHierarchyIterator {
}
};
-class USDHierarchyIteratorTest : public testing::Test {
+class USDHierarchyIteratorTest : public BlendfileLoadingTest {
protected:
- BlendFileData *bfile;
- Depsgraph *depsgraph;
TestingHierarchyIterator *iterator;
virtual void SetUp()
{
- bfile = nullptr;
- depsgraph = nullptr;
+ BlendfileLoadingTest::SetUp();
iterator = nullptr;
-
- /* Minimal code to make the exporter not crash, copied from main() in creator.c. */
- DNA_sdna_current_init();
- DEG_register_node_types();
- RNA_init();
- init_nodesystem();
}
virtual void TearDown()
{
iterator_free();
- depsgraph_free();
- blendfile_free();
- }
-
- /* Load a blend file, return 'ok' (true=good, false=bad) and set bfile.
- * Fails the test if the file cannot be loaded.
- */
- bool blendfile_load(const char *filepath)
- {
- bfile = BLO_read_from_file(filepath, BLO_READ_SKIP_NONE, NULL /* reports */);
- if (bfile == nullptr) {
- ADD_FAILURE();
- return false;
- }
-
- /* Create a dummy window manager. Some code would SEGFAULT without it. */
- bfile->main->wm.first = MEM_callocN(sizeof(wmWindowManager), "Dummy Window Manager");
- return true;
- }
- /* Free bfile if it is not nullptr */
- void blendfile_free()
- {
- if (bfile == nullptr) {
- return;
- }
- BLO_blendfiledata_free(bfile);
- bfile = nullptr;
- }
-
- /* Create a depsgraph. Assumes a blend file has been loaded. */
- void depsgraph_create()
- {
- /* TODO(sergey): Pass scene layer somehow? */
- depsgraph = DEG_graph_new(
- bfile->main, bfile->curscene, bfile->cur_view_layer, DAG_EVAL_RENDER);
-
- DEG_graph_build_from_view_layer(
- depsgraph, bfile->main, bfile->curscene, bfile->cur_view_layer);
- BKE_scene_graph_update_tagged(depsgraph, bfile->main);
- }
- /* Free the depsgraph if it's not nullptr. */
- void depsgraph_free()
- {
- if (depsgraph == nullptr) {
- return;
- }
- DEG_graph_free(depsgraph);
- depsgraph = nullptr;
+ BlendfileLoadingTest::TearDown();
}
/* Create a test iterator. */
@@ -193,10 +117,10 @@ class USDHierarchyIteratorTest : public testing::Test {
TEST_F(USDHierarchyIteratorTest, ExportHierarchyTest)
{
/* Load the test blend file. */
- if (!blendfile_load("../../lib/tests/usd/usd_hierarchy_export_test.blend")) {
+ if (!blendfile_load("usd/usd_hierarchy_export_test.blend")) {
return;
}
- depsgraph_create();
+ depsgraph_create(DAG_EVAL_RENDER);
iterator_create();
iterator->iterate();
diff --git a/tests/gtests/usd/blendfile_loading_test.cc b/tests/gtests/usd/blendfile_loading_test.cc
new file mode 100644
index 00000000000..c6c9d56678e
--- /dev/null
+++ b/tests/gtests/usd/blendfile_loading_test.cc
@@ -0,0 +1,102 @@
+#include "blendfile_loading_test.h"
+
+extern "C" {
+#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_scene.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 "MEM_guardedalloc.h"
+
+#include "RNA_define.h"
+}
+
+DEFINE_string(test_assets_dir,
+ "../../lib/tests",
+ "lib/tests directory from SVN, containing the test assets.");
+
+BlendfileLoadingTest::BlendfileLoadingTest() : testing::Test(), bfile(nullptr), depsgraph(nullptr)
+{
+}
+
+BlendfileLoadingTest::~BlendfileLoadingTest()
+{
+}
+
+void BlendfileLoadingTest::SetUp()
+{
+ testing::Test::SetUp();
+
+ /* Minimal code to make loading a blendfile and constructing a depsgraph not crash, copied from
+ * main() in creator.c. */
+ DNA_sdna_current_init();
+ DEG_register_node_types();
+ RNA_init();
+ init_nodesystem();
+}
+
+void BlendfileLoadingTest::TearDown()
+{
+ depsgraph_free();
+ blendfile_free();
+
+ testing::Test::TearDown();
+}
+
+bool BlendfileLoadingTest::blendfile_load(const char *filepath)
+{
+ const char *test_assets_dir = FLAGS_test_assets_dir.c_str();
+ if (test_assets_dir == nullptr || test_assets_dir[0] == '\0') {
+ ADD_FAILURE()
+ << "Pass the flag --test_assets_dir and point to the lib/tests directory from SVN.";
+ return false;
+ }
+
+ char abspath[FILENAME_MAX];
+ BLI_path_join(abspath, sizeof(abspath), test_assets_dir, filepath, NULL);
+
+ bfile = BLO_read_from_file(abspath, BLO_READ_SKIP_NONE, NULL /* reports */);
+ if (bfile == nullptr) {
+ ADD_FAILURE();
+ return false;
+ }
+
+ /* Create a dummy window manager. Some code would SEGFAULT without it. */
+ bfile->main->wm.first = MEM_callocN(sizeof(wmWindowManager), "Dummy Window Manager");
+ return true;
+}
+
+void BlendfileLoadingTest::blendfile_free()
+{
+ if (bfile == nullptr) {
+ return;
+ }
+ BLO_blendfiledata_free(bfile);
+ bfile = nullptr;
+}
+
+void BlendfileLoadingTest::depsgraph_create(eEvaluationMode depsgraph_evaluation_mode)
+{
+ depsgraph = DEG_graph_new(
+ bfile->main, bfile->curscene, bfile->cur_view_layer, depsgraph_evaluation_mode);
+ DEG_graph_build_from_view_layer(depsgraph, bfile->main, bfile->curscene, bfile->cur_view_layer);
+ BKE_scene_graph_update_tagged(depsgraph, bfile->main);
+}
+
+void BlendfileLoadingTest::depsgraph_free()
+{
+ if (depsgraph == nullptr) {
+ return;
+ }
+ DEG_graph_free(depsgraph);
+ depsgraph = nullptr;
+}
diff --git a/tests/gtests/usd/blendfile_loading_test.h b/tests/gtests/usd/blendfile_loading_test.h
new file mode 100644
index 00000000000..e4db06673b2
--- /dev/null
+++ b/tests/gtests/usd/blendfile_loading_test.h
@@ -0,0 +1,37 @@
+#ifndef __BLENDFILE_LOADING_TEST_H__
+#define __BLENDFILE_LOADING_TEST_H__
+
+#include "testing/testing.h"
+#include <DEG_depsgraph.h>
+
+struct BlendFileData;
+struct Depsgraph;
+
+class BlendfileLoadingTest : public testing::Test {
+ protected:
+ struct BlendFileData *bfile;
+ struct Depsgraph *depsgraph;
+
+ public:
+ BlendfileLoadingTest();
+ virtual ~BlendfileLoadingTest();
+
+ virtual void SetUp();
+ virtual void TearDown();
+
+ protected:
+ /* Load a blend file, return 'ok' (true=good, false=bad) and set bfile.
+ * Fails the test if the file cannot be loaded (still returns though).
+ * Requires the environment variable TEST_ASSETS_DIR to point to ../lib/tests.
+ */
+ bool blendfile_load(const char *filepath);
+ /* Free bfile if it is not nullptr */
+ void blendfile_free();
+
+ /* Create a depsgraph. Assumes a blend file has been loaded. */
+ void depsgraph_create(eEvaluationMode depsgraph_evaluation_mode);
+ /* Free the depsgraph if it's not nullptr. */
+ void depsgraph_free();
+};
+
+#endif /* __BLENDFILE_LOADING_TEST_H__ */
More information about the Bf-blender-cvs
mailing list