Commit graph

81 commits

Author SHA1 Message Date
Daniel Leung 78fe66834f tests: c_lib/thrd: more stack for up_squared board
Similar to qemu_x86_64, the up_squared needs more stack space
to run the tests.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2024-02-14 19:08:02 +01:00
Keith Packard c4d05b5f9e tests/c_lib: Remove define of _POSIX_C_SOURCE for newlib
This test does not use any APIs beyond those provided in the Zephyr
standard set, so it should not define _POSIX_C_SOURCE.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-02-02 19:54:33 +01:00
Alberto Escolar Piedras f53cf8f54c tests/lib/c_lib: Set standard source macro appropriately
strnlen() and strtok_r() are tested in this files
which are extensions to the the
std C library. Let's explicity select one of the extensions
also when building with the host C library,
instead of relaying on somebody having
set it for this file somewhere else.

Also, let's be nice and undefine them first in case they had
been defined somewhere else in the build scripts.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-01-26 07:48:55 -05:00
Keith Packard 3cc4c5eb7a posix: Use _POSIX_C_SOURCE=200809L instead of 200809
This constant is supposed to be defined as a long instead of an int,
presumably to support systems where int isn't large enough.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-01-26 07:48:55 -05:00
Christopher Friedt dbf7003162 tests: posix + libc: qemu_x86*: use dynamic stack size of 4096
For qemu_x86 and qemu_x86_64, it would seem that
heap-allocated thread stacks, as well as thread stacks
defined via K_THREAD_STACK_ARRAY_DEFINE(), must be at least
4096 bytes in size.

Using those sizes will ensure that these tests do not
fail with stack overflows or MMU faults.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2024-01-26 06:50:11 -05:00
Keith Packard 4f40dd1f95 tests/strerror: Remove test for non-standard strerror_r function
Zephyr does not include this function under Rule A.4: C Standard Library
Usage Restrictions in Zephyr Kernel, hence a conforming C library need not
provide it.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-01-25 12:07:19 +01:00
Ryan McClelland 9804c60a4e tests: lib: c_lib: fix double promotion error
Fix double promotion warnings

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-12-18 09:21:12 +00:00
Martin Åberg 0d0b17095d tests: c_lib: Enable sqrt tests in non-FPU configurations
This enables the sqrt() and sqrtf() tests also in case of soft-float
configurations. It is expected that the tests will link, run and pass
also in such configuration.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2023-12-05 10:47:18 -05:00
Alberto Escolar Piedras 12bf3bae0f tests/lib/c_lib/common: Do not skip part of test for all posix boards
It is not just native_posix that supports the sqrt test,
but all posix arch based ones.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-11-30 09:42:25 -05:00
Peter Mitsis 77abd6f89d tests: Allow thrd test to run on xtensa
On some SMP platforms (such as intel_adsp_ace15_mtpm) it is not
safe to access the stack of a thread that is currently executing
on another CPU. This requires that tests be written such that
objects and data that are shared between threads that may execute
concurrently on different CPUs be placed into memory that is not
a thread's stack.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2023-11-28 14:46:15 -05:00
Christopher Friedt 2fc19aa033 tests: lib: c_lib: tests for C11 call_once()
Add tests for C11 call_once().

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-14 18:23:42 +09:00
Christopher Friedt 44a431bbba tests: lib: c_lib: tests for C11 thread-specific storage
Add tests for C11 thread-specific storage.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-14 18:23:42 +09:00
Christopher Friedt 70b03111eb tests: lib: c_lib: tests for C11 condition variables
Add tests for C11 condition variables.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-14 18:23:42 +09:00
Christopher Friedt 0c2da383d3 tests: lib: c_lib: add tests for C11 mutexes
Add tests to cover C11 mutexes

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-14 18:23:42 +09:00
Christopher Friedt ded97fd5b3 tests: libc: add tests for iso c11 threads
Add tests to verify functionality of the C11 `<threads.h>` API.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-14 18:23:42 +09:00
Christopher Friedt dd27dff492 tests: lib: c_lib: separate libc tests into smaller suites
C library testing is mainly there to support what is
necessary to support Zephyr. We do test a variety of libcs
currently, which is where YAML comes in handy.

However, the main libc testsuite can be overkill for testing
some things, and might not be suitable for testing optional
features.

