Skip to content

Commit

Permalink
tests/c_lib: Run basic libc tests using newlib and newlib-nano
Browse files Browse the repository at this point in the history
Validate some basic Zephyr requirements from the newlib C library.

Signed-off-by: Keith Packard <[email protected]>
  • Loading branch information
keith-packard authored and carlescufi committed Jul 11, 2023
1 parent 54155df commit f5e4621
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tests/lib/c_lib/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
* it guarantee that ALL functionality provided is working correctly.
*/

#ifdef CONFIG_NEWLIB_LIBC
#define _POSIX_C_SOURCE 200809
#endif

#include <zephyr/kernel.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/ztest.h>
Expand All @@ -35,6 +39,9 @@
#ifdef CONFIG_PICOLIBC
#include <unistd.h>
#endif
#ifdef CONFIG_NEWLIB_LIBC
#include <unistd.h>
#endif

#define STACK_SIZE (512 + CONFIG_TEST_EXTRA_STACK_SIZE)
#define LIST_LEN 2
Expand Down Expand Up @@ -1083,7 +1090,7 @@ ZTEST(test_c_lib, test_time)
*/
ZTEST(test_c_lib, test_rand)
{
#ifndef CONFIG_PICOLIBC
#ifdef CONFIG_MINIMAL_LIBC
int a;

a = rand();
Expand All @@ -1101,7 +1108,7 @@ ZTEST(test_c_lib, test_rand)
*/
ZTEST(test_c_lib, test_srand)
{
#ifndef CONFIG_PICOLIBC
#ifdef CONFIG_MINIMAL_LIBC
int a;

srand(0);
Expand Down Expand Up @@ -1135,7 +1142,7 @@ ZTEST(test_c_lib, test_srand)
*/
ZTEST(test_c_lib, test_rand_reproducibility)
{
#ifndef CONFIG_PICOLIBC
#ifdef CONFIG_MINIMAL_LIBC
int a;
int b;
int c;
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/c_lib/src/test_strerror.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

#ifdef CONFIG_NEWLIB_LIBC
#define _POSIX_C_SOURCE 200809
#endif

#include <errno.h>
#include <string.h>

Expand Down
13 changes: 13 additions & 0 deletions tests/lib/c_lib/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ tests:
ignore_faults: true
extra_configs:
- CONFIG_PICOLIBC=y
libraries.libc.newlib:
filter: CONFIG_NEWLIB_LIBC_SUPPORTED
tags: newlib
ignore_faults: true
extra_configs:
- CONFIG_NEWLIB_LIBC=y
libraries.libc.newlib_nano:
filter: CONFIG_NEWLIB_LIBC_SUPPORTED and CONFIG_HAS_NEWLIB_LIBC_NANO
tags: newlib
ignore_faults: true
extra_configs:
- CONFIG_NEWLIB_LIBC=y
- CONFIG_NEWLIB_LIBC_NANO=y
libraries.libc.minimal.strerror_table:
tags: minimal_libc
extra_configs:
Expand Down

0 comments on commit f5e4621

Please sign in to comment.