Commit graph

422 commits

Author SHA1 Message Date
Christopher Friedt
80e3f4aee6 tests: posix: common: rwlock: remove overspecified pthread_attr_t
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>
2024-01-04 15:13:47 -05:00
Christopher Friedt
e14f362547 tests: posix: common: sem: remove overspecified pthread_attr_t
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>
2024-01-04 15:13:47 -05:00
Christopher Friedt
90021b81d5 tests: posix: common: pthread: do not overspecify pthread_attr_t
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>
2024-01-04 15:13:47 -05:00
Christopher Friedt
d9cffcfc36 tests: posix: common: mutex: remove overspecified pthread_attr_t
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>
2024-01-04 15:13:47 -05:00
Christopher Friedt
bfb4a5141c tests: posix: common: mqueue: remove overspecified pthread_attr_t
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>
2024-01-04 15:13:47 -05:00
Christopher Friedt
aefbbe2788 tests: posix: common: key: remove overspecified pthread_attr_t
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>
2024-01-04 15:13:47 -05:00
Christopher Friedt
67a74e4350 tests: posix: test_realtime: improve test reliability
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>
2024-01-04 08:27:29 +09:00
Christopher Friedt
10156f5f1d posix: mqueue: pop mode as int with va_arg()
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
#
2024-01-01 16:36:31 -05:00
Christopher Friedt
1f67dcbd89 posix: remove deprecated non-standard PTHREAD_MUTEX_DEFINE, etc
Remove the previously deprecated and non-standard macros
* PTHREAD_MUTEX_DEFINE()
* PTHREAD_COND_DEFINE()

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-12-28 03:40:57 -05:00
Christopher Friedt
b702c8e8f0 tests: posix: pthread: test that big stacks can be allocated
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>
2023-12-23 22:29:41 -05:00
Christopher Friedt
5c78c66fc2 tests: posix: headers: check for pthread get / set guardsize
Add checks to ensure that pthread_getguardsize() and
pthread_setguardsize() are callable.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-12-20 14:20:58 +00:00
Christopher Friedt
5e245bd42e tests: posix: tests for pthread_getguardsize() pthread_setguardsize()
Add tests for pthread_getguardsize() and pthread_setguardsize().

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-12-20 14:20:58 +00:00
Christopher Friedt
746a3b943d tests: posix: use consistent min stack sizes
* 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>
2023-12-20 14:20:58 +00:00
Christopher Friedt
04c9903055 posix: pthread_once: simplify and reduce size of pthread_once_t
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>
2023-12-14 09:32:58 +01:00
Christopher Friedt
4153a396f8 tests: posix: headers: enable tests for signal.h entities
Enable existsence checks for newl(-ish)ly added signal.h
definitions.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-12-04 20:49:35 -05:00
Christopher Friedt
c2ab4020b0 tests: posix: pthread: add test for pthread_sigmask()
Add a test for pthread_sigmask().

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-12-04 20:49:35 -05:00
Christopher Friedt
e867c6f36d tests: posix: pthread: use MIN instead of min
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>
2023-12-04 20:49:35 -05:00
Anas Nashif
e11a71dea0 tests: posix: remove unrelated tags
Remove unrelated tags: net, socket.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-11-30 11:23:11 -05:00
Christopher Friedt
fe456ee5be tests: posix: test pthread_cleanup_push() / pop()
Add a test for pthread_cleanup_push() and
pthread_cleanup_pop().

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-29 10:08:44 +01:00
Peter Mitsis
a51bd53cef tests: Update posix common test for Xtensa
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>
2023-11-27 20:10:51 -05:00
Christopher Friedt
caf72569a9 tests: posix: common: test pthread_getconcurrency()
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>
2023-11-27 08:26:31 -05:00
Christopher Friedt
c0f2038c26 tests: posix: headers: check for pthread_getconcurrency()
Check for the existence of pthread_getconcurrency() and
pthread_setconcurrency().

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-27 08:26:31 -05:00
Christopher Friedt
5f64a47d52 tests: posix: headers: support pthread_setcancelstate() / type()
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>
2023-11-26 05:55:08 -05:00
Christopher Friedt
d2e729233d tests: posix: headers: add verification tests for more constants
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>
2023-11-25 06:29:16 -05:00
Christopher Friedt
505e9be2e1 tests: posix: headers: ensure pthread_condattr_getclock() exist
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>
2023-11-25 06:29:16 -05:00
Christopher Friedt
131220cb95 tests: posix: headers: check pthread_spin_lock() et al exist
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>
2023-11-25 06:29:16 -05:00
Christopher Friedt
0e11bcf5a0 tests: posix: add tests to ensure pthread_key_delete() works
Ensure that the correct key is deleted via pthread_key_delete().

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-11-24 10:47:28 -05:00
Christopher Friedt
41b7c17ac4 tests: posix: pthread: check that pthread_atfork() exists
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>
2023-11-23 00:59:32 -05:00
Alberto Escolar Piedras
587c43a602 tests/posix/common: Fix filtering for POSIX arch
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>
2023-10-25 07:44:12 -04:00
Alberto Escolar Piedras
32ea1566db tests/posix/fs: Improve filtering around posix arch
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>
2023-10-25 07:44:12 -04:00
Alberto Escolar Piedras
a2d1e979ef tests posix timer: Fix timer check
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>
2023-10-25 07:44:12 -04:00
Anas Nashif
345735d0a8 tests: remove CONFIG_ZTEST_NEW_API in all tests
Remove all usage of CONFIG_ZTEST_NEW_API from tests and sample as this
is now enabled by default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Alberto Escolar Piedras
826c54efc9 tests posix pthread_pressure: Fix for native targtets
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>
2023-10-20 15:01:25 +02:00
Alberto Escolar Piedras
11aa5c513f tests posix getopt: Minor fix for native targets
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>
2023-10-20 15:01:25 +02:00
Alberto Escolar Piedras
50793e32a8 tests posix event_fd: Fix for native targets
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>
2023-10-20 15:01:25 +02:00
Arunmani Alagarsamy
71c1f89440 tests: posix: common: timer: add test for SIGEV_THREAD
this flag enables the timer expiry handler runs on thread

