Commit graph

186 commits

Author SHA1 Message Date
Christopher Friedt 13a2294f9d sys_clock: define NSEC_PER_MSEC
NSEC_PER_MSEC should be defined along with the rest of the
per-sec macros in sys_clock.h. Currently, it's defined
multiply in a few separate locations.

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-09-01 16:29:25 -04:00
Martí Bolívar d5b0bd55e0 tests: kernel: common: adjust fudge factors
Loosen some timing constraints in order to hack arond spurious
failures in upstream Zephyr's CI while working on an unrelated task.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2022-08-08 10:44:41 +02:00
Fabio Baltieri def230187b test: fix more legacy #include paths
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>
2022-08-02 16:41:41 +01:00
Tomislav Milkovic 0fe2c1fe90 everywhere: Fix legacy include paths
Any project with Kconfig option CONFIG_LEGACY_INCLUDE_PATH set to n
couldn't be built because some files were missing zephyr/ prefix in
includes
Re-run the migrate_includes.py script to fix all legacy include paths

Signed-off-by: Tomislav Milkovic <milkovic@byte-lab.com>
2022-07-18 16:16:47 +00:00
Guo Lixin 94936ca202 tests: kernel: common: move to new ztest API
Move tests/kernel/common/ to use new ztest API.

Signed-off-by: Guo Lixin <lixinx.guo@intel.com>
2022-07-14 22:09:57 -04:00
Keith Packard 394a0485fb tests/kernel/common: Let picolibc pick a malloc heap size
Now that picolibc's malloc arena configuration always allocates
some space, we don't need explicit allocations for tests.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-30 10:33:24 +02:00
Anas Nashif dba3d31ddd tests: kernel: common: increase timeout
Some platforms need more time when under load, 60s are not enough.

Seen on hifive_unleashed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-06-29 17:00:21 -04:00
Keith Packard 88ca3aca98 tests/kernel: Provide expected output for picolibc in printk test
Picolibc has subtly different output from the minimal libc as a result
of different handling for code built without real long long support.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-24 20:30:03 +02:00
Keith Packard f79eaba7e6 tests/kernel: Run common tests using picolibc
This runs the existing kernel common tests using picolibc as some of those
depend on libc functionality.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-23 09:16:32 +02:00
Nicolas Pitre f00573555b Z_POW2_CEIL: simplify implementation
Avoid potentially calling __builtin_clz() twice with non-constant
values. Also add a test for it.

Clang produces false positive vla warnings so disable them. GCC will
spot real vla's already.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-06-16 10:28:15 +02:00
Keith Packard d24e975a71 tests/kernel/common: Include errno_private.h
This ensures that we have a definition of z_errno in case
that isn't pulled in with errno.h

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-05-27 15:34:34 -07:00
Andy Ross 4b9a8a8471 tests/kernel/common: Extend nested_irq_offload case to do a context switch
Bug #45779 discovered an edge case with nested interrupts on Xtensa
where they might select an incorrect thread context to return to
instead of the (mandatory!) return to the outer interrupt context.

Cleverly adjust the nested_irq_offload to exercise this.  It now
creates a thread that it knows it will interrupt, then suspends that
thread from within the inner/nested interrupt.  This guarantees that
_current will be different on exit from the second interrupt, which is
the case that tripped up Xtensa.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2022-05-20 12:37:59 +02:00
Gerard Marull-Paretas ade7ccb918 tests: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all tests to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:02:14 +02:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Daniel Leung 45940cf8cf tests: kernel/common: fix inadequate failing to thread context
The thread context test has insufficient checkings for failing
so add them:

() The variable rv for pass/fail is set but never checked. So
   add a check to fail the test if such indicated.
() Each thread's pass variable is set to TC_FAIL (== 1) and
   the check for successful thread execution simply checks
   if pass variable is not zero, which is always true. So
   change it so the check for failing condition is reasonable.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-02-24 08:38:38 -06:00
