diff --git a/CODEOWNERS b/CODEOWNERS index 0c67e951905072..2c21235b280b20 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -369,6 +369,7 @@ /subsys/testsuite/ @nashif /subsys/usb/ @jfischer-phytec-iot @finikorg /tests/ @nashif +/tests/application_development/libcxx/ @pabigot /tests/arch/arm/ @ioannisg /tests/boards/native_posix/ @aescolar /tests/boards/intel_s1000_crb/ @dcpleung @sathishkuttan diff --git a/tests/application_development/libcxx/CMakeLists.txt b/tests/application_development/libcxx/CMakeLists.txt new file mode 100644 index 00000000000000..4fcc2391b6dddf --- /dev/null +++ b/tests/application_development/libcxx/CMakeLists.txt @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(cpp) + +FILE(GLOB app_sources src/*.cpp) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/application_development/libcxx/prj.conf b/tests/application_development/libcxx/prj.conf new file mode 100644 index 00000000000000..aade1fafb7d700 --- /dev/null +++ b/tests/application_development/libcxx/prj.conf @@ -0,0 +1,7 @@ +CONFIG_NEWLIB_LIBC=y +CONFIG_CPLUSPLUS=y +CONFIG_LIB_CPLUSPLUS=y +CONFIG_STD_CPP17=y +CONFIG_HEAP_MEM_POOL_SIZE=1024 +CONFIG_ZTEST=y +CONFIG_ZTEST_STACKSIZE=2048 diff --git a/tests/application_development/libcxx/src/main.cpp b/tests/application_development/libcxx/src/main.cpp new file mode 100644 index 00000000000000..9bac859bf6f590 --- /dev/null +++ b/tests/application_development/libcxx/src/main.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2019 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +BUILD_ASSERT(__cplusplus == 201703); + +std::array array = {1, 2, 3, 4}; +std::vector vector; + +static void test_array(void) +{ + zassert_equal(array.size(), 4, "unexpected size"); + zassert_equal(array[0], 1, "array[0] wrong"); + zassert_equal(array[3], 4, "array[3] wrong"); + + std::array local = {1, 2}; + zassert_equal(local.size(), 2, "unexpected size"); + zassert_equal(local[0], 1, "local[0] wrong"); + zassert_equal(local[1], 2, "local[1] wrong"); +} + +static void test_vector(void) +{ + zassert_equal(vector.size(), 0, "vector init nonzero"); + for (auto v : array) { + vector.push_back(v); + } + zassert_equal(vector.size(), array.size(), "vector store failed"); +} + +void test_main(void) +{ + TC_PRINT("version %u\n", (u32_t)__cplusplus); + ztest_test_suite(libcxx_tests, + ztest_unit_test(test_array), + ztest_unit_test(test_vector) + ); + + ztest_run_test_suite(libcxx_tests); +} diff --git a/tests/application_development/libcxx/testcase.yaml b/tests/application_development/libcxx/testcase.yaml new file mode 100644 index 00000000000000..17cdd168c54de6 --- /dev/null +++ b/tests/application_development/libcxx/testcase.yaml @@ -0,0 +1,5 @@ +tests: + misc.app_dev.libcxx: + arch_exclude: posix + platform_exclude: qemu_x86_coverage qemu_x86_64 + tags: cpp