Signed-off-by: Arunmani Alagarsamy <arunmani@linumiz.com>
2023-10-20 14:52:07 +02:00
Evgeniy Paltsev
433a85e7bf test: posix: skip nanosleep testcase for ARC HSDK boards
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>
2023-10-13 21:59:40 -04:00
Christopher Friedt
254c6711ed tests: posix: common: init check for stdin, stdout, and stderr
Add a test to help ensure stdin, stdout, and stderr are
initialized statically.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2023-10-13 04:48:47 -04:00
Hake Huang
cdd17ce100 test: posix: nanosleep: use k_cycle_64 as possible
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>
2023-10-13 10:05:06 +03:00
Hake Huang
0136759707 test: posix: common: nanosleep test fix
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>
2023-10-13 10:05:06 +03:00
Martin Åberg
7a9600816a tests: posix: Enable pthread_pressure test on SPARC
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>
2023-10-08 11:24:19 +01:00
Flavio Ceolin
15aa3acaf6 kconfig: Remove MP_NUM_CPUS usage
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>
2023-10-03 17:45:53 +01:00
Jaxson Han
eeaf3bdb2d tests: posix: eventfd: Move thread from stack to data section
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>
2023-09-22 09:25:12 +02:00
Johann Fischer
f67dd39bb2 drivers: ramdisk: use devicetree to instantiate RAM disk
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>
2023-09-18 17:36:50 +02:00
Tom Finet
ceb59951c5 posix: clock_nanosleep tests
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>
2023-08-30 13:02:58 -07:00
Mateusz Marszalek
295eb1b1a0 POSIX: Add tests for pthread_condattr
Add test coverage for init, destroy, setclock, getclock

Signed-off-by: Mateusz Marszalek <matti.marszalek@gmail.com>
2023-08-30 13:01:03 -07:00
Anas Nashif
71eee6da4b tests: fs: add more tags
Add module names as tags, to trigger CI on those tests when module has
changed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-08-24 13:41:26 -04:00
Jaxson Han
f840b85b15 tests: posix: pthread_pressure: Correct the 64BIT naming
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>
2023-08-21 13:27:07 +02:00
Grant Ramsay
973393ae18 Revert "test: Exclude qemu_cortex_a53_smp from portability.posix.eventfd"
This reverts commit d24880e358.

The issue was fixed by a2d29025038dece141ab71545c83166384821369.

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
2023-08-17 11:54:08 -04:00
Johan Hedberg
03905f7e55 boards: x86: Add intel_ prefix to Elkhart Lake boards
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>
2023-08-15 11:24:35 +00:00