2892 Commits

Author SHA1 Message Date
Peter Mitsis
e18a048c84 kernel: Add K_TIMEOUT_SUM() macro
The K_TIMEOUT_SUM() macro is intended as a means to add two
k_timeout_t values together. This may be useful for a developer
applying an exponential backoff algorithm.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-01-22 14:33:23 -06:00
Jamie McCrae
70fcffd5de tests: Update to use SOC_SERIES_NRF Kconfigs without X suffix
Updates usage of the old Kconfig to use the new Kconfig

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-01-20 13:21:38 +00:00
Vijay Sharma
83f1b8ba49 kernel: timer: Add timer observer hooks for extensibility
Introduce lifecycle observer callbacks (init, start, stop, expiry)
for k_timer using Zephyr's iterable sections pattern. This enables
external modules to extend timer functionality without modifying
kernel internals.

Signed-off-by: Vijay Sharma <vijshar@qti.qualcomm.com>
2026-01-09 14:25:31 -06:00
Abderrahmane JARMOUNI
9f1eec508e dts: bindings: replace '.yml' file extension with '.yaml'
Replace the '.yml' extension of the few binding files that has it,
with '.yaml'.

Signed-off-by: Abderrahmane JARMOUNI <git@jarmouni.me>
2026-01-07 19:41:03 +01:00
Peter Mitsis
8fa52bf82f tests: Add smp_metairq test
Adds a new meta-IRQ test just for SMP. This test verifies that
a cooperative thread preempted by a meta-IRQ thread resumes on
the same CPU after the meta-IRQ thread finishes.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-12-10 10:32:50 +00:00
Daniel Leung
169304813a cache: move arch_mem_coherent() into cache subsys
arch_mem_coherent() is cache related so it is better to move it
under cache subsys. It is renamed to sys_cache_is_mem_coherent()
to reflect this change.

The only user of arch_mem_coherent() is Xtensa. However, it is
not an architecture feature. That's why it is moved to the cache
subsys.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Daniel Leung
4e54b2f37f tests: mem_protect/stack_random: more randomness for intel_adsp
Due to CONFIG_DCACHE_LINE_SIZE=64, the stack is always aligned
on 64 bytes. With data cache line size and the default of
CONFIG_STACK_POINTER_RANDOM=64 in test, there is not much
randomness as any added offset (<= 64) would be rounded up to
64 bytes due to stack alignment. For the added offset to stack
pointer to actually mean something, CONFIG_STACK_POINTER_RANDOM
has to be larger.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-12-09 09:25:33 +01:00
Peter Mitsis
0d4856bb38 tests: Fix variable name
Updates the spawn_threads() sleep_sec parameter name to sleep_msec
to more accurately reflect the units of measurement.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-12-04 06:34:47 +00:00
Krzysztof Chruściński
9d09993ce6 tests: kernel: timer: timer_api: Fix hanging for slow platforms
Test had forever loop that was attempting to read k_timer_remaining_ticks
while system tick did not change. If target has relatively fast system
clock then it might be impossible.

Tweak test to repeat few times and if k_timer_remaining_ticks is not
read in the known tick then range is used to validate correctness of
the returned value.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-12-02 11:31:41 +01:00
Paweł Pelikan
76701217f1 tests: kernel: usage: Adjustments for slower platforms
Adjusting sleep times as core is to slow too run
the test with the default system clock frequency,
and fixing outdated comment in the test manifest file.

Signed-off-by: Paweł Pelikan <pawel.pelikan@nordicsemi.no>
2025-12-01 12:26:31 -05:00
Kyle Bonnici
a510704ed2 devicetree: format files in tests
Applying dts-linter results for files in

tests

Signed-off-by: Kyle Bonnici <kylebonnici@hotmail.com>
2025-11-28 10:09:39 +00:00
Carles Cufi
84a85ed9d8 tests: Add LTO tests variants with LTO_SINGLE_THREADED
Add variants of existing tests to cover this new Kconfig option.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2025-11-28 09:50:04 +00:00
Daniel Leung
29c478361a tests: kernel/smp: rework signals in stress test
The k_poll signal and event code is reworked a bit such that
signal is raised and event is processed only when appropriate.
We want to avoid changing the internal of event and signal
objects at the same time we try to raise the signal (which
changes the internal states too).

