diff options
Diffstat (limited to 'tests/gtests/guardedalloc')
-rw-r--r-- | tests/gtests/guardedalloc/CMakeLists.txt | 35 | ||||
-rw-r--r-- | tests/gtests/guardedalloc/guardedalloc_alignment_test.cc | 121 | ||||
-rw-r--r-- | tests/gtests/guardedalloc/guardedalloc_overflow_test.cc | 60 |
3 files changed, 0 insertions, 216 deletions
diff --git a/tests/gtests/guardedalloc/CMakeLists.txt b/tests/gtests/guardedalloc/CMakeLists.txt deleted file mode 100644 index 6ca444f28b3..00000000000 --- a/tests/gtests/guardedalloc/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# ***** 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. -# ***** END GPL LICENSE BLOCK ***** - -set(INC - . - .. - ../../../intern/guardedalloc - ../../../source/blender/blenlib -) - -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 "") -BLENDER_TEST(guardedalloc_overflow "") diff --git a/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc b/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc deleted file mode 100644 index 4c676c6cc76..00000000000 --- a/tests/gtests/guardedalloc/guardedalloc_alignment_test.cc +++ /dev/null @@ -1,121 +0,0 @@ -/* Apache License, Version 2.0 */ - -#include "testing/testing.h" - -#include "BLI_utildefines.h" - -#include "MEM_guardedalloc.h" - -#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ((size_t)ptr % align, 0) - -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, LockfreeAlignedAlloc1) -{ - DoBasicAlignmentChecks(1); -} - -TEST(guardedalloc, GuardedAlignedAlloc1) -{ - MEM_use_guarded_allocator(); - DoBasicAlignmentChecks(1); -} - -TEST(guardedalloc, LockfreeAlignedAlloc2) -{ - DoBasicAlignmentChecks(2); -} - -TEST(guardedalloc, GuardedAlignedAlloc2) -{ - MEM_use_guarded_allocator(); - DoBasicAlignmentChecks(2); -} - -TEST(guardedalloc, LockfreeAlignedAlloc4) -{ - DoBasicAlignmentChecks(4); -} - -TEST(guardedalloc, GuardedAlignedAlloc4) -{ - MEM_use_guarded_allocator(); - DoBasicAlignmentChecks(4); -} - -TEST(guardedalloc, LockfreeAlignedAlloc8) -{ - DoBasicAlignmentChecks(8); -} - -TEST(guardedalloc, GuardedAlignedAlloc8) -{ - MEM_use_guarded_allocator(); - DoBasicAlignmentChecks(8); -} - -TEST(guardedalloc, LockfreeAlignedAlloc16) -{ - DoBasicAlignmentChecks(16); -} - -TEST(guardedalloc, GuardedAlignedAlloc16) -{ - MEM_use_guarded_allocator(); - DoBasicAlignmentChecks(16); -} - -TEST(guardedalloc, LockfreeAlignedAlloc32) -{ - DoBasicAlignmentChecks(32); -} - -TEST(guardedalloc, GuardedAlignedAlloc32) -{ - MEM_use_guarded_allocator(); - DoBasicAlignmentChecks(32); -} - -TEST(guardedalloc, LockfreeAlignedAlloc256) -{ - DoBasicAlignmentChecks(256); -} - -TEST(guardedalloc, GuardedAlignedAlloc256) -{ - MEM_use_guarded_allocator(); - DoBasicAlignmentChecks(256); -} - -TEST(guardedalloc, LockfreeAlignedAlloc512) -{ - DoBasicAlignmentChecks(512); -} - -TEST(guardedalloc, GuardedAlignedAlloc512) -{ - MEM_use_guarded_allocator(); - DoBasicAlignmentChecks(512); -} diff --git a/tests/gtests/guardedalloc/guardedalloc_overflow_test.cc b/tests/gtests/guardedalloc/guardedalloc_overflow_test.cc deleted file mode 100644 index bd47482d033..00000000000 --- a/tests/gtests/guardedalloc/guardedalloc_overflow_test.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* Apache License, Version 2.0 */ - -#include "testing/testing.h" - -#include "MEM_guardedalloc.h" - -/* We expect to abort on integer overflow, to prevent possible exploits. */ -#ifdef _WIN32 -# define ABORT_PREDICATE ::testing::ExitedWithCode(3) -#else -# define ABORT_PREDICATE ::testing::KilledBySignal(SIGABRT) -#endif - -namespace { - -void MallocArray(size_t len, size_t size) -{ - void *mem = MEM_malloc_arrayN(len, size, "MallocArray"); - if (mem) { - MEM_freeN(mem); - } -} - -void CallocArray(size_t len, size_t size) -{ - void *mem = MEM_calloc_arrayN(len, size, "CallocArray"); - if (mem) { - MEM_freeN(mem); - } -} - -} // namespace - -TEST(guardedalloc, LockfreeIntegerOverflow) -{ - MallocArray(1, SIZE_MAX); - CallocArray(SIZE_MAX, 1); - MallocArray(SIZE_MAX / 2, 2); - CallocArray(SIZE_MAX / 1234567, 1234567); - - EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, ""); - EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, ""); - EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, ""); - EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, ""); -} - -TEST(guardedalloc, GuardedIntegerOverflow) -{ - MEM_use_guarded_allocator(); - - MallocArray(1, SIZE_MAX); - CallocArray(SIZE_MAX, 1); - MallocArray(SIZE_MAX / 2, 2); - CallocArray(SIZE_MAX / 1234567, 1234567); - - EXPECT_EXIT(MallocArray(SIZE_MAX, 2), ABORT_PREDICATE, ""); - EXPECT_EXIT(CallocArray(7, SIZE_MAX), ABORT_PREDICATE, ""); - EXPECT_EXIT(MallocArray(SIZE_MAX, 12345567), ABORT_PREDICATE, ""); - EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, ""); -} |