-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <vincent.wan@linaro.org>
- Loading branch information
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
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}) |
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,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 |
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,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); | ||
} |
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,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); | ||
} |
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,6 @@ | ||
tests: | ||
portability.posix: | ||
tags: posix | ||
arch_exclude: posix | ||
filter: TOOLCHAIN_HAS_NEWLIB == 1 | ||
min_ram: 64 |