In addition, print out some information on how many signals
raised and received to indicate we are actually switching
all related threads.

Fixes #98136

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-25 17:36:16 +00:00
Jamie McCrae
cf08b9062f tests: kernel: device: Add CONFIG_DEVICE_DEINIT_SUPPORT
Adds this Kconfig, which is needed for the test, because it will
no longer be globally enabled by default

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-11-20 17:14:50 +00:00
Jerzy Kasenberg
3591f5cc82 tests: kernel: context: Disable PM for Smartbond
kernel context test check timing and extra interrupts
being thrown during sleep tests.

Power management is disabled because during tests
code tests sleep and with power management enabled
it could result in going to deep sleep that takes
more time than is allowed.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg.xr@bp.renesas.com>
2025-11-20 06:01:14 -05:00
Jerzy Kasenberg
31c05b13e7 test: scheduling: Disable works for Smartbond
Smartbond device schedules periodic calibrations work
and delayed work for xtal32 settle.
Those works can disrupt strict timing that test checks.

This change disables calibration for RCX and RC32K.
Xtal32k settle work is schedule late as not to be
executed during tests.

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg.xr@bp.renesas.com>
2025-11-19 15:55:40 -05:00
Nicolas Pitre
106d3db360 arch: arm64: Increase MAX_XLAT_TABLES for userspace tests
Memory protection and userspace tests require more MMU translation
tables than the default. Without this increase, tests fail with:

  E: CONFIG_MAX_XLAT_TABLES too small
  ASSERTION FAIL [ret == 0] @ arch/arm64/core/mmu.c:1244
	privatize_page_range() returned -12

Increase defaults when both USERSPACE and TEST are enabled:
- 32 tables for SMP configurations
- 24 tables for non-SMP configurations

This fixes:
- sample.kernel.memory_protection.shared_mem (all platforms)
- rtio.api.userspace (v8a, v9a)
- rtio.api.userspace.submit_sem (v8a, v9a)
- portability.posix.common.userspace

Consequently the demand paging test needed adjustment to its
qemu_cortex_a53 configs to keep working as this test is highly
sensitive to the amount of available free memory.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-11-18 17:49:40 -05:00
Nicolas Pitre
c01e0943c0 boards: arm: Create unified fvp_base_revc_2xaem board structure
Create unified board configuration to replace verbose board naming
with shorter hierarchical structure. This board works with the new
unified fvp_aem SOC series and supports the v8a architecture variant.

This enables board targets like:
- fvp_base_revc_2xaem/v8a (basic ARMv8-A)
- fvp_base_revc_2xaem/v8a/smp (ARMv8-A SMP)
- fvp_base_revc_2xaem/v8a/smp/ns (ARMv8-A SMP non-secure)

This structure replaces the existing overly verbose board designations
with a cleaner, more maintainable organization and provides a foundation
for adding v9a variants.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-11-18 17:49:40 -05:00
Josuah Demangeon
e6e7fc549e style: tests: apply coding style on CMakeLists.txt files
Apply the CMake style guidelines to CMakeList.txt files in tests/.

Signed-off-by: Josuah Demangeon <me@josuah.net>
2025-11-17 13:48:03 -05:00
Paweł Pelikan
fddce23e03 tests: kernel: timer: behavior: Adjustments for NRF54H20 PPR
Adjusting CONFIG_SYS_CLOCK_TICKS_PER_SEC as core is to slow too run
the test with the default system clock frequency.

Signed-off-by: Paweł Pelikan <pawel.pelikan@nordicsemi.no>
2025-11-15 11:43:37 +01:00
Daniel Leung
e63f9fb6de tests: kernel/smp: move switching stress test into its own group
This moves the switching stress test into its own group simply
to signify that there is a group for stress testing. And also
rename torture to stress.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-13 23:20:54 +02:00
Daniel Leung
c7ec8b9353 tests: kernel/pipe_api: skip zero size test if KERNEL_COHERENCE
Zero size buffer pipes are not currently supported if memory is
not coherent between CPUs (CONFIG_KERNEL_COHERENCE=y) due to
possibility of buffers being in incoherent memory. So skip
the zero size test for now.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-11-13 23:14:20 +02:00
Pete Johanson
112871afa4 tests/kernel/context: Properly idle on MAX32 family
Make sure MAX32_ON_ENTER_CPU_IDLE_HOOK is disabled for the context test, so
the CPU will actually idle with WFI and not return before the timer
expires for test_cpu_idle test.

