Implement tests for `sched_setparam()` and `sched_setscheduler()` .
Both functions are actually placeholders and just return `ENOSYS`
since Zephyr does not yet support processes or process scheduling.
signed-off-by: Gaetan Perrot <gaetanperrotpro@gmail.com>
Adds test cases for sysconf() basic implementation.
Test case does not cover scenario where invalid value is passed
to the name argument of the function.
Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
Previously, the number 2 seemed to be somewhat magical. This
removes some of the mystery by labeling it.
So threads >= DETACH_THR_ID will be detached (we should not
attempt to join detached threads).
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
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>
Rather than shadowing most of the fields from pthread_attr_t
(struct posix_thread_attr) inside of struct posix_thread, just
embed the structure itself.
Additionally, use pthread_attr_init() to allocate a thread
stack and pthread_attr_destroy() to destroy a thread stack,
dramatically simplifying pthread_create().
A fair bit of rework was needed already to mitigate bitrot
issues in the testsuite. More should probably be done later.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The testsuite has been shifted to use dynamic thread
stacks (either statically allocated via a pool, or
dynamically allocated via the heap).
However, we definitely still need coverage for manually
specified thread stacks - but lets avoid duplicating
tests unnecessarily.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Rather than fail when attempting to set an extraordinarily large
pthread stack size (much larger than most Zephyr platforms have)
consider the test non-fatal and skip it.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Adds test cases testing following features:
- function error handling
- basic notification type
- thread notification type
- adding notification to non-empty queue
Signed-off-by: Adam Wojasinski <awojasinski@baylibre.com>
Reduce N_LOOPS from 999 to 32 by default and use a Kconfig
to encode it as CONFIG_TEST_SEM_N_LOOPS.
Running TESTSUITE semaphore
===============================================================
START - test_named_semaphore
PASS - test_named_semaphore in 5.685 seconds
===============================================================
START - test_semaphore
PASS - test_semaphore in 5.010 seconds
===============================================================
TESTSUITE semaphore succeeded
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Adds test for clock_getcpuclockid() to
make sure clock_id is equal to CLOCK_PROCESS_CPUTIME_ID
after a successful call
Fixes#59954
Signed-off-by: Jai Arora <infolinesoni@gmail.com>
Create a separate ZTEST_SUITE() to properly manage resources
that are shared between test cases. Add some assertions where
they were missing.
Additionally, we don't need verbose printing in this testsuite,
so change `printk()` to `LOG_DBG()`
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Made the conversion functions non-static and added ztests for
them to make sure that they work across the full range of
Zephyr priorities.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
The POSIX standard doesn't specify if the argument to store
previous state/type in
`pthread_setcancelstate`/`pthread_setcancelstate` can be
`NULL`, but threading implementations in Linux & Apache NuttX
permit the arguments to be `NULL`.
This commit changes Zephyr's implementation to mimic that of
Linux & NuttX, so that user do not get caught off-guard by
NULL pointer dereferencing when porting code over from those
OSes.
Updated test accordingly.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
As there isn't any ZTEST under the `posix_apis` testsuite, its
the testsuite is skipped and its setup function never ran,
let's convert the fdtable initialization setup function into a
test of `posix_apis`.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Currently all components live under the `posix_apis` testsuite,
this commit split them into a testsuite of their own.
This commit also prefixed a few local functions/variables with
the `static` keyword.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
In order to make state more manageable among the other
posix api tests, create a separate ZTEST_SUITE() called pthread
and another ZTEST_SUITE() called pthread_attr.
The tests in the pthread suite mainly operate on the pthread_t
type, while tests in the pthread_attr suite mainly operate on
the pthread_attr_t type.
The pthread_attr testsuite is moved to a separate file
(pthread_attr.c).
Having separate test suites allows us to narrow the scope of
the tests and have a better degree of control over the state.
Some effort went in to highlighting undefined behaviour at the
API level. This was quite intentional, as we will need to be
be able to test / verify that we do in fact have deterministic
outcomes when users attempt operations that result in undefined
behaviour (e.g. assert).
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Initial implementation of `sched_getparam()` and `sched_getscheduler()`
POSIX APIs as a part of PSE53 `_POSIX_PRIORITY_SCHEDULING` option group.
Both functions are actually placeholders and just return `ENOSYS`
since Zephyr does not yet support processes or process scheduling.
Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
Refactor the existing `pthread_sigmask` test function to
get its function-under-test via arg and test `sigprocmask` with
that.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
- Adjust refcount checks with regards to previous commit.
- Remove redundant zassert_not_null() on local pointers after a
sem_close(). There is no implicit reference passing in C.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
- Regroup refcount decrement and semaphore destruction by making the
linked state into a counted reference for it. This allows for
simplifying the code and cleanly adding a few assertions in a common
location.
- Remove redundant initialization to NULL on memory about to be freed
and local pointer in nsem_cleanup().
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Much of tests/posix/common still overspecifies pthread_attr_t
options.
Default thread attributes are perfectly fine for the vast
majority of spawned threads in this testsuite, so simply use
a NULL pthread_attr_t* argument.
This fixes piles of bugs because we have not properly used
pthread_attr_destroy() appropriately.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Much of tests/posix/common still overspecifies pthread_attr_t
options.
Default thread attributes are perfectly fine for the vast
majority of spawned threads in this testsuite, so simply use
a NULL pthread_attr_t* argument.
This fixes piles of bugs because we have not properly used
pthread_attr_destroy() appropriately.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Much of tests/posix/common still overspecifies pthread_attr_t
options.
Default thread attributes are perfectly fine for the vast
majority of spawned threads in this testsuite, so simply use
a NULL pthread_attr_t* argument.
This fixes piles of bugs because we have not properly used
pthread_attr_destroy() appropriately.
This is only a partial cleanup for pthread.c
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Much of tests/posix/common still overspecifies pthread_attr_t
options.
Default thread attributes are perfectly fine for the vast
majority of spawned threads in this testsuite, so simply use
a NULL pthread_attr_t* argument.
This fixes piles of bugs because we have not properly used
pthread_attr_destroy() appropriately.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Much of tests/posix/common still overspecifies pthread_attr_t
options.
Default thread attributes are perfectly fine for the vast
majority of spawned threads in this testsuite, so simply use
a NULL pthread_attr_t* argument.
This fixes piles of bugs because we have not properly used
pthread_attr_destroy() appropriately.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Much of tests/posix/common still overspecifies pthread_attr_t
options.
Default thread attributes are perfectly fine for the vast
majority of spawned threads in this testsuite, so simply use
a NULL pthread_attr_t* argument.
This fixes piles of bugs because we have not properly used
pthread_attr_destroy() appropriately.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Previously posix_apis.test_realtime was failing (very)
frequently in CI, and in particular, when running on Qemu,
POSIX, or SMP targets.
We are using CLOCK_REALTIME for this test, which incurs an
additional syscall overhead above CLOCK_MONOTONIC. The act
of sleeping itself also incurs a syscall overhead.
The latency from one iteration to the next of the internal
loop is a bit of a random process due to scheduler or clock
noise (although the noise itself is still bounded).
In order to make this test robust against such noise, assert
only on the average time from one iteration to the next,
rather than the instantaneous time.
Rather than calculating a sample mean, use a running average
(aka Cumulative Moving Average) to save some bytes.
Report results, including low and high watermarks before
asserting that the average iteration time within expected
range.
==============================================================
START - test_realtime
I: n: 20, sleep: 100, margin: 10, lo: 110, avg: 110, hi: 110
PASS - test_realtime in 2.198 seconds
==============================================================
Expect to see the low and high watermarks change more on
Qemu and POSIX platforms when running several jobs in parallel
with twister (such as in CI).
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
There was some discussion about whether it was suitable to have
an architecture-specific workaround in mqueue.c after that
workaround was copied to a different source file in a PR.
The original issue was that newlib and picolibc declare mode_t
to be unsigned short instead of unsigned long when __svr4__
is not defined along with __sparc__. This is specifically
impactful, because va_arg() deals (mainly) with 32-bit and
64-bit values that are all naturally aligned to 4 bytes.
#if defined(__sparc__) && !defined(__sparc_v9__)
#ifdef __svr4__
typedef unsigned long __mode_t;
#else
typedef unsigned short __mode_t;
#endif
A uint16_t is naturally aligned to 2 bytes, so not only would
a 16-bit mode_t be corrupted, it would also generate a warning
with recent gcc versions which is promoted to error (rightfully
so) when run through CI.
mqueue.c:61:35: error: 'mode_t' {aka 'short unsigned int'} is
promoted to 'int' when passed through '...' [-Werror]
61 | mode = va_arg(va, mode_t);
Instead of using an architecture-specific workaround, simply
add a build assert that the size of mode_t is less than or
equal to the size of an int, and use an int to retrieve it
via va_arg().
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
# Please enter the commit message for your changes. Lines starting
# with '#' will be kept; you may remove them yourself if you want to.
# An empty message aborts the commit.
#
# Date: Fri Dec 29 10:06:44 2023 -0500
#
# On branch posix-mqueue-always-use-int-for-mode-t-va-arg
# Changes to be committed:
# modified: lib/posix/mqueue.c
# modified: tests/posix/common/testcase.yaml
#
Remove the previously deprecated and non-standard macros
* PTHREAD_MUTEX_DEFINE()
* PTHREAD_COND_DEFINE()
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
In some cases, users want to allocate (comparatively) massive
thread stacks.
Add a test to ensure we can allocate such a stack by default.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
* Use PTHREAD_STACK_MIN as provided by the specification
instead of a hard-coded value of 1024
* add extra stack size to semaphore tests
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Since pthread_once() is both the initializer and executor of
pthread_once_t, it can have maximally two states. Since the
implementation in Zephyr previously aimed to maximize libc
compatibility, we opted to use the definition of pthread_once_t
from newlib, which is a structure with two ints.
It does not make sense to use 64 bits to manage 2 possible
states. The control for that should effectively be a bool.
We maintain compatibility with newlib by asserting (at build
time), that newlib's pthread_once_t is larger than Zephyr's
new struct pthread_once (which just contains a bool).
This allows us to delete the non-standard pthread_key.h
header file (finally).
Reuse the pthread_pool_lock in order to synchronize the related
init function (so that it is only called maximally once from any
thread). The spinlock is only used to test the state and the
init function is not called with the spinlock held.
The alternative was to use an atomic inside of
struct pthread_once. But again, that could be up to 64-bits with
Zephyr's atomics implementation.
Ideally we would use C11 generics or something to support atomics
on 8, 16, 32, and 64-bit primitives.
Lastly, also update declarations for C11 threads as they mostly
mirror our pthread implementation.
This needed to be done as a single commit in order to ensure
continuity of build.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
MIN() has been defined in sys/util.h for a long time. It doesn't
make sense to separately define a lowercase version.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>