Skip to content

Commit e5a92a1

Browse files
stephanosiocfriedt
authored andcommitted
tests: cpp: cxx: Add static global constructor invocation test
This commit adds a test to verify that the C++ static global object constructors are invoked called during the system initialisation. Signed-off-by: Stephanos Ioannidis <[email protected]> (cherry picked from commit 6e0063a)
1 parent 74f0b64 commit e5a92a1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ static int test_init(const struct device *dev)
5757

5858
SYS_INIT(test_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
5959

60+
/* Check that global static object constructors are called. */
61+
foo_class static_foo(12345678);
62+
63+
static void test_global_static_ctor(void)
64+
{
65+
zassert_equal(static_foo.get_foo(), 12345678, NULL);
66+
}
6067

6168
static void test_new_delete(void)
6269
{
@@ -68,6 +75,7 @@ static void test_new_delete(void)
6875
void test_main(void)
6976
{
7077
ztest_test_suite(cpp_tests,
78+
ztest_unit_test(test_global_static_ctor),
7179
ztest_unit_test(test_new_delete)
7280
);
7381

0 commit comments

Comments
 (0)