Commit graph

193 commits

Author SHA1 Message Date
Vincent van Beveren bd0d98bb9e tests: posix: fs: Add tests for stat command
This commit adds tests for the stat command. Stat on the
root of the filesystem is not yet supported.

Signed-off-by: Vincent van Beveren <v.van.beveren@nikhef.nl>
2023-06-23 17:04:34 -04:00
Marcin Niestroj 2bc980f831 tests: eventfd: test wake-up from pending poll()
Make sure that `poll(..., POLLIN)` executed from another thread returns
when `eventfd_write()` is called. Test also the same with `poll(...,
POLLOUT)` and `eventfd_read()` on eventfd with counter equal to
`UINT64_MAX - 1`.

Signed-off-by: Marcin Niestroj <m.niestroj@emb.dev>
2023-06-22 16:09:42 -04:00
Christopher Friedt bfa0a87277 tests: posix: pthread_pressure: enable pthread barrier in twister
In some cases, when GitHub CI is running several Qemu processes,
each with heavy loads, SMP tests have shown some flakiness. This
exhibits itself as something like

```
... pthread_pressure on qemu_riscv32 failed (Timeout)
```

That is actually not at all limited to POSIX or any particular
architecture, but is mainly to do with the host scheduler and
perhaps memory barrier operations being lost in ISA translation
by Qemu.

Collectively, we can refer to these issues as "scheduler noise".

To reduce scheduler noise in the `pthread_pressure` testsuite,
enable `CONFIG_PTHREAD_CREATE_BARRIER` in `testcase.yaml`.

Note: end-users will likely not experience the need to enable
this in `prj.conf`. E.g. the following basic test demonstrates
0 failures locallly.

