Skip to content

Commit

Permalink
tests/libcxx: Test aligned allocation with C++ new operator
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
keith-packard committed May 18, 2023
1 parent a1c2776 commit e278a95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/lib/cpp/libcxx/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ CONFIG_CPP=y
CONFIG_STD_CPP17=y
CONFIG_ZTEST=y
CONFIG_ZTEST_STACK_SIZE=5120
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=32768
CONFIG_ZTEST_NEW_API=y
12 changes: 12 additions & 0 deletions tests/lib/cpp/libcxx/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <memory>
#include <vector>
#include <zephyr/ztest.h>
#include <zephyr/kernel.h>

BUILD_ASSERT(__cplusplus == 201703);

Expand Down Expand Up @@ -95,6 +96,17 @@ ZTEST(libcxx_tests, test_exception)
}
#endif

struct ThreadStack
{
K_KERNEL_STACK_MEMBER(threadStack, 1024) {};
};

ZTEST(libcxx_tests, test_new_aligned)
{
auto test_aligned = std::make_unique<ThreadStack>();
zassert_not_null(test_aligned, "aligned allocation failed");
}

static void *libcxx_tests_setup(void)
{
TC_PRINT("version %u\n", (uint32_t)__cplusplus);
Expand Down

0 comments on commit e278a95

Please sign in to comment.