Skip to content

Commit 023d0e9

Browse files
keith-packardnashif
authored andcommitted
tests/libcxx: Test aligned allocation with C++ new operator
Make sure the underlying allocation system can support an allocation request generated by the new operator which has stricter alignment requirements than the default. For G++, this ends up using the 'memalign' function which is not part of any C standard. Signed-off-by: Keith Packard <[email protected]>
1 parent 101cdcd commit 023d0e9

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tests/lib/cpp/libcxx/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ CONFIG_CPP=y
22
CONFIG_STD_CPP17=y
33
CONFIG_ZTEST=y
44
CONFIG_ZTEST_STACK_SIZE=5120
5+
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=32768
56
CONFIG_ZTEST_NEW_API=y

tests/lib/cpp/libcxx/src/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <memory>
1010
#include <vector>
1111
#include <zephyr/ztest.h>
12+
#include <zephyr/kernel.h>
1213

1314
BUILD_ASSERT(__cplusplus == 201703);
1415

@@ -95,6 +96,17 @@ ZTEST(libcxx_tests, test_exception)
9596
}
9697
#endif
9798

99+
struct ThreadStack
100+
{
101+
K_KERNEL_STACK_MEMBER(threadStack, 1024) {};
102+
};
103+
104+
ZTEST(libcxx_tests, test_new_aligned)
105+
{
106+
auto test_aligned = std::make_unique<ThreadStack>();
107+
zassert_not_null(test_aligned, "aligned allocation failed");
108+
}
109+
98110
static void *libcxx_tests_setup(void)
99111
{
100112
TC_PRINT("version %u\n", (uint32_t)__cplusplus);

0 commit comments

Comments
 (0)