tests: Add base test for C++ exceptions handling.

Try to throw and catch C++ exception of int type.

Related to: #32448 and #34229


Signed-off-by: Artur Lipowski <Artur.Lipowski@hidglobal.com>
This commit is contained in:
Artur Lipowski 2021-04-14 18:26:07 +02:00 committed by Carles Cufí
commit bc2ad24d1a
2 changed files with 31 additions and 2 deletions

View file

@ -67,14 +67,42 @@ static void test_make_unique(void)
zassert_equal(make_unique_data::dtors, 1, "dtor count not incremented"); zassert_equal(make_unique_data::dtors, 1, "dtor count not incremented");
} }
#if defined(CONFIG_EXCEPTIONS)
static void throw_exception(void)
{
throw 42;
}
static void test_exception(void)
{
try
{
throw_exception();
}
catch (int i)
{
zassert_equal(i, 42, "Incorrect exception value");
return;
}
zassert_unreachable("Missing exception catch");
}
#else
static void test_exception(void)
{
ztest_test_skip();
}
#endif
void test_main(void) void test_main(void)
{ {
TC_PRINT("version %u\n", (uint32_t)__cplusplus); TC_PRINT("version %u\n", (uint32_t)__cplusplus);
ztest_test_suite(libcxx_tests, ztest_test_suite(libcxx_tests,
ztest_unit_test(test_array), ztest_unit_test(test_array),
ztest_unit_test(test_vector), ztest_unit_test(test_vector),
ztest_unit_test(test_make_unique) ztest_unit_test(test_make_unique),
ztest_unit_test(test_exception)
); );
ztest_run_test_suite(libcxx_tests); ztest_run_test_suite(libcxx_tests);
} }

View file

@ -13,5 +13,6 @@ tests:
toolchain_exclude: xcc toolchain_exclude: xcc
min_flash: 54 min_flash: 54
tags: cpp tags: cpp
timeout: 5
extra_configs: extra_configs:
- CONFIG_EXCEPTIONS=y - CONFIG_EXCEPTIONS=y