Skip to content

Commit

Permalink
tests: posix: Add test with both pthread and newlib enabled
Browse files Browse the repository at this point in the history
This commit adds a test case that reproduces sdk-ng#45.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
  • Loading branch information
vanti committed Feb 20, 2019
1 parent b75115a commit d63d5b8
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/posix/newlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
6 changes: 6 additions & 0 deletions tests/posix/newlib/prj.conf
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions tests/posix/newlib/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2019 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <ztest.h>

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);
}
40 changes: 40 additions & 0 deletions tests/posix/newlib/src/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2019 Linaro Limited
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <ztest.h>
#include <stdlib.h>
#include <posix/pthread.h>

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);
}
6 changes: 6 additions & 0 deletions tests/posix/newlib/testcase.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
tests:
portability.posix:
tags: posix
arch_exclude: posix
filter: TOOLCHAIN_HAS_NEWLIB == 1
min_ram: 64

0 comments on commit d63d5b8

Please sign in to comment.