Carles Cufi e83a13aabf kconfig: Rename the TEST_EXTRA stack size option to align with the rest
All stack sizes should end with STACK_SIZE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-02-22 08:23:05 -05:00
Andy Ross 59d5dc4dcf tests/kernel/common: Add nested irq_offload() test
Add a very simple test of the CONFIG_IRQ_OFFSET_NESTED feature that
exercises nested interrupts in a portable way.  It calls irq_offset()
from within a k_timer callback and validates that the return lands
back in the original interrupt successfully.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2022-02-21 22:10:03 -05:00
Mahesh Mahadevan 7e4d8c9cd5 tests: skip arch_nop test for ARM platforms
ARM does not guarantee the timing effects of NOP
instruction. Hence skip the test_nop test.
Fix for Issue#42666

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
2022-02-21 21:54:53 -05:00
TOKITA Hiroshi da68cde759 tests: skip arch_nop test when machine timer uses divided sys clock
When the case machine timer clock uses the divided system clock,
k_cycle_get_32() can't measure accurately how many cycles elapsed.

For example, use the value as timer clock obtained by dividing
the system clock by 4.
In this case, measuring a duration with k_cycle_get32() has up to 3
(4-1) cycles systematic error.

To run this test, we need to insert an appropriate of nops
with consideration for the errors.
'nop' can not repeat with for loop.
Must insert as separated statement.
But we don't have a convenient function such as
BOOST_PP_REPEAT in C++.

At this time, Implementing a generic test is a bit difficult.
Skipping this test in the case.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
2021-12-20 17:51:30 +01:00
Christopher Friedt ed7eec4c94 tests: kernel: atomics: expand atomic operations to 64-bit
This change updates the atomic tests to validate 32-bits on
32-bit architectures and 64-bits on 64-bit architectures.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-11-15 09:59:01 -05:00
Christopher Friedt 964b153f96 tests: clock: tests for k_cycle_get_64
This change adds tests for 64-bit cycle counters.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-11-08 13:41:53 -05:00
Enjia Mai 495d10234d tests: common: add test for ffs function
Add a testcase for find_msb_set() and find_lsb_set() functions.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-09-07 11:30:43 -04:00
Nicolas Pitre 5a384b9ea8 lib/os/cbprintf_nano.c: avoid sign extension on unsigned formats
There might be a sign extension when a long is promoted to
int_value_type and the former type is smaller than the later.
This produces the wrong output if the specified format is unsigned.

Let's avoid this problem by handling signed and unsigned cases
explicitly. When the type already matches int_value_type then the
compiler is smart enough to recognize the redundancy and removes
unneeded duplications automatically, meaning that the code will stay
small when code size matters.

A similar issue also existed in the restricted %llu case.
The fix is the same as above.

Those fixes exposed wrong results in the printk.c test with %llx
so fix that as well.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-09-02 19:37:06 -04:00
Naiyuan Tian 4cb1f0ef94 tests: common: fix typos in the commits
While reading the code, find typo in the code comment.
In file irq_offload.c, line 163.

Signed-off-by: Naiyuan Tian <naiyuan.tian@intel.com>
2021-08-26 06:54:55 -04:00
Torsten Rasmussen 1cccc8a8fe cmake: increase minimal required version to 3.20.0
Move to CMake 3.20.0.

At the Toolchain WG it was decided to move to CMake 3.20.0.

The main reason for increasing CMake version is better toolchain
support.

Better toolchain support is added in the following CMake versions:
- armclang, CMake 3.15
- Intel oneAPI, CMake 3.20
- IAR, CMake 3.15 and 3.20

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-08-20 09:47:34 +02:00
Enjia Mai ee327803e3 tests: common: skip arch_nop testing on some physical x86 board
Using the NOP instructions to do timing control on some physical board
such as ehl_crb, up_squared and intel adsp board, that doesn't work.
It seems like it can only be used for instruction alignment purposes.
We skip this test on this board because it's not meaningful.

