Commit: 16d64a99b42171f201496a33f987fb687e3dabb1
Author: Sergey Sharybin
Date: Thu Jun 19 12:45:00 2014 +0600
https://developer.blender.org/rB16d64a99b42171f201496a33f987fb687e3dabb1
Add unit tests for aligned alloc
This was really handy on initial work of aligned alloc
and would be handy as well when we'll need to support
arbitrary alignment on Apple platforms.
===================================================================
M tests/gtests/CMakeLists.txt
A tests/gtests/guardedalloc/CMakeLists.txt
A tests/gtests/guardedalloc/guardedalloc_alignment_test.cc
===================================================================
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt
index 2ab62fa..317f030 100644
--- a/tests/gtests/CMakeLists.txt
+++ b/tests/gtests/CMakeLists.txt
@@ -9,5 +9,6 @@ if(WITH_GTESTS)
add_subdirectory(testing)
add_subdirectory(blenlib)
+ add_subdirectory(guardedalloc)
endif()
diff --git a/tests/gtests/guardedalloc/CMakeLists.txt
b/tests/gtests/guardedalloc/CMakeLists.txt
new file mode 100644
index 0000000..c09f872
--- /dev/null
+++ b/tests/gtests/guardedalloc/CMakeLists.txt
@@ -0,0 +1,36 @@
+# ***** 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) 2014, Blender Foundation
+# All rights reserved.
+#
+# Contributor(s): Sergey Sharybin
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ .
+ ../
+ ../../../intern/guardedalloc
+)
+
+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}")
+
+
+BLENDER_TEST(guardedalloc_alignment "")
diff --git a/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc
b/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc
new file mode 100644
index 0000000..34c4773
--- /dev/null
+++ b/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc
@@ -0,0 +1,47 @@
+#include "testing/testing.h"
+
+#include "MEM_guardedalloc.h"
+
+#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ(0, (size_t)ptr % align)
+
+namespace {
+
+void DoBasicAlignmentChecks(const int alignment) {
+ int *foo, *bar;
+
+ foo = (int *) MEM_mallocN_aligned(sizeof(int) * 10, alignment, "test");
+ CHECK_ALIGNMENT(foo, alignment);
+
+ bar = (int *) MEM_dupallocN(foo);
+ CHECK_ALIGNMENT(bar, alignment);
+ MEM_freeN(bar);
+
+ foo = (int *) MEM_reallocN(foo, sizeof(int) * 5);
+ CHECK_ALIGNMENT(foo, alignment);
+
+ foo = (int *) MEM_recallocN(foo, sizeof(int) * 5);
+ CHECK_ALIGNMENT(foo, alignment);
+
+ MEM_freeN(foo);
+}
+
+} // namespace
+
+TEST(guardedalloc, LockfreeAlignedAlloc16) {
+ DoBasicAlignmentChecks(16);
+}
+
+TEST(guardedalloc, GuardedAlignedAlloc16) {
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(16);
+}
+
+// On Apple we currently support 16 bit alignment only.
+// Harmless for Blender, but would be nice to support
+// eventually.
+#ifndef __APPLE__
+TEST(guardedalloc, GuardedAlignedAlloc32) {
+ MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(16);
+}
+#endif
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs