Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey@blender.org>2020-11-17 13:38:42 +0300
committerSergey Sharybin <sergey@blender.org>2020-11-19 18:17:48 +0300
commita44bb8603e551285f569ef43669b0eb378da1dd8 (patch)
tree49652861c8579782e2ea626fe6dbff7a55ac64b6
parent39ec64b13d18a17db86f9e93fb2aad5d8faa1f40 (diff)
Guarded allocator: Fix lock-free allocator tests
Previously the lock-free tests were actually testing guarded allocator because the main entry point of tests was switching allocator to the guarded one. There seems to be no allocations happening between the initialization sequence and the fixture's SetUp(), so easiest seems to be just to switch to lockfree implementation in the fixture's SetUp(). The test are passing locally, so the "should work" has high chance of actually being truth :) Differential Revision: https://developer.blender.org/D9584
-rw-r--r--intern/guardedalloc/tests/guardedalloc_alignment_test.cc83
-rw-r--r--intern/guardedalloc/tests/guardedalloc_overflow_test.cc8
-rw-r--r--intern/guardedalloc/tests/guardedalloc_test_base.h26
3 files changed, 40 insertions, 77 deletions
diff --git a/intern/guardedalloc/tests/guardedalloc_alignment_test.cc b/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
index 4c676c6cc76..cd19a43695c 100644
--- a/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
+++ b/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
@@ -5,6 +5,7 @@
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
+#include "guardedalloc_test_base.h"
#define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ((size_t)ptr % align, 0)
@@ -32,90 +33,26 @@ void DoBasicAlignmentChecks(const int alignment)
} // namespace
-TEST(guardedalloc, LockfreeAlignedAlloc1)
+TEST_F(LockFreeAllocatorTest, MEM_mallocN_aligned)
{
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)
+TEST_F(GuardedAllocatorTest, MEM_mallocN_aligned)
{
- MEM_use_guarded_allocator();
+ DoBasicAlignmentChecks(1);
+ DoBasicAlignmentChecks(2);
+ DoBasicAlignmentChecks(4);
+ DoBasicAlignmentChecks(8);
+ DoBasicAlignmentChecks(16);
+ DoBasicAlignmentChecks(32);
+ DoBasicAlignmentChecks(256);
DoBasicAlignmentChecks(512);
}
diff --git a/intern/guardedalloc/tests/guardedalloc_overflow_test.cc b/intern/guardedalloc/tests/guardedalloc_overflow_test.cc
index efbfc171fff..1424005e181 100644
--- a/intern/guardedalloc/tests/guardedalloc_overflow_test.cc
+++ b/intern/guardedalloc/tests/guardedalloc_overflow_test.cc
@@ -4,6 +4,8 @@
#include "MEM_guardedalloc.h"
+#include "guardedalloc_test_base.h"
+
/* We expect to abort on integer overflow, to prevent possible exploits. */
#if defined(__GNUC__) && !defined(__clang__)
@@ -31,7 +33,7 @@ void CallocArray(size_t len, size_t size)
} // namespace
-TEST(guardedalloc, LockfreeIntegerOverflow)
+TEST_F(LockFreeAllocatorTest, LockfreeIntegerOverflow)
{
MallocArray(1, SIZE_MAX);
CallocArray(SIZE_MAX, 1);
@@ -44,10 +46,8 @@ TEST(guardedalloc, LockfreeIntegerOverflow)
EXPECT_EXIT(CallocArray(SIZE_MAX, SIZE_MAX), ABORT_PREDICATE, "");
}
-TEST(guardedalloc, GuardedIntegerOverflow)
+TEST_F(GuardedAllocatorTest, GuardedIntegerOverflow)
{
- MEM_use_guarded_allocator();
-
MallocArray(1, SIZE_MAX);
CallocArray(SIZE_MAX, 1);
MallocArray(SIZE_MAX / 2, 2);
diff --git a/intern/guardedalloc/tests/guardedalloc_test_base.h b/intern/guardedalloc/tests/guardedalloc_test_base.h
new file mode 100644
index 00000000000..c56cb9abe29
--- /dev/null
+++ b/intern/guardedalloc/tests/guardedalloc_test_base.h
@@ -0,0 +1,26 @@
+/* Apache License, Version 2.0 */
+
+#ifndef __GUARDEDALLOC_TEST_UTIL_H__
+#define __GUARDEDALLOC_TEST_UTIL_H__
+
+#include "testing/testing.h"
+
+#include "MEM_guardedalloc.h"
+
+class LockFreeAllocatorTest : public ::testing::Test {
+ protected:
+ virtual void SetUp()
+ {
+ MEM_use_lockfree_allocator();
+ }
+};
+
+class GuardedAllocatorTest : public ::testing::Test {
+ protected:
+ virtual void SetUp()
+ {
+ MEM_use_guarded_allocator();
+ }
+};
+
+#endif // __GUARDEDALLOC_TEST_UTIL_H__