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>
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>
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>
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>
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>
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>
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>
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>
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>
Set up a test fixture to reduce repetition and split
testsuite into blocking and nonblocking tests.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Previously, there was no test coverage for `sleep()` and
`usleep()`.
This change adds full test coverage.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
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>
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>
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>
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>
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>
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>
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>