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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
26
intern/guardedalloc/tests/guardedalloc_test_base.h
Normal file
26
intern/guardedalloc/tests/guardedalloc_test_base.h
Normal file
@@ -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__
|
Reference in New Issue
Block a user