From d63d5b847dc31afaefb3cb952da420892bf1f8bb Mon Sep 17 00:00:00 2001 From: Vincent Wan Date: Wed, 20 Feb 2019 14:11:44 -0800 Subject: [PATCH] tests: posix: Add test with both pthread and newlib enabled This commit adds a test case that reproduces sdk-ng#45. Signed-off-by: Vincent Wan --- tests/posix/newlib/CMakeLists.txt | 8 +++++++ tests/posix/newlib/prj.conf | 6 +++++ tests/posix/newlib/src/main.c | 17 +++++++++++++ tests/posix/newlib/src/test.c | 40 +++++++++++++++++++++++++++++++ tests/posix/newlib/testcase.yaml | 6 +++++ 5 files changed, 77 insertions(+) create mode 100644 tests/posix/newlib/CMakeLists.txt create mode 100644 tests/posix/newlib/prj.conf create mode 100644 tests/posix/newlib/src/main.c create mode 100644 tests/posix/newlib/src/test.c create mode 100644 tests/posix/newlib/testcase.yaml diff --git a/tests/posix/newlib/CMakeLists.txt b/tests/posix/newlib/CMakeLists.txt new file mode 100644 index 00000000000000..a4a187f83e9373 --- /dev/null +++ b/tests/posix/newlib/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.13.1) +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(posix_newlib) + +target_include_directories(app PRIVATE $ENV{ZEPHYR_BASE}/include/) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/tests/posix/newlib/prj.conf b/tests/posix/newlib/prj.conf new file mode 100644 index 00000000000000..2d7e102f8e8304 --- /dev/null +++ b/tests/posix/newlib/prj.conf @@ -0,0 +1,6 @@ +CONFIG_NEWLIB_LIBC=y +CONFIG_PTHREAD_IPC=y +CONFIG_POSIX_API=y +CONFIG_MAX_PTHREAD_COUNT=20 +CONFIG_ZTEST=y +CONFIG_MAIN_STACK_SIZE=4096 diff --git a/tests/posix/newlib/src/main.c b/tests/posix/newlib/src/main.c new file mode 100644 index 00000000000000..59ce958edf7530 --- /dev/null +++ b/tests/posix/newlib/src/main.c @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2019 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +extern void test_posix_newlib(void); + +void test_main(void) +{ + ztest_test_suite(posix_newlib_test, + ztest_unit_test(test_posix_newlib) + ); + ztest_run_test_suite(posix_newlib_test); +} diff --git a/tests/posix/newlib/src/test.c b/tests/posix/newlib/src/test.c new file mode 100644 index 00000000000000..9260b612048004 --- /dev/null +++ b/tests/posix/newlib/src/test.c @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2019 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +static int test(void) +{ + int *res = NULL; + int ret; + pthread_attr_t attr; + + /* Using something from POSIX */ + ret = pthread_attr_init(&attr); + + /* Using something from libc */ + res = malloc(10); + + if ((res != NULL) && (ret == 0)) { + TC_PRINT("\nhello world!\n"); + } else { + return TC_FAIL; + } + + free(res); + + /* We have gotten this far, so the build succeeded with both + * POSIX and newlib enabled. + */ + return TC_PASS; +} + +void test_posix_newlib(void) +{ + zassert_true(test() == TC_PASS, NULL); +} diff --git a/tests/posix/newlib/testcase.yaml b/tests/posix/newlib/testcase.yaml new file mode 100644 index 00000000000000..d7ef761bd030e4 --- /dev/null +++ b/tests/posix/newlib/testcase.yaml @@ -0,0 +1,6 @@ +tests: + portability.posix: + tags: posix + arch_exclude: posix + filter: TOOLCHAIN_HAS_NEWLIB == 1 + min_ram: 64