Signed-off-by: Pete Johanson <pete.johanson@analog.com>
2025-11-07 16:12:48 -05:00
Nicolas Pitre
f5f258f0cc tests: kernel: smp_abort: add delay to ensure circular dependency
The test_smp_thread_abort_deadlock test assumes all CPUs will
simultaneously establish a circular abort dependency (each thread
aborts the next in a ring). However, on platforms with large
emulator/simulator quantum sizes, one thread's ISR may complete
and return before another thread even calls k_thread_abort() on it,
preventing the circular dependency from forming.

This manifested on ARMv8-R FVP but not on QEMU or ARMv8-A/ARMv9-A FVP
due to different timing characteristics and quantum sizes.

Add a k_busy_wait(100) after k_thread_abort() to give all CPUs time
to call abort before any ISR completes.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2025-11-06 12:29:02 +02:00
Måns Ansgariusson
8c07902a90 tests: kernel: pipe: Add concurrency test for zero-length pipes
This commit adds a new test case to the pipe API concurrency tests to
verify the behavior of zero-length pipes. The test ensures that writing
to a zero-length pipe blocks until data is read, and reading from a
zero-length pipe blocks until data is written—unless the pipe is closed,
reset, or the operation times out.

The test creates two pipes with zero-length buffers and spawns a helper
thread that performs complementary read/write operations. The two threads
use the pipe API as their only synchronization mechanism, validating the
correct blocking and wake-up behavior of zero-length pipes under
concurrent access.

Signed-off-by: Måns Ansgariusson <Mansgariusson@gmail.com>
2025-10-29 20:32:38 -04:00
Rob Barnes
ef844cee55 kernel: make k_is_pre_kernel safe to call from user mode
Make k_is_pre_kernel safe to call from user mode. Since
z_sys_post_kernel memory is not accessible to user threads, calling
k_is_pre_kernel would result in a memory access fault.

This change adds k_is_user_context guard. It can be assumed the system
is post-kernel if k_is_user_context is true.

Signed-off-by: Rob Barnes <robbarnes@google.com>
2025-10-28 11:52:34 +02:00
Mohamed Moawad
4bdcc53de9 tests: stackprot: add guard area to ensure portable overflow behavior
The stackprot test currently depends on compiler-generated stack frame
layouts, which can vary between toolchains and optimization levels.
This makes the overflow check fragile and may cause unintended faults.

Add a small guard buffer in alternate_thread so the intentional overflow
is always contained within the thread stack. This ensures the test
behaves consistently across toolchains, architectures, and optimization
settings.

Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
2025-10-24 13:27:06 -04:00
William Tambe
ee149a3fd9 tests: kernel/common: skip test_nested_irq_offload if more than 1 CPU
test_nested_irq_offload is meant for single CPU.
Skip it if there is more than 1 CPU.

Signed-off-by: William Tambe <williamt@cadence.com>
2025-10-24 13:22:09 -04:00
Jerzy Kasenberg
9aeb7e7669 tests: kernel: sched: Fix for variable hw cycles systems
Code was using CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC value.
System can have non constant value for cycle counter when
this constant is not valid.

Now code calls sys_clock_hw_cycles_per_sec() that will expand
to CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC (as before) when needed.
It only impacts systems that can change hw cycles per second
at runtime (due to calibration or some other clock change).

Signed-off-by: Jerzy Kasenberg <jerzy.kasenberg@codecoup.pl>
2025-10-24 09:43:15 +03:00
Daniel Leung
579225f370 tests: kernel/smp: intel_adsp needs more relaxing NOPs
It has been observed that, during the switching stress test,
the context switching becomes very slow due to enough CPUs
doing RCW transaction on hardware bus (e.g. spin locks).
Since the number of NOPs are the same for all CPUs, they are
simply entering and exiting the relax loop at the same time,
and hitting the bus with RCW transactions at the same time.
Not exactly a deadlock but it slows down the execution
enough to result in the test timing out. The SoC layer has
added an option to offset the number of NOPs per CPU by
adding the CPU to the number of NOPs. So enabling it for
the Intel ADSP boards to workaround the above mentioned
issue. I haven't encountered another slowdown after turning
on this option. So hopefully this lowers the probability of
that happening such that a simple retry can pass the test.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-10-21 22:54:34 +03:00
Mohamed Moawad
7920c385dc tests: kernel: fatal: Add ARC-specific stack protection test
Add ARC-specific variant of kernel.common.stack_protection test that
omits frame pointers to work around GNU toolchain code generation issue.

