Skip to content

Commit 5b7b15f

Browse files
stephanosiocfriedt
authored andcommitted
tests: cpp: cxx: Add dynamic memory availability test for static init
This commit adds a test to verify that the dynamic memory allocation service (the `new` operator) is available and functional when the C++ static global object constructors are invoked called during the system initialisation. Signed-off-by: Stephanos Ioannidis <[email protected]> (cherry picked from commit dc4895b)
1 parent e5a92a1 commit 5b7b15f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/subsys/cpp/cxx/src/main.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ static void test_global_static_ctor(void)
6565
zassert_equal(static_foo.get_foo(), 12345678, NULL);
6666
}
6767

68+
/*
69+
* Check that dynamic memory allocation (usually, the C library heap) is
70+
* functional when the global static object constructors are called.
71+
*/
72+
foo_class *static_init_dynamic_foo = new foo_class(87654321);
73+
74+
static void test_global_static_ctor_dynmem(void)
75+
{
76+
zassert_equal(static_init_dynamic_foo->get_foo(), 87654321, NULL);
77+
}
78+
6879
static void test_new_delete(void)
6980
{
7081
foo_class *test_foo = new foo_class(10);
@@ -76,6 +87,7 @@ void test_main(void)
7687
{
7788
ztest_test_suite(cpp_tests,
7889
ztest_unit_test(test_global_static_ctor),
90+
ztest_unit_test(test_global_static_ctor_dynmem),
7991
ztest_unit_test(test_new_delete)
8092
);
8193

0 commit comments

Comments
 (0)