Create a 'common' subdirectory for common libc tests.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-14 18:23:42 +09:00
Keith Packard 6d38ecae1d tests/c_lib: Test picolibc module configurations
Make sure the picolibc module builds and runs in both TLS
and non-TLS variants.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-11-07 09:42:19 +01:00
Keith Packard 51fee43122 tests/c_lib: Run tests on native/posix targets
With a few minor adjustments, these tests now run fine on native
targets.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-10-26 10:06:35 -04:00
Keith Packard 8780bd2b70 test/c_lib: Make sure time_t is at least 64-bits
Check to ensure that the C library doesn't have obvious 2038 issues.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-10-26 10:06:35 -04:00
Keith Packard 83db6ee7f5 test/c_lib: Skip strerror invalid input test for EXTERNAL_LIBC
Passing an invalid errno value to strerror is undefined behavior in
POSIX. While all Zephyr-specific C libraries may be required to return a
specific value, we can't hold an external C library to that standard.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-10-26 10:06:35 -04:00
Keith Packard e4681a0634 test/c_lib: Don't fail to compile tests with 32-bit time_t
The native library may use a 32-bit time_t, so we need to avoid
having the compiler generate an error during compilation.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-10-26 10:06:35 -04:00
Keith Packard dfd584204c test/c_lib: Skip 'abort' test for EXTERNAL_LIBC
The native C library abort function isn't trapped within Zephyr.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-10-26 10:06:35 -04:00
Keith Packard 8283f8ca09 test/c_lib: Skip 'exit' test for EXTERNAL_LIBC
The native C library exit function does not do what we want.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-10-26 10:06:35 -04:00
Anas Nashif 345735d0a8 tests: remove CONFIG_ZTEST_NEW_API in all tests
Remove all usage of CONFIG_ZTEST_NEW_API from tests and sample as this
is now enabled by default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Ryan McClelland f851d2a61b tests: lib: c_lib: fix test_sqrt double promotion warnings
Double promotion warnings are generated with the flag -Wdouble-promotion
Exponent was defined as a float, but was really be used a double here
Change the type of exponent in sqrt from float to double.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2023-07-21 06:30:32 -04:00
Francois Ramu 256b0c5bfb tests: lib: c_lib testcase running with 32KB min ram
Limit the testcase to targets with more than 32KB RAM
Because of the CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE 8192,
the RAM used by the testcase on a too small target might fail
at runtime. For example on a nucleo_l073rz target:
    RAM:       15292 B        20 KB     74.67%

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2023-07-20 04:40:57 -04:00
Lawrence King 7dae27a90d libc: minimal: math sqrt: sqrtf: fix numeric accuracy of sqrt and sqrtf.
Changed initial guess from a simple x/3 to dividing the exponent by 2.
This makes large or small numbers like 10e10 and 01e-10 converge in a few
loops.

Added a loop counter to ensure that the algorithm breaks out of the loop in
the case that the algorithm doesn't converge (toggling between two
numbers).

Added test cases for sqrt and sqrtf in libc. Tested with a range of numbers
between 10e10 and 10e-10. Verify good accuracy in test case.

Closes: #55962

Signed-off-by: Lawrence King <lawrencek52@gmail.com>
2023-07-14 12:42:41 -04:00
Keith Packard f5e462137f tests/c_lib: Run basic libc tests using newlib and newlib-nano
Validate some basic Zephyr requirements from the newlib C library.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-07-11 09:42:55 +02:00
Alberto Escolar Piedras ee67bdfc56 tests libC: Filter based on type of target not whole arch
The POSIX arch now also supports embedded libCs for some
targets. Narrow the test filter accordingly.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-26 16:16:46 +02:00
Anas Nashif 0064b6e8b6 tests: samples: cleanup test tags, add integration_platforms
Use integration platforms and sanitize tags.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-06-02 04:47:06 -04:00
Kumar Gala f66b149742 tests: c_lib: test exit not _exit
Tweak test to test exit and not _exit, as _exit is not a standard
libc function.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-05-09 11:53:41 -07:00
Alberto Escolar Piedras d22a343887 tests: Use posix arch exclude where appropriate
Some tests were filtering by explicitly listing
all posix arch boards.
Filter by the arch instead.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-05-04 16:48:01 -04:00
Kumar Gala 0e43b8861b libc: fix armclang compiler warnings with is*() functions
We get compile warnings of the form:

