Fixes wrongly setting a Kconfig for all devices for a Kconfig
that is SoC specific and moves it directly to the test
Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
Raise the minimum required CMake version from 3.20.0 (documented as
3.20.5) to 3.28.0, which is satisfied by the CMake 3.28.3 package
shipped in the Ubuntu 24.04 LTS repositories. Ubuntu 24.04 is the
current Ubuntu LTS release targeted by the Zephyr getting started
guide, and by the time of the next Zephyr release, Ubuntu 22.04 will be
within months of its end of standard support. Users of distributions
shipping an older CMake can use the Kitware APT repository or a
pip-installed CMake, as the documentation already suggests.
Raising the floor to 3.28 unlocks a range of modern CMake features for
the build system, among which the cmake_file_api() command (3.27),
file(COPY_FILE) (3.21), block()/endblock() (3.25), and allows removal
of several version-conditional workarounds.
The tree-wide cmake_minimum_required() occurrences in samples, tests
and boards are updated accordingly, together with the documentation
and the sysbuild CMake presets. The IAR C-STAT integration keeps its
own higher requirement (4.1.0).
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Header file include/zephyr/sys_clock.h is deprecated and will be removed
someday. Update the whole file tree to include zephyr/sys/clock.h
straight instead of zephyr/sys_clock.h.
This change was made running the sed shell command below:
$ sed -i 's/zephyr\/sys_clock\.h/zephyr\/sys\/clock\.h/' \
`grep -rsl "zephyr/sys_clock\.h" tests/`
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
Allows the test_cpu_idle_atomic to have one spurious timer interrupt
when using the Intel ADSP simulator. When using the simulator, the
timer is programmed to wake one tick early when the current cycle
count matches the 'last_count' -- a scenario that does not occur
on real hardware.
Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Rename the test metadata file(s) in this area from testcase.yaml to
tests.yaml so sample and test metadata share one consistent filename
across the tree. Pure rename, no content change.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Replace the outdated README.txt that still referenced "make run", the
"make clean/pristine" troubleshooting boilerplate and legacy tc_start()
output. Describe the current context, context_one_cpu and
context_cpu_idle Ztest suites and use twister/west build-and-run
instructions with current Ztest output.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Assisted-by: Claude:opus-4.8
Close two minor coverage gaps in the context suite:
- k_can_yield() was only checked incidentally inside other tests, so it
had no named traceability entry. Add test_k_can_yield, asserting it is
true in thread context and false in an irq_offload() ISR handler.
- The conditional skips in test_cpu_idle(_atomic), test_interrupts and
test_timer_interrupts were silent. Print the reason before
ztest_test_skip() so reports show why a platform skipped instead of
reading as covered.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
irq_lock() reentrancy was only exercised indirectly via the spinlock
tests; the context suite checked a single lock/unlock level only. Add
test_irq_lock_nested to verify the key property of nested locking: a
nested irq_lock() keeps interrupts masked, balancing the inner key must
NOT re-enable them while the outer lock is held, and only the unlock
balancing the outermost lock restores the original state.
arch_cpu_irqs_are_enabled() is used as the observable at each step,
extending the single-level coverage already provided by
test_arch_cpu_irqs_are_enabled. Verified on native_sim, qemu_x86,
qemu_cortex_m3 and qemu_riscv32.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Assisted-by: Claude:claude-opus-4-8
test_thread was effectively a no-op. Its worker, kernel_thread_entry(),
blocked on k_sem_take(&sem_thread, K_FOREVER) before running any checks,
but the test never gave that semaphore. The worker only reached
_test_kernel_thread() because test_k_yield(), which runs earlier in the
same suite, happened to leak a semaphore count of one - a fragile
ordering dependency that silently dropped all coverage when the test ran
in isolation. The body itself contained no assertions and did not join
the worker, so a worker that blocked forever still passed. The parent
thread id was also passed as NULL, making the worker's "id differs from
spawner" check trivially true.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Bring the context test documentation in line with the test
documentation conventions: rename the Doxygen module from
kernel_context_tests to the tests_-prefixed tests_kernel_context so it
groups under all_tests consistently, and rewrite the remaining cases
that still used the older "Test Objective / Testing techniques /
Pass/Fail criteria" format into the concise @details / Test steps /
Expected result template already used by the rest of the file.
Assisted-by: Claude:claude-opus-4-8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Convert the file-level group comment from a plain /* block to a /**
Doxygen comment so the kernel_context_tests group is actually picked up,
and rewrite the individual test descriptions to consistently document
what each case verifies.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The documentation for timer objects in
doc/kernel/services/timing/timers.rst has always stated:
The timer's duration is a **minimum** delay relative to the time
the timer was started.
However the implementation did not actually honour that contract. When
starting a relative duration, k_timer_start() was subtracting one from
duration.ticks before passing it to z_add_timeout(), cancelling out
z_add_timeout()'s conservative round-up. The net result was that
k_timer_start(K_TICKS(N), ...) could fire anywhere from just after 0
up to N ticks later -- strictly less than the documented minimum.
The in-tree comment acknowledged the mismatch ("i.e. k_timer_start()
doesn't treat its initial sleep argument the same way k_sleep() does,
but historical") and kept the subtraction for backwards compatibility.
This has lasted long enough. Drop the subtraction (and the companion
max(1, ...) whose only purpose was to keep the subtraction from
underflowing). k_timer_start() now honours its documented "minimum
delay" contract, matching the behaviour of k_sleep() for the same
tick count.
Callers that relied on the old "approximately N ticks" timing will
see up to one extra tick of delay on the initial fire, when the
call happens partway through a tick. Subsequent periodic fires are
unaffected: they are rescheduled from the timer ISR at an exact
tick boundary and continue to honour the period as before.
Note that a timer manually re-armed from within its own expiry
callback (rather than via the periodic 'period' argument) does not
suffer from the extra tick either: the callback runs inside
sys_clock_announce_locked(), so z_add_timeout()'s round-up is skipped
and the new fire lands at an exact tick stride. This preserves the
behaviour that the original -1 on the duration was presumably trying
to achieve in the first place, now obtained via the proper mechanism.
A few in-tree tests were tuned too tightly against the old
"approximately N" timing. Widen their tolerances to match the new
"at least N" contract:
- tests/kernel/timer/timer_api: add one tick of slack in
interval_check() to absorb the round-up.
- tests/kernel/context: widen idle-timer slop by one tick.
- tests/kernel/workq/work: express the busy-wait margin in ticks
in the "running cancel" tests.
- tests/kernel/threads/no-multithreading: on tickful kernels the
pending IRQ delivered after irq_unlock()/k_cpu_idle() only
announces one tick; wait one extra tick or loop idling until
the timer callback runs.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
test_cpu_idle asserts that while k_cpu_idle() is suspended, the only
interrupt that wakes the CPU is the one from the user's scheduled
timer. Several in-tree subsystems and drivers schedule their own
periodic timeouts independently of the test and can spuriously wake
the idle:
- CONFIG_TIMESLICING arms a per-CPU slice timeout on every thread
swap. That timeout fires regardless of the test's idle timer.
- CONFIG_EVICTION_NRU (demand paging) runs a periodic pulse every
CONFIG_EVICTION_NRU_PERIOD to clear accessed bits, also firing
behind the test's back.
- The Renesas RX CMT timer driver uses a 16-bit counter that
cannot span more than one tick period, so it has to schedule
multi-tick timeouts in multiple stages and delivers an
intermediate tick announcement before the requested deadline.
All three have been able to break the test for a long time when
enabled; they just happened not to be exercised under the old
k_timer_start() timing. Disable TIMESLICING in prj.conf, filter out
configurations where EVICTION_NRU is selected, and bump MAX_IDLE_WAKES
to 1 for RENESAS_RX_TIMER_CMT, which is what actually makes the test
invariant hold.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Introduce an architecture API that reports the calling CPU's current
interrupt-enable state without modifying it. Unlike arch_irq_unlocked()
which inspects a saved key, this one probes the live CPU register, which
lets callers avoid the lock/unlock dance when all they need is to test
whether IRQs are currently masked.
Most arches can serve this from a single register read (DAIF on arm64,
PRIMASK/BASEPRI/CPSR on arm, mstatus on riscv, PS on xtensa, STATUS32
on arc, c0_status on mips, SPR_SR on openrisc, PSW on rx, EFLAGS on
x86). SPARC, POSIX, and riscv with custom SoC IRQ-lock ops have no
direct probe and fall back to a brief arch_irq_lock()/unlock() pair.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
The whisper simulator does not have a working implementation
for wfi instruction and simply treats it as no-op. Therefore,
any CPU idle test will fail as wfi returns immediately. So
skip those tests.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
The OpenRISC 1000 architecture can be tested through the qemu_or1k emulated
SoC and board. Because this emulated device has minimal external hardware
by default, this patch enables a minimal suite of tests covering core
kernel features for the CPU architecture.
When running the test suite, OpenRISC was found to require additional stack
space to prevent an overflow. Therefore, a minimal additional amount of
storage: 128-bytes, was added that was found in practice to allow tests to
complete.
Note that Qemu version 9.2.0 or newer is required so as to include the
following commit:
commit 3eb43aeb164f1f83c97ff693c7d464b49755110c
Author: Joel Holdsworth <jholdsworth@nvidia.com>
Date: Fri Jun 7 15:29:33 2024 -0700
hw/openrisc: Fixed undercounting of TTCR in continuous mode
This fixes a bug in the implementation of the emulated OpenRISC Tick Timer
which prevents the Zephyr OpenRISC port from task-scheduling properly.
Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com>
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>
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>
Fix issues reported by string validation which was added to strings
used in zassert macros.
Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
native_posix has been removed. There is no need to check for it
anymore.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Mostly a revert of commit b1def7145f ("arch: deprecate `_current`").
This commit was part of PR #80716 whose initial purpose was about providing
an architecture specific optimization for _current. The actual deprecation
was sneaked in later on without proper discussion.
The Zephyr core always used _current before and that was fine. It is quite
prevalent as well and the alternative is proving rather verbose.
Furthermore, as a concept, the "current thread" is not something that is
necessarily architecture specific. Therefore the primary abstraction
should not carry the arch_ prefix.
Hence this revert.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
CONFIG_ENTROPY_GENERATOR is now enabled by default as soon as
"zephyr,entropy" is set in the device-tree. Since the sub-Kconfig
CONFIG_ENTROPY_NRF5_RNG is also enabled by default on nrf boards,
this means that the driver is pulled in the build and intialized
at boot. This might cause runtime issues during some IRQ/kernel
tests, so it's better to remove "zephyr,entropy" on these tests.
Signed-off-by: Valerio Setti <vsetti@baylibre.com>
Convert them to native YAML lists. Support for space-separated
lists was deprecated in Twister a long time ago.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
`_current` is now functionally equals to `arch_curr_thread()`, remove
its usage in-tree and deprecate it instead of removing it outright,
as it has been with us since forever.
Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This case fails to build on boards having APIC TSC timer enabled.
This change is needed after moving APIC TSC timer support from
apic_timer.c to apic_tsc.c.
Signed-off-by: Dong Wang <dong.d.wang@intel.com>
An ifdef should have been also checking for native_sim,
let's correct it.
Note: By now native_sim builds with "native_posix compatibility mode"
enabled, which sets BOARD_NATIVE_POSIX to avoid breaking all this kind
of dependencies. But that will stop soon.
So let's fix the dependencies.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
In 972a4d9f6f
the test was relaxed to allow a possible parallel thread
waking the CPU during the idle timeout checks.
How this was done though, a system timer driver
which wakes the kernel spuriously a bit before the
correct deadline would not be detected, even
though it should.
Let's fix this, ensuring the timer has been
called when we check the wake time in inside the
expected range.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This test assumes that nothing will wake the CPU apart from
the timer set by the test.
But that is not necessarily the case.
Some other platform thread started at boot
may be waking the CPU every now and then.
Let's allow for some spurious wakes while we are testing k_cpu_idle,
while at the same time ensuring we are not just busy waiting
all the way.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Because it was exclusively used by the "common" RISC-V privileged code
to build CPU idle routines that are now handled by arch level code.
Also, all platforms defaulted to "y", making it pointless in practice.
Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This test assumes nothing else is running in the background
but when the logger is on, this board will by default
start the RTC sync mechanism, which will awake the CPU
every now and then.
Let's disable this mechanism to avoid disturbing the test.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
With picolibc being the default C library, we need to explicitly include
testing against the minimal C library for kernel components.
Signed-off-by: Keith Packard <keithp@keithp.com>
The original issue is fixed some time ago, so re-enable the
test.
This reverts commit 52992b0658
("tests: skip the cpu_idle test for nsim_hs_smp")
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
- Add integration_platforms to avoid excessive filtering
- Make sure integration platforms are actually part of the filter
- Fix some tags and test meta data
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
The kernel/context test_timer_interrupts() test has a loop calibration
phase to estimate the number of loops needed for 1 system tick.
By initializing this calibration to 1 instead of 0, we can avoid an
edge condition where the calibration phase indicates 0 loops are
required (a case that could happen when running on a slow simulator).
Signed-off-by: Peter Mitsis <peter.mitsis@intel.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>
Clang complains when an unsigned value is passed to abs, even though there
is an implicit cast to a signed type. Insert an explicit cast to make clang
happy.
Signed-off-by: Keith Packard <keithp@keithp.com>
A new Z_SPIN_DELAY() macro has been added which
can be used to reduce a bit the amount of noise
due to the POSIX arch need to break busy loops with
k_busy_wait().
Use it.
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
Tune quantum parameter for selected kernel tests
targetting the HiFive Unleashed platform.
Those tests require higher fidelity of the virtual
time flow which is achievable on multi-core platforms
in Renode by reducing the quantum.
Signed-off-by: Jan Malek <jmalek@internships.antmicro.com>
Signed-off-by: Mateusz Holenko <mholenko@antmicro.com>
For tests that set CONFIG_MP_NUM_CPUS, switch to using
CONFIG_MP_MAX_NUM_CPUS instead as we work to phase out
CONFIG_MP_NUM_CPUS.
Signed-off-by: Kumar Gala <kumar.gala@intel.com>
In test_busy_wait and test_k_sleep test cases of
tests/kernel/context test we measure not only execution time of the
primitives itself (k_busy_wait and k_msleep respectively) but also
the overall test thread execution time.
The issue here is that we do printing in test threads which
means that we do printing in time-critical sections. That breaks
test if we do printing via some device which isn't fast enough.
Fix that by removing print from time-critical section
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Add a bunch of missing "zephyr/" prefixes to #include statements in
various test and test framework files.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>