Fixes #35971

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-08-06 20:20:32 -04:00
Daniel Leung e3704ccda3 tests: kernel/common: avoid using compiler builtin popcount
Not all arch has native support for __builtin_popcount() on
hardware and GCC falls back in using software only implementation.
However, with GCC 11, this is no longer included automatically
and requires linking explicitly with libgcc.a. This is not
trivial as it requires changes some linker magic and a sizable
change to most linker scripts. So opt for an easy solution
by implementing our own popcount in the test.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-07-22 07:24:11 -05:00
Anas Nashif 8581b6d1f0 tests: remove kernel tag from key tests/samples
Thos tests/samples are used to build any PR onl all available boards to
verify basic sanity. Having the kernel tag means they can get excluded
for random non-kernel changes causing regressions. so remove kernel tag
to keep them in all CI runs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-07-08 08:59:51 -04:00
Daniel Leung 8fd3d18b40 tests: kernel/common: incorrect use of k_poll in timeout order
In the timeout order test, the usage of k_poll() assumes that it
only returns after all events are ready. However, that is not
the case, as k_poll() returns when non-zero number of events are
ready. This means the check for all semaphore being ready after
k_poll() will not always pass. So instead of using k_poll(),
simply wait a bit for timers to fire, then check results.

Also add some bits to clean up at the end of test.

Fixes #34585

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-25 07:34:59 -05:00
Andy Ross 58bc81573f tests/kernel/common: Remove needless 1cpu limitation from test_clock_uptime
It's not at all clear to me why this was set to 1cpu, it's a single
thread doing sequential things.  (I tripped over it because the 1cpu
happened to tickle an unrelated arm64 bug with interrupt state.  But
we might as well fix it here.)

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-05-17 15:27:37 -04:00
Andy Ross 653e7a28ea tests/kernel/common: Skip bitarray tests when KERNEL_COHERENCE
Kernel objects that contain embedded synchronization structures like
spinlocks can't be palced in the (cached/incoherent) stack memory on
coherence platforms like intel_adsp.

The normal fix in a test case is just to make the offending data
static, but that's painful here because SYS_BITARRAY_DEFINE declares
two objects (i.e. you can't put a "static" in front of it as with
similar macros) and it happens to be used in this case to define local
variables with collliding names, so I'd have to go in and rename
everything.

And there's little value anyway.  Bitarrays are nearly-pure data
structures and extremely unlikely to show up platform-dependent
behavior.

Fixes #35242

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-05-15 15:28:43 -04:00
Erwan Gouriou 77a751ecf9 tests/kernel/common: Fix test test_nop for ARMV7_M_ARMV8_M_MAINLINE
Treat ARMV7_M_ARMV8_M_MAINLINE similarly to ARMV6_M_ARMV8_M_BASELINE
and add arch_nop() calls to test_nop function.
Additionally add one arch_nop() call to fit comment and update
comments when required on other archs.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2021-05-11 07:15:17 -05:00
Enjia Mai a7d8ff40aa tests: common: fix newly added test_nop failing the CI
The newly added testcase test_nop failed the CI. Give RISCV more
arch_nop() instructions to archieve one cycle.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-08 17:08:17 -04:00
Anas Nashif 76f59b24df test: kernel: skip new failing test
new test failed which means we missed something in CI or the failing
platform changed after CI was initially run. skip it for now while we
investigate.

Do some minor cleanup in the metadata.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-08 07:26:24 -04:00
Enjia Mai e92ca60b4e tests: arch: add a test case for testing arch_nop() interface
Add a test case to test arch interface arch_nop(), the main focus here
is for coverage of the code. arch_nop() is a special implementation
and it will behave differently on different platforms. By the way, this
also measures how many cycles it spends for platforms that support it.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-07 22:17:24 -04:00
Ying ming 8a91bbf69b test: atomic: multiple equal priority threads access atomic variable
Add an testcase. Creat two preempt threads with equal priority to
atomiclly access the same atomic value. Because these preempt
threads are of equal priority, so enable time slice to make
them scheduled. The thread will execute for some time.
In this time, the two sub threads will be scheduled separately
according to the time slice.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-05-07 18:23:27 -04:00
Andy Ross 4898e2c613 tests/kernel/common: Skip boot delay tests on systems that are too fast
First, this test is a little suspect.  It's assuming that the value
returned from k_cycle_get_32() represents the time since system
power-on.  While that's an obvious implementation choice and surely
often true, it's definitely not the way we document this API to the
arch layer.  It's perfectly legal for a platform to return any value
as long as the counter is increasing at the correct rate.  Leaving for
now as there's no other way to test CONFIG_BOOT_DELAY, but this will
likely be coming back to confuse us at some point.

