Skip to content

Commit

Permalink
tests: add C++ 17 standard library test
Browse files Browse the repository at this point in the history
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
pabigot authored and galak committed Aug 20, 2019
1 parent 96c1b05 commit aded6a5
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions tests/application_development/libcxx/CMakeLists.txt
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})
7 changes: 7 additions & 0 deletions tests/application_development/libcxx/prj.conf
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
47 changes: 47 additions & 0 deletions tests/application_development/libcxx/src/main.cpp
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);
}
5 changes: 5 additions & 0 deletions tests/application_development/libcxx/testcase.yaml
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

0 comments on commit aded6a5

Please sign in to comment.