Commit graph

162 commits

Author SHA1 Message Date
Chris Friedt 93e67fb73f tests: posix: add coverage for fnmatch
Previously, the `fnmatch()` function was available in `lib/util`
but it did not have any test coverage.

After moving it to `lib/posix`, add test coverage to the POSIX
testsuite.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-03-03 17:40:14 +09:00
Guillaume Gautier 4f129551d4 tests: posix: headers: Add min_ram to fix nucleo_f103rb compilation error
Compilation of this test on nucleo_f103rb fails because "region 'RAM'
overflowed by 136 bytes". Since this board has a ram size of 20k, we set
the limit for this test at the next usual size 32k.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
2023-02-06 10:06:45 +01:00
Chris Friedt ab6102f70f tests: posix: existence tests for standard POSIX includes
Add a trivial suite that simply ensures headers exist and that
they supply standard symbols and constants.

These tests are intended to be ordered exactly as the respective
feature appears in the respective specification at

https://pubs.opengroup.org/onlinepubs/9699919799

Over time, as POSIX support improves, we can enable additional
checks.

If `CONFIG_POSIX_API=n`, then we simply ensure that the header
can be included, that constants and structures exist, including
the existence of required fields in each structure.

We check that a constant exist, by comparing its value against
an arbitrary number. If the constant does not exist, it would
of course be a compile error.

```
zassert_not_equal(-1, POLLIN);
```

We check that a structure contains required fields by
comparing the field offset with an arbitrary number. If
the field does not exist, of course, there would be a
compile error.

```
zassert_not_equal(-1, offsetof(struct pollfd, fd));
```

For non-scalar constants, we simply attempt to assign
a value to the specific type:

```
struct in6_addr any6 = IN6ADDR_ANY_INIT;
```

If `CONFIG_POSIX_API=y`, then we additionally check that required
functions are non-NULL (limited to what is currently supported in
Zephyr).

```
zassert_not_null(pthread_create);
```

Note: functional verification tests should be done outside of this
test suite.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-23 09:57:31 -08:00
Chris Friedt 1f20503e46 tests: posix: common: avoid direct pthread_attr_t field access
Avoid directly accessing fields in `pthread_attr_t` and only
access / mutate them with POSIX functions.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt 7be31813da posix: sched: use newlib-compatible SCHED_RR FIFO definitions
Zephyr's `SCHED_RR` and `SCHED_FIFO` definitions were slightly
different than Newlib's. Additionally, the test had hard-coded
magic numbers instead of using symbolic values.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt ecb82784b7 posix: newlib compatible PTHREAD_CREATE_DETACHED and JOINABLE
Define `PTHREAD_CREATE_DETACHED` and
`PTHREAD_CREATE_JOINABLE` to be compatible with the Newlib
definitions.

This is a temporary workaround for #51211 until Newlib
headers are pulled in.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt d1e7ccec24 tests: posix: common: remove duplicate call to pthread_attr_init
There was a second call to `pthread_attr_init()` that reallly had
no sense being there. Also, it seems that there was a call to
`pthread_attr_destroy()` out of perhaps paranoia.

The duplicate call and `pthread_attr_destroy()` can be removed.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-10 09:02:21 +09:00
Chris Friedt 8e4137f149 tests: posix: clock: ensure overflow is consistent
Add a test to verify previous fixes when calculating time in
seconds for `clock_gettime()`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-01-04 21:12:58 +01:00
Fabio Baltieri 7db1d17ee3 yamllint: fix all yamllint line-length errors
Fix all line-length errors detected by yamllint:

yamllint -f parsable -c .yamllint $( find -regex '.*\.y[a]*ml' ) | \
  grep '(line-length)'

Using a limit is set to 100 columns, not touching the commandlines in
GitHub workflows (at least for now).

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-01-04 01:16:45 +09:00
Chris Friedt ff3aaa6ef3 posix: getopt: move declarations to unistd.h
Declarations for `getopt()` should be in `<unistd.h>`
according to the spec. The extended versions `getopt_long()`
and `getopt_long_only()` are declared in `<getopt.h>`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-12-04 14:51:52 +01:00
Chris Friedt 027b79ecc4 tests: posix: add tests for sleep() and usleep()
Previously, there was no test coverage for `sleep()` and
`usleep()`.

This change adds full test coverage.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-24 19:31:33 -05:00
Chris Friedt 23a1f0a672 tests: posix: clock: do not use usleep in a broken way
Using `usleep()` for >= 10000000 microseconds results
in an error, so this test was kind of defective, having
explicitly called `usleep()` for seconds.