The GNU toolchain generates FP-relative memory accesses (st r0,[fp,-8])
for local variables when frame pointers are enabled, which bypasses ARC
hardware stack checking that only monitors SP-based instructions. This
causes the test to fail with MPU violations instead of
stack check violations.

Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
2025-10-16 17:11:01 +03:00
Daniel Leung
545d40e314 tests: mem_protect/userspace: add thread switching tests
This adds a few tests to test switching between threads where
they are under different memory domains. This is mainly to test
if permissions are set correctly during context switch.

By default the new tests are disabled and must be explicitly
enabled. This is due to some architectures requiring some config
changes (for example, x86 needing more reserved memory domains,
and ARM64 needing more translation tables). To avoid causing
mass CI failures, only enable platforms that have been tested,
for now.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-10-15 11:47:25 -04:00
Daniel Leung
1a6a1bf28b tests: mem_protect/userspace: fix privilege stack ptr for Xtensa
The priv_stack_ptr for reading and writing tests was not set
correctly on Xtensa, and was always 0. Test would pass since
the NULL page should always generate access faults on most
Xtensa platforms. However, those tests are supposed to test
reading and writing to the privilege stack. So fix that by
populating the priv_stack_ptr correctly.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-10-15 11:47:25 -04:00
Anas Nashif
9198b9d1ba tests: increase stack sizes to support coverage
Increase stack sizes to allow coverage to complete.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-14 17:32:46 -04:00
Anas Nashif
de8200c53a tests: workqueue: increase stacks to allow coverage
Test was failing to build on some scenarios when coverage was enabled.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-10-14 17:32:46 -04:00
Tim Pambor
110f4ee4bf tests: kernel: fix -Wformat errors
Fix format specifiers that did not match the argument type.
Use %zu format specifier for size_t type to ensure compatibility
with both 32-bit and 64-bit platforms. Escape percent signs in
format strings using %% to prevent warnings about unknown format
specifiers.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
2025-10-10 12:56:14 -04:00
Måns Ansgariusson
a5b2d58812 tests/kernel/mem_protect: Fix comment referencing old k_pipe api
The comment was referencing the old k_pipe api which has since been
retired. Updated the comment to reflect the current k_pipe api.

Signed-off-by: Måns Ansgariusson <Mansgariusson@gmail.com>
2025-10-10 12:55:37 -04:00
Benjamin Cabé
02551294f9 tests: kernel: device: add missing node in hifive board overlays
A follow-up to commit d6ce2f4f41 that
introduced a new fakedeferdriver node in app.overlay, but due to how
overlays are applied, the board specific overlay files also need to
be updated to avoid build errors, as they override whatever app.overlay
has.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-10-08 12:04:14 +02:00
Daniel Leung
9b25d8a440 tests: mem_protect/mem_map: remove intel_adsp test case
This removes the special test case for intel_adsp to skip
the mapped code execution test. The test can now run on
the ACE3.0 hardware without issue.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-10-06 20:16:31 -04:00
Daniel Leung
35b26e9368 tests: mem_protect/mem_map: fix mapped code execution test
The mapped code execution test uses the simple k_mem_phys_addr()
to do virtual to physical address translation. And this requires
the virtual address to be inside the kernel permanent mapping
(i.e. between __kernel_ram_start and __kernel_ram_end). With
demand paging, the translation is no longer static and it can be
mapped into any physical address. So a simple memory mapping
in the test would map an incorrect physical address which may
not even contain the said function. It has been working when
demand paging is not enabled is due to the custom sections is
immediately after the text section, so that the simple address
translation still works. But a custom linker script (i.e. board
config) may make that not true anymore.

