Skip to content

Commit 26bedf0

Browse files
committed
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]>
1 parent 3aee7b8 commit 26bedf0

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@
368368
/subsys/testsuite/ @nashif
369369
/subsys/usb/ @jfischer-phytec-iot @finikorg
370370
/tests/ @nashif
371+
/tests/application_development/libcxx/ @pabigot
371372
/tests/arch/arm/ @ioannisg
372373
/tests/boards/native_posix/ @aescolar
373374
/tests/boards/intel_s1000_crb/ @dcpleung @sathishkuttan
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
5+
project(cpp)
6+
7+
FILE(GLOB app_sources src/*.cpp)
8+
target_sources(app PRIVATE ${app_sources})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CONFIG_NEWLIB_LIBC=y
2+
CONFIG_CPLUSPLUS=y
3+
CONFIG_LIB_CPLUSPLUS=y
4+
CONFIG_STD_CPP17=y
5+
CONFIG_HEAP_MEM_POOL_SIZE=1024
6+
CONFIG_ZTEST=y
7+
CONFIG_ZTEST_STACKSIZE=2048
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2019 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <vector>
8+
#include <array>
9+
#include <functional>
10+
#include <ztest.h>
11+
12+
BUILD_ASSERT(__cplusplus == 201703);
13+
14+
std::array<int, 4> array = {1, 2, 3, 4};
15+
std::vector<int> vector;
16+
17+
static void test_array(void)
18+
{
19+
zassert_equal(array.size(), 4, "unexpected size");
20+
zassert_equal(array[0], 1, "array[0] wrong");
21+
zassert_equal(array[3], 4, "array[3] wrong");
22+
23+
std::array<u8_t, 2> local = {1, 2};
24+
zassert_equal(local.size(), 2, "unexpected size");
25+
zassert_equal(local[0], 1, "local[0] wrong");
26+
zassert_equal(local[1], 2, "local[1] wrong");
27+
}
28+
29+
static void test_vector(void)
30+
{
31+
zassert_equal(vector.size(), 0, "vector init nonzero");
32+
for (auto v : array) {
33+
vector.push_back(v);
34+
}
35+
zassert_equal(vector.size(), array.size(), "vector store failed");
36+
}
37+
38+
void test_main(void)
39+
{
40+
TC_PRINT("version %u\n", (u32_t)__cplusplus);
41+
ztest_test_suite(libcxx_tests,
42+
ztest_unit_test(test_array),
43+
ztest_unit_test(test_vector)
44+
);
45+
46+
ztest_run_test_suite(libcxx_tests);
47+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
tests:
2+
misc.app_dev.libcxx:
3+
arch_exclude: posix
4+
platform_exclude: qemu_x86_coverage qemu_x86_64
5+
tags: cpp

0 commit comments

Comments
 (0)