Also, check the return values of `clock_gettime()`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-24 19:31:33 -05:00
Chris Friedt 909185f79c tests: posix: cond: test to ensure there is no resource leakage
Add a test to ensure that `pthread_cond_t` can be used over
and over again and that there is no resource leakage with proper
usage.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-19 14:16:38 +09:00
Chris Friedt 47d09c04af tests: posix: mutex: test to ensure there is no resource leakage
Add a test to ensure that `pthread_mutex_t` can be used over
and over again and that there is no resource leakage with proper
usage.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-15 05:56:31 +09:00
Chris Friedt ce054404a2 posix: use uint32_t instead of void* for pthread_t
Several other widely-used pthread implementations
abstract `pthread_t` as `uint32_t`. The benefit
there is that we avoid passing around a pointer to
an internal structure (implementation detail).

Additionally, this removes the alias from `k_tid_t`
to `pthread_t` inside of `struct pthread_mutex`.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2022-11-02 15:39:44 +09: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
Manuel Arguelles 7f26c1c25c tests: samples: revert timeout change for FVP BaseR
Partially revert commit 0028e9733295316d152eba07bf56677d83f4b1b5.
Timeout for tests/posix/common must be still increased for slow
platforms (previously was 120 sec).

Signed-off-by: Manuel Arguelles <manuel.arguelles@nxp.com>
2022-08-16 15:51:38 +02:00
Stephanos Ioannidis c19fbce9d1 tests: posix: common: Disable for qemu_leon3
This commit disables the `tests/posix/common` test for the `qemu_leon3`
platform because of the alignment-related failure reported in the
GitHub issue zephyrproject-rtos/zephyr#48992.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-12 10:35:19 +01: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
Christopher Friedt fe8dcdf4a3 tests: posix: eventfd: make min_ram a common test parameter
Some platforms with insufficient ram were incorrectly included
in this test since #47288.

Fixes #47734

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-07-13 11:56:42 -04:00
Christopher Friedt d37350bc19 tests: posix: pthread: test for pthread descriptor leaks
Add a simple test to ensure that we can create and join a
single thread `CONFIG_MAX_PTHREAD_COUNT` * 2 times. If
there are leaks, then `pthread_create()` should
eventually return `EAGAIN`. If there are no leaks, then
the test should pass.

Fixes #47609

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-07-12 10:16:02 +02:00
Manuel Arguelles f2ae4b67b2 tests: samples: bump timeout for FVP BaseR board
Timeout must be increased for fvp_baser_aemv8r_aarch32 board. Enabling
MPU on this board makes simulation slower.

Signed-off-by: Manuel Arguelles <manuel.arguelles@nxp.com>
2022-07-11 11:17:02 +02:00
Christopher Friedt 5874b8424c tests: posix: increase coverage for picolibc
This change adds coverage for picolibc in
* tests/posix/eventfd
* tests/posix/eventfd_basic
* tests/posix/getopt

Fixes #47288

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-07-05 12:53:49 -04:00
Christopher Friedt 0583ef71f5 tests: posix: additional tests against newlib
Add test permutations that run against the newlib
libc against
* tests/posix/eventfd
* tests/posix/eventfd_basic
* tests/posix/getopt

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-07-05 12:53:49 -04:00
Christopher Friedt 2bf3b45cbb tests: posix: consistent naming and tagging for posix tests
* ensure test permutations are prefixed with `portability.posix`
* ensure test permutations include the `posix` tag
* ensure consistent order of `arch_exclude` and `tags`

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-07-05 12:53:49 -04:00
Christopher Friedt f51b0f9883 tests: posix: getopt: remove unnecessary filter
Since `CONFIG_GETOPT=y` is specified in `prj.conf`,
it does not make sense to filter for `CONFIG_GETOPT`.

Additionally, we should run a permutation explicitly
with newlib, for consistency.

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-07-05 12:53:49 -04:00
Reto Schneider 7a6c5710ff cmake: Update cmake_minimum_required to 3.20.0
As Zephyr currently requires CMake version 3.20.0, update all
occurrences of cmake_minimum_required.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2022-07-04 10:18:45 +02:00
Keith Packard bea139f0f4 tests/posix/common: 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
Christopher Friedt d0f497c821 tests: posix: use new ztest api
* Convert test suite declaration to `ZTEST_SUITE()`
  and test case declaration to `ZTEST()`.
* add `CONFIG_ZTEST_NEW_API=y` to prj.conf

Fixes #46793

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-06-28 11:07:12 +02: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
Rico Ganahl 1cf7361f44 tests/posix/fs: extend readdir test
Test Zephyr POSIX readdir implementation for native POSIX behavior.

