diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/gtests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/gtests/guardedalloc/CMakeLists.txt | 36 | ||||
-rw-r--r-- | tests/gtests/guardedalloc/guardedalloc_alignment_test.cc | 47 |
3 files changed, 84 insertions, 0 deletions
diff --git a/tests/gtests/CMakeLists.txt b/tests/gtests/CMakeLists.txt index 2ab62fa05b0..317f030a658 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 00000000000..c09f8729ab0 --- /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 00000000000..34c47738276 --- /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 |