error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
 [-Werror,-Wint-in-bool-context]
                if (!isprint(byte)) {
                     ^

Since isprint (and the other is* functions) return an int, change check
to an explicit test against the return value.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-04 13:47:34 +02:00
Kumar Gala 831bd2f841 armclang: fix compiler warnings with isprint()
We get compile warnings of the form:

drivers/console/uart_console.c:508:8: error: converting the result of
'<<' to a boolean; did you mean
'((__aeabi_ctype_table_ + 1)[(byte)] << 28) != 0'?
 [-Werror,-Wint-in-bool-context]
                if (!isprint(byte)) {
                     ^

Since isprint returns an int, change check to an explicit test against
the return value.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-03-17 09:30:01 +01:00
Anas Nashif 0bc4fd4cb9 tests: fix various test identifiers
lib -> libraries to be consistent with everything else.
And fix identifier for a few stray tests that were wrongly
labeled/tagged.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-02-06 10:06:10 +01:00
Andrei Emeltchenko e8f0e66bc4 tests: libc: Fix "unused" type of warnings
Follow example several lines below and fix warnings from static tools.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-01-05 08:00:09 -05:00
Anas Nashif 808266a493 tests: use ignore_fault field instead of tags
Use dedicated field in the yaml file instead of mixing this testing
feature with tags.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-25 06:38:05 -05:00
Michał Barnaś dae8efa692 ztest: remove the obsolete NULL appended to zassert macros
This commit removes the usage of NULL parameter as message in
zassert_* macros after making it optional

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-09-09 07:05:38 -04:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Fabio Baltieri def230187b test: fix more legacy #include paths
Add a bunch of missing "zephyr/" prefixes to #include statements in
various test and test framework files.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-08-02 16:41:41 +01:00
Anas Nashif 02f2896586 tests: add mising braces to single line if statements
Following zephyr's style guideline, all if statements, including single
line statements shall have braces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-07-06 11:00:45 -04:00
Christopher Friedt e08f84ab0b tests: lib: c_libc: tests for strerror, strerror_r
Add tests for strerror() and strerror_r()

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-07-04 22:53:36 +02:00
Keith Packard 7da1fca3d4 tests/c_lib: Let picolibc pick a malloc heap size
Now that picolibc's malloc arena configuration always allocates
some space, we don't need explicit allocations for tests.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-30 10:33:24 +02:00
Lauren Murphy ef3e66c2bc tests: lib: c_lib: ifndef out gcc pragmas
Ifndefs out GCC pragmas causing build failures for
compilers with older GNUC versions, e.g. XCC <= 2020.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2022-06-28 14:38:54 -04:00
Keith Packard d0a788669e tests: Add picolibc tests
This adds picolibc-specific configurations for a couple of tests

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-22 13:15:55 +02:00
Keith Packard 8bbad143ca tests/c_lib: Ignore stringop-overflow warning
One test reads too few bytes from the source to ensure nul-termination of
the result which generates a compiler warning.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-22 13:15:55 +02:00
Keith Packard 88cfad5531 tests/c_lib: Don't assume a particular PRNG from Picolibc [v2]
The random/rand tests assume the PRNG operates in a specific fashion,
which is not true when running Picolibc.

v2:
	Call ztest_test_skip for picolibc

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-22 13:15:55 +02:00
Stephanos Ioannidis 4735e10630 libc: minimal: Introduce CONFIG_MINIMAL_LIBC_NON_REENTRANT_FUNCTIONS
This commit introduces a new configuration called
`CONFIG_MINIMAL_LIBC_NON_REENTRANT_FUNCTIONS`, which enables the
traditional non-reentrant (i.e. not thread-safe) version of the C
standard library functions such as rand() and gmtime() when the
respective configs are enabled.

The non-reentrant functions make use of the globals and require an
additional memory partition (MPU region), which is scarce on low-end
devices, when CONFIG_USERSPACE=y.

The purpose of this option is to classify the MPU resource intensive
functions as a separate category and only enable them when there is a
demand for such.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-06-01 11:03:38 +02:00
Keith Packard ced4ff29ea tests/c_lib: Set _GNU_SOURCE for qsort_r test
qsort_r is a GNU addition, so we need to #define _GNU_SOURCE to ensure
the prototype is defined in the header file.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-05-27 15:34:34 -07:00
Gerard Marull-Paretas ade7ccb918 tests: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all tests to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:02:14 +02:00