Signed-off-by: Rico Ganahl <rico.ganahl@bytesatwork.ch>
2022-05-13 11:10:04 -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
Anas Nashif 2d97bdd85d samples: add module requirement into samples
Do not build those samples if the needed modules are not available in
the workspace.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-04-19 09:38:55 -04:00
Christopher Friedt ddf3c57a39 tests: posix: test support for pthread_attr_setstacksize
Tests for `pthread_attr_setstacksize(3)` and
`pthread_attr_getstacksize(3)`.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2022-04-12 22:02:04 +09:00
Jaxson Han 0e1ff84fe7 posix: Fix pthread_once has incorrect behavior
As described in
https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_once.html.
The behavior of pthread_once() is undefined if once_control has
automatic storage duration or is not initialized by PTHREAD_ONCE_INIT

However, in Zephyr, the implementation is incorrect. If the init value
is PTHREAD_ONCE_INIT, the program will never run the init_func.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
2022-04-05 10:38:30 -07:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Hake Huang 574e166e13 test: portability.posix.common.newlib: exclude lpcxpresso55s06
exclude newlib for posix testing as the MAX_HEAP_SIZE will be
too small if enabled NEWLIBC

fixing: #43873

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2022-03-17 20:47:47 -04:00
Carles Cufi e83a13aabf kconfig: Rename the TEST_EXTRA stack size option to align with the rest
All stack sizes should end with STACK_SIZE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-02-22 08:23:05 -05:00
Christopher Friedt ec0d878019 tests: pthread: cond: check return from pthread_cond_wait()
The expectation is that this call succeeeds in order for
the test to pass.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2022-02-09 22:16:45 -05:00
Jakub Rzeszutko 2caf587095 tests: lib: getopt
Add tests for the getopt library.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2022-01-06 21:26:59 +01:00
Anas Nashif 05ecd46a84 tests: fix typos and misnamed platforms
Various obsolote and misnamed platfomrs in test filters theat went
undetected for a while.

Fixes #41222

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-12-17 12:24:37 -05:00
Gerard Marull-Paretas a6a296d050 tests: posix: common: increase main stack for TLS tests
Increase main stack size (in 128 bytes) to make these tests run
successfully on qemu_x86 platform.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-19 10:11:32 +01:00
Henrik Brix Andersen 265cdf8dc6 cmake: use find_package() instead of literal include in tests and samples
Convert remaining tests and samples to using find_package() instead of
literally including the CMake boilerplate code.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2021-11-01 10:33:09 -04:00
Christopher Friedt 51030e4ccf tests: posix: common: clock: remove poorly conditioned tests
The test assumed initial equality between CLOCK_MONOTONIC and
CLOCK_REALTIME and also assumed coarse granularity for each clock.
Neither of those assumptions are solid.

Furthermore, the test failed on multiple vendor boards which caused
some concern.

Remove the poorly conditioned tests and remove some comments
/ printks.

Fixes #35703

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-09-09 21:20:27 -04:00
Torsten Rasmussen 1cccc8a8fe cmake: increase minimal required version to 3.20.0
Move to CMake 3.20.0.

At the Toolchain WG it was decided to move to CMake 3.20.0.

The main reason for increasing CMake version is better toolchain
support.

Better toolchain support is added in the following CMake versions:
- armclang, CMake 3.15
- Intel oneAPI, CMake 3.20
- IAR, CMake 3.15 and 3.20

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-08-20 09:47:34 +02:00
Evgeniy Paltsev ce47512c09 tests: posix: common: add option to build with arcmwdt libc
Add testcase to tests/posix/common with ARC MWDT libc usage.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2021-08-13 13:43:19 -05:00
Jennifer Williams 7e6e05c5e4 tests: posix: common: clock: exclude ehl_crb from test posix realtime
The ehl_crb board has hardware issue that prevents this test from
being able to pass this otherwise-correct test. So exclude ehl_crb
from the testcase.yaml.

Fixes #33544.

Signed-off-by: Jennifer Williams <jennifer.m.williams@intel.com>
2021-06-02 08:49:45 -05:00
Jennifer Williams bd365cc42e tests: posix: common: clock.c: rephrase comment on tick alignment
This k_usleep(1) is a tick alignment, not a workaround. Simple
reword to avoid confusion.

Signed-off-by: Jennifer Williams <jennifer.m.williams@intel.com>
2021-05-27 15:56:15 -05:00
David Leach 507a06fa82 tests: posix: Fix unchecked return coverity error
New test cases did not check return value of pthread_attr_init()

Fixes #33809

Signed-off-by: David Leach <david.leach@nxp.com>
2021-04-01 04:52:10 -04:00