forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add C++ 17 standard library test
Confirms build (and run) of C++17 applications that make use of STL containers and other features. Signed-off-by: Peter Bigot <[email protected]>
- Loading branch information
Showing
5 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2019 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <vector> | ||
#include <array> | ||
#include <functional> | ||
#include <ztest.h> | ||
|
||
BUILD_ASSERT(__cplusplus == 201703); | ||
|
||
std::array<int, 4> array = {1, 2, 3, 4}; | ||
std::vector<int> 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<u8_t, 2> 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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tests: | ||
misc.app_dev.libcxx: | ||
arch_exclude: posix | ||
platform_exclude: qemu_x86_coverage qemu_x86_64 | ||
tags: cpp |