```
TEST=tests/posix/pthread_pressure
twister --build-only -T $TEST &>/dev/null
FAIL=0
for ((i=0; i < 100; i++)); do
  echo "Run $((i+1))/100"
  twister --test-only -T $TEST &>/dev/null
  if [ $? -ne 0 ]; then
    FAIL=$((FAIL+1))
    echo "Failed $FAIL times"
  fi
done
echo "Failure Rate: $((FAIL))/100"
```

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-12 14:06:10 -04:00
Christopher Friedt d9bae7ce65 tests: posix: improvements to pthread_pressure test
* allow `qemu_cortex_a53`
* disallow `qemu_leon3
* remove `TEST_DURATION_S` range
* additional report formatting

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-09 12:27:04 -04:00
Christopher Friedt f35fb33b94 posix: pthread: reimplement pthread_barrier using zephyr objects
Previously pthread_barrier_t was implemented in terms of wait
queues and internal scheduler functions.

This introduced some obstacles and inconsistency. In order
to be more consistent, rely only on Zephyr's public API and
reuse as many concepts as possible.

Deprecate `PTHREAD_BARRIER_DEFINE()` since it's non-standard.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-09 12:27:04 -04:00
Christopher Friedt 2d4874dd65 tests: posix: stress test for pthread_create and pthread_join
Recently, a race condition was discovered in `pthread_create()`
and `pthread_join()` that would trigger an assertion in
`kernel/sched.c` of the form below.
```
aborted _current back from dead
```

This was mainly observed in Qemu. Unfortunately, Qemu SMP
platforms exhibit a real and measurable "scheduler noise"
which makes testing rather difficult.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-05 19:48:39 -04:00
Christopher Friedt 15ea0412e4 tests: posix: common: add a small delay in pthread_descriptor_leak
The `aborted _current back from dead` error may appear in this
particular test under Qemu (and in particular Qemu SMP) systems.

A small delay between `pthread_create()` and `pthread_join()`
is sufficient to mitigate the issue.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-05 19:48:39 -04:00
Christopher Friedt d95ecab47e Revert "tests: posix: pthread: init pthread_attr_t on each iteration"
This reverts commit 7c17bda3c2.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-05 19:48:39 -04:00
Declan Snyder 4c8b18920a tests: posix headers: RT1015 increase RAM
RT1015 needs more RAM to do this test, increase size of Zephyr SRAM
by switching zephyr,sram to the OCRAM allocation of the FLEXRAM.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-06-05 10:35:38 +02:00
Christopher Friedt 386f6c7006 tests: posix: eventfd: add stress test
This test simply counts how many times `eventfd_read()`
and `eventfd_write()` can be called on an
`eventfd(0, EFD_SEMAPHORE | EFD_NONBLOCK)` file
descriptor.

Prior to the recent changes in `eventfd`, we were seeing
approximately < 1000 writes / s. However, the previous
`eventfd` implementation would fail this test with the
result that the number of successful reads was far greater
than the number of successful writes.

This should be impossible, and with the recent `eventfd`
changes that was fixed. Additionally, we are seeing an
increase in over 40x for non-blocking eventfd reads and
writes.

```
START - test_stress
I: BOARD: qemu_riscv64_smp
I: TEST_DURATION_S: 5
I: UPDATE_INTERVAL_S: 1
I: avg: 48537 reads/s
I: avg: 48575 writes/s
PASS - test_stress in 5.002 seconds
```

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-02 18:45:46 -04:00
Christopher Friedt d370361fe5 tests: eventfd: blocking read-write test for deadlock bug
Previously, the prototypical use case for `eventfd()` was not
possible in Zephyr due to a deadlock associated with the
`fdtable.c` `k_mutex`.

The prototypical use case for `eventfd()` is to make a
blocking call to `eventfd_read()` from one thread, and then
from another thread, call `eventfd_write()` to "wake up" the
reading thread.

This additional test case ensures that Zephyr supports the
prototypical `eventfd()` use case.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-02 18:45:46 -04:00
Christopher Friedt cf7c404aeb tests: posix: eventfd: use reopen in test_write_then_read
Use `reopen()` in one additional place in the eventfd
testsuite.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-06-02 18:45:46 -04:00
Christopher Friedt 5a7b343d9d tests: posix: eventfd: split into blocking and nonblocking
Set up a test fixture to reduce repetition and split
testsuite into blocking and nonblocking tests.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-05-30 10:46:06 -04:00
Christopher Friedt d3a602ef85 tests: posix: eventfd: normalize includes
Include standard headers first, and then ensure that the
convention of `<zephyr/posix/...>` is followed for internal
POSIX sources.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-05-30 10:46:06 -04:00
Christopher Friedt 26b523bf06 tests: posix: eventfd: reduce testing requirements and scope
In order to reduce churn in CI, test only with the default libc.

Additionally, reduce Kconfig options in `prj.conf` to minimum.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-05-30 10:46:06 -04:00
Christopher Friedt 49d0dface4 tests: posix: eventfd: be less repetitive in naming
Instead of `ZTEST(eventfd, test_eventfd_...)` use
`ZTEST(eventfd, test_...)`.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-05-30 10:46:06 -04:00
Christopher Friedt 6da81c8ebf tests: posix: eventfd: consistent testsuite name
Make the cmake project and suite name consistent.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-05-30 10:46:06 -04:00
Christopher Friedt cc9bc2a5e0 tests: posix: eventfd: consilidate into one testsuite
Merge the `eventfd_basic` testsuite with the `eventfd`
testsuite in order to reduce churn in CI.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-05-30 10:46:06 -04:00
Anas Nashif a543ba1f4d tests: use integration_platforms where applicable
Use integration_platforms where coverage is provided using one or few
targets instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-05-26 17:52:02 -04:00
Gerard Marull-Paretas 93b63df762 samples, tests: convert string-based twister lists to YAML lists
Twister now supports using YAML lists for all fields that were written
as space-separated lists. Used twister_to_list.py script. Some artifacts
on string length are due to how ruamel dumps content.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-10 09:52:37 +02:00
Jakub Rzeszutko 25a3977709 getopt: extend ztests scope
Adding a test to detect problems in the cooperation of the getopt
and logger modules. It would detect issue: #57520

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2023-05-09 11:03:44 -04:00
Kumar Gala 70e921dbc7 tests: posix: fs: disable CONFIG_EVENTFD
The test doesn't use eventfd so we can disable it to save some space.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-05-09 23:32:57 +09:00
Christopher Friedt 12ed08a2fb tests: posix: pthread: remove unused pthread return value
Rather than pass an variable address to a `void *` in
`pthread_join()` and do nothing with it, just pass `NULL`.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-04-29 16:53:59 -04:00
Christopher Friedt 7c17bda3c2 tests: posix: pthread: init pthread_attr_t on each iteration
The `test_pthread_descriptor_leak` test was causing a kernel
panic on some platforms. Initially, it was not clear why.

The usual cases were examined - race conditions, stack sizes,
etc. Still no luck.

As it turns out, recycling a thread stack (or at least the
`pthread_attr_t`) in-place does not work on some platforms,
and we need to reinitialize the `pthread_attr_t` and set
set the stack property again prior to calling
`pthread_create()`.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-04-29 16:53:59 -04:00
Chris Friedt 27c25e9b42 tests: posix: test support for SCHED_OTHER
Ensure we test `SCHED_OTHER` functionality along with other
scheduling policies and priorities.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-04-29 13:14:40 -07:00
Chris Friedt ad71b78770 tests: posix: ensure that min and max priority are schedulable
Verify that threads are actually schedulable for min and max
scheduler priority for both `SCHED_RR` (preemptive) and
`SCHED_FIFO` (cooperative).

Fixes #56729

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-04-29 13:14:40 -07:00
Marc Desvaux d7a3585d45 test: posix: getopt: boards : add nucleo_c031c6.conf
add boards/nucleo_c031c6.conf with
CONFIG_NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE=4096
to avoid twister issue due to a too low heap size on the co31c6

Signed-off-by: Marc Desvaux <marc.desvaux-ext@st.com>
2023-04-28 20:37:24 +02:00
Gerard Marull-Paretas 0ebe14beb4 sys: util: migrate all files to DIV_ROUND_UP
ceiling_fraction is deprecated, use DIV_ROUND_UP.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-11 12:00:37 +02:00
Kumar Gala 9d8c7b8f1f tests: posix: common: Add testcase for arm-clang
Add a testcase variant to cover building with arm-clang and
CONFIG_ARMCLANG_STD_LIBC set.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-06 19:50:23 -04:00
Anas Nashif 7de0d6efcf tests: posix: prefix tests with test_
Prefix tests with test_ to allow correct evaluation of output.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-04-05 10:27:28 +02:00
Chris Friedt 9bde7ec919 Revert "tests: posix: clock: ensure overflow is consistent"
This reverts commit 662f37d9066402d1532eb98f17d65c98f578c09d.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
2023-04-04 14:32:10 +02:00
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