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>
Updates the posix common test so that it will pass on Xtensa SMP
boards such as intel_adsp_ace15_mtpm. This involves ensuring that
a newly created thread does not attempt access/modify the stack of
a thread that is currently running on a different CPU.
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Add functional tests for pthread_getconcurrency() and
pthread_setconcurrency().
Note: the specification explicitly says
> an implementation can always ignore any calls to
> pthread_setconcurrency() and return a constant for
> pthread_getconcurrency()
The implementation and tests could be up for revision at a future
time when optimizations are considered and there is a better
system in placeo for documenting POSIX options and deviations.
Any such optimizations should be explicitly controlled via
Kconfig.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The function pthread_setcancelstate() has been supported for
some time already in Zephyr. For some reason, it was not being
checked in the "headers" testsuite.
Additionally, check for pthread_setcanceltype() since it was
added in a prior commit.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Ensure that the "headers" test checks that the following constants
are defined:
* PTHREAD_PROCESS_SHARED
* PTHREAD_PROCESS_PRIVATE
* PTHREAD_COND_INITIALIZER
* PTHREAD_MUTEX_INITIALIZER
* PTHREAD_CANCELED
They were already defined by previous commits, but the test had not
been updated.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
These calls were added some time ago, so ensure they are checked
for existence.
* pthread_condattr_getclock()
* pthread_condattr_setclock()
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The simple header test was not updated to verify that the
following functions were implemented even though they were
implemented some time ago.
* pthread_spin_destroy()
* pthread_spin_init()
* pthread_spin_lock()
* pthread_spin_trylock()
* pthread_spin_unlock()
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add a simple existence check that pthread_atfork() has
some kind of implementation. The function is mandatory
by all conforming POSIX systems.
Signed-off-by: Christopher Friedt <cfriedt@meta.com>
All these tests where filtered for the whole POSIX
architecture, but quite a few of them can be run in
native_sim.
So let's filter out native_posix(_64) in general,
(allowing other native simulator based targes),
and filter for thsi arch out explicitly the 2 tests
which need NEWLIB as this arch does not provide it.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
These tests cannot be run on the native_posix(_64) targets,
so let's filter them explicitly. Before they were filtered
due to the "filter", but using platform_exclude is faster.
Also the tests that depend on newlib cannot be run
in this architecture at all, so let's filter them by
architecture too.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The timer check does not work properly for platforms
which have a system tick timer with a period that
does not properly divide the configured time interval.
In those, depending on when the timer is started and
stopped, one signal less may be received.
This is for example the case for nrf5x platforms,
where the system tick timer is driven by a 32.768KHz
clock.
=> Correct the test, to accept receiving 1 signal
too little during the wait.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The infinite loop during the test needs to be broken
with a small delay when built for native targets.
Let's add it.
Note that this delay is only added for ARCH_POSIX targets
and not any other.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This test should be compiled without host headers
when built without the host libC, and at the same
time, it does not support building with the host
libC, so let's remove the condition that includes
the host libC header to avoid extra confusion.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The infinite loop during the stress needs to be broken
with a small delay when built for native targets.
Let's add it.
Note that this delay is only added for ARCH_POSIX targets
and not any other.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The comparison of cycles we get with k_cycle_get_32 may be
incorrect if counter wrap happened. In case of ARC HSDK and
ARC HSDK4xD platforms we have high counter clock frequency
(500MHz or 1GHz) so counter wrap quite likely to happen if
we wait long enough. As in some test cases we wait more than
1 second, there are significant chances to get false-positive
assertion.
So let's skip nanosleep testcase for ARC HSDK and ARC HSDK4xD
boards.
The proper fix is to use k_cycle_get_64 in this test case,
but we need to provide k_cycle_get_64 support for ARC HSDK and
ARC HSDK4xD platforms first.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
as posix nanosleep is actually call us, so we need use a
higher clock to compare the result. try to use k_cycle_64
as possible.
Co-authored-by: Christopher Friedt <cfriedt@meta.com>
Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
in test_nanosleep_execution, the
actual_ns = k_cyc_to_ns_ceil64((now - then * selection));
is wrong, according to posix driver code
lib/posix/clock.c
line: 156
if ((flags & TIMER_ABSTIME) == 0) {
ns += uptime_ns;
}
so we need change to
actual_ns = k_cyc_to_ns_ceil64((now + then * selection));
fixing: #62889
Co-authored-by: Christopher Friedt <cfriedt@meta.com>
Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
This sets the stack size appropriate for SPARC. Tested on the board
configurations qemu_leon3 and gr716a_mini.
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
Zephyr's code base uses MP_MAX_NUM_CPUS to
know how many cores exists in the target. It is
also expected that both symbols MP_MAX_NUM_CPUS
and MP_NUM_CPUS have the same value, so lets
just use MP_MAX_NUM_CPUS and simplify it.
Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
The test case allocate struct k_thread thread in the stack. This will
lead the random initial value of thread and thus cause the test cases
randomly hang. To fix such issue, move the declartion of struct k_thread
thread outside the function as a stacic variable.
Signed-off-by: Jaxson Han <jaxson.han@arm.com>
Rework RAM disk driver to be configured using devicetree and
support multiple instances.
This patch also removes a copy of the RAM disk driver,
tests/subsys/fs/fat_fs_dual_drive/src/disk_access_test_drv.c,
that was there for testing multiple disk drivers support.
Bonus: one SYS_INIT() less and a memory region can be exported to the
host.
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Adds error and lower bounds tests for the posix clock_nanosleep
function. Refactors common test functions to be shared by both
clock_nanosleep and nanosleep tests.
Signed-off-by: Tom Finet <tom.codeninja@gmail.com>
Correct the Kconfig with 64BIT condition instead of 64_BIT.
Slightly refine the if condition as they are mutually exclusive.
Signed-off-by: Jaxson Han <jaxson.han@arm.com>
This reverts commit d24880e358.
The issue was fixed by a2d29025038dece141ab71545c83166384821369.
Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
This follows the same convention that has already been adopted by Intel
Alder Lake and Raptor Lake boards.
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>