Regardless, that convention holds for x86 devices using any of the
existing drivers.  But on an EFI PC using the TSC counter as the clock
source: (1) the counter is running at 1-2 GHz and (2) the time to get
through an EFI BIOS and into Zephyr is routinely 10+ seconds,
especially on reference hardware.  The poor 32 bit API will roll over
several times, and effectively be a random number by the time it
reaches this test.

Just skip this test with fast counter.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-05-07 16:48:58 -04:00
Evgeniy Paltsev 0a5137f109 ARC: ARCv3: add qemu HS6x board
Add QEMU board with single core ARCv3 HS6x 64 bit CPU

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2021-05-07 14:55:49 -05:00
Lauren Murphy 771a643051 tests: kernel/common: add tests for bit array
This adds some tests to make sure sys_bitarray_*() are
working correctly.

Signed-off-by: Lauren Murphy <lauren.murphy@intel.com>
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-07 13:36:22 -04:00
Anas Nashif a09b5ade26 tests: kernel: remove debug message for LLVM
Remove debug message in test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-04-22 07:42:58 -04:00
Peter Bigot f69a38162a kernel: atomic: consistently use named type for atomic pointer values
There's a typedef for non-pointer values compatible with atomic
non-pointer objects.  Add a similar typedef for pointer values, and
the corresponding macro for initializing atomic pointer types.

This also will simplify replacing the Zephyr atomic API with one
based on C11 atomics, should that be desirable.  C11 atomic pointer
values are not void*.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-04-19 15:22:13 +02:00
Anas Nashif 0ec3774bde userspace: rename _is_user_context -> k_is_user_context
This functions is being called across the tree, no reason why it should
not be a public API.

The current usage violates a few MISRA rules.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-04-01 05:34:17 -04:00
Enjia Mai 702f89d885 tests: common: add test case for testing errno
Add test case for testing errno, shows it works properly.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-03-02 14:29:58 -05:00
Andy Ross 015b4f7303 tests/kernel: Coherence: no shared data on stacks
A fairly common idiom in our test code is to put test-local data
structures onto the stack, even when they are to be used from another
thread.  But stacks are incoherent memory on some platforms, which
means that such things may not get a consistent view of memory between
threads.

Just make these things static.  A few of these spots were causing test
failures on intel_adsp_cavs15.  More were found by inspection while
hunting for mistakes.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-11 14:47:40 -05:00
Andy Ross 4d4a636555 tests/kernel/common: Skip the printk test when not applicable
When CONFIG_LOG_PRINTK is set, the printk hook mechanism doesn't exist
and this test can't pass.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-03 20:56:14 -05:00
Watson Zeng 0bc64a7946 tests: tls: add toolchain filter
tls rely on both arch has tls and toolchain support tls, add filter:
CONFIG_TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE for
some tests enabled tls.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2020-12-15 11:22:38 +01:00
Anas Nashif 98981ec05e tests: kernel: do not build on all platforms
build_on_all here was supposed to be a smoke test to test building on
all platforms, it should not be used for more than 1 just test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-11-30 13:10:32 -08:00
Meng xianglin e696c65de1 test: context: Refine descriptions for some test cases
Add or refine comments for some test cases for readability

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2020-11-17 22:11:45 -05:00
Martin Åberg d2409ec0f7 tests: Big endian support in bitfield test
The BIT_INDEX() macro assumed little-endian. This commit adds
big-endian support, conditioned on the preprocessor define
CONFIG_BIG_ENDIAN.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-11-13 14:53:55 -08:00
Peter Bigot bb99422c8a lib/os: replace z_vprintk with cbprintf
Using the same implementation as the rest of Zephyr reduces code size.

Update options and expected results for formatting test.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-13 06:38:01 -05:00