So fix this by putting transplanted_function() into
snippets-text-sections.ld such that this would appear inside
.text section.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-10-06 20:16:31 -04:00
Peter Mitsis
482d183087 tests: Update smp test to support 12 CPUs
Updates the smp test to support nsim/nsim_hs5x/smp/12cores.
Furthermore, if someone attempts to build the smp test for more
than 12 CPUs, report an error message informing the user to
reduce the number of CPUs. This reduction can be in the form
of a custom overlay for the board in question.

Fixes #96339

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-10-06 15:06:37 -04:00
TaiJu Wu
61bc4451f6 kernel: essential work queue should not stop
consider follow case
```
ZTEST(workqueue_api, test_k_work_queue_stop_sys_thread)
{
	size_t i;
	struct k_work work;
	struct k_work_q work_q = {0};
	struct k_work works[NUM_TEST_ITEMS];
	struct k_work_queue_config cfg = {
		.name = "test_work_q",
		.no_yield = true,
		.essential = true,
	};

	k_work_queue_start(&work_q, work_q_stack,
			   K_THREAD_STACK_SIZEOF(work_q_stack),
			   K_PRIO_PREEMPT(4), &cfg);

	zassert_true(k_work_queue_drain(&work_q, true) >= 0,
	    "Failed to drain & plug work queue");
	zassert_not_ok(k_work_queue_stop(&work_q, K_FOREVER),
	    "Failed to stop work queue");
}
```

If we allow stop essential work queue, system will panic.

Signed-off-by: TaiJu Wu <tjwu1217@gmail.com>
2025-10-01 08:21:56 +02:00
Lauren Murphy
d64e6260fa tests: adjust CONFIG_MAX_THREAD_BYTES for some
For these particular tests, many platforms require higher
CONFIG_MAX_THREAD_BYTES than the default 2, so guard
against failures by setting it high.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2025-10-01 08:20:05 +02:00
Lauren Murphy
f29878089b tests: smp_suspend: run only on qemu, native and hardware
Control where the test runs.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
2025-10-01 08:20:05 +02:00
Daniel Leung
20417c4363 tests: kernel/smp: customize for test_smp_ipi
This adds some kconfigs to allow customizing the SMP IPI
broadcast test.

* Can running for more iterations.
* The wait period can be changed.
* Retry waiting for the other processors to complete
  processing the IPI.
  * This is mainly to avoid having a single long wait.
    The whole wait period is broken down so that we can
    bail out early if that iteration is deemed a success.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-09-26 06:40:40 +02:00
Hoang Nguyen
8aaddb1916 tests: kernel: tickless: Add system timer support for RZ/V2L, RZ/A3UL
Add tickless concept test support for RZ/V2L-SMARC, RZ/A3UL-SMARC

Signed-off-by: Hoang Nguyen <hoang.nguyen.jx@bp.renesas.com>
Signed-off-by: Tien Nguyen <tien.nguyen.zg@renesas.com>
2025-09-23 09:39:35 +01:00
Anas Nashif
e3d2e7d60d tests: kernel: fix issue with stack overflow detection
on arc, the test fails with an MPU error instead of a stack
overflow because the priv stack is merged into the defined
stack.

Fixes #68682

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-09-21 18:10:16 -04:00
Ayush Singh
f2dcb6c1f3 tests: kernel: mem_protect: sys_sem: Fix pocketbeagle_2_am6254_a53
- Since PocketBeagle 2 RevA1 has 4 cores, we need to adjust the variable
  CONFIG_MAX_THREAD_BYTES to allow this test to build.
- Does not affect Rev A0 (2 cores).

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-09-16 16:07:40 -04:00
Ayush Singh
df3e28375d tests: kernel: mutex: sys_mutex: Fix pocketbeagle_2_am6254_a53
- Since PocketBeagle 2 RevA1 has 4 cores, we need to adjust the variable
  CONFIG_MAX_THREAD_BYTES to allow this test to build.
- Does not affect Rev A0 (2 cores).

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-09-16 16:07:40 -04:00
Ayush Singh
ad2990ab25 tests: kernel: queue: Fix pocketbeagle_2_am6254_a53
- Since PocketBeagle 2 RevA1 has 4 cores, we need to adjust the variable
  CONFIG_MAX_THREAD_BYTES to allow this test to build.
- Does not affect Rev A0 (2 cores).

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
2025-09-16 16:07:40 -04:00