This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/intern/guardedalloc/tests/guardedalloc_alignment_test.cc
Campbell Barton c434782e3a File headers: SPDX License migration
Use a shorter/simpler license convention, stops the header taking so
much space.

Follow the SPDX license specification: https://spdx.org/licenses

- C/C++/objc/objc++
- Python
- Shell Scripts
- CMake, GNUmakefile

While most of the source tree has been included

- `./extern/` was left out.
- `./intern/cycles` & `./intern/atomic` are also excluded because they
  use different header conventions.

doc/license/SPDX-license-identifiers.txt has been added to list SPDX all
used identifiers.

See P2788 for the script that automated these edits.

Reviewed By: brecht, mont29, sergey

Ref D14069
2022-02-11 09:14:36 +11:00

59 lines
1.3 KiB
C++

/* SPDX-License-Identifier: Apache-2.0 */
#include "testing/testing.h"
#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)
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_F(LockFreeAllocatorTest, MEM_mallocN_aligned)
{
DoBasicAlignmentChecks(1);
DoBasicAlignmentChecks(2);
DoBasicAlignmentChecks(4);
DoBasicAlignmentChecks(8);
DoBasicAlignmentChecks(16);
DoBasicAlignmentChecks(32);
DoBasicAlignmentChecks(256);
DoBasicAlignmentChecks(512);
}
TEST_F(GuardedAllocatorTest, MEM_mallocN_aligned)
{
DoBasicAlignmentChecks(1);
DoBasicAlignmentChecks(2);
DoBasicAlignmentChecks(4);
DoBasicAlignmentChecks(8);
DoBasicAlignmentChecks(16);
DoBasicAlignmentChecks(32);
DoBasicAlignmentChecks(256);
DoBasicAlignmentChecks(512);
}