summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bx/tests/allocator_test.cpp
diff options
context:
space:
mode:
author Miodrag Milanović <mmicko@gmail.com>2023-01-05 15:32:40 +0100
committer GitHub <noreply@github.com>2023-01-05 09:32:40 -0500
commit812e6094f47bb8d1da5a6b421aa4c724cf2035c0 (patch)
tree0f5bab2fe9393d1f629e9bf63e76cecca74ec0c9 /3rdparty/bx/tests/allocator_test.cpp
parent4a1b41854bba8fc2567906b88bab8ca81e75d187 (diff)
Update BGFX, BX and BIMG (#10789)
* Update to bgfx a93a714632b79b5ddbf5c86ac323fa9b76ed3433 Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
Diffstat (limited to '3rdparty/bx/tests/allocator_test.cpp')
-rw-r--r--3rdparty/bx/tests/allocator_test.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/3rdparty/bx/tests/allocator_test.cpp b/3rdparty/bx/tests/allocator_test.cpp
new file mode 100644
index 00000000000..635d01a3175
--- /dev/null
+++ b/3rdparty/bx/tests/allocator_test.cpp
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2010-2022 Branimir Karadzic. All rights reserved.
+ * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
+ */
+
+#include "test.h"
+
+#include <bx/allocator.h>
+
+struct MockNonFreeingAllocator : public bx::AllocatorI
+{
+ MockNonFreeingAllocator()
+ : m_sbrk(1)
+ {
+ }
+
+ ~MockNonFreeingAllocator() override
+ {
+ }
+
+ void* realloc(void* _ptr, size_t _size, size_t _align, const char* _file, uint32_t _line) override
+ {
+ BX_ASSERT(_ptr == NULL, "MockNonFreeingAllocator can't realloc or free.");
+ BX_ASSERT(m_sbrk + _size < BX_COUNTOF(m_storage), "");
+ BX_UNUSED(_ptr, _file, _line);
+
+ const uint32_t sbrk = bx::alignUp(m_sbrk, bx::max(_align, 1) );
+ m_sbrk = sbrk + _size;
+
+ return &m_storage[sbrk];
+ }
+
+ uint32_t m_sbrk;
+ BX_ALIGN_DECL(256, uint8_t) m_storage[0x10000];
+};
+
+bool testAlignment(size_t _expected, void* _ptr)
+{
+ bool aligned = bx::isAligned(_ptr, _expected);
+// BX_TRACE("%p, %d", _ptr, _expected);
+ BX_WARN(aligned, "%p not aligned to %d bytes.", _ptr, _expected);
+ return aligned;
+}
+
+TEST_CASE("Allocator", "")
+{
+ MockNonFreeingAllocator mnfa;
+
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(2, bx::alloc (&mnfa, 1, 2 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(4, bx::alloc (&mnfa, 1, 4 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(8, bx::alloc (&mnfa, 1, 8 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(16, bx::alloc (&mnfa, 1, 16 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(32, bx::alloc (&mnfa, 1, 32 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(64, bx::alloc (&mnfa, 1, 64 ) ) );
+ REQUIRE(testAlignment(1, bx::alloc (&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(128, bx::alloc (&mnfa, 1, 128) ) );
+
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(2, bx::alignedAlloc(&mnfa, 1, 2 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(4, bx::alignedAlloc(&mnfa, 1, 4 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(8, bx::alignedAlloc(&mnfa, 1, 8 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(16, bx::alignedAlloc(&mnfa, 1, 16 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(32, bx::alignedAlloc(&mnfa, 1, 32 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(64, bx::alignedAlloc(&mnfa, 1, 64 ) ) );
+ REQUIRE(testAlignment(1, bx::alignedAlloc(&mnfa, 1, 1 ) ) );
+ REQUIRE(testAlignment(128, bx::alignedAlloc(&mnfa, 1, 128) ) );
+}