Commit graph

2597 commits

Author SHA1 Message Date
Gerard Marull-Paretas
18519ffe8d tests: use common PM action callback naming
The PM callback is no longer referenced as "pm_control" but
"pm_action_cb", so reflect this new naming on the callbacks.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 20:27:18 -04:00
Ying ming
56ef5aac52 test: change test suite name and testcase name
Because there are two testcases be the same name
in directory tests/kernel/sched/, so change one of
them to avoid confusion.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-11-03 16:44:50 -04:00
Gerard Marull-Paretas
1cee284a46 pm: device: runtime: use pm_device_runtime* namespace
Move all PM device runtime API calls from pm_device* to the
pm_device_runtime* namespace.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-11-03 16:37:33 -04:00
Krzysztof Chruscinski
5d73d81ca1 tests: kernel: mem_slab: Fix test for no multithreading
Modified test to exit early when multithreading is disabled to
fix linking errors.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-11-03 09:18:40 -04:00
Christopher Friedt
213ad01ed0 tests: kernel: disable one test for qemu_cortex_a9
Currently a test is failing.

```
twister -i -p qemu_cortex_a9 \
  -s tests/kernel/fatal/exception/kernel.common.stack_sentinel
```

Disable those temporarily until a fix is in place.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-11-01 22:10:04 -04:00
Lixin Guo
a13b907398 tests: mslab: add test case for coverage
Add test case to test thread pending operation
in k_mem_slab_alloc() API.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-11-01 11:17:09 -04:00
Lixin Guo
4b9b30c99d tests: msgq: improve code coverage for msgq API
This improves code coverage for the branch whether
write pointer in message queue reaches buffer end.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-11-01 11:15:15 -04:00
Lixin Guo
7fb38330f6 tests: queue: add a test case for coverage
Add a test case for k_queue_unique_append() API.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-10-28 12:06:25 -04:00
Lixin Guo
5b9c6264af tests: userspace: add a test for code coverage
Add a test case for getting all the kernel objects in
kobject list.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-10-28 12:01:01 -04:00
Immo Birnbaum
52a5c08325 tests: enable kernel test fatal/exception for aarch32 Cortex-A CPUs
Add consideration of aarch32 Cortex-A CPUs to a test case in which
architecture-specific assembly instructions are used in order to
explicitly trigger an exception. This test case already considers
aarch32 Cortex-R CPUs, the same instruction will be used by
Cortex-A CPUs.

Signed-off-by: Immo Birnbaum <Immo.Birnbaum@Weidmueller.com>
2021-10-28 15:26:50 +02:00
Lixin Guo
2643e8d62d tests: mutex: fix improper test identifier
The test identifier of mutex error case in testcase.yaml is
exactly the same as mutex api's test identifier.
So I fix this.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-10-20 10:19:18 -04:00
Peter Mitsis
10637afc00 tests: add event test code
Adds both kernel and user space test code for the events API.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2021-10-16 06:27:10 -04:00
Lixin Guo
fb18038e55 tests: stack: fix improper assert message
I find that there has a description error and a spelling
mistake in assert message. So I fixed this.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-10-13 06:17:23 -04:00
Lixin Guo
d460a6361d Test: stack: add a test case for code coverage
Add a testcase for stack_alloc_init API.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-10-13 06:17:02 -04:00
Keith Short
0bfde7bc5d tests: Add PM control to dummy_driver
Add the pm_control fn to the dummy_driver so the full PM API is tested.
This change also bypasses all PM APIs if the device driver doesn't
support PM.

Signed-off-by: Keith Short <keithshort@google.com>
2021-10-13 06:16:13 -04:00
Carlo Caione
43cb00df08 multi_heap: Introduce shared multi-heap memory pool manager
The shared multi-heap memory pool manager uses the multi-heap allocator
to manage a set of reserved memory regions with different capabilities /
attributes (cacheable, non-cacheable, etc...) defined in the DT.

The user can request allocation from the shared pool specifying the
capability / attribute of interest for the memory (cacheable /
non-cacheable memory, etc...)

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-10-12 07:44:46 -04:00
Flavio Ceolin
5027c356cd test: pm: device: Fix build options
The test is using device and device runtime power management. Just
including them to the test build.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-10-07 15:44:32 -04:00
Andy Ross
13d3036e37 tests/msgq_usage: Correct memory usage for cache-incoherent platforms
When CONFIG_KERNEL_COHERENCE=y (e.g on the various intel_adsp
platforms under SMP) it's not legal to share stack memory between
CPUs, because the stack is cached, and the L1 cache is incoherent.
The kernel will automatically detect the mistake when the memory
contains a kernel object (spinlock, IPC object, etc...).  But here the
test was just passing async buffers into the msgq layer, and nothing
watches that.

The fix is simple: make them static.

Fixes #35857

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-10-06 17:40:53 -04:00
Andy Ross
f3ed0feb47 tests/kernel/mheap_api_concept: Add sys_multi_heap test
Add a simple coverage test for the multi_heap utility, validating all
cases with a simple configuration value that specifies an index in an
array of heaps.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-10-01 20:38:35 -04:00
Alexandre Bourdiol
25432ecfa4 tests: kernel: sched: schedule_api: enlarge timeslice criterion
From time to time, measured slice time is one less/more than requested.
Fixes #35793

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2021-09-30 20:39:31 -04:00
Lixin Guo
a5a360d319 Tests: memory protect: add some error test cases
Add some error case for adding and removing memory partition
API.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-09-29 06:29:19 -04:00
Andy Ross
0f20abda8d tests/kernel/threads_apis: Add case for CPU_MASK_PIN_ONLY
Add testing for the PIN_ONLY API variant (which has a separate run
queue per CPU).  Predicate on SMP systems only, to keep needless
duplicate testing to a minimum.

Note that one of the cases in this test exercises an "all cpus" option
for the cpu mask, which is illegal when CONFIG_SCHED_CPU_MASK_PIN_ONLY
is set.  Skip.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-09-28 20:15:05 -04:00
Yuguo Zou
5b590faab5 tests: threads: fix kernel/thread_stack test
Fix the broken logic in the kernel/thread_stack test
The modified test should do direct read & write from estimated stack
pointer to highest address in the stack buffer.
Previously this test was start from lowest address in the stack
which would trigger exception of hardware stack checking scheme
violation on ARC boards and other targets with hardware stack
overflow detection.

Signed-off-by: Yuguo Zou <yuguo.zou@synopsys.com>
2021-09-27 12:25:12 -04:00
Naiyuan Tian
1f99a0ca18 tests: threads: fix uninitialized scalar variable
In the file variable val is not initialized,
causing the variable stack_ptr, pos, points to uninitialized data.
Initialize the variable val according to the code and commits.

Fixes #37916

Signed-off-by: Naiyuan Tian <naiyuan.tian@intel.com>
2021-09-17 22:30:50 -04:00
NingX Zhao
ca4c71ca02 tests: thread: Add an initialization
Add an initialization to the global variable to make sure testcases
can be ran correctly.

Signed-off-by: NingX Zhao <ningx.zhao@intel.com>
2021-09-17 10:30:54 -04:00
Chen Peng1
0774ce94ed tests: mem_map: limit memory below 0x10000000 on up_squared.
there is a memory hole from address 0x10000000-0x12150fff
in the ram on up_squared, we don't have access to read/write
this range, so limit the memory range below 0x10000000.

Signed-off-by: Chen Peng1 <peng1.chen@intel.com>
2021-09-16 09:32:36 -04:00
Francois Ramu
30db452aec tests: kernel: timer api with real time slot in test_sleep_abs
This patch is testing the test_sleep_abs with a longer
real time slot value. The reason is that for platforms
like stm32wb55rg with PM, the real time slot must be adjusted
because of the LPTIM ticker.

Signed-off-by: Francois Ramu <francois.ramu@st.com>
2021-09-10 16:20:30 -04: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
Filip Kokosinski
19fc1ee77c subsys/random: change parameters for timer-based PRNG
PR #36996 disabled running mem_protect/stack_random test on qemu_riscv32
platform because of this test consistently failing on said platform.
This test starts new threads in equal time intervals, and because of
that we get repeating values after performing the modulus operation when
calculating the stack pointer address.

This can be solved by changing the value of the _RAND32_INC constant
that is used to increase the value returned by the timer-based PRNG.

This commit decreases the value of the mentioned constant from
1000000013U to 1000000003U.

Fixes #37006.

Signed-off-by: Filip Kokosinski <fkokosinski@antmicro.com>
2021-08-30 09:32:36 -04:00
Torsten Rasmussen
2760fb9eda tests: added kernel tests for arm arch with linker script generator
This commit adds an additional test case for several kernel test suites
to ensure that the linker script generator is working correctly for a
subset of the Zephyr test suites.

The ensures that the basic functionality of the linker script generator
is working while still keep the performance impact on CI at a minimal
level.

Using the kernel tests is a trade-off between testing coverage of the
linker script generator and the time it takes to complete CI.

The kernel tests is considered to have the broadest coverage of various
features important for the generated linker script.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-08-30 08:54:23 -04:00
Torsten Rasmussen
c6aded2dcb linker: align _image_rodata and _image_rom start/end/size linker symbols
Cleanup and preparation commit for linker script generator.

Zephyr linker scripts provides start and end symbols for each larger
areas in the linker script.

The symbols _image_rom_start and _image_rom_end corresponds to the group
ROMABLE_REGION defined in the ld linker scripts.

The symbols _image_rodata_start and _image_rodata_end is not placed as
independent group but covers common-rom.ld, thread-local-storage.ld,
kobject-rom.ld and snippets-rodata.ld.

This commit align those names and prepares for generation of groups in
linker scripts.

The symbols describing the ROMABLE_REGION will be renamed to:
_image_rom_start -> __rom_region_start
_image_rom_end   -> __rom_region_end

The rodata will also use the group symbol notation as:
_image_rodata_start -> __rodata_region_start
_image_rodata_end   -> __rodata_region_end

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-08-28 08:48:03 -04:00
Flavio Ceolin
2549160d69 pm: device: Remove PM_DEVICE_STATE_FORCE_SUSPEND
This is not a state but an action. Just remove it.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-08-27 17:47:10 -04:00
Daniel Leung
27f36bda51 boards: qemu_x86_tiny: enabled for general demand paging testing
This enables qemu_x86_tiny to be used for more general demand
paging testing where non-pinned code and data is not available
in physical memory at boot. This adds a custom linker script to
qemu_x86_tiny for pinning code and data. In the process, a new
kconfig CONFIG_BOARD_QEMU_X86_TINY has to be introduced to
distinguish from other qemu_x86* boards. This linker script
is based on the generic x86-32 one in
include/arch/x86/ia32/linker.ld, with additions to
put symbols into boot and pinned sections.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-26 21:16:22 -04:00
Daniel Leung
1203289143 tests: mem_protect/mem_map: pin test_page in memory
This pins the test_page in memory for tests about memory
mapping. This is simply to make sure the whole array
is in physical memory for mapping or else the mapping
function would fail due to having nothing to map.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-26 21:16:22 -04:00
Daniel Leung
ba94780662 tests: device: pin symbols for testing with demand paging
There are quite a few symbols which are needed before the paging
mechanism is initialized. So they need to be pinned in memory
to prevent page fault early in the boot process.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-26 21:16:22 -04:00
Daniel Leung
802b55bb50 tests: mbox_api: a bit more stack for qemu_x86_tiny
For testing on qemu_x86_tiny, a little bit more stack is needed.
So add the extra stack for testing.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-26 21:16:22 -04:00
Daniel Leung
bb1656abc6 tests: mem_protect/userspace: _k_neg_eagain maybe in pinned sect
If pinned section is enabled, _k_neg_eagain should be in pinned
rodata section. So add the check if pinned section is enabled.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-26 21:16:22 -04:00
Daniel Leung
46ae0a5664 tests: demand_paging: pin fatal error handler
This puts the fatal error handler into pinned sections so
it can be used to handle fatal errors without causing
page faults.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-26 21:16:22 -04:00
Daniel Leung
b70d44c94d tests: fatal/exception: pin stack before stack overflow test
For hardware stack overflow test, pin the whole stack if
demand paging is enabled and generic sections are not all present
at boot. The whole stack may not be in memory at the time of
test, which would result in double fault (exception being
handled + page fault). So make sure the stack is in physical
memory and mapped before doing any tests.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-08-26 21:16:22 -04:00
Naiyuan Tian
66c931dbd4 tests: interrupt: fix typos in the commits
While reading the code, find typos in the code commits.
tests:kernel:interrupt:src:dynamic_isr, line 110 and 115.

Signed-off-by: Naiyuan Tian <naiyuan.tian@intel.com>
2021-08-26 06:54:55 -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
Michał Barnaś
5a1fcb609c doc: replace courge with corge
Grault and corge are both syntactical variables used globally.
Courge is misspelling of corge.

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2021-08-23 18:54:27 -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
NingX Zhao
c0d18079cc poll: add a testcase to detect is_polling
Add a testcase to detect is_polling, to avoid some
issues.

Fixed #12405

Signed-off-by: NingX Zhao <ningx.zhao@intel.com>
2021-08-18 20:09:01 -04:00
Bradley Bolen
60f23a5dc2 tests: userspace: Add Cortex-R test
Try to read the stclr register from userspace.  This should generate an
exception.

Signed-off-by: Bradley Bolen <bbolen@lexmark.com>
2021-08-17 06:06:33 -04:00
Bradley Bolen
ce85892916 tests: mem_protect: syscalls: Add bad address for qemu_cortex_r5
The default address for FAULTY_ADDRESS is valid on the qemu_cortex_r5
board, so use a value that is not mapped for that board.

Signed-off-by: Bradley Bolen <bbolen@lexmark.com>
2021-08-17 06:06:33 -04: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
Gerard Marull-Paretas
d41dadc569 pm: rename PM_DEVICE_STATE_SUSPEND to PM_DEVICE_STATE_SUSPENDED
The verb tense for the suspended state was not consistent with other
states. The likely reason: state was being used as a command/action.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-08-04 08:23:01 -04:00
Johann Fischer
3240e0cc51 tests: remove USB configuration option
Remove USB configuration option, replace it where necessary
with USB_DEVICE_STACK.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2021-08-03 19:00:12 -04:00
Enjia Mai
c2ac8fe7d7 acrn_ehl_crb: fix the incorrect configuration of timer IRQ priority
The default CONFIG_APIC_TIMER_IRQ_PRIORITY is 4, but it should be 1 for
ACRN. That's why the testcase failed due to no timer interrupt was
triggered.

And we also temporary adjust the testing IRQ for dynamic isr due to it
conflict with the IRQ of the APIC TSC deadline TIMER.

Fixes #36203.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-08-03 07:30:15 -04:00
Gerard Marull-Paretas
6c3beb928e pm: adjust busy check API call return types and naming
Busy check APIs now return boolean type. Due to that change, the
function names have also been adjusted. The common name pattern for
boolean check type APIs is "PREFIX_is_CONDITION". For example,
"pm_device_is_busy".  pm_device_busy_check has been renamed to
pm_device_is_busy and pm_device_any_busy_check to pm_device_is_any_busy.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-30 09:28:42 -04:00
Gerard Marull-Paretas
90c61a3702 tests: kernel: device: remove redundant busy set and clear
The test_dummy_device test has nothing to do with device busy testing,
so remove the calls to pm_device_busy_set/pm_device_busy_clear.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-30 09:28:42 -04:00
Gerard Marull-Paretas
70322853a8 pm: device: move device busy APIs to pm subsystem
The following device busy APIs:

- device_busy_set()
- device_busy_clear()
- device_busy_check()
- device_any_busy_check()

were used for device PM, so they have been moved to the pm subsystem.
This means they are now prefixed with `pm_` and are defined in
`pm/device.h`.

If device PM is not enabled dummy functions are now provided that do
nothing or return `-ENOSYS`, meaning that the functionality is not
available.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-30 09:28:42 -04:00
Flavio Ceolin
96d5a58a46 tests: profiling: Remove unnecessary stubs
It is not necessary to implement stubs for system pm functions.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-07-26 04:31:54 -04:00
Daniel Leung
9debd59368 tests: schedule_api: use stack array extern macro
The stack array tstacks was declared in the header file using
the same macro which defines the same stack array but with
an added "extern" in front. This macro adds alignment and section
attribute which are actually not the same as the actual stack array
defined in main.c. The section name used in the section attribute
contains the file name where the stack array is defined or extern
declared. So the same symbol, in this case z_interrupt_stacks, has
different attributes in two places, and GCC 11 starts to complain
about this. So use the newly introduced macro to extern declare
the stack array without adding/replacing any symbol attributes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-07-22 07:24:11 -05:00
Daniel Leung
15a46cfee4 tests: mem_protect: fix warning on uninitialized variable
In test_kobject_release_null(), dummy is not initialized
before being fed to k_object_release(). So set it.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-07-22 07:24:11 -05: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
Christopher Friedt
a87a5ea22b tests: kernel: mem_protect: stack_random: disable qemu_riscv32
Test fails consistently in CI but local builds succeed. Puzzling. In
order to keep main green, disabling this test only for qemu_riscv32
until a solution is found.

```
% west build -p always -b qemu_riscv32 -t run \
  tests/kernel/mem_protect/stack_random
...
*** Booting Zephyr OS build zephyr-v2.6.0-1039-g523764b3fd75  ***
Running test suite stack_pointer_randomness
===================================================================
START - test_stack_pt_randomization
Test Stack pointer randomization
stack pointer changed 13 times out of 64 tests
 PASS - test_stack_pt_randomization in 0.5 seconds
===================================================================
Test suite stack_pointer_randomness succeeded
===================================================================
PROJECT EXECUTION SUCCESSFUL
```

```
*** Booting Zephyr OS build zephyr-v2.6.0-1063-g0106d8f2a391  ***
Running test suite stack_pointer_randomness
===================================================================
START - test_stack_pt_randomization
Test Stack pointer randomization
stack pointer changed 0 times out of 64 tests
 Assertion failed at WEST_TOPDIR/zephyr/tests/kernel/mem_protect/\
  stack_random/src/main.c:68: test_stack_pt_randomization: \
  (sp_changed equal to 0)
 Stack pointer is not randomized
FAIL - test_stack_pt_randomization in 0.6 seconds
===================================================================
Test suite stack_pointer_randomness failed.
===================================================================
PROJECT EXECUTION FAILED
```

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-07-16 14:48:21 -04:00
Kumar Gala
ab9d935fed tests: kernel: device: Exclude beaglev_starlight_jh7100
We excluded the beaglev_starlight_jh7100 from this test but only did
the kernel.device.pm test.  We should have excluded the platform
from both tests.

The beaglev_starlight_jh7100 uses a full 64-bit devicetree map
which uses #{address/size}-cells = 2.  The device test expects
that #{address/size}-cells = 1 so exclude beaglev_starlight_jh7100
from the test.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-07-14 16:12:57 +03:00
Hake Huang
3a3ca2b3b2 tests: add min_ram to test applications
add min_ram to some test applications
as we found below platforms have size issues
TWR_KE18F and FRDM_KL25Z

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2021-07-13 10:20:18 -05:00
Gerard Marull-Paretas
26ad8376bd pm: remove callback from control function
The callback is not used anymore, so just delete it from the pm_control
callback signature.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-13 09:36:45 -04:00
Gerard Marull-Paretas
1b716cfe3a tests: kernel: device: fix incorrect device power state type
The type used by device PM state was not changed to the recently
introduced enum type. The state is also initialized to a value distinct
from the first expected value.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-08 12:08:20 -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
Gerard Marull-Paretas
cc2f0e9c08 pm: use enum for device PM states
Move all PM_DEVICE_STATE_* definitions to an enum. The
PM_DEVICE_STATE_SET and PM_DEVICE_STATE_GET definitions have been kept
out of the enum since they do not represent any state. However, their
name has not been changed since they will be removed soon.

All drivers and tests have been adjusted accordingly.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-07-07 14:13:12 -04:00
Kumar Gala
1e71415214 tests: kernel: device: Exclude beaglev_starlight_jh7100
The beaglev_starlight_jh7100 uses a full 64-bit devicetree map
which uses #{address/size}-cells = 2.  The device test expects
that #{address/size}-cells = 1 so exclude beaglev_starlight_jh7100
from the test.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-06-30 13:39:52 -04:00
Watson Zeng
e451bf44fe tests: mem_protest: workaround aggressive optimization
We have some static variables var, zeroed_var and bss_var
in mem_partition.c and we only assert the value of them in
the same file, so the compiler may pre-calculate it in compile
stage, it's fine usually.
But for variable zeroed_var (= 20420), we force to put it in bss
section in link stage, the value will change in bss clean stage, so
we will get a wrong result.
Let's add volatile for these variables to disable pre-calculation.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2021-06-28 09:15:43 -04:00
Ioannis Glaropoulos
1a7228a462 tests: add fpu tag the tests which enable FPU and FPU_SHARING options
Introduce the fpu tag to tests that explicitly enable
the FPU and FPU_SHARING Kconfig options. The tag could
be used to run all FPU-related tests in the tree.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-06-22 08:45:41 -04:00
Mulin Chao
38eaabc9c7 tests: kernel: gen_isr_table: Add workaround for npcx9 series.
Both NPCX7/9 uses the IRQs at the end of the vector table, for example,
the IRQ 60 and 61 used for Multi-Input Wake-Up Unit (MIWU) devices by
default, and conflicts with ISR used for testing.

This CL changes TEST_NUM_IRQS (The value is changed from 46 to 44) to
move IRQ used for this test suite from 42 to 40 which is reserved in
both NPCX7 and NPCX9 series to resolve the issue.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2021-06-08 00:40:14 -04:00
Anas Nashif
86209aced7 boards: qemu_x86_coverage: remove board testing coverage
This board was added to test coverage feature when coverage was
introduced. This is now being testing with other boards and
configurations on a regular basis, so no need for this extra overhead in
CI.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-06-01 14:06:56 -05:00
Daniel Leung
dfa4b7e375 kernel: mmu: z_backing_store* to k_mem_paging_backing_store*
These functions are those that need be implemented by backing
store outside kernel. Promote them from z_* so these can be
included in documentation.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-28 11:33:22 -04:00
Daniel Leung
31c362d966 kernel: mmu: rename z_eviction* to k_mem_paging_eviction*
These functions and data structures are those that need
to be implemented by eviction algorithm and application
outside kernel. Promote them from z_* so these can be
included in documentation.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-28 11:33:22 -04:00
Ioannis Glaropoulos
d105a2b76c arm: shrink names for null-pointer exception detection Kconfigs
Reduce the length of the Kconfig defines related to
null-pointed dereference detection in Cortex-M.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-05-26 12:30:05 -05: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
Nicolas Pitre
b8d24ffb45 arm64: mitigate FPU-in-exception usage side effects
Every va_start() currently triggers a FPU access trap if FPU is not
already used. This is due to the fact that va_start() must copy FPU
registers that are used for float argument passing into the va_list
object. Flushing the FPU context to its owner and granting access to
the current thread is wasteful if this is only for va_start(),
especially since in most cases there are simply no FP arguments
being passed by the caller.

This is made even worse with exception code (syscalls, IRQ handlers,
etc.) where the exception code has to be resumed with interrupts
disabled upon FPU access as there is no provision for preserving an
interrupted exception mode's FPU context.

Fix those issues by simply simulating the sequence of STR instructions
that the va_start() generates without actually granting FPU access.
We limit ourselves only to exception context to keep changes to a
minimum for now.

This also allows for reverting the ARM64 exception in the nested IRQ
test as it now works properly even if FPU_SHARING is enabled.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-05-21 04:52:44 -05:00
Andy Ross
3953e07822 tests/kernel/mem_heap: Add minimum-size heap test
Add test to statically allocate a minimum-size heap, verify that it
works to allocate a single byte and that it doesn't overrun its memory
bounds.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-05-20 17:52:21 -04:00
Enjia Mai
04c736d98d tests: interrupt: refine the offload case not rely on delay timing
The interrupt offload testcases fail on some boards because the timing
of the delay is too short. Refine the testcases and make it not rely
on the delay timing.

Fixes #35097
Fixes #35241

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-20 17:34:09 -04:00
Henrik Brix Andersen
aa78a6473b tests: kernel: gen_isr_table: do not use IRQ 57 on NXP LPC55S16
IRQ 57 is reserved in the NXP LPC55S16 SoC. Thus, limit the number of
interrupts reported to the test, so that it does not try to use it.

Fixes #34915

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2021-05-19 16:16:32 -05:00
Anas Nashif
1e74ddd709 kernel: remove dead workq code
work_q.c is not being built or used, it was replaced by user_work.c
which now has k_work_user_queue_start.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-18 11:21:27 -05:00
Andy Ross
d058ed3011 tests/kernel/fatal: Don't swap while locked
This test takes an interrupt lock and tries to call z_swap_unlocked()
while holding it.  That's not legal (in the general case it means
you're breaking a caller's lock!), though in this particular case it
was safe because we'll never return to this.

Regardless, there is a natural z_swap_irqlock() that releases the lock
atomically.  Use that.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-05-17 15:27:37 -04: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
2a7edbdbd6 tests/kernel/smp: Remove release_global_lock_irq case
This test case was taking a (traditional) irq_lock(), which masks
interrupts, and then calling k_mutex_lock() with a timeout of
K_FOREVER, which is a blocking call.  That's not legal, because it
will obviously schedule other threads to run in a context where the
code was promised it would not.  This used to be an uncaught error,
but now we have an assertion that catches this.

It's not clear what this test case is supposed to be testing, as the
behavior is actually identical to the release_global_lock case except
for the (incorrect) addition of the irq_lock().  If this is needed for
code coverage we can work to figure out the real root cause of the
missing coverage later.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-05-17 15:27:37 -04:00
Anas Nashif
009dee157d doc: fix doxygen grouping
Fix various grouping issues in doxygen and name groups correctly in some
cases.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-17 11:51:44 -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
Enjia Mai
05d8c6fc78 tests: kernel: fix two semaphroe testcases failed on ADSP
Two testcases of semaphore failed in ADSP due to the timeout value
we got back from the child thread is invalid. We put the variable in
the bss instead of in a stack, trying to avoid this.

Fixes #34687

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-14 16:41:21 -04:00
Watson Zeng
3e369f935c tests: msgq_usage: ensure all services started before client query
add semaphores to ensure all services started before client query.
otherwise client query services may fail.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2021-05-13 22:03:55 -04:00
Andy Ross
6941c8fda9 tests/kernel/smp: Misc synchronization fixups
A few mistakes in recent changes to this test:

There was a "LOCK_NO" (i.e. no locking!) case being exercised in
test_inc_concurrency, where three threads would race against each
other incrementing and decrementing a single count without
synchronization.  And... it failed on cAVS.  Because there was no
synchronization.  Just remove.

The LOCK_IRQ (irq_un/lock()) case of the same test was was casting
taking a pointer to an integer (that stored the irq_lock() result) and
casting the pointer value to an integer instead of dereferencing it.

Also the workq test had a work item on the stack, which is forbidden
when KERNEL_COHERENCE=y

Fixes #34152

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-05-13 22:03:05 -04:00
Enjia Mai
e2f6b9536c tests: interrupt: fix coverity issue of newly added testcases
Should not use -1 as an input parameter for unsigned int. Use zero
instead of -1 as invaild interrupt number to fix coverity warning.

Fixes #35146
CID: 235994

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-13 22:02:47 -04:00
Enjia Mai
36a1a88884 tests: smp: correct the inappropriate testcase
Update testcase test_fatal_on_smp(), and refine it and correct some
inappropriate usage such as unnecessary irq_lock(). This prevents
the error propagation to the later executing testcase.

Fixes #35200
Fixes #35202

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-12 17:04:20 -04:00
Watson Zeng
f100566f7a tests: mheap_api_concept: fix non-reentrant thread_id
in test case test_mheap_threadsafe, we will create 3 threads using
same thread handler tmheap_handler, we should make thread_id
to be a local variable, otherwise tmheap_handler is non-reentrant.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2021-05-12 08:30:46 -05:00
Daniel Leung
fb88c77ac2 tests: mem_protect/mem_map: remove unused assignment to cnt
The variable cnt is assigned twice in a row, so remove
the first one.

Coverity-CID: 235962
Fixes #35161

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-11 15:45:39 -05: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
0622bde3bf tests: condvar: fix one testcase failure on qemu_cortex_a53_smp
After enabled FPU context switch, one condvar testcase failed due to
the order of spawning thread cannot be guaranteed. Add a delay to
make sure the thread which initializing the condvar run first.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-08 17:08:48 -04: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
c9c8cec3b6 tests: interrupt: add test cases of direct interrupt for arch x86 and posix
Add test cases of direct interrupt for arch x86 and posix.

We register two direct interrupt at build time, then triggering
interrupt and check if ISR handler has executed or not. We also
check irq_enable and irq_disable works.

Why we add an extra compiler option "-mgeneral-regs-only" to make
it works in arch x86. because there might be some existing x87
instructions executing inside interrupt context.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-07 23:24:17 -04:00
Enjia Mai
f70225863b tests: interrupt: add test cases of regular interrupt for arch x86
Add test cases of regular interrupt for arch x86. This tests basic
functionailty of IRQ_CONNECT(), irq_enable(), irq_disable(),
irq_lock(), irq_unlock().

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-07 22:19:08 -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
Anas Nashif
4d994af032 kernel: remove object tracing
Remove this intrusive tracing feature in favor of the new object tracing
using the main tracing feature in zephyr. See #33603 for the new tracing
coverage for all objects.

This will allow for support in more tools and less reliance on GDB for
tracing objects.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-05-07 22:10:21 -04:00
Peter Bigot
353aa8757b tests: kernel: workq: inhibit warnings on tests of deprecated API
Legacy k_work API has been marked deprecated, but it is still present
in tree and should be tested.  Avoid CI warnings by disabling warnings
on use of deprecated API within the test source files.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-05-07 18:12:06 -05:00
Flavio Ceolin
0c607adb63 pm: device: Align state names with system states
Change device pm states to the same pattern used by system power
management.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-05-07 18:35:12 -04:00
Enjia Mai
70f8f3302b tests: interrupt: add test cases of offloading job from isr
Add 3 test cases to test offload job from isr, include:

1. test_isr_offload_job_multiple()
Validate the offloaded work executes immediately or not depends on its
priority, and it offloads to different k_work.

2. test_isr_offload_job_identi()
Validate the offloaded work executes immediately or not depends on its
priority, and it offloads to the identical k_work.

3. test_isr_offload_job()
Use dynamic interrupt instead of irq_offload() to verify the offloaded
work.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-07 18:24:32 -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
Ying ming
5d872f6e91 test: thread : test run k_thread_resume on unsuspend thread
If calling function k_thread_resume() when the thread is not suspend,
it takes no effect. This change improve coverage of function
k_thread_resume() in sched.c

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-05-07 18:21:23 -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
Andy Ross
7d5e238162 tests/kernel/context: Support APIC_TSC_DEADLINE timer
New timer driver needs an entry in the hard-coded list of IRQs

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
Daniel Leung
452a06104f tests: mem_protect/mem_map: add testing for k_mem_unmap()
This adds a few bits to test k_mem_unmap() to make sure
memory is actually being reclaimed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-07 13:36:22 -04:00
Daniel Leung
7741e9f7b0 tests: mem_protect/mem_map: test k_mem_map guard pages
Tests that the guard pages setup by k_mem_map() will cause
exception when accessed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-07 13:36:22 -04:00
Daniel Leung
cb0e3ede11 tests: mem_protect/mem_map: add test for z_phys_unmap
This adds a test for z_phys_unmap() to make sure that memory
can be unmapped and is no longer accessible.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-07 13:36:22 -04:00
Daniel Leung
bf287c6e2b tests: mem_protect/demand_paging: wait a bit for NRU to work
This waits a bit for NRU eviction algorithm (which is the default)
to work its magic to clear the access bit of physical frames.
This increases the number of clean pages which can be evicted,
to make sure the number of clean pages evicted is not zero, which
would cause an assertion.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-07 13:36:22 -04:00
Daniel Leung
c9c5221b96 tests: mem_protect/demand_paging: add config for qemu_x86_tiny
The test itself is highly sensitive to the size of the kernel
image. When the kernel gets larger, the number of pages used by
the backing store needs to shrink. So here this is.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-07 13:36:22 -04: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
Krzysztof Chruscinski
4a382ae2ce tests: kernel: threads: no-multithreading: Add more platforms
Add more platforms (including non-emulators) on which test runs.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-05-07 14:40:27 +02:00
Watson Zeng
b2aab9f0e8 board: qemu_arc: disable test: tests/kernel/mem_protect/mem_protect
This test fails on qemu_arc_{em|hs} consistently,
due to bug in quem_arc, details:
https://github.com/foss-for-synopsys-dwc-arc-processors/qemu/issues/14.
To get clean results we need to disable this test until the
bug is fixed and fix gets propagated to new Zephyr-SDK.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2021-05-07 13:15:13 +02:00
Meng xianglin
f397f1774f tests: msgq: add new test case for msgq
An intergration testing make use of message queue interfaces
provided by kernel

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2021-05-05 20:52:04 -04:00
Enjia Mai
a9edb1f46a tests: smp: add some module and integration test cases
This PR add 2 module test cases:
- test_smp_release_global_lock() and test_smp_release_global_lock_irq()
  verify z_smp_release_global_lock() works.

And 1 integration test cases:
- test_inc_concurrency() to verify parallelly increase operations will
  fail if not applying synchronization on SMP.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-05-05 20:34:28 -04:00
Gerard Marull-Paretas
7988ab4a26 pm: rename device_set/get_power_state to pm_device_set/get
Make name consistent with other device PM APIs.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas
2c7b763e47 pm: replace DEVICE_PM_* states with PM_DEVICE_*
Prefix device PM states with PM.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas
5a4cdd24a0 tests: replace power/power.h with pm/pm.h
Replace old header with the new one.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Gerard Marull-Paretas
c524075780 pm: runtime: rename API with pm_device prefix
Use `pm_device_*` prefix for the device runtime PM API. This adds the
API to the `pm` namespace, making it clear part of the PM subsystem.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-05-05 18:35:49 -04:00
Daniel Leung
3a7e0f875c tests: semaphore: add k_thread_join to test_sem_take_timeout_isr
This adds k_thread_join() to the thread being used in
test_sem_take_timeout_isr() to avoid a thread re-use error
in the test after this one.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-03 17:28:12 -04:00
Daniel Leung
8b7252cd41 tests: condvar_api: fix permissions to multiple condvar
The permission to use multiple_condvar is not granted to test
test_condvar_multiple_threads_wait_wake, which results in
bunch or permission error messages, and actually not testing
the conditional variables. This grants the permission to
the those conditional variables to the test threads. Also,
replace the k_yield() with k_msleep() to allow all created
threads time to run. A simply k_yield() might let a few to
run before the next batch of "waking" threads start to run,
resulting in some conditional variables not being initialized
but trying to wake.

Fixes #34777

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-05-03 17:28:12 -04:00
Nicolas Pitre
f1f63dda17 arm64: FPU context switching support
This adds FPU sharing support with a lazy context switching algorithm.

Every thread is allowed to use FPU/SIMD registers. In fact, the compiler
may insert FPU reg accesses in anycontext to optimize even non-FP code
unless the -mgeneral-regs-only compiler flag is used, but Zephyr
currently doesn't support such a build.

It is therefore possible to do FP access in IRS as well with this patch
although IRQs are then disabled to prevent nested IRQs in such cases.

Because the thread object grows in size, some tests have to be adjusted.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2021-05-03 11:56:50 +02:00
Krzysztof Chruscinski
acd8d8ebda tests: kernel: fatal: Add no multithreading test
Added test which verifies that when multithreading is disabled
exception as correctly handled by the kernel.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-29 14:50:35 +02:00
Krzysztof Chruscinski
4f949a28fb tests: kernel: mem_heap: Add CONFIG_MULTITHREADING=n configuration
Extended mheap_api_concept test suite to support case when
multithreading is disabled.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-29 14:50:35 +02:00
Krzysztof Chruscinski
693c3fbb9d tests: kernel: mem_slab: Add no multithreading support
Extended mslab_api test suite with CONFIG_MULTITHREADING=n
configuration.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-29 14:50:35 +02:00
Krzysztof Chruscinski
e99a015ba3 tests: kernel: threads: no-multithreading: Extend test
Extended test to validate following functionality:
- k_busy_wait
- k_timer
- irq_lock/irq_unlock
- k_cpu_idle
- SYS_INIT()

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-29 14:50:35 +02:00
Krzysztof Chruscinski
2e085a5202 tests: kernel: timer: timer_api: Extend with CONFIG_MULTITHREADING=n case
Extended test to validate that timer API is working as expected
when CONFIG_MULTITHREADING=n.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-04-29 14:50:35 +02:00
Enjia Mai
e53d549e21 tests: mem_protect: add a test case of adding memory partition
Add a test case to validate when adding a new partition into a memory
domain with over its maximum specified limit number, an assertion
failure happens.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-04-28 14:34:17 -04:00
Paul Sokolovsky
bb77186cc6 tests: kernel: no-multithreading: Use tc_util.h
The comment in this test says that it cannot use ztest, as the latter
spawns some threads. However, still format the output in a way
compatible with ztest output, by using tc_util.h macros. This is
similar to a few other tests which can't use ztest library directly.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2021-04-28 12:54:13 -04:00
Maksim Masalski
2c138fb59f tests: add new kernel objects tests
Found out that important requirements are not tested by current
kernel objects tests. Decided to fix that situation

New added tests:
1. test_kobj_assign_perms_on_alloc_obj()
Create kernel object semaphore, dynamically allocate it from the
calling thread's resource pool.
Check that object's address is in bounds of that memory pool.
Then check the requestor thread will implicitly be assigned
permission on the allocated object by using
semaphore API k_sem_init()

2. test_no_ref_dyn_kobj_release_mem()
Dynamically allocated kernel objects whose access is controlled by
the permission system will use object permission as a reference count
If no threads have access to an object, the object's memory released.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2021-04-28 12:53:55 -04:00
Gerard Marull-Paretas
1eabc24469 tests: kernel: remove usage of device_pm_control_nop
device_pm_control_nop is now deprecated in favour of NULL.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-28 12:53:09 -04:00
Gerard Marull-Paretas
e25dc6ff80 tests: kernel: device: adjust for device pm changes
- If device PM is not supported -ENOSYS is returned, update test case to
  account for that
- Remove usage of device_pm_control_nop

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2021-04-27 16:28:49 -04:00
Enjia Mai
d3747db66f tests: kernel: fix two test cases of condvar hang up in SMP
Make some change on two codvar test cases to fit testing under SMP,
and shorter the test cases execution time.

Fixes #33558.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-04-27 13:30:24 -04:00
Enjia Mai
2e1ac6b46b tests: smp: cancel CONFIG_MP_NUM_CPUS limit of some testcases
Try to remove CONFIG_MP_NUM_CPUS=1 configuration for the test of
condvar, sysmutex and semaphore, in order to test SMP condition more.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-04-27 13:30:24 -04:00
Peter Bigot
707dc22fb0 kernel: fix error in synchronous work cancellation return value
The return value is documented to be true if the work was pending, but
the implementation returned true only if the work was actually running
(i.e. the caller had to wait).  It should also return true if
scheduled or submitted work was cancelled.

Note that this means the return value cannot be used to determine
whether the call slept.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-04-27 13:28:45 -04:00
Thomas Stranger
32fe8a23af tests: gen_isr_table: nucleo_g071rb: decr. NUM_IRQS to avoid conflicts
After the introduction of usart1 the kernel/genisr_table test could
no longer build, due to an interrupt conflict.
Adopt the TEST_NUM_IRQS to resolve the conflict.

Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2021-04-26 14:16:03 -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
Julien Massot
68c54bfa33 test: kernel: context: Add Renesas RCar CMT timer
This test require explicit definition of the timer irq.

Signed-off-by: Julien Massot <julien.massot@iot.bzh>
2021-04-22 10:38:45 +02:00
Peter Bigot
2cff32b6c4 tests: kernel: pending: replace to-be-deprecated k_work API use
The new standard API has a different name with an additional parameter.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-04-21 20:42:36 -04:00
Ying ming
facd0f57db test: schedule_api : test some negative test
Add error test of api to improve
branch and line coverage in sched.c.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-04-19 16:23:12 -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
Nick Graves
56b9a422f7 tests/kernel: Add k_poll test for polling on message queues
Add tests for message queue polling functionality.

Fixes: #26728

Signed-off-by: Nick Graves <nicholas.graves@samsara.com>
2021-04-17 07:47:26 -04:00
Ningx Zhao
05e5f4842b tests: mutex: fixed a testcase assert failure
Modify the testcase design to solve some threads
can't lock mutex. Using array index to detect the order
of threads getting mutex instead of delaying.

Fixed #34116

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-04-12 11:55:04 -04:00
Peter Bigot
bf45af5dcb tests: kernel: workq: critical: replace to-be-deprecated k_work API use
The new standard API has a different name with an additional parameter.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-04-09 05:41:50 -05:00
Daniel Leung
b6fd177d92 test: mem_protect/demand_paging: support using timing funcs
This adds bits to support using timing functions for displaying
paging histograms. Currently on qemu_x86_tiny is supported.

Also shorten the test names.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-04-06 16:43:55 -04:00
Daniel Leung
dd239be6ec tests: mem_protect/demand_paging: add paging stats tests
This uses the new functions to get paging statistics and test
if they are valid.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-04-06 16:43:55 -04:00
Daniel Leung
ae86519819 kernel: mmu: collect more demand paging statistics
This adds more bits to gather statistics on demand paging,
e.g. clean vs dirty pages evicted, # page faults with
IRQ locked/unlocked, etc.

Also extends this to gather per-thread demand paging
statistics.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-04-06 16:43:55 -04:00
Jennifer Williams
a7ea624d7e tests: kernel: key has wrong type in test_prevent_interruption
The test_prevent_interruption() uses a key for the irq_lock(),
but the key has incorrect data type. This commit makes the key
unsigned int according to API docs.

Fixes #34023

Signed-off-by: Jennifer Williams <jennifer.m.williams@intel.com>
2021-04-06 14:37:24 -04:00
Ningx Zhao
7e91223ae0 tests: mutex: verify mutil-threads take a mutex
Add a testcase to verify mutil-threads competition
for a mutex.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-04-06 10:19:49 -04:00
Ningx Zhao
8af2e07ada tests: pipe: test some error conditions
Add some testcases to test some error conditions
about pipe's APIs.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-04-06 10:19:24 -04:00
Jian Kang
a1db16d292 tests: kernel: Add a new testcases for mailbox
Design a new testing that send and receive mailbox message with
different priority thread, and verify the high priority of receive
thread will receive firstly.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2021-04-06 10:18:36 -04:00
Jian Kang
0124e08e0f kernel: semaphore: Add two testcases of semaphore
Add two testcases to test semaphore feature on system side. For example,
test semaphore usage and sync process between different priority threads
to verify the semaphore can be take by higher priority thread, and give
sem more than max value of semaphore that set in init step to verify sem
count is correct or not.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2021-04-06 10:18:07 -04:00
Ying ming
fa2724b263 test: smp :add testcase
This is an integration testcase for smp. It tests
the situation when smp is configed. Fatal can be invoked on
different core and system workq can also be run on different
core.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-04-06 10:17:44 -04:00
Ningx Zhao
fa8bc742b8 Test: queue: Add a testcase to test queue
Test point:
1. Any number of threads may wait on an empty FIFO simultaneously.
2. When a data item is added, it is given to the highest priority
thread that has waited longest.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-04-06 10:13:49 -04:00
Ningx Zhao
ec61259f26 kernel: pipe: add a return value check.
Add a ASSERT to check tpipe_put_small_size return
value.

Fixes #33827

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-04-06 15:32:04 +02:00
Andy Ross
8505e5e00c tests/workq/work: KERNEL_COHERENCE fixups
Shared data can't live on thread stacks if they are incoherent.  These
are all just per-test-case data, so make them static.

Fixes #33898

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-04-02 07:23:51 -04: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
Carlo Caione
3539c2fbb3 arm/arm64: Make ARM64 a standalone architecture
Split ARM and ARM64 architectures.

Details:

- CONFIG_ARM64 is decoupled from CONFIG_ARM (not a subset anymore)
- Arch and include AArch64 files are in a dedicated directory
  (arch/arm64 and include/arch/arm64)
- AArch64 boards and SoC are moved to soc/arm64 and boards/arm64
- AArch64-specific DTS files are moved to dts/arm64
- The A72 support for the bcm_vk/viper board is moved in the
  boards/bcm_vk/viper directory

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-03-31 10:34:33 -05:00
Enjia Mai
95cddd4df7 testsuite: utils: move the interrupt_util.h into testsuite
The interrupt_util.h provides utils of trigger irq, now move them into
testsuite. All of the needed test cases can make use of them.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-03-30 08:18:23 -04:00
Ningx Zhao
b7bd2e5173 tests: stack: add a testcase
Add a testcase to test pop data from stack by
mutil-threads, verify data will be poped by
the highest priority thread that has waited longest
firstly.

stack integration

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-03-29 16:19:50 -05:00
Peter Bigot
fed035231f kernel: work: fix schedule from running work
k_work_schedule() is supposed to be a no-op if the work item is
already scheduled or submitted: the previous schedule is left
unchanged.  The check incorrectly inhibited the schedule operation
when the work item was neither scheduled nor submitted, but was
running.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-29 12:27:36 -04:00
Kumar Gala
658151da3e tests: device: tweak test to test linker sorting
There was a linker script change the broke the sorting such that
priority 2 and 20 would not necessary get sorted correctly.  Modify
the test to try and catch any such issues in the future.

We modify the DEVICE_DEFINE of the larger priority first, so if the
linker isn't sorting it would get linked first in theory, and we also
tweak the priority value from 4 to 20 so if we aren't sorting correctly
between 2 and 20 we'll catch that.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-03-26 11:25:01 -04:00
Flavio Ceolin
9fd4ea91b7 coccinelle: Remove extra semicolon
coccicheck --mode=patch --cocci=semicolon.cocci

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-25 11:35:30 -05:00
Katsuhiro Suzuki
19db485737 kernel: arch: use ENOTSUP instead of ENOSYS in k_float_disable()
This patch replaces ENOSYS into ENOTSUP to keep consistency with
the return value specification of k_float_enable().

Signed-off-by: Katsuhiro Suzuki <katsuhiro@katsuster.net>
2021-03-25 14:13:23 +01:00
Carlo Caione
807991e15f AArch64: Do not use CONFIG_GEN_PRIV_STACKS
We are setting CONFIG_GEN_PRIV_STACKS when AArch64 actually uses a
statically allocated privileged stack.

This error was not captured by the tests because we only verify whether
a read/write to a privileged stack is failing, but it can fail for a lot
of reasons including when the pointer to the privileged stack is not
initialized at all, like in this case.

With this patch we deselect CONFIG_GEN_PRIV_STACKS and we fix the
mem_protect/userspace test to correctly probe the privileged stack.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-03-25 07:23:19 -04:00
Eugeniy Paltsev
1b41da2630 ARC: Kconfig: rename CPU_ARCV2 option to ISA_ARCV2
* Rename CPU_ARCV2 to ISA_ARCV2. That helps to avoid conflict between
  CPU families naming and ISAs naming and aligns this options
  with other ARC OSS projects.

* Generalize ARCV2 check to ARC check where it is required.

NOTE: we add ISA_ARCV2 option in a choice list as a preparation
for ISA_ARCV3 addition.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2021-03-25 07:23:02 -04:00
Eugeniy Paltsev
106528e48e tests: interrupts: generalize ARC-specific part for all ARC CPUs
Generalize ARC-specific interrupt triggering for all ARC CPUs
instead of ARCv2 only.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2021-03-25 07:23:02 -04:00
Anas Nashif
5d6c219210 drivers: device: do not reuse tag name 'device'
Do not reuse tag name (misra rule 5.7).

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-22 19:48:14 -04:00
Kumar Gala
a56bdc4c6c device: remove deprecated device_list_get
device_list_get has been deprecated for 2 releases so remove the code
associated with it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-03-22 10:15:26 -05:00
Enjia Mai
3a500dfdfc tests: mem_protect: add error test case of userspace
Add some error test cases for userspace of memory protection module.
This increase the code coverage of testing.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-03-19 19:15:56 +01:00
Anas Nashif
c076d94eec kernel: remove tickless idle
This feature predated the tickless kernel and has been in legacy mode
for a while. We now have no drivers or systems that do not support
tickless, so remove this option and cleanup the code to only use
tickless.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-19 11:22:17 -04:00
Anas Nashif
a518f48796 clock: renmae z_timeout_end_calc -> sys_clock_timeout_end_calc
Do not use z_ for internal APIs, z_ is for private APIs within one
subsystem only.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-19 11:22:17 -04:00
Anas Nashif
fe0872c0ab clocks: rename z_tick_get -> sys_clock_tick_get
Do not use z_ for internal APIs, z_ is for private APIs within one
subsystem only.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-19 11:22:17 -04:00
Anas Nashif
5c90ceb105 clock: rename z_tick_get_32 -> sys_clock_tick_get_32
Do not use z_ for internal APIs, z_ is for private APIs within one
subsystem only.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-19 11:22:17 -04:00
Anas Nashif
9c1efe6b4b clock: remove z_ from semi-public APIs
The clock/timer APIs are not application facing APIs, however, similar
to arch_ and a few other APIs they are available to implement drivers
and add support for new hardware and are documented and available to be
used outside of the clock/kernel subsystems.

Remove the leading z_ and provide them as clock_* APIs for someone
writing a new timer driver to use.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-19 11:22:17 -04:00
Carlo Caione
ff14bb5027 tests: userspace: Increase mem pool size for AArch64
Fix tests/kernel/threads/dynamic_thread/ increasing the mem pool size.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-03-18 19:33:59 -04:00
Carlo Caione
6fb42bb316 tests: userspace: Fix test for AArch64
Fix tests/kernel/mem_protect/mem_protect/ adding support for AArch64.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-03-18 19:33:59 -04:00
Carlo Caione
5941713e4d tests: userspace: Add AArch64 case
Fix tests/kernel/mem_protect/userspace test adding the arch-specific
code to support AArch64.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-03-18 19:33:59 -04:00
Shihao Shen
477f4d4e2b tests: kernel: pipe: second part of testcases to improve pipes coverage
Added test_pipe_get_large to cover branches in both k_pipe_put and
k_pipe_get. Added trivial testcases in test_pipe_avail_no_buffer to
cover trivial branches for k_pipe_read_avail and k_pipe_write_avail.
This is the second patch as the continuation of #31037.

Signed-off-by: Shihao Shen <shihao.shen@intel.com>
2021-03-18 12:53:06 -04:00
Dean Weiten
14f541325a tests: kernel: mem_protect: add Ronoth Lodev to supported boards
The Ronoth LoDev in an open source board which uses
the AcSIP S76S, which itself contains an STM32L073.

Signed-off-by: Dean Weiten <dmw@weiten.com>
2021-03-18 08:48:30 -05:00
Shihao Shen
084989564a tests: kernel: pipe: testcases to improve code coverage for pipes
Added back test_pipe_alloc because the z_thread_malloc called in the
API has been updated to use k_heap instead of k_mem_pool.
Adjusted test_resource_pool_auto_free by replacing z_mem_pool_malloc
with k_heap_alloc. Added new test_k_pipe_cleanup to cover one more
branch in k_pipe_cleanup. Modified test_half_pipe_put_get to cover
branches for (reader != NULL) in k_pipe_put. Added test
test_pipe_get_put to cover branches for (writer != NULL)
in k_pipe_get. Added trivial tests to cover input validity checks.
Line coverage has been improved by 52%, function cov by 56%, and
branch cov by 46%.

Signed-off-by: Shihao Shen <shihao.shen@intel.com>
2021-03-17 19:10:25 -04:00
Ying ming
c0b240fdf3 test: mheap: add testcase
This is an intergration testcase for mem_heap.
Add an testcase to verify that multiple threads
can share the same heap space without interfering
with each other.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-03-17 11:28:56 +01:00
Jian Kang
ba51bbd73d tests: kernel: Change a mbox testcase that condition unsuitable
Fix issue #33114 #33120. Modify the testcase that run failed on iotdk
and nsim. This testing do not need receive thread ID when invoke
k_mbox_data_get() with NULL param. The testcase purpose is invoke
this API with NULL buffer and NULL receive_id. It will cause fatal
error if use a uninitialize receive id.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2021-03-16 17:07:17 -05:00
Daniel Leung
a120799b85 tests: mem_protect/mem_map: no need to skip test if link in virt
This reverts commit 9de70a78fe.

The tests have been updated so there is no need to skip tests
when the kernel is linked in virtual address space.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-03-16 15:03:44 -04:00
Andrew Boie
2b48f591e1 tests: mem_map: use physical address of test page
It may not be identity-mapped.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-03-16 15:03:44 -04:00
Yasushi SHOJI
a3e0f8c316 doc: Replace *_thread_resource_pool_assign with k_thread_heap_assign
Replace *_thread_resource_pool_assign() in the reference with the new
k_thread_heap_assign() since both k_thread_resource_pool_assign() and
z_thread_resource_pool_assign() has been removed prio to v2.5 (by the
commit c770cab1a3 and 3c2c1d85b0 respectively) along with the
k_mem_pool API removal.

For the resource pool inheritance test, the variables with "res_pool"
string has been replaced by "heap_mem" to align with the documentation
fix.  No functionality has been changed.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2021-03-11 18:22:12 -05:00
Carlo Caione
6f5a1529d4 test: mem_map: Fix compilation by removing __test_mem_map_size
This is the same problem as seen for #32053. Refer to that for the
details and propose a similar fix.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-03-10 14:55:01 -05:00
Peter Bigot
057e4cbc5d tests: kernel: work_queue: remove unpassable tests
The original implementation of resubmitting a delayed work item
removed the item not only from the schedule, but also from the work
queue if it was already in the work queue.  This is not the semantics
of the new implementation, which will leave the work item in the queue
if the previous deadline had elapsed and the work item was submitted.

The new semantics is preferred, as it improves consistency with SMP
targets where once an item has been submitted to a queue it can be run
at any time, and scheduling it again doesn't magically reverse the
submission.  The original test would never have passed on an SMP
target, and passes now on qemu_x86 only because the timing granularity
prevents the work item from being both scheduled and queued at the
same time.

The problematic test application is the one developed for the original
implementation.  Correct functioning of the new implementation is
fully verified by the sibling work test.  That the legacy API does not
precisely preserve the original behavior where it was not consistent
between SMP and uniprocessor targets is regrettable, but unavoidable.

Remove the tests that cannot pass reliably.

Also fix a missing reset() after a test.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-10 06:10:59 -05:00
Ying ming
fcad2b37e3 test: fatal exception: Add code description and testcases
Improve the test case of CPU exception.
Add equivalence classes and input partition testing
when give an integer reason code.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-03-09 12:33:51 +01:00
Andy Ross
6f82ebe2e8 tests/kernel/workq/work: KERNEL_COHERENCE fixups
Putting IPC elements on the stack isn't allowed when KERNEL_COHERENCE
is set, just make test case data static (not all apps or subsystems
are going to work with incoherent stacks, but we should support it
where we can).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-08 19:25:25 -05:00
Andy Ross
3d81464194 tests: samples: Add targetted platform_excludes for intel_adsp_cavs15
This platform has a tiny handful of remaining tests that fail.  We
will track them as issues, but let's exclude them from integration
testing to allow full runs to complete.  Often a hung device in one
test will break an entire twister run.

Tests with known (and tracked) failures:

  samples/application_development/external_lib
  samples/posix/eventfd
  samples/userspace/hello_world_user
  tests/kernel/fatal/message_capture
  tests/net/socket/socketpair
  tests/portability/cmsis_rtos_v2

These tests never fail in isolated testing, but are reliable timeouts
when run in sequence in a big twister run.  It's possible that the bug
here may be in twister or the flash/serial scripts:

  tests/crypto/tinycrypt
  tests/subsys/logging/log_immediate
  tests/subsys/logging/log_output

See: #32836

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-08 19:25:25 -05:00
Andy Ross
589c781506 tests: No thread-shared/synchronized data on stack (coherence)
CONFIG_KERNEL_COHERENCE forbids synchronized data on the stack: no
spinlocks, IPC primitives, or things that contain them.  Application
code obviously doesn't have to follow these inconvenient rules, but
our test code needs to run on platforms with incoherent stack memory.

Make these things static.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-08 19:25:25 -05:00
Andy Ross
afbc044322 tests/kernel/thread_apis: Fix timing order
This test understood that it can't demand equality in timing because
of races against real time, so it simply validated that the test
started at or later than the expected timeout expiration.

But when calculating the expected time, it called k_uptime_ticks()
AFTER the timeout was registered.  So on systems with fast ticks (or
just bad luck) a tick expiring between the two steps will look like an
"early" expiration and fail the test.  Do things in the proper order.

Also, use the correct APIs for unit conversion and timeout
construction.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-08 18:15:53 -05:00
Carlo Caione
b76cbe9af9 test: dynamic_thread: Fix race condition
There is a race between k_sem_take() and k_object_access_grant() so it
is possible (especially when testing SMP) that the thread tries to take
the semaphore before the originating thread has had the chance to
grant it permission.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-03-08 14:22:29 -05:00
Ying ming
cd8ea791f7 test: scheduling: add testcase
Add testcase for deadline_set. Test the situation when threads are
in unqueued state. The k_thread_deadline_set() call should not make
these threads run before there delay time pass.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-03-08 12:59:34 -05:00
Ying ming
14b733aaa6 test: scheduling: change code annotation
Change the code annotation of testcase test_busy_wait_cooperative.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-03-08 11:32:16 -05:00
Andy Ross
2197d46a43 tests/queue: tests/lifo_usage: Address ADSP/coherence issues
These tests would pass pointers to data on their own stacks to other
threads, which is forbidden when CONFIG_KERNEL_COHERENCE (because
stack memory isn't cache-coherent).  Make the variables static.

Also, queue had two sleeps of 2 ticks (having been written in an era
where that meant "20-30ms"), and on a device with a 50 kHz tick rate
that's not very much time at all.  It would sometimes fail spuriously
because the spawned threads didn't consume the queue entries in time.
How about 10ms of real time instead?

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-08 11:14:27 -05:00
Andy Ross
fed9f5aa04 tests/fifo_api: Move k_fifo off stack
Putting spinlocks (or things containing them) onto the stack is a
KERNEL_COHERENCE violation.  This doesn't need to be there so just
make it static.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-08 11:14:27 -05:00
Eric Johnson
0916c58c68 tests: kernel: timer: timer_api: Correct one-shot typo
Fixed typos for one-shot to match Zephyr docs

Signed-off-by: Eric Johnson <eric@liveathos.com>
2021-03-07 08:00:08 -05:00
Eric Johnson
723b638476 tests: kernel: timer: timer_api: Fix test_timer_period_0
This test was not waiting long enough to ensure one-shot behavior.

Signed-off-by: Eric Johnson <eric@liveathos.com>
2021-03-07 08:00:08 -05:00
Eric Johnson
f7ca7350b5 tests: kernel: timer: timer_api: Add test K_FOREVER period test
Adds a test to ensure valid one-shot behavior when a timer is started
with a period of K_FOREVER

Signed-off-by: Eric Johnson <eric@liveathos.com>
2021-03-07 08:00:08 -05:00
Flavio Ceolin
98dbea0979 power: Get rid of deep sleep and sleep concepts
New power states have more granularity than deep sleep and sleep
states. Just get rid of this and keep the same behavior for now.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-03-07 07:59:53 -05:00
Enjia Mai
cabb64df4b tests: kernel: mbox: fix uninitialized scalar variable of coverity
Given an zero initialized value before using struct k_mbox_msg, to fix
CID: 219511.
Fix #32934

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-03-06 07:41:00 -05:00
James Harris
8c7748c697 tests: kernel: semaphore: add test for k_sem_reset with waiting threads
Test to ensure that a reset with a waiting thread properly aborts the
wait, and the semaphore remains functional after.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-06 07:39:43 -05:00
James Harris
269794878c tests: kernel: semaphore: better explain test failures
Debugging long-tail semaphore test failures currently is rather
annoying, both because many semaphore test failures do not print
their failing values, and because some semaphore tests do not
check return codes, leading to test failures well after the actual
failure.

Redo the semaphore tests to at least give consistent failure
messages including the actual return code and consistently check
return codes of k_sem_* APIs.

Also driveby-fix several places that used an insufficiently-
sized type to store k_uptime.

Signed-off-by: James Harris <james.harris@intel.com>
2021-03-06 07:39:05 -05:00
Kumar Gala
53b104d461 tests: kernel: Add missing kernel tag to tests
Add kernel to any testcase.yaml files that happen to be missing for
tests under tests/kernel/

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-03-05 14:52:55 -05:00
Peter Bigot
f0d0e01b45 tests: kernel: work: fix unchecked return values
Coverity wants these to be checked in a few places where the check was
elided.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-05 10:43:04 -05:00
Enjia Mai
b488b396bb tests: improve test cases for interrupt testing
Improve dynamic interrupt test cases of interrupt for platform such as
x86, x86_64, native_posix, this improve code coverage of it.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-03-04 14:54:17 -05:00
Andy Ross
d72b5d16a6 tests/kernel/tickless: Remove use of CONFIG_TICKLESS_IDLE_THRESHOLD
This kconfig isn't actually exercised in this test, it's just being
used to compute some sleep durations.  Also I want it gone.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-03-04 14:31:12 -05:00
Daniel Leung
9de70a78fe tests: mem_protect/mem_map: skip z_phys_map when linking in virt
When the kernel links in virtual address space, the data
structures needed for the z_phys_map() no longer point to physical
addresses (which are required for z_phys_map() to work). So skips
these tests if CONFIG_KERNEL_LINK_IN_VIRT=y.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-03-03 20:10:22 -05:00
Peter Bigot
b706a5e999 kernel: remove old work queue implementation
Now that the old API has been reimplemented with the new API remove
the old implementation and its tests.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-03 20:06:00 -05:00
Peter Bigot
4e3b92609b kernel: provide functional equivalent to old userspace work queue API
The new API cannot be used from userspace because it is not merely a
wrapper around existing userspace-capable objects (threads and
queues), but instead requires much more complex and lower-level access
to memory that can't be touched from userspace.  The vast majority of
work queue users are operating from privileged mode, so there's little
motivation to go through the pain and complexity of converting all
functions to system calls.

Copy the necessary pieces of the existing userspace work queue API out
and expose them with new names and types:

* k_work_handler_t becomes k_work_user_handler_t
* k_work becomes k_work_user
* k_work_q becomes k_work_user_q

etc.  Because the replacement API cannot use the same types new API
names are also introduced to make it more clear that the userspace
work queue API is a separate functionality.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-03 20:06:00 -05:00
Peter Bigot
06665f9652 tests: kernel: add test of new work queue API
Covers all lines that can be reached in controlled conditions.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-03-03 20:06:00 -05:00
Ioannis Glaropoulos
1b22f6b8c8 arm: cortex_m: enable null-pointer exception detection in the tests
Enable the null-pointer dereferencing detection by default
throughout the test-suite. Explicitly disable this for the
gen_isr_table test which needs to perform vector table reads.
Disable null-pointer exception detection on qemu_cortex_m3
board, as DWT it is not emulated by QEMU on this platform.
Additionally, disable null-pointer exception detection on
mps2_an521 (QEMU target), as DWT is not present and the MPU
based solution won't work, since the target does not have
the area 0x0 - 0x400 mapped, but the QEMU still permits
read access.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-03-03 10:38:29 +01: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
Meng xianglin
80ec588e46 test: thread_api: refine test coverage of thread_api
Add new test cases for some interfaces in thread.c

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2021-03-02 14:28:24 -05:00
Jian Kang
088acda054 kernel: mailbox: Add some testcases for mailboxs
Add some testcases to tesing different condition of mailbox
API. Check API robust in different input parameters is handled.
such as invoke API to get data with NULL input.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2021-03-02 10:47:07 -05:00
Ningx Zhao
8fe9f523e7 tests: poll: code coverage improve
Some poll source code is tested in workq
so the negative testcase code is also placed in workq.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-03-02 10:42:09 -05:00
Ying ming
ef763543d8 test: heap : improve coverage to kernel/mempool.c
Add some testcase to improve coverage of mempool.c

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-03-02 10:29:43 -05:00
Ningx Zhao
39555408ce Kernel: poll: code coverage improvement
Add some testcases to test some unnormal branches,
for covering branches that not covered.Meanwhile,
Using the public fatal handler function to handle
fatal errors.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-03-01 15:45:57 -06:00
Ying ming
a941b6a8a7 test: kheap: add testcase to improve coverage
Add a testcase to prove the thread can be waited on waitq when
there isn't enough space on heap.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-03-01 15:39:34 -06:00
Ioannis Glaropoulos
a6d1754aef tests: kernel: fatal: add missing CONFIG_TEST=y in test suite
Enable CONFIG_TEST in the message_capture test suite.
This allows certain Kconfig configurations, depending
on TEST, to be enabled.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-03-01 15:55:10 +01:00
Ioannis Glaropoulos
ae505e97bd tests: thread: thread_api: fix to allow test to run for non-secure
Allow the test to run for non-secure firmware builds, by
removing the test-case for nonsense string, as this test-case
will likely produce a secure fault which will crash the kernel.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-02-28 16:50:47 -05:00
Ioannis Glaropoulos
ec1bce58d1 tests: kernel: interrupt: do not run for Cortex-M Non-Secure mode
tests/kernel/interrupt tests interrupt trigger functionality,
however, the Non-Secure Cortex-M mode does not have full control
of the interrupt handling, so this test cannot be guaranteed to
pass when executing in Non-Secure mode. Filter the test out for
Non-Secure Cortex-M builds.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-02-28 16:49:54 -05:00
Ioannis Glaropoulos
038de00d61 tests: kernel: device: adaptation for the test to run in Non-Secure mode
Exclude the test_null_dynamic_name test-suite from running the
test, in Non-Secure mode (Cortex-M), because passing a NULL
device name de-references memory at 0x0 which is likely to
cause a SecureFault and crash the kernel.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-02-28 16:49:54 -05:00
James Harris
c2a777c139 tests: kernel: sched: add z_yield under deadline
Add a test case for the error fixed by the previous commit.

Signed-off-by: James Harris <james.harris@intel.com>
2021-02-27 10:25:47 +01:00
Andy Ross
63972d6df7 tests/timer_api: Fix absolute timeout logic
The test_timeout_abs case had baked in similar mistakes to the
off-by-one in the absolute timer implementation.  FOR THE RECORD:

If you have an absolute timeout expiration set for a tick value "N",
and the current time returned by k_uptime_ticks() is "T", then the
time returned (at the same moment) by any of the *_remaining_ticks()
APIs must ALWAYS AND FOREVER BE EXACTLY "N - T" (also: "N - T > 0"
always, until the moment the kernel ISR hands off control to the first
timeout handler expiring at that tick).

The tick math is exact.  No slop is needed on any systems, no matter
whether their clocks divide by milliseconds or not.

The only gotcha is that we need to be sure that the calls don't
interleave with a real time tick advance, which we do here with a
simple retry loop.

But, about slop... This patch also includes a related fix for the
test_sleep_abs().  On an intel_adsp (which has 50 kHz ticks, a
comparatively slow idle resume and interrupt entry, and even has two
CPUs to mess with latency measurements) I would occasionally see the
k_sleep() take more than a tick to wake up from the interrupt handler
until the return to application code.  Add some real time slop there
(just 100us) to handle systems like this.

Fixes #32572

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-25 22:16:51 -05:00
Andy Ross
c0c8cb0e97 kernel: Remove abort and join implementation (UNBISECTABLE)
THIS COMMIT DELIBERATELY BREAKS BISECTABILITY FOR EASE OF REVIEW.
SKIP IF YOU LAND HERE.

Remove the existing implementatoin of k_thread_abort(),
k_thread_join(), and the attendant facilities in the thread subsystem
and idle thread that support them.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-24 16:39:15 -05:00
Andy Ross
419f37043b kernel/sched: Clamp minimum timeslice when TICKLESS
When the kernel is TICKLESS, timeouts are set as needed, and drivers
all have some minimum amount of time before which they can reliably
schedule an interrupt.  When this happens, drivers will kick the
requested interrupt out by one tick.  This means that it's not
reliably possible to get a timeout set for "one tick in the
future"[1].

And attempting to do that is dangerous anyway.  If the driver will
delay a one-tick interrupt, then code that repeatedly tries to
schedule an imminent interrupt may end up in a state where it is
constantly pushing the interrupt out into the future, and timer
interrupts stop arriving!  The timeout layer actually has protection
against this case.

Finally getting to the point: in recent changes, the timeslice layer
lost its integration with the "imminent" test in the timeout code, so
it's now able to run into this situation: very rapidly context
switching code (or rapidly arriving interrupts) will have the effect
of infinitely[2] delaying timeouts and stalling the whole timeout
subsystem.

Don't try to be fancy.  Just clamp timeslice duration such that a
slice is 2 ticks at minimum and we'll never hit the problem.  Adjust
the two tests that were explicitly requesting very short slice rates.

[1] Of course, the tradeoff is that the tick rate can be 100x higher
or more, so on balance tickless is a huge win.

[2] Actually it only lasts until a 31 bit signed rollover in the HPET
cycle count in practice.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-24 16:39:15 -05:00
Wealian Liao
a92ae82355 test: fix gen_isr_table for npcx soc
gen_isr_table uses 6 IRQs for testing. Originally, it uses IRQ 41-36.
However, the IRQ37 & 36 are enabled by other modules in NPCX chips.
Change TEST_NUM_IRQS to use 45-40 for the test.

Signed-off-by: Wealian Liao <WHLIAO@nuvoton.com>
2021-02-24 11:02:32 -05:00
Daniel Leung
803eb1ea10 tests: schedule_api: lengthen interval for slicing reset test
When calculating the expected interval for threads other than
the first one, the test uses ms->ticks->cycles conversion to
figure out the bound of cycles permitted. Both lower and upper
bound conversions are using the k_*_to_*_floor32(). When
numbers involved are not wholly divisible, decimal points are
being truncated, resulting in incorrect intervals, and thus
failing tests. So change the calculation to appropriate
floor() or ceil() based on the boundary.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-23 10:36:21 -05:00
Anas Nashif
f4ad56ee8b tests: kernel: tls: fix testsuite setup
Do not declare 2 testsuite, use skip function for test not supported
with userspace instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-02-22 14:36:06 -05:00
Anas Nashif
057c610ed5 tests: sched: fix test identifier
Fix duplicate test identifier.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-02-22 14:36:06 -05:00
Andy Ross
3633860ff1 tests/timer_api: Add test for absolute expiration time
Absolute timeouts were covered, but nothing was testing their actual
expiration time and there was an off-by-one.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-22 08:45:24 -05:00
Mulin Chao
30a5424d0e tests: kernel: profiling: Add customized pm device policy handler.
Besides implementing a customized pm_policy_next_state() in the
application layer, a customized device policy handler of power
management, pm_policy_low_power_devices(), is also needed if
CONFIG_PM_POLICY_APP is enabled. This CL adds this function to prevent
build errors.

Signed-off-by: Mulin Chao <mlchao@nuvoton.com>
2021-02-19 22:39:53 -05:00
Daniel Leung
e0fe89cdda tests: fpu_sharing: allow board qemu_x86_lakemont
This adds qemu_x86_lakemont to the platform allow list
for the FPU sharing tests. Since Lakemont supports SSE3
and SSSE3, it is better to test them also.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-19 18:51:04 -05:00
Carlo Caione
3f055058dc aarch64: Remove QEMU 'wfi' issue workaround
The problem is not reproducible when CONFIG_QEMU_ICOUNT=n. We can now
revert the commit aebb9d8a45.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2021-02-19 16:26:38 +03:00
Andy Ross
c2339db996 tests/timer_api: Correct precision and fix correctness mistakes
Correct a bunch of precision/analysis errors in this test:

* Test items weren't consistent about tick alignment and resetting of
  the timestamp, so put these steps into init_timer_data() and call
  that immediately before k_timer_start().

* Many items would calculate the initial timestamp AFTER
  k_timer_start(), leading to an extra (third!) point where the timer
  computation could alias by an extra tick.  Always do this
  consistently before the timer is started (via init_timer-data()).

* Tickless systems with high tick rates can easily advance the system
  uptime while the timer ISR is running, so the system can't expect
  perfect accuracy even there (this test was originally written for
  ticked systmes where the ISR was by definition happening "at the
  same time").

  (Unfortunately our most popular high tick rate tickless system,
  nRF5, also has a clock that doesn't divide milliseconds exactly, so
  it had a special path through all these precision comparisons and
  avoided the bugs.  We finally found it on a x86 HPET system with 10
  kHz ticks.)

* The interval validation was placing a minimum bound on the interval
  time but not a maximum (this mistake was what had hidden the failure
  to reset the timestamp mentioned above).

Longer term, the millisecond precision math in these tests is at this
point an out of control complexity explosion.  We should look at
reworking the core OS tests of k_timer to use tick precision (which is
by definition exact) pervasively and leave the millisecond stuff to a
separate layer testing the alternative/legacy APIs.

Fixes #31964 (probably -- that was reported against up_squared, on
which I had trouble reproducing, but it was a common failure on
ehl_crb).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-16 12:08:36 -05:00
Daniel Leung
ce44048d46 x86: rename CONFIG_SSE* to CONFIG_X86_SSE*
This adds X86 keyword to the kconfigs to indicate these are
for x86. The old options are still there marked as
deprecated.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-15 08:21:15 -05:00
Daniel Leung
735c0096ae tests: fpu_sharing: test both FPU and SSE on x86
On x86, it is possible to use FPU (387) and SSE for floating
point operations. So test both.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-15 08:21:15 -05:00
Ioannis Glaropoulos
2573f4b99c tests: remove nrf5340 PDK boards from test .yml files
Remove references to the nRF5340 PDK boards
from samples and tests .yml files.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-02-15 07:59:43 -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
95bcba5946 tests/kernel/thread_stack: Fix KERNEL_COHERENCE interactions
Thread stack memory on coherence platforms needs to be linked into a
special section (so it can be cached).

Also, the test_idle_stack case just can't work with coherence.  It's
measuring the CPU's idle stack's unused data, which was initialized at
boot from CPU0, and not necessarily the CPU on which the test is
running.  In practice on intel_adsp_cavs15, our CPU has stale zeroes
in the cache for its unused stack area (presumably from a firmware
memory clear at boot or something?).  Making this work would require a
cache invalidate on all CPUs at boot time before the idle threads
start, we can't do it here in the test because we don't know where the
idle stack pointer is.

Too much work for an esoteric stack size test, basically.  Just
disable on these platforms.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-11 14:47:40 -05:00
Daniel Leung
89a9096334 tests: threads/tls: add more thread variables
It was discovered that TLS data/bss in stack need to be
aligned correctly or else incorrect variables would be
accessed. This makes tdata and tbss sections to have
odd sizes to make sure everything still works.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-07 23:28:43 -05:00
Enjia Mai
8474d785f4 tests: memory protect: add some error test cases
Add some error case for initializing memory domain and removing
memory partition.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-02-05 08:29:44 -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
Andy Ross
782c121dd3 tests/sched/deadline: Fix precision rollover
The deadline scheduler as of commit ef626571b2 ("kernel/sched:
Optimize deadline comparison") got an optimization that requires that
the the cycle difference of the deadline time of the "first" and
"last" runnable thread never be higher than 2^31.

The test code here was masking off the bottom 31 bits of the generated
deadlines, so it looked OK.  But because the actual setting of the
deadline values takes time too, it was still possible to select values
that would roll over.  The window was VERY small, but the RNG on one
platform (up_squared) hit it.

Shrink the selected deadlines to live in a 30 bit space for safety.

Fixes #31508

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-03 13:10:33 -05:00
Daniel Leung
890e9846c8 Revert "tests: context: disable if DEMAND_PAGING"
This reverts commit 79d73063af.
The issue #31333 is fixed so this can be reverted to
enable tests/kernel/context to run with demand paging enabled.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-02 21:57:43 -05:00
Daniel Leung
d19307fa45 tests: mem_protect: fix failing inheritance test under SMP
The inheritance test first creates a parent thread, and then
creates a child thread inside this parent thread. At the same
time inside the main thread, a resource pool is assigned to
the parent thread. However, when under SMP, it is possible
that the pool assignment is done between both parent/child
threads are getting pointers to the pool, due to multiple
threads are running. So when doing pool pointer comparison,
there is a mismatch between those pointers (like parent has
a null pool pointer while child is pointing to the actual
pool), and thus failing the test. So fix this by delaying
the parent from running under after pool assignment is done.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-02 14:00:01 -05:00
Daniel Leung
af37e9d999 tests: mem_map: fix execution test for x86_64 with coverage
When coverage is enabled on x86_64, GCC uses relative addressing
to increment the gcov counters. The generated code of the test
function assumes execution is in the same location where
the linker places the test function. This does not work with
the execution test as it copies the function into another part
of memory and tries to execute from there. When the copied
function starts to run, the instruction pointer is at the newly
copied function. So any relative addressing with regard to
the instruction pointer now is invalid. Instead of
<generated code RIP + offset> for gcov counter as it should be,
now the copied code is trying to access the counter at
<copied code RIP + offset>, which points to incorrect
memory location (and possibly invalid/non-mapped memory).
To fix this, we need to tell GCC not to use relative addressing.
This can be accomplished by telling GCC to use the large memory
model. This is only used for this test as this option increases
code size quite a bit, and should not be used in general.

Fixes #30434

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-02 13:59:41 -05:00
Daniel Leung
1f62817e43 tests: mem_map: put transplanted_function into its own section
This puts the transplanted_function into its own section so that
z_phys_map() can correctly map the whole range of memory used
by the function, in case someone decides to expand the function
to be bigger than a MMU page.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-02-02 13:59:41 -05:00
Enjia Mai
8595a390a7 tests: msgq: Fix uncheck return value of coverity scan
Add a return value check of message queue test cases, to fix
issue #31680, which is for CID :216795.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-02-01 20:33:51 -05:00
Peter Bigot
c72e2320e4 tests: exclude nrf5340dk_nrf5340_cpunet when CONFIG_PM=y
The required regulator control features are only available on the
application core.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2021-02-01 15:05:03 -05:00
Daniel Leung
3740f60631 tests: mem_protect: use MP_NUM_CPUS instead of SMP
The test_mem_domain_migration test creates a new thread with
different priority based on whether SMP is enabled. This causes
an issue where SMP=y and MP_NUM_CPUS=1 where the spin_entry()
would spin forever (with k_busy_wait()) and not yielding since
it has cooperative priority. Fix this by using MP_NUM_CPUS to
figure out which priority to use, as it is valid configuration
to have SMP=y and MP_NUM_CPUS=1.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-01-29 19:37:25 -05:00
Flavio Ceolin
be2f447f61 tests: schedule_api: Improve log on error
Increase thread counter before the assert, otherwise in case of fail
the output will give the impression that the same thread ran more than
once.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-27 16:55:58 -05:00
Flavio Ceolin
e34f104693 tests: schedule_api: Do not mess ms with ticks
TASK_SWITCH_TOLERANCE is set in ms but it was being used directly as
ticks.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-27 16:55:58 -05:00
Andy Ross
2f6b202ed5 tests/schedule_api: Correct tick/ms math for non-divisible clocks
Adjusting the tick alignment of this test caused it to start breaking
on nRF5 platforms, which use a 32768 Hz clock that doesn't divide
evenly into the millisecond precision used by the test.  The "half
slice" math ended up being wrong by a bit.

Convert to ticks first before computing the cycle delay needed.

Fixes #29705

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-01-27 16:55:58 -05:00
Watson Zeng
f71cd2aaf5 spinlock: validate: fix the dependency with MP_NUM_CPUS
the implementation of spinlock validation uses two LSB bits in the
bottom of a pointer union to store a CPU index, which only has space
for 4 CPUS. the MP_NUM_CPUS should be <= 4.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2021-01-26 08:43:45 -05:00
Krzysztof Chruscinski
7f08061f0c logging: Revamp menuconfig
Clean up logging menuconfig by grouping configuration into
sections like: mode, processing configuration, backends.

Additionlly, removed LOG_ENABLE_FANCY_OUTPUT_FORMATTING which is no
longer in use.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-01-26 06:15:42 -05:00
Enjia Mai
e89fe33a5a tests: thread: refine the thread abort test case
Refine the thread abort test case and add one extra condition.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-01-24 14:18:00 -05:00
Jian Kang
30bf585e10 tests: kernel: Add some testcases for thread
Add some error condition of testcases to verify whether the
robustness of API. Such as give a NULL to some API and check
the response if get result that we were expacted.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2021-01-24 14:13:29 -05:00
Andrew Boie
14c5d1f1f7 kernel: add CONFIG_ARCH_MAPS_ALL_RAM
Some arches like x86 need all memory mapped so that they can
fetch information placed arbitrarily by firmware, like ACPI
tables.

Ensure that if this is the case, the kernel won't accidentally
clobber it by thinking the relevant virtual memory is unused.
Otherwise this has no effect on page frame management.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
6c97ab3167 mmu: promote public APIs
These are application facing and are prefixed with k_.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
79d73063af tests: context: disable if DEMAND_PAGING
Until #31333 is resolved, the periodic timer in the eviction
algorithm interacts with this test in such a way that the system
deadlocks.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
c7be5dddda mmu: backing stores reserve page fault room
If we evict enough pages to completely fill the backing store,
through APIs like k_mem_map(), z_page_frame_evict(), or
z_mem_page_out(), this will produce a crash the next time we
try to handle a page fault.

The backing store now always reserves a free storage location
for actual page faults.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
cad944e259 tests: demand_paging: add more API tests
Add remaining APIs in mem_manage.h even though not all have
been promoted to public (yet).

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
60d306642e kernel: add z_num_pagefaults_get()
Simple counter of number of successfully handled page faults by
the core kernel.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
ef65597b73 tests: add intial demand paging testcase
More to be added, but for now show that we can map more
anonymous memory than we physically have, and that reading/
writing to it works as expected.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
146eaf4335 tests: add basic k_mem_map() test
Show we can measure free memory properly and map a page of
anonymous memory, which has been zeroed and is writable.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
d50b2419b8 tests: mem_map: pin test pages
These get mapped to multiple virtual addresses and must be
pinned.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Andrew Boie
893822fbda arch: remove KERNEL_RAM_SIZE
We don't map all RAM at boot any more, just the kernel image.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-23 19:47:23 -05:00
Ying ming
9625576b3c test: scheduling :add new conf file
Add a conf file to make sure the kernel will use simple linked-list
ready queue as scheduling algorithm. This operation will increase module
testcase coverage and z_priq_dumb_add z_prj_dum_remove function are
called.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-01-23 11:04:51 -05:00
Anas Nashif
d95a5f9b35 tests: fifo: exclude m2gl025_miv
Excluding while we figure out the issue with this failing sporadically.
See bug #31549.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-23 00:42:13 -05:00
Anas Nashif
e6d3fc6700 test: schedule_api: increase timeout
Some qemu plaforms might need some more time.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-23 00:42:13 -05:00
Alexey Brodkin
c1d5229549 Revert "tests: Exclude qemu_arc{em|hs} in some"
This reverts commit b98058ecd0.

With icount finally working in QEMU for ARC these tests start to
pass reliably, so no need to exclude them any longer.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
2021-01-23 00:42:13 -05:00
Alexey Brodkin
3cd64c91bd Revert "tests: exclude qemu_arc_hs in lifo_usage test"
This reverts commit 6f4f5b1fe5.

With icount finally working in QEMU for ARC these tests start to
pass reliably, so no need to exclude them any longer.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
2021-01-23 00:42:13 -05:00
Alexey Brodkin
47944bd12e Revert "tests: kernel: lifo_usage: Exclude on qemu_arc_em"
This reverts commit 27d42f060d.

With icount finally working in QEMU for ARC these tests start to
pass reliably, so no need to exclude them any longer.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
2021-01-23 00:42:13 -05:00
Ioannis Glaropoulos
b0a85fb855 tests: kernel: thread: increase heap mem pool size
Increase the heap memory pool size in the
prj_armv8m_mpu_stack_guard.conf, to match
the value in the default configuration in
proj.conf (and fix an out-of memory issue
when allocating a kernel object).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-01-22 12:39:25 -05:00
Flavio Ceolin
321ce7fb77 power: Use substate-id in pm subsystem
Change subsystem to use struct pm_state with substate-id instead of
using only the power state category.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-22 09:31:20 -05:00
Flavio Ceolin
d21808b0b1 power: Remove residency and states from Kconfig
Residency time and power states are defined using device tree now.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-22 09:31:20 -05:00
Flavio Ceolin
579f7049c7 power: Move pm subsystem to new power states
Migrate the whole pm subsystem to use new power states information
from power_state.h and get states and residency properties from
device tree.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-22 09:31:20 -05:00
Anas Nashif
34e9c09330 Revert "arch: remove KERNEL_RAM_SIZE"
This reverts commit 73561be500.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Anas Nashif
6785d2a2dc Revert "tests: mem_map: pin test pages"
This reverts commit 24eb50d7f4.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Anas Nashif
cf34c9174a Revert "tests: add basic k_mem_map() test"
This reverts commit 0f8dc1c109.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Anas Nashif
6e4b33e8a5 Revert "tests: add intial demand paging testcase"
This reverts commit 060462d5c6.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Anas Nashif
c2c87c99c7 Revert "kernel: add z_num_pagefaults_get()"
This reverts commit d7e6bc3e84.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Anas Nashif
fb4db2c0a8 Revert "tests: demand_paging: add more API tests"
This reverts commit 7370895c0e.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Anas Nashif
5e978d237c Revert "mmu: backing stores reserve page fault room"
This reverts commit 7a642f81ab.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Anas Nashif
43cd3d3fac Revert "tests: context: disable if DEMAND_PAGING"
This reverts commit 6af87480d0.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Anas Nashif
ef17f889dc Revert "mmu: promote public APIs"
This reverts commit 63fc93e21f.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-22 08:39:45 -05:00
Andy Ross
e932a1537c arch: tests: Document interrupt delivery behavior after arch_irq_disable()
Upcoming changes from Andrew that add a global timeout to the kernel
broke because of some voodoo behavior in the kernel/context test.  It
will use arch_irq_disable() on the timer interrupt directly to prevent
interrupts and measure timekeeping in their absence.  But some
architectures[1] don't reliably deliver interrupts that arrive, which
means that a running timeout that exists across this period will
result in a corrupt timeout queue.

Document that rule for architectures, move the offending test to the
end of the test suite (to minimize the chance of interacting with
other test code) and put a giant warning about the situation on it.
Long term, we may want to rework this test to do its job in other
ways.

[1] On x86, the interrupt disable happens at the IO-APIC level, while
interrupt latching and delivery is downstream in each CPU's Local
APIC.  An IO-APIC masked interrupt is completely invisible to the APIC
and can never be delivered once the line goes low.

Fixes #31333

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-01-21 17:50:01 -05:00
Andrew Boie
63fc93e21f mmu: promote public APIs
These are application facing and are prefixed with k_.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Andrew Boie
6af87480d0 tests: context: disable if DEMAND_PAGING
Until #31333 is resolved, the periodic timer in the eviction
algorithm interacts with this test in such a way that the system
deadlocks.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Andrew Boie
7a642f81ab mmu: backing stores reserve page fault room
If we evict enough pages to completely fill the backing store,
through APIs like k_mem_map(), z_page_frame_evict(), or
z_mem_page_out(), this will produce a crash the next time we
try to handle a page fault.

The backing store now always reserves a free storage location
for actual page faults.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Andrew Boie
7370895c0e tests: demand_paging: add more API tests
Add remaining APIs in mem_manage.h even though not all have
been promoted to public (yet).

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Andrew Boie
d7e6bc3e84 kernel: add z_num_pagefaults_get()
Simple counter of number of successfully handled page faults by
the core kernel.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Andrew Boie
060462d5c6 tests: add intial demand paging testcase
More to be added, but for now show that we can map more
anonymous memory than we physically have, and that reading/
writing to it works as expected.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Andrew Boie
0f8dc1c109 tests: add basic k_mem_map() test
Show we can measure free memory properly and map a page of
anonymous memory, which has been zeroed and is writable.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Andrew Boie
24eb50d7f4 tests: mem_map: pin test pages
These get mapped to multiple virtual addresses and must be
pinned.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Andrew Boie
73561be500 arch: remove KERNEL_RAM_SIZE
We don't map all RAM at boot any more, just the kernel image.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2021-01-21 16:47:00 -05:00
Enjia Mai
a086e19d3b tests: fatal: fix test case fail while assertion off
Fix one test case of fatal error. This case shall be skip
while CONFIG_ASSERT=n.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-01-19 19:27:52 -08:00
Jian Kang
bf55de2d67 kernel: timer: Add some testcases to testing timer and clock
Add some error condition or testing cases to verify whether the
robustness of API. Such as give a NULL to some API and check
the response if get result that we were expacted.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2021-01-19 09:06:28 -05:00
Anas Nashif
6d53606777 tests: kernel: add test for condition variables
add a test for condition variables.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-01-19 08:55:47 -05:00
Ying ming
812914ff5d test: kheap: add testcase
Add testcase when use kheap api in isr context.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-01-18 23:19:33 -05:00
Ningx Zhao
66c55d9b75 kernel: queue: develop the code coverage
Add some testcases to test some failure scenario
to enhance the coverage of queue's source code.
And add the fatal error function to handler the
fatal error by ourself.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-01-18 23:14:12 -05:00
Jian Kang
1a369f5cdd kernel: semaphore: Add some error case testing for semaphore
Add some error case tesing such as invoke k_sem_take with duration
timeout or set input to NULL. This is check if API robust in error
condition handing.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2021-01-18 22:10:09 -05:00
Ying ming
c77ae15c99 test: scheduling: add configuration item
When using Red/black tree ready queue as scheduling algorithm,
there are no limit to the number of priority levels. So set the
CONFIG_NUM_COOP_PRIORITIES to 30, testcase test_bad_prooritiesi()
will prove both cooperative and preemptive thread have no quantitative
limit.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-01-18 17:22:34 -05:00
Martin Åberg
4604c45541 tests: enable and run many tests on RISC-V
This commit enables lots of tests on riscv32 and riscv64 which were
previously disabled.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2021-01-15 13:06:33 -05:00
Enjia Mai
07d67c1bd4 tests: device: add two more error case testing
1. Add a null dynamic name testing for device_get_binding().
2. Add a driver which initialization failed in SYS_INIT.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-01-15 12:18:16 -05:00
Enjia Mai
173b192602 tests: mutex: remove and refine some error test cases
1. Remove the error test cases that trigger assertion.
2. Refine the NULL and invalid kobject parameter test case.
3. Use the common fatal error handler to reduce code.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-01-15 12:13:52 -05:00
Meng xianglin
912914a915 test: msgq: imporve test coverage for message queue
Add code to wake up a thread waiting for message on a message
queue.

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2021-01-15 11:35:22 -05:00
Ningx Zhao
11f89c1fda tests: stack: remove and refine some test cases
Use the common fatal error handler to reduce code.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2021-01-15 11:18:40 -05:00
Hake Huang
129ddfe5c6 tests: fpu_sharing fix print size issue
As FPU enalbed the printf code size is changed,
so increase main stack size to make test pass on NXP RT platforms

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2021-01-14 07:30:30 -05:00
Ying ming
ab68d88c53 test: mslab: improve coverage for mslab
Improve branch coverage for k_mem_slab_init api.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-01-12 22:16:33 -05:00
Enjia Mai
478ddde6cc tests: skip memory mapping execution testing of qemu_x86_64 coverage
Skip the memory mapping execution test case when code coverage enabled
for qemu_x86_64 platform. See issue #30434.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-01-05 10:32:38 -08:00
Andy Ross
eb3734168a tests/kernel/fatal/exception: Remove ticked kernel from stack sentinel test
The "sentinel" variant of this test runs the same code, but enables
the stack sentinel feature.  Inexplicably, it's also disabling
TICKLESS_KERNEL, forcing a timer interrupt at every tick boundary.

That doesn't seem to be required for any test functionality I can see.

And worse, by changing that setting without adjusting the tick rate,
it runs afoul of more modern platforms which were designed with
tickless operation in mind.  Specifically, the intel_adsp platforms
have a default tick rate of 50 kHz, which is just too fast for
reasonable operation.  It leaves almost no time available for
application code and something falls behind and fails.

Just remove it.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-01-04 20:40:55 -05:00
Ying ming
49e992ac8c test: workqueue: imporve coverage for workqueue
Add module testcase of function k_work_submit_to_user_queue().

Signed-off-by: Ying ming <mingx.ying@intel.com>
2021-01-04 16:25:40 +01:00
Flavio Ceolin
8fe3866e19 power: rename _pm_power_state_ -> pm_power_state
Leftover from old renaming commits. This function is not private and
should not start with underscore.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2021-01-04 09:02:23 -05:00
Enjia Mai
3026df2a24 tests: spinlock: add some error test cases
Add some error test cases for spinlock, include:
1.Validate indentical spinlock cannot be used recursively.
2.Validate unlocking incorrect spinlock will trigger assertion.
3.Validate releasing incorrect spinlock will trigger assertion.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-12-27 18:19:42 +01:00
Andy Ross
c2c6bee036 drivers/timer: Remove legacy APIC driver
For a while now, we've had two APIC drivers.  The older was preserved
initially as the new (much smaller, "new style") code didn't have
support for Quark interrupt handling.  But that's long dead now.  Just
remove it.

Note that this migrates the one board using this driver (acrn) to
CONFIG_APIC_TIMER instead.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-27 18:19:17 +01:00
Ningx Zhao
187697c2d7 tests: stack: add some testcases
Add some testcases for stack source code coverage,
and add a fatal handler function to hand the error
by null parameter.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2020-12-27 18:17:22 +01:00
Christopher Friedt
05a08a3b66 tests: kernel/k_malloc: tests for k_aligned_alloc
This change adds tests for k_aligned_alloc.

Fixes #29519

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-12-27 18:17:07 +01:00
Kumar Gala
1706bd2b41 tests: convert DEVICE_AND_API_INIT to DEVICE_DEFINE
Convert tests to DEVICE_{DT_}DEFINE instead of DEVICE_AND_API_INIT
so we can deprecate DEVICE_AND_API_INIT in the future.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-12-19 20:05:40 -05:00
Andrew Boie
d2ad783a97 mmu: rename z_mem_map to z_phys_map
Renamed to make its semantics clearer; this function maps
*physical* memory addresses and is not equivalent to
posix mmap(), which might confuse people.

mem_map test case remains the same name as other memory
mapping scenarios will be added in the fullness of time.

Parameter names to z_phys_map adjusted slightly to be more
consistent with names used in other memory mapping functions.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-12-16 08:55:55 -05:00
Cheryl Su
46efefbbe5 soc/riscv: it8xxx2 soc system
A new platform soc for it8xxx2.
Revising the test/kernel/context/src/main.c for it8xxx2 test case.

Signed-off-by: Cheryl Su <cheryl.su@ite.com.tw>
2020-12-16 08:47:36 -05:00
Enjia Mai
eedfb30b62 tests: mutex: add some error case testing
Add some error case testing such as invoking mutex with null parameter
or using it interrupt context. This is for checking if API robust
enough in error condition handling.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-12-16 14:26:55 +01: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
Ioannis Glaropoulos
4f4dd9f29f tests: mem_protect: exclude nRF5340 DK from the gap filling test
Modify test .yaml file, to allow the .gap_filling test
variant to execute only on cortex-m33 platforms with
sufficient number of MPU regions. Copy pasting the
configuration from mem_protect/userspace test.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-12-11 11:24:32 +01:00
Ioannis Glaropoulos
cebf726a99 tests: usermode: skip arm_mpu_disable test for non-secure builds
Skip the test_disable_mmu_mpu test case for
Cortex-M non-secure builds, since the test
may enter a BusFault which is not banked
between security states and the system
may hang.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-12-11 11:21:34 +01:00
Ioannis Glaropoulos
810e62ea05 tests: mem_protect: syscalls: skip scenarios for non-secure builds
Skip the scenario of accesing a faulty address
in test_string_nlen for Non-Secure Zephyr builds,
because accessing faulty addresses in this case
triggers SecureFault that may hang the system
completely.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-12-11 11:21:34 +01:00
Anas Nashif
72cab9a2d0 power: sys_set_power_state -> pm_power_state_set
remove sys_ prefix and rename API to be more consistent with guidelines.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Anas Nashif
e3937453a6 power: rename _sys_suspend/_sys_resume
Be consistent in PM namespaces.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Anas Nashif
e0f3833bf7 power: remove SYS_ and sys_ prefixes
Remove SYS_ and sys_ from all PM related functions and defines.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Anas Nashif
dd931f93a2 power: standarize PM Kconfigs and cleanup
- Remove SYS_ prefix
- shorten POWER_MANAGEMENT to just PM
- DEVICE_POWER_MANAGEMENT -> PM_DEVICE

and use PM_ as the prefix for all PM related Kconfigs

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-12-09 15:18:29 -05:00
Peter Bigot
060b4a5c5c tests: kernel: exception: use cbprintf_nano for arm fpu
Use of a printk that supports floating point changes the stack
requirements causing kernel.common.stack_protection_arm_fpu_sharing to
fail.  The test doesn't need this capability so revert to nano
formatting.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-12-08 09:25:36 -05:00
Andy Ross
fcd392f6ce kernel: subsys: lib: drivers: Use k_heap instead of z_mem_pool wrappers
Use the core k_heap API pervasively within our tree instead of the
z_mem_pool wrapper that provided compatibility with the older mempool
implementation.

Almost all of this is straightforward swapping of one alloc/free call
for another.  In a few cases where code was holding onto an old-style
"mem_block" a local compatibility struct with a single field has been
swapped in to keep the invasiveness of the changes down.

Note that not all the relevant changes in this patch have in-tree test
coverage, though I validated that it all builds.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
78614bf271 tests/kernel/pipe/pipe_api: Remove mem_pool-related test cases
Remove test cases that exercise the deprecated mem_pool features of
the pipe utility.

Note that this leaves comparatively few cases left, we should probably
audit coverage after this merges and rewrite tests that aren't
interdependent.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
c844bd87b3 kernel: Remove legacy mem_pool usage
The mailbox and msgq utilities had API variants that could pass old
mem_pool blocks through the data structure.  That API is being
deprected (and the features were obscure), so remove the internal
support.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
76b4e4f917 tests/kernel/mem_protect: Remove mem_pool test case
The sys_mem_pool data structure is going away.  And this test case
didn't actually do much.  All it did was create a sys_mem_pool in the
app data section (I guess that's the "mem_protect" part?) and validate
that it was usable.  We have tests for sys_heap to do that already
elsewhere anyway; no point in porting.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
0a4a282cdc tests/kernel/thread_stack: Increase heap size
This test was written to use a TINY system heap (64 bytes) from which
it has to allocate on behalf of a userspace process.  The change in
convention from mem_pool (where the byte count now includes metadata
overhead) means it runs out of space.  Bump to 192 bytes.  Still tiny.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
2f661fd17a tests/kernel/mheap_api_concept: Remove whitebox tests
These two test cases were making whitebox assumptions of both the
block header size and memory layout of an old-style k_mem_pool that
aren't honored by the k_heap allocator.  They aren't testing anything
that isn't covered elsewhere.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
7db52bf451 tests/kernel/mem_protect: Port to k_heap API
The kernel resource pool is now a k_heap.  There is a compatibility
API still, but this is a core test that should be exercising the core
API.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
55e85928d9 tests/kernel: Remove sys_mem_pool test
This data structure is going away, and its replacement (sys_heap) has
tests already.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
c770cab1a3 kernel: Make thread resource pools into sys_heaps
The k_mem_pool allocator is no more, and the z_mem_pool compatibility
API is going away.  The internal allocator should be a k_heap always.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
9413922625 kernel/k_malloc: Decouple k_malloc/k_free from mem_pool
These were implemented in terms of the mem_pool/block API directly
(for complicated reasons, the pointers returned from this API may have
been allocated from allocators other than the single system heap).
Have them use a k_heap instead.

Requires a tweak to one test which had hard-coded an assumption about
the header size.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
6965cf526d kernel: Deprecate k_mem_pool APIs
Mark all k_mem_pool APIs deprecated for future code.  Remaining
internal usage now uses equivalent "z_mem_pool" symbols instead.

Fixes #24358

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
27b1394331 tests/kernel: Remove mem_pool tests
This API is being deprecated, and the underlying sys_heap code has its
tests elsewhere.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Andy Ross
8a6aee9cac kernel: Make the "heap" backend to mem_pool default
Remove the MEM_POOL_HEAP_BACKEND kconfig, treating it as true always.
Now the legacy mem_pool cannot be enabled and all usage uses the
k_heap/sys_heap backend.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-12-07 21:50:14 -05:00
Ying ming
79b8e23a2c test: workqueue : add testcase to improve coverage
Set work item's flag in pending state, it cannot be append to a
workqueue. Improve branch coverage of function k_work_submit_to_queue().

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-12-07 12:56:01 +01:00
Martin Åberg
ebcdb210e3 tests/float_disable: ported to SPARC
Enable the test for SPARC and take into account that
arch_float_disable() returns -ENOSYS.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-12-04 14:33:43 +02:00
Martin Åberg
5fc94948a8 tests/fpu_sharing: ported to SPARC
Added the bits and pieces required to run the test on SPARC.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-12-04 14:33:43 +02:00
Wu Han
df8f6c282b tests: kernel: gen_isr_table: Exclude stm32f103_mini board
This test is not suitable for stm32f103

Signed-off-by: Wu Han <wuhanstudio@qq.com>
2020-12-03 10:54:38 -06:00
Maksim Masalski
555408d4e7 tests: access kernel object with private data using system call
When defining system calls, it is very important to ensure that
access to the API’s private data is done exclusively through system
call interfaces. Private kernel data should never be made available
to user mode threads directly. For example, the k_queue APIs were
intentionally not made available as they store bookkeeping
information about the queue directly in the queue buffers which are
visible from user mode.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-12-01 10:14:35 -06: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
Trond Einar Snekvik
7986f94275 kernel: Add K_DELAYED_WORK_DEFINE
Adds a K_DELAYED_WORK_DEFINE, matching the K_WORK_DEFINE macro, with
accompanying Z_DELAYED_WORK_INITIALIZER macro.

Makes k_delayed_work_init a static inline function, like its K_WORK
counterpart.

Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
2020-11-27 20:08:30 -05:00
Maksim Masalski
80123899c1 tests: add test to verify assertion cathes overlapped partitions
When adding the new partition to a memory domain the system must
assert that it does not overlap with any other existing partitions
in the domain.
Test to add new partition which has same start address as an
existing one, after that must happen an assertion error indicating
that new partition overlaps existing one.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-11-26 14:18:09 +01:00
Peter Bigot
fbb7eb81b8 tests: kernel: work_queue: avoid improper access to internal structures
Nothing in the API description the delayed work structure sanctions
direct reference to internal fields.  Do not assume that a delayed
work item can be initialized in any way other than by invoking the
delayed work item init function.  Do not assume that a delayed work
item can be submitted without delay by invoking k_work_submit() with a
reference to the contained work item.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-24 13:04:48 +02:00
Steven Wang
fcbbd32445 Test: correct an error in test_pipe_user_thread2thread().
In test_pipe_user_thread2thread(), what should be tested is
the pipe, which allocated with k_object_alloc(), rather than
"pipe" and "kpipe". That two pipes are already teseted in
test_pipe_thread2thread().

Signed-off-by: Steven Wang <steven.l.wang@linux.intel.com>
2020-11-20 10:57:05 +01:00
Andrew Boie
5a58ad508c arch: mem protect Kconfig cleanups
Adds a new CONFIG_MPU which is set if an MPU is enabled. This
is a menuconfig will some MPU-specific options moved
under it.

MEMORY_PROTECTION and SRAM_REGION_PERMISSIONS have been merged.
This configuration depends on an MMU or MPU. The protection
test is updated accordingly.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-11-18 08:02:08 -05: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
Enjia Mai
a9bacf552c tests: improve test case descriptions of some interrupt APIs
To add some test case descriptions for testing irq_lock(), irq_unlock()
, irq_enable(), irq_disable().

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-11-17 19:25:59 -05:00
Peter Bigot
057a173e33 tests: fpu_sharing: avoid stack overflow due to unnecessary feature
CONFIG_FPU selects support for formatting floating point numbers,
which increases the stack requirements for cbprintf, causing this test
to overrun its stack.

Since this test doesn't format floating point numbers, use
CBPRINTF_NANO to revert to using the small-footprint formatter.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-17 17:49:22 -05:00
Peter Bigot
1d048df553 tests: add FP formatting to all tests that require it
Tests that include floating-point format specifications may need
cbprintf FP support.  Make sure it's available.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-17 14:44:59 -06:00
Martin Åberg
b5bab421b7 tests: Avoid out-of-bounds array access on SPARC
The test reads and writes outside the bounds of an array allocated on
the stack in check_input(). This commit disables the test on SPARC.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-11-13 14:53:55 -08:00
Martin Åberg
645b411448 tests: kernel: context: SPARC support
This test requires explicit architecture support, which this commit adds
for SPARC.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-11-13 14:53:55 -08: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
Wentong Wu
6221439fbd tests: kernel: syscalls: add more than 6 arguments syscall test case
Add more than 6 arguments syscall test case.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-11-12 17:12:38 -05:00
iva kik
10fdf95b94 tests: k_heap api: add tests for k_heap_api
Add test cases to test k_heap_alloc() and k_heap_free() APIs

Fixes #29654

Signed-off-by: iva kik <megatheriumiva@gmail.com>
2020-11-12 15:51:45 -05:00
Andy Ross
f3fe8af985 tests: Remove filtering on KERNEL_COHERENCE
These tests were suppressed when KERNEL_COHERENCE=y because of a
feature collision with CONFIG_POLL that has since been fixed.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-11-11 10:59:52 -05:00
Andy Ross
9487a1d0ca tests/queue: Remove fifo/queue "poll" variant tests
These test variants were there to test an older backend to the kernel
queue utility that used k_poll() as the blocking mechanism.  That code
got removed a while back, so these tests were just dupicates of the
main cases now.  Remove.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-11-11 10:59:52 -05:00
Ying ming
5829fd88a5 test: workqueue: add code description
Add testcase descriptions for test_work_item_supplied_with_func(),
test_sched_delayed_work_item(), test_workqueue_max_number(),
test_workq_start_before_submit(), test_work_submit_handler()

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-11-10 21:47:03 -05:00
Ying ming
255c4df04b test: workqueue: modify testcase
The thread name is used to judge whether the thread of
user-defined workqueue is created successfully.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-11-10 21:47:03 -05:00
Andrew Boie
ea6e4ad098 kernel: support non-identity RAM mapping
Some platforms may have multiple RAM regions which are
dis-continuous in the physical memory map. We really want
these to be in a continuous virtual region, and we need to
stop assuming that there is just one SRAM region that is
identity-mapped.

We no longer use CONFIG_SRAM_BASE_ADDRESS and CONFIG_SRAM_SIZE
as the bounds of kernel RAM, and no longer assume in the core
kernel that these are identity mapped at boot.

Two new Kconfigs, CONFIG_KERNEL_VM_BASE and
CONFIG_KERNEL_RAM_SIZE now indicate the bounds of this region
in virtual memory.

We are currently only memory-mapping physical device driver
MMIO regions so we do not need virtual-to-physical calculations
to re-map RAM yet. When the time comes an architecture interface
will be defined for this.

Platforms which just have one RAM region may continue to
identity-map it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-11-09 20:19:13 -05:00
Alexandre Mergnat
0a5b25916c tests: protection: add riscv support
Execute tests are disabled for RISC-V because is isn't able
to set an execution restriction. From RISC-V documentation:
  "Instruction address-translation and protection are unaffected
  by the setting of MPRV"
MPRV is used to apply memory protection restriction when CPU is
running in machine mode (kernel).

Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
2020-11-09 15:37:11 -05:00
Alexandre Mergnat
39208c2700 tests: mem_protect: add riscv support
Add a memory region allocation for RISCV architecture.
Also fix an arbitraty value which can't work with
RISC-V granularity.

Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
2020-11-09 15:37:11 -05:00
Alexandre Mergnat
52e6b7fe6b tests: userspace: add riscv support
Add support for the following tests:
- test_write_control
- test_disable_mmu_mpu
- test_read_priv_stack
- test_write_priv_stack

Signed-off-by: Alexandre Mergnat <amergnat@baylibre.com>
2020-11-09 15:37:11 -05:00
Steven Wang
788dd6356c Test: add doxygen comment for test_pipe_thread2thread().
Add doxygen comments for details of test_pipe_thread2thread().

By the way, plan to do the same thing to all test cases
in test_pipe_contexts.c.

Signed-off-by: Steven Wang <steven.l.wang@linux.intel.com>
2020-11-06 13:14:36 -05:00
Ying ming
d40fad4dcd test: atomic operation : add test case
Add tests with negative parameters to supplement black box tests.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-11-05 11:56:52 -08:00
Andrew Boie
4303d35380 tests: mem_protect: add migration test case
We need to make sure that if we migrate a thread to another
memory domain, the migration process doesn't cause the target
thread to explode. This is mostly a concern on SMP systems;
the thread could be running on another CPU at the same time.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-11-05 09:33:40 -05:00
Andrew Boie
eeab568a27 tests: userspace: fix tests that don't hold on MMU
MMU threads within the same memory domain have access to
each other's stacks.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-11-05 09:33:40 -05:00
Enjia Mai
5b2f00779b Tests: Minor change in description and group of SMP test cases
Do minor change of the descriptions and doxygen group name in order to
pave the way for generation the test specification.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-11-03 11:04:50 +01:00
Peter Bigot
758c8b34b1 tests: kernel: work_queue_api: relax test to eliminate racy checks
We can't control ticks accurately enough to detect the transition
between on a queue and being handled, so relax the checks to make
things pass.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-02 14:25:21 -05:00
Enjia Mai
90e6f21d20 tests: modify the test case gen_isr_table using ztest
Modify the gen_isr_table test case to using ztest. Although it was
split up to three test cases, the test logic and the tested platform
are totally the same as previous one.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-10-30 15:57:03 +01:00
Enjia Mai
761eafa57b tests: improve test case descriptions of arch layer interface
To add more test case descriptions for architecture layer interface
arch_start_cpu().

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-10-30 15:55:42 +01:00
Andy Ross
0875740a34 tests/kernel/schedule_api: Fix slop in timeslice test
This test is a little subtle: it wants to spawn three threads to run
and be switched out by a timeslice interrupt.  And it wants to consume
half a time slice itself before it starts running.  And, because
timeslicing runs out of the same tick framework in the timer driver,
it needs to align to the start of a tick before the process starts.
And further: it does its own time math not in ticks but in timer
cycles, so it's quite sensitive to slop.

But it's "synchronize to tick boundary" code was actually
synchronizing to a CYCLE boundary, which is just wrong.  And it was
doing this in the wrong order.  It was resetting the timeslice first
and then synchronizing to a tick by spinning, which means that the
test was always going to begin as much as a tick late.  Do the tick
synchronization (via a sleep) first.

Finally, the manager thread that was spawning the new threads lives at
the same priority as the highest priority child threads, which means
it can potentitially wake up on the semaphores that they are giving in
the middle of the test and consume CPU unexpectedly.  Make sure it's
sleeping for the duration.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-10-29 07:39:39 -04:00
Andrew Boie
f4a4583e13 tests: sys_sem: add k_thread_join() calls
There is a race condition between the child threads
exiting, and the child threads getting re-used in the
next scenario. This reproduces more often on SMP systems.

Close the race by joining on the child threads before
exiting any test scenario.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-28 10:29:49 -07:00
Ying ming
783155ad99 test: atomic operation : add code description
The existing testcase's doxygen describes are the general
implementation idea of a function.On this basis, adding
more descriptive statements to describe which conditions need
to be preset when running the testcase, which test techniques
are applied, and describe the testcase Design steps in detail.
Make it more readable.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-10-27 09:14:08 -04:00
YouhuaX Zhu
f83041f2e8 Test: Refine annotaion and testcase for poll.
1. Add more detail info to make the purpose and process
of the test cases more clear which include test goal,
test step, input, judging criteria, constraints, etc.,
and these can be seen in our Zephyr documentations.
2. Add some negative test code.

Signed-off-by: YouhuaX Zhu <youhuax.zhu@intel.com>
2020-10-27 09:06:35 -04:00
YouhuaX Zhu
4772d40d5f Test: Refine annotaion and testcase for pipe.
1. Add more detail info to make the purpose and process
of the test cases more clear which include test goal,
test step, input, judging criteria, constraints, etc.,
and these can be seen in our Zephyr documentations.
2. Add more negative testcase.

Signed-off-by: YouhuaX Zhu <youhuax.zhu@intel.com>
2020-10-27 09:05:47 -04:00
Andrew Boie
5e18b5512b tests: mem_protect: rewrite memory domain tests
This suite now uses far less memory and is much simpler.
We still maintain coverage of all the memory domain APIs
and ensure that the maximum number of partitions can be
applied.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-26 08:58:00 -04:00
Andrew Boie
e26f21c96c tests: mem_protect: merge two duplicate tests
The tests test_mem_part_auto_determ_size and
test_mem_part_auto_determ_size_per_mpu are supposed to
just be checking the construction of automatic memory
partitions.

test_mem_part_auto_determ_size had a bunch of extraneous
stuff covered by other test cases and reserved three
different thread stacks.

These two tests have been drastically simplified and
combined.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-26 08:58:00 -04:00
Andrew Boie
54aa0f0c81 tests: mem_protect: delete duplicate test
test_mem_part_inherity_by_child_thr duplicates logic already
present in test_permission_inheritance. That test puts a
buffer called 'inherit_buf' in 'inherit_memory_partition'
and shows that it is accessible by a child thread by
writing to it.

Delete this unnecessary test.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-26 08:58:00 -04:00
Andrew Boie
ae69f87fac tests: mem_protect: improve main.c organization
Tests are now grouped in the C file they occur in.

test_mark_thread_exit_uninitialized no longer occurs twice.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-26 08:58:00 -04:00
Andrew Boie
4ae0f9b867 tests: mem_protect: update bss vars test
ztest_mem_partition is fine for this test. We can also run it
in user mode.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-26 08:58:00 -04:00
Andrew Boie
8022aabbe8 tests: mem_protect: move partition tests
Some tests only evaluate characteristics of k_mem_partitions.
Move these to a separate C file.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-26 08:58:00 -04:00
Andrew Boie
44ca58181a tests: mem_protect: static scope globals
put all globals only used in this C file in static scope, which
revealed that a few of them were not used at all.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-26 08:58:00 -04:00
Andrew Boie
5c5e3597c8 tests: userspace: reduce memory domains to one
We now just use two memory domains; the default domain and an
'alternate_domain' used for tests that need to handle a memory
domain switch.

Along the way the test code was simplified.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-26 13:01:29 +01:00
Daniel Leung
d963bda4c2 tests: kernel/common: enable testing TLS
This enables testing of thread local storage as this tests
errno.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-10-24 10:52:00 -07:00
Daniel Leung
55c3fb3ff1 tests: add a simple test for thread local storage
This adds a simple test to make sure TLS works.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-10-24 10:52:00 -07:00
Andrew Boie
933b420235 kernel: add context pointer to thread->fn_abort
For compatibility layers like CMSIS where thread objects
are drawn from a pool, provide a context pointer to the
exited thread object so it may be freed.

This is somewhat obscure and has no supporting APIs or
overview documentation and should be considered a private
kernel feature. Applications should really be using
k_thread_join() instead.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-22 23:32:37 -04:00
Andrew Boie
ba7e89b1d6 tests: sys_mutex: don't add to default domain
This is unnecessary; static threads start in the default
memory domain.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-22 16:47:07 -07:00
Daniel Leung
14b398778f tests: kernel: timer_api: align tick for duration period test
Add a k_usleep() in test_timer_duration_period test to align ticks
before starting the timer. This fixes some rare off-by-1 failures.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-10-22 06:18:14 -04:00
Andy Ross
728c73f5d7 tests/kernel/context: Update for cavs_timer
There are now two timer drivers available for various xtensa
platforms.  Select based on their driver and not the architecture.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-10-21 06:38:53 -04:00
Andy Ross
4a8b3d194c kernel/poll: Mark incompatibility with KERNEL_COHERENCE
The k_poll implementation places a struct _poller on the stack and
shares it with other threads, which is incompatible with the
KERNEL_COHERENCE model of cached stacks.

Make this a hard build failure instead of a kconfig dependency for
clarity.  The failures if a user actually enables both are subtle and
difficult to debug.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-10-21 06:38:53 -04:00
Andrew Boie
c3e285acea tests: mem_protect: add default mem domain checks
Ensure that both the main thread and any static threads are
properly assigned to the default memory domain.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-20 09:37:49 -07:00
Andrew Boie
13457ae46a Revert "tests: add new kernel objects tests"
This test is generating build warnings as it is making
checks that can never be false.

This reverts commit a4f1a5f58f.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-16 14:50:56 -04:00
Maksim Masalski
a4f1a5f58f tests: add new kernel objects tests
Found out that important requirements are not tested by current
kernel objects tests. Decided to fix that situation

New added tests:
1. test_kobj_assign_perms_on_alloc_obj()
Create kernel object semaphore, dynamically allocate it from the
calling thread's resource pool.
Check that object's address is in bounds of that memory pool.
Then check the requestor thread will implicitly be assigned
permission on the allocated object by using
semaphore API k_sem_init()

2. test_no_ref_dyn_kobj_release_mem()
Dynamically allocated kernel objects whose access is controlled by
the permission system will use object permission as a reference count
If no threads have access to an object, the object's memory released.

3. test_krnl_obj_static_alloc_build_time()
Take addresses of the kernel objects which are statically allocated
during the build time and verify that they are not null.
That kernel objects shouldn't require manual
registration by the end user.

4. Clean-up. Removed unused variable from userspace test.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-10-15 11:53:55 -07:00
Maksim Masalski
3ce7afdaaa tests: sched_api remove misprints and etc
I reviewed that test to find a bug root cause, unfortunately,
bug dissapeared, so nothing to fix, but I noticed several
misprints and wrong comment styles. It's something at least.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-10-14 19:38:11 -04:00
Andrew Boie
c1ccd6b14e tests: sys_mutex: remove stack size override
This was causing stack usage to be right on the margin
for some platforms, without a clear reason why it
needs to be here (it was copied from another test case
which no longer exists).

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-13 17:16:47 -07:00
Andrew Boie
25e6c1fece tests: userspace: conserve memory
We don't need 3 different threads/stacks and the stack size
can be smaller, the threads don't do much.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-09 11:48:53 +02:00
Peter Bigot
85733c01d3 tests: kernel: work_queue_api: align schedule tests to tick
Detection of transition from delayed to pending can fail in some cases
if the timeouts are not precisely managed.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-10-09 11:48:00 +02:00
Peter Bigot
9cc608a5b1 tests: kernel: work_queue_api: validate legacy no-wait behavior
The current implementation of delayed work will cancel and re-submit a
pending work item that is no-wait, putting it at the back of the
queue.  Verify this behavior.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-10-09 11:48:00 +02:00
Peter Bigot
bd76994dc2 tests: kernel: work_queue_api: validate legacy multiq behavior
The current implementation of delayed work retains a pointer to the
queue unless the work item is successfully cancelled, preventing a
completed item from being resubmitted to a different queue.  Confirm
this behavior and its workaround.

Also validates some unsuccessful cancel return values.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-10-09 11:48:00 +02:00
Peter Bigot
9cce1b0a2e tests: kernel: work_queue_api: coverage for delayed pending
This API function wasn't being tested.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-10-09 11:48:00 +02:00
Peter Bigot
a808475c1d tests: kernel: work_queue_api: clean up work_pending arguments
Pass a pointer to the work item member rather than casting the
augmented work item pointer to a base work item pointer.

Also the return type of k_work_pending() is bool, so use that rather
than comparing it to zero.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-10-09 11:48:00 +02:00
Christopher Friedt
310d149d8b boards: cc1352r_sensortag: add support for TI CC1352R SensorTag
The TI CC1352R SensorTag (LPSTK-CC1352R) is a development kit that
features the CC1352R SoC.

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-10-08 16:08:36 -04:00
Eugeniy Paltsev
ea8c4b91b5 tests: exception: workaround agressive optimization
The memset in the 'blow_up_stack' function can be optimized
away as it is called in the end of the function on the buffer
allocated on the stack (so it has 'no' effect on program
execution)

The 'stack_smasher' call can be optimized away as it's results
isn't used anywhere and stack_smasher function has no visible
side effects.

Fix that by disabling optimization on these functions.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2020-10-06 11:41:23 -04:00
Eugeniy Paltsev
90bcf3da6a tests: preempt: workaround aggressive oprimization
We use several variables (like do_sleep, etc...) to share
statuses between threads, however they are not marked as
volatile. That may lead to their unexpected optimization
(tat really happens with ARC MWDT when loop with waiting
on the sleep timeout in 'wakeup_src_thread' is optimized
away). Fix that by defining these variables as volatile.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2020-10-06 11:41:23 -04:00
Eugeniy Paltsev
effd2fa834 toolchain: define __no_optimization attribute across toolchains
The __attribute__((optimize("-O0"))) attribute is used to disable
optimization of some test functions. ARC MWDT toolchain doesn't
support it, however it supports __attribute__((optnone)) with
similar functionality.

Define __no_optimization attribute across all toolchains so it
can be used in tests.

NOTE: we don't define __no_optimization for XCC as it includes
GCC header with __no_optimization defined.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2020-10-06 11:41:23 -04:00
Eugeniy Paltsev
f55080e4f9 tests: mem_protect: avoid RO region access optimization
Compiler may optimize away write to RO region and following
readback so we won't trigger fault (that actually happens with
arc MWDT toolchain).

Add volatile to avoid that.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2020-10-06 11:41:23 -04:00
Daniel Leung
1cd545d5ae tests: work_queue: wait longer for expired triggering items
The test_triggered_wait_expired test submits the items with
2*SUBMIT_WAIT timeout and waits for the timeout to expire
so the items are being worked on. It waits one SUBMIT_WAIT
and checks none of the items have started. Then waits
another SUBMIT_WAIT to check if they have all finished.
However, since the timeout is at 2*SUBMIT_WAIT, the work
queue may have just started going through the list of items.
This means some items may have started while others have not.
This results in the test failing as not all items have
finished. So lengthen the second sleep to allow items to
finish before checking.

Fixes #28589

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-10-05 14:36:33 -05:00
Enjia Mai
39696e3c1b tests: smp: improving the description for SMP test cases
Add more detail description for test case of arch_curr_cpu() and
arch_sched_ipi(). This is in order to make the purpose and process of
the test cases more clear.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-10-04 14:26:31 -07:00
Enjia Mai
9ec3983c3e tests: device: update test case
Update pm test case to fix some error last time submission. Add test
case that simply check device_pm_enable and device_pm_disable interface.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-10-02 11:38:30 +02:00
Maksim Masalski
9eddc69029 tests: added new tests for memory partitions
Add new tests to improve of the Zephyr QA testing of the memory
protection for memory domains and partitions.
I created new tests for memory protection->memory partitions for
the requirements which I think necessary to be tested.
I added Doxygen tag for each test to make it clear to understand
what each test is doing and how.

New tests for memory domains and partitions:

-test_mem_domain_api_kernel_thread_only()
By creating that test I wanted to prove that access to memory
domain APIs must be restricted only to supervisor threads.
At the same time I wanted to prove that system can support the
definition of memory domains.

-test_mem_part_auto_determ_size()
By creating that test I want to prove that system can automatically
determine application memory partition base addresses and sizes
at build time, determined by its contents. Also system can support
definition of memory partitions. At the same time test proves that OS
supports adding and removing a thread from its memory domain
assignment.

-test_mem_part_auto_determ_size_per_mmu()
That test is very important and it proves that memory partitions are
automatically sized and aligned per the constraints of the platform's
memory management hardware.

-test_mem_part_inheirt_by_child_thr()
Prove that child thread inherits memory domain assignment of its
parent.

-test_macros_obtain_names_data_bss()
Test system provides tools to obtain the names of the data and BSS
sections related to a particular application memory partition at
build time.

-test_mem_part_assign_bss_vars_zero()
Test that global data and BSS values can be assigned to application
memory partitions using macros at build time. Test that BSS values
will be zeroed at the build time.

1. According to the reviews made changes.
2. Switched test_mem_part_assert_add_overmax
and test_create_new_invalid_prio_thread_from_user
That way I exposed problem (bug) with assertion
in L171 kernel/mem_protect.c

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-10-02 11:35:28 +02:00
Andrew Boie
9c9312c8c5 tests: thread_stack: add idle stack size scenario
Show that trampolining thread self-aborts to the idle thread
works and that we have sufficiently set the idle stack size
for this, PM hooks, and dynamic kernel object cleanup.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-30 14:11:59 -04:00
Andrew Boie
e3796b95a2 tests: metairq: add extra verbosity
No functional change, just add some extra printouts and comments
to make it a little clearer the expected sequencing.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-30 14:11:59 -04:00
Flavio Ceolin
cc0244bdd7 tests: gen_isr_table: Disable tables generation
Add a new sample disabling GEN_ISR_TABLES.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-09-29 12:36:33 +02:00
Peter Bigot
3aea86e777 tests: kernel/common: align time test with system tick
Reduce the error between the timer (which is tick-aligned) and
busy_wait (which is not) by aligning the busy_wait to start at
a tick boundary.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-09-29 10:47:03 +02:00
Ioannis Glaropoulos
8ef34566ed tests: explicitly disable HW Stack Protection when needed
Some ARM platforms, now, enable HW Stack Protection by
default in the Board definition. So if some tests
need to run without stack protection, it is not
sufficient to disable TEST_HW_STACK_PROTECTION;
we need to explicitly disable HW_STACK_PROTECTION.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-09-24 15:42:09 -05:00
Alexandre Bourdiol
74be161694 tests: kernel: timer: timer_api: reorder test_timer_remaining step
Move init_timer_data() out of k_usleep() tick alignment.
Compute rem_ticks just after busy_wait_ms() to avoid slew
due to 'now' and 'rem_ms' computations.
With slow CPU 32MHz: -2 Ticks.

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-09-24 13:26:27 -05:00
Alexandre Bourdiol
4133cb5f72 tests: kernel: timer: timer_api: tick align for test_timer_k_define
Insert k_usleep(1) just before k_timer_start()
to guaranty tick alignment for step "test_timer_k_define"

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-09-24 13:26:27 -05:00
Daniel Leung
2f7cc4ac9b tests: thread_apis: move uptime gathering in join scenario
When doing test_thread_join with OTHER_ABORT_TIMEOUT, the interval
between two k_uptime_get() includes the two k_thread_create() which
means the interval delta does not exactly count the time spent
in k_thread_join(). On x86_64 with userspace, time spent inside
k_thread_create() scales with memory size as it needs to create
a new page table for the thread. So to actually measure
the time spent in k_thread_join(), the locations where uptime is
obtained need to be moved.

Fixes #28549

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2020-09-24 09:54:11 -05:00
Peter Bigot
470176e668 tests: kernel/sleep: increase maximum threshold for nRF51
nRF51 MCUs are Cortex-M0 running with a 16 MHz clock.  The overhead of
work done in k_usleep() requires adding three more ticks (92 us) to the
expected loop iteration time.  (Two ticks is enough on most boards, but
some require a little more time.)

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-09-24 09:52:32 -05:00
Andrew Boie
04fe7c6eeb tests: exception: fix thread entry points
- They all had the wrong prototype and hard-casts can sometimes
lead to problems
- Several renamed to something more descriptive

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-23 17:07:25 -05:00
Alexandre Bourdiol
7cd921c9d2 tests: kernel: mem_protect: syscalls: FAULTY_ADDRESS for nucleo_l073rz
Configure faulty address for nucleo_l073rz to 0x0FFFFFFF
Fixes #28621

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-09-23 13:11:19 -05:00
Wentong Wu
6cf50ac89c tests: kernel: mem_map: Explicitly cast function pointer to (void *)
To make Coverity happy.

Coverity-CID: 212956
Fixes: #27837.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-09-21 16:49:21 -05:00
Eric Johnson
a142f5a26c tests: kernel: common: Add tests for 24-bit byteorder functions
Adds missing tests for 24-bit byteorder functions

Signed-off-by: Eric Johnson <eric@liveathos.com>
2020-09-21 11:17:59 +02:00
Eric Johnson
a18688eebd tests: kernel: common: Add tests for 48-bit byteorder functions
Adds missing tests for 48-bit byteorder functions

Signed-off-by: Eric Johnson <eric@liveathos.com>
2020-09-21 11:17:59 +02:00
Alexandre Bourdiol
8afcffc231 tests: kernel: context: align timer init on ticks
Align to ticks so the first iteration sleeps long enough
(k_timer_start() rounds its duration argument down, not up,
to a tick boundary)

Fixes #28319

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-09-18 13:23:45 -05:00
Ying ming
13e1c919d4 test: fatal exception: add test case
Add regex in testcase.yaml to verify the kernel will dump
thread id information and error type when exception occurs.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-09-17 21:37:39 -04:00
Ying ming
5b8569b305 test: fatal exception: Modify test case file location
Modify the location of the test case file because new
test cases need to be submitted. If the old test
cases are not in a folder, CI will fail and
prompts "the command exited with status 1".

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-09-17 21:37:39 -04:00
Jian Kang
339c8b1b00 tests: mailbox: add new tests
Add 2 new test cases for verify mailbox features

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2020-09-16 12:13:05 -04:00
Jian Kang
f4c7dbd043 test: add new test cases for timer
Add new test cases for timer to improve testing infrastructure.
Add different waiting time in existing cases. For new test cases,
restart timer and check for status of timer.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2020-09-16 08:15:47 -04:00
Ying ming
e3355067f5 test: scheduling: add test case
Add a test case of preemptive thread scheduling.
The scheduler will select the highest priority and
waiting longest thread to be the current thread.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-09-16 08:06:42 -04:00
Watson Zeng
6bddbc95c6 tests: kernel: stack: fix for memcmp with wrong length
fix for memcmp with wrong length

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2020-09-16 12:03:32 +02:00
Andrew Boie
5397353dde tests: mem_protect: fix SMP race
We try to invoke `ztest_test_pass()` from inside
a fatal exception in a child thread.

On SMP this can result in the next test case starting
on another CPU, re-using the child thread before it
has a chance to exit.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-14 17:28:33 -04:00
Andrew Boie
2ba861cb4f tests: mem_protect: fix test prototypes
The implementations of the test cases had the wrong prototype.
The extern declarations (which were in a C file for some reason)
were correct.

I don't want to talk about the subtle code generation and stack
corruption issues that emerged from this which at one point made
me question my own sanity.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-14 17:28:33 -04:00
Andrew Boie
aebb9d8a45 aarch64: work around QEMU 'wfi' issue
Work around an issue where the emulator ignores host OS
signals when inside a `wfi` instruction.

This should be reverted once this has been addressed in the
AARCH64 build of QEMU in the SDK.

See https://github.com/zephyrproject-rtos/sdk-ng/issues/255

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-10 21:31:15 +02:00
Ioannis Glaropoulos
840db3ab6a tests: kernel: fatal: minor #ifdef guard fix
HW Stack protection is required to successfully run the
stack overflow-related tests, so guard all these tests
inside #ifdef CONFIG_HW_STACK_PROTECTION. Otherwise this
test-suite fails for platforms that implement USERSPACE
but do not have HW_STACK_PROTECTION capability.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-09-09 15:40:06 -04:00
Yuguo Zou
9badde98d0 tests: toggle off a test scenario for em_starterkit_7d
em_starterkit_7d is not capable to generate error when access unmapped
address at kernel mode. So toggle off this part of test.

Signed-off-by: Yuguo Zou <yuguo.zou@synopsys.com>
2020-09-09 13:06:16 +02:00
Andrew Boie
1554926c4a tests: userspace: fix flaky behavior
- No longer call ztest_test_pass() out of a fatal exception,
  as if this took place on some child thread, the next test
  case could start on another CPU before the child has exited,
  leading to issues if the child thread object is recycled

- Get rid of some unnecessary synchronization semaphores.
  Use the scheduler and/or k_thread_join() instead.

- Simplify tests for read/write other threads not to spawn
  a child thread and then take a fatal fault on the ztest
  thread

- Add set_fault() clear_fault() as I do not enjoy typing.
  Despite these variables being voliatile, a barrier is
  needed to prevent re-ordering around non-volatile memory
  access

- Don't call ztest_test_pass() from child thread in
  test_user_mode_enter() due to possible races

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-09 13:05:38 +02:00
Andrew Boie
47b4a5c47b test: thread_stack: relax ram requirement
Possibly copypasta, or improvements to the test, either way
this test doesn't use that much RAM especially if memory
protection isn't active.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-04 22:24:48 -04:00
Andrew Boie
860e965a4f tests: spinlock: fix occasional crash
lock_runtime is a stack variable whose contents could be completely
garbage, but only the 'locked' member was zeroed. zero the whole
thing to prevent spurious "recursive spinlock" errors from occasionally
popping up as the validation framework gets confused from garbage
data in the other memebers of this data structure.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-03 21:55:05 +02:00
Andrew Boie
5e0b55c30e kernel: demote k_mem_map to z_mem_map
Memory mapping, for now, will be a private kernel API
and is not intended to be application-facing at this time.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-03 14:24:38 -04:00
Andrew Boie
7d32e9f9a5 mmu: support only identity RAM mapping
We no longer plan to support a split address space with
the kernel in high memory and per-process address spaces.
Because of this, we can simplify some things. System RAM
is now always identity mapped at boot.

We no longer require any virtual-to-physical translation
for page tables, and can remove the dual-mapping logic
from the page table generation script since we won't need
to transition the instruction point off of physical
addresses.

CONFIG_KERNEL_VM_BASE and CONFIG_KERNEL_VM_LIMIT
have been removed. The kernel's address space always
starts at CONFIG_SRAM_BASE_ADDRESS, of a fixed size
specified by CONFIG_KERNEL_VM_SIZE.

Driver MMIOs and other uses of k_mem_map() are still
virtually mapped, and the later introduction of demand
paging will result in only a subset of system RAM being
a fixed identity mapping instead of all of it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-09-03 14:24:38 -04:00
Tomasz Bursztyka
4dcfb5531c isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs

This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.

Note that only the ISR passed to IRQ_CONNECT are of interest here.

In order to do so, the script fix_isr.py below is necessary:

from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os

cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
(
 const struct device *D = (const struct device *)P;
|
 const struct device *D = P;
)
 ...
}

@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
 ...
 const struct device *D;
 ...
(
 D = (const struct device *)P;
|
 D = P;
)
 ...
}

@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
 ...
}

@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);

@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
 ...
}

@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
 ...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
 ...
}
"""

def find_isr(fn):
    db = []
    data = None
    start = 0

    try:
        with open(fn, 'r+') as f:
            data = str(mmap.mmap(f.fileno(), 0).read())
    except Exception as e:
        return db

    while True:
        isr = ""
        irq = data.find('IRQ_CONNECT', start)
        while irq > -1:
            p = 1
            arg = 1
            p_o = data.find('(', irq)
            if p_o < 0:
                irq = -1
                break;

            pos = p_o + 1

            while p > 0:
                if data[pos] == ')':
                    p -= 1
                elif data[pos] == '(':
                    p += 1
                elif data[pos] == ',' and p == 1:
                    arg += 1

                if arg == 3:
                    isr += data[pos]

                pos += 1

            isr = isr.strip(',\\n\\t ')
            if isr not in db and len(isr) > 0:
                db.append(isr)

            start = pos
            break

        if irq < 0:
            break

    return db

def patch_isr(fn, isr_list):
    if len(isr_list) <= 0:
        return

    for isr in isr_list:
        tmplt = cocci_template.replace('<!fn!>', isr)
        with open('/tmp/isr_fix.cocci', 'w') as f:
            f.write(tmplt)

        cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]

        subprocess.run(cmd)

def process_files(path):
    if path.is_file() and path.suffix in ['.h', '.c']:
        p = str(path.parent) + '/' + path.name
        isr_list = find_isr(p)
        patch_isr(p, isr_list)
    elif path.is_dir():
        for p in path.iterdir():
            process_files(p)

if len(sys.argv) < 2:
    print("You need to provide a dir/file path")
    sys.exit(1)

process_files(Path(sys.argv[1]))

And is run: ./fix_isr.py <zephyr root directory>

Finally, some files needed manual fixes such.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka
50edd19f3a tests: Apply dynamic IRQ API change
Switching to constant parameter.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka
4b9134d8d2 tests: Apply IRQ offload API change
Switching to constant parameter.

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Tomasz Bursztyka
e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00
Mulin Chao
fb1c2b58ac tests: kernel: gen_isr_table: Add workaround for npcx7m6fb soc.
In NPCX7M6FB, it uses some the IRQs at the end of the vector table,
for example, the irq 60 and 61 used for Multi-Input Wake-Up Unit (MIWU)
device by default, and conflicts with isr used for testing. Moving IRQs
for this test suite to solve the issue.

Signed-off-by: Mulin Chao <MLChao@nuvoton.com>
2020-09-01 13:35:25 +02:00
Ioannis Glaropoulos
9163da09d6 tests: mem_protect: fix partition remove test on v8-m with 8 regions
Some ARMv8-M platforms may come with only 8 (instead of 16)
MPU regions. In these platforms, by design, a memory domain
may contain up to 2 application memory partitions, when we
build with MPU_GAP_FILLING support. To be able to test this
valid configuration we slightly modify the test code in the
mem_protect suite, and add-remove the second partition (with
index-1) instead of the third (index-2).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-08-28 12:55:37 +02:00
Ioannis Glaropoulos
0dd300f365 tests: kernel: userspace: restrict gap-filling test to valid boards
We need to exclude the .gap_filling test from running on
ARMv8-M platforms with 8 MPU regions available, since the
userspace test defines and uses a memory domain whose number
of partitions exceed the maximum number of permitted partitions
in ARMv8-m SoCs with MPU_GAP_FILLING=y.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-08-28 12:55:37 +02:00
Fabio Utzig
58a75eb50e tests: fix list usage in @details section
Adding the first list item in the same line as @details, creates a list
with a single item inside a paragraph, and another list with the
remaining items. What is wanted here is to have a single list with all
items, so the first item needs to be in a new line.

Signed-off-by: Fabio Utzig <fabio.utzig@nordicsemi.no>
2020-08-28 11:33:45 +02:00
Anas Nashif
dca317c730 sanitycheck: inclusive language
change whitelist -> allow.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-08-27 07:04:07 -04:00
Andrew Boie
f1d12aa45b userspace: deprecate k_mem_domain_remove_thread()
This is just equivalent to calling k_mem_domain_add_thread()
on the default memory domain now.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-26 20:35:02 -04:00
Andrew Boie
d650b4e800 ztest: remove ztest_mem_domain
Just add ztest's partition to the default domain, as well as the
malloc partition if it exists.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-26 20:35:02 -04:00
Andrew Boie
1a9f490353 userspace: deprecate k_mem_domain_destroy()
We don't have use-cases and it introduces complexities with
allocating page tables on MMU systems.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-26 20:35:02 -04:00
Anas Nashif
509b1dad60 tests: msgq: address unchecked return values
Check for return values and make coverity happy.

Fixes #27645
Fixes #27646
Fixes #27648

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-08-26 16:40:57 -04:00
Peter Bigot
ce47c809b9 tests: kernel: timer_api: fix formatting specifiers in diagnostic
Several of the values passed to the conversion failure diagnostic are
unsigned and/or 32-bit values, while all format specifiers are for
signed 64-bit integers.  Make the specifiers consistent with the
argument.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-26 12:24:58 +02:00
Andrew Boie
4b3f50b529 tests: protection: skip XD tests on IA32
Ancient 2-level IA32 page tables don't support "eXecute Disable".
Skip the test scenarios for them.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-25 15:49:59 -04:00
Andrew Boie
069aca22c1 tests: add k_mem_map() tests
Show that k_mem_map() works in various scenarios.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-25 15:49:59 -04:00
Andrew Boie
2dcb80aa41 tests: syscalls: fix "faulty" memory address
If the MMU is enabled, use the page right after permanent RAM
mappings, it should be non-present.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-25 15:49:59 -04:00
Flavio Ceolin
0aaae4a039 guideline: Make explicit fallthrough cases
-Wimplicit-fallthrough=2 requires a fallthrough comment or a compiler
to tells gcc that this happens intentionally.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-08-24 20:28:47 -04:00
Meng xianglin
560b8d9fe0 test: thread: add a test case for essential thread abort
Abort a essential thread and handle the fatal error.

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2020-08-21 13:58:35 -04:00
Ningx Zhao
92530b5fbb tests: tests/kernel/device modify yaml config
Modify platform tag into kernel.device.pm

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2020-08-19 09:34:28 -04:00
Ningx Zhao
0da89e6a98 tests: kernel/device can't run at EVB board
this case can't run at mec15xxevb_assy6853 board.
see github issue #27363

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2020-08-18 14:20:49 -04:00
Andrew Boie
72bab8c720 tests: show k_thread_abort works in an ISR
This wasn't covered in this context. I found an issue with
native_posix with it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-18 08:36:35 +02:00
David Leach
85cad85077 tests: kernel: Fix coverity warning CIDs 211474 and 211479
Added assert tests around two of the k_mutex_locks() that
did not have them.

Fixes #26997
Fixes #26998

Signed-off-by: David Leach <david.leach@nxp.com>
2020-08-16 09:29:41 -04:00
Henrik Brix Andersen
7d49a73f0e tests: kernel: context: add ARM Cortex-M1 support
The Wait For Interrupt (WFI) instruction ARM Cortex-M1 CPU does not
operate as a powersave instruction. It is always executed as a NOP.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2020-08-14 13:35:39 -05:00
Henrik Brix Andersen
a115e44246 tests: kernel: interrupt: check that irq is not constantly pending
Extend check to determine a usable ARM NVIC IRQ line to verify that the
IRQ line is not always pending.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2020-08-14 13:35:39 -05:00
Henrik Brix Andersen
f04f2e4278 tests: kernel: interrupt: add support for the ARM Cortex-M1
Add support for the ARM Cortex-M1 CPU to the kernel interrupt test case.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2020-08-14 13:35:39 -05:00
Greg Leach
e44f04d4f9 boards: Add BT510 support
Add support for the Laird Connectivity BT510 sensor

Signed-off-by: Greg Leach <greg.leach@lairdconnect.com>
2020-08-14 12:58:03 -05:00
Andrew Boie
63c3e153d6 drivers: use node IDs for DEVICE_MMIO.*_INIT
There is nothing wrong with instance numbers and they are
recommended for use whenever possible, but this is an API
design problem because it's not always possible to get nodes
by instance number; in some cases, drivers need to get node
identifiers from node labels, for example.

Change these APIs (which are not yet in any Zephyr release)
to take node IDs instead of instance IDs.

Fixes: #26984

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-14 13:35:02 +02:00
Meng xianglin
9f8d745b7f test: msgq: Add two corner cases in message queue
Put message to a full queue or get message from an empty queue with
different timeout: K_NO_WAIT, a period of time, K_FOREVER.

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2020-08-11 19:32:52 +02:00
Tomasz Bursztyka
98d9b01322 device: Apply driver_api/data attributes rename everywhere
Via coccinelle:

@r_device_driver_api_and_data_1@
struct device *D;
@@
(
D->
-	driver_api
+	api
|
D->
-	driver_data
+	data
)

@r_device_driver_api_and_data_2@
expression E;
@@
(
net_if_get_device(E)->
-	driver_api
+	api
|
net_if_get_device(E)->
-	driver_data
+	data
)

And grep/sed rules for macros:

git grep -rlz 'dev)->driver_data' |
	xargs -0 sed -i 's/dev)->driver_data/dev)->data/g'

git grep -rlz 'dev->driver_data' |
	xargs -0 sed -i 's/dev->driver_data/dev->data/g'

git grep -rlz 'device->driver_data' |
	xargs -0 sed -i 's/device->driver_data/device->data/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Tomasz Bursztyka
af6140cc0d device: Apply config_info rename everywhere
Via coccinelle:

@r_device_config@
struct device *D;
@@

D->
-	config_info
+	config

And 2 grep/sed rules for macros:

git grep -rlz 'dev)->config_info' |
	xargs -0 sed -i 's/dev)->config_info/dev)->config/g'

git grep -rlz 'dev->config_info' |
	xargs -0 sed -i 's/dev->config_info/dev->config/g'

Fixes #27397

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-08-11 19:30:53 +02:00
Anas Nashif
b08ce6f8ca tests: threads: mark cpu_mask skipped where it does not run
Mark as skipped if cpu_mask is not supported.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-08-06 12:07:38 -05:00
Maksim Masalski
435b9a1e4b tests: memory protection thread stack exit uninit
When thread is initialized and running z_object_validate
will return 0 for thread object and its thread stack object.
When thread exit, z_object_validate
will return -1 for thread object and its thread stack object.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-08-06 07:33:39 -04:00
Maksim Masalski
e9ffd9574d tests: copyright message add year to the existing
Instead of replacing of copyright year with the new one,
necessary to add new to the existing one

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-08-06 07:31:46 -04:00
Maksim Masalski
d70ee1eda7 tests: copyright message add year to the existing
Instead of replacing of copyright year with the new one,
necessary to add new to the existing one

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-08-06 07:31:46 -04:00
Maksim Masalski
d735e971f6 tests: mem protection tests updated tags
Updated current tests tags to make them more informative.
1. test_mslab updated Doxygen tag
2. test_create_alt_thread updated Doxygen tag
3. test_sys_heap_mem_pool_assign updated Doxygen tag

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-08-06 07:31:46 -04:00
Maksim Masalski
39fe4ef51a tests: semaphore tests overhaul
Modify current semaphore tests.
I checked the semaphore tests, and find out many gaps.
Overhaul semaphore tests:
1. Modify some tests
2.Doxygen tags update
3. Update text in zassert messages
4. Remove misprints
5. Test cases names change. Some test cases had a semaphore name in
their name, for example simple_sem, I removed it from the test
case names. Also some test cases used sema, some used word sem.
I decided to make standard short word for a semaphore sem

Detailed explanation of the changes:
-test_k_sema_init() -updated name to test_sem_init, updated doxygen
tag, updated zassert text
-test_sem_take_timeout() -updated doxygen tag, added zassert to check
that reset was correct, updated zassert text
-test_sem_take_timeout_fails() -updated doxygen tag, added zassert
to check that reset was correct, updated zassert text
-test_sem_take_timeout_forever() -updated doxygen tag, added zassert
to check that reset was correct, updated zassert text
-test_sem_take_multiple() -updated doxygen tag, modified that test,
added one more thread sem_tid_4, with high priority and added one
more semaphore high_prio_long_sem
-test_simple_sem_from_isr() -updated name to test_sem_give_from_isr,
updated doxygen tag, zassert text fix
-test_simple_sem_from_task() -updated name
to test_sem_give_from_thread, updated doxygen tag, zassert text fix

Tested on qemu_x86, qemu_x86_64, reel_board, and iotdk

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-08-06 07:30:46 -04:00
Joakim Andersson
ea9590448d kernel: Add k_delayed_work_pending to check if work has been submitted
Add k_delayed_work_pending similar to k_work_pending to check if the
delayed work item has been submitted but not yet completed.
This would compliment the API since using k_work_pending or
k_delayed_work_remaining_get is not enough to check this condition.
This is because the timeout could have run out, but the timeout handler
not yet processed and put the work into the workqueue.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2020-08-04 17:32:56 +02:00
Andrew Boie
e90873f290 tests: thread_stack: armv8 without SPLIM
Need to test MPU guards on ARMv8.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Andrew Boie
8067127a6f tests: thread_stack: enforce identities
There are predictable relationships between the actual size
of a stack object, the return value of K_*_STACK_SIZEOF() macros,
and the original size passed in when the stack was declared.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Andrew Boie
8ce260d8df kernel: introduce supervisor-only stacks
These stacks are appropriate for threads that run purely in
supervisor mode, and also as stacks for interrupt and exception
handling.

Two new arch defines are introduced:

- ARCH_KERNEL_STACK_GUARD_SIZE
- ARCH_KERNEL_STACK_OBJ_ALIGN

New public declaration macros:

- K_KERNEL_STACK_RESERVED
- K_KERNEL_STACK_EXTERN
- K_KERNEL_STACK_DEFINE
- K_KERNEL_STACK_ARRAY_DEFINE
- K_KERNEL_STACK_MEMBER
- K_KERNEL_STACK_SIZEOF

If user mode is not enabled, K_KERNEL_STACK_* and K_THREAD_STACK_*
are equivalent.

Separately generated privilege elevation stacks are now declared
like kernel stacks, removing the need for K_PRIVILEGE_STACK_ALIGN.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Andrew Boie
c7f33a7759 tests: thread_stack: show carveout, unused space
Currently for informational purposes, although we do check that
the carveout is smaller than the stack_size.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Andrew Boie
7151947c07 tests: thread_stack: dump IRQ stack information
Purely for informational purposes.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Andrew Boie
7111f162b8 tests: thread_stack: strengthen access check
thread->stack_info is now much more well maintained. Make these
tests that validate that user mode has no access just outside
the bounds of it, instead of the entire object.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Andrew Boie
f856d0cf40 tests: move stacks testing to its own application
Most of these checks can be performed on non-userspace
supporting platforms.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Andrew Boie
1331a83905 tests: userspace: enforce sub-stacks are aligned
Check that the base of every stack object is properly
defined. This can get messed up if K_THREAD_STACK_ARRAY_DEFINE
isn't specified properly.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Andrew Boie
b0c155f3ca kernel: overhaul stack specification
The core kernel computes the initial stack pointer
for a thread, properly aligning it and subtracting out
any random offsets or thread-local storage areas.
arch_new_thread() no longer needs to make any calculations,
an initial stack frame may be placed at the bounds of
the new 'stack_ptr' parameter passed in. This parameter
replaces 'stack_size'.

thread->stack_info is now set before arch_new_thread()
is invoked, z_new_thread_init() has been removed.
The values populated may need to be adjusted on arches
which carve-out MPU guard space from the actual stack
buffer.

thread->stack_info now has a new member 'delta' which
indicates any offset applied for TLS or random offset.
It's used so the calculations don't need to be repeated
if the thread later drops to user mode.

CONFIG_INIT_STACKS logic is now performed inside
z_setup_new_thread(), before arch_new_thread() is called.

thread->stack_info is now defined as the canonical
user-accessible area within the stack object, including
random offsets and TLS. It will never include any
carved-out memory for MPU guards and must be updated at
runtime if guards are removed.

Available stack space is now optimized. Some arches may
need to significantly round up the buffer size to account
for page-level granularity or MPU power-of-two requirements.
This space is now accounted for and used by virtue of
the Z_THREAD_STACK_SIZE_ADJUST() call in z_setup_new_thread.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 21:11:14 -04:00
Anas Nashif
d6bf5279a2 tests: device: remove whitelisting
Remove whitelisting and use --integration instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-07-30 08:00:03 -04:00
Andrew Boie
a7354ab391 tests: xip: remove hack and add qemu_x86_xip
We now have a variant x86 build target that only is run
for tests tagged with "xip", which is this one.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-30 12:25:37 +02:00
Maksim Masalski
d18ffc9307 tests: add new threads permissions tests, modify existing
1. Found out that thread tests doesn't test next ideas of requirements,
which I think necessary to be tested and verified:
-the kernel need to prevent user threads creating new threads from
using thread or thread stack objects which are in an initialized state
-Upon thread exit, the kernel need to mark the exiting thread
and thread stack objects as uninitialized

Add new tests to test requirements above, that way we can cover more
features to be tested:
- test_new_user_thread_with_in_use_stack_obj()
- test_mark_thread_exit_uninitialized()

2. Modified test test_create_new_thread_from_user() to verify that
kernel provides new user threads access to their own thread object.

3. Also I added detailed Doxygen tags for each new test and existing
modified test.
4. Added Doxygen tag to the existing test test_stack_buffer, it
covers requirement:
-The kernel need to provide all threads read and write access to their
own stack memory buffer.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-28 17:41:24 -04:00
Maksim Masalski
4f35917d1b tests: add check return value in futex_wake()
Inside function futex_wake() result of   k_futex_wait() is not checked.
Coverity-CID: 211508
Fixes: #27149

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-28 12:34:20 -04:00
Anas Nashif
bbea52c746 tests: fix device model tests and remove wrong doxygen grouping
Device test defines were pulled into doxygen in the wrong level.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-07-28 08:14:23 -05:00
Ioannis Glaropoulos
f9e1ef9684 tests: kernel: gen_isr_table: extend test for Cortex-M Baseline
Extend the gen_isr_table test suite to build and run
on Cortex-M baseline platforms. Add a few platforms
in the whitelist so the test builds and runs for some
common Baseline Cortex-M insluding the QEMU.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-07-27 11:11:48 +02:00
Ioannis Glaropoulos
98ad9d4a77 tests: kernel: gen_isr_table: yml fixes for ARC test variant
Adding tags for ARC-variant of the test.
Rename test string to comply with ARM-variant name.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-07-27 11:11:48 +02:00
Josep Puigdemont
7cafe7e74b boards: arm: olimex stm32-h103: Add board
The Olimex STM32-h103 is a development board based on the STM32F103RB,
very similar to the stm32_mini, which was used as a reference for the
pinmux configuration.

Signed-off-by: Josep Puigdemont <josep.puigdemont@gmail.com>
2020-07-24 14:48:07 +02:00
Maksim Masalski
9ccbfbd84e tests: code review changes
Code review changes.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-23 12:55:47 +02:00
Maksim Masalski
32aa91d803 tests: add new futex test
Add new standalone futex test that verifies next requirements:
-Futex can be placed in user memory using ZTEST_BMEM
-User thread can write to futex value
-User threads can make wait/wake syscalls on it

Added detailed Doxygen tag with information about the test

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-23 12:55:47 +02:00
Ningx Zhao
06ce1e4c32 tests: stack modifying and adding test case
1.Add some comments to describe functions performance
2.add a new testcase to implement push can be waited
when there are no items available.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2020-07-21 21:54:11 -04:00
Anas Nashif
1fbbfc819a tests/samples: add tags to some tests
Some tests/samples had no tags, fill those..

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-07-20 17:44:16 -04:00
Andrew Boie
13f2b7b848 tests: mslab_threadsafe: cleanup
Clean up the code some, and disable CONFIG_TIMESLICE_SIZE=1
until #13813 is resolved.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-17 11:38:18 +02:00
Andrew Boie
8ec248a0f9 tests: device: add device_mmio tests
Exercise the public macros as well as device_map().
This test has a whitelist for whatever reason; add
mps2_an385 so that the !DEVICE_MMIO_IS_IN_RAM stuff
is tested.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-07-17 11:38:18 +02:00
Maksim Masalski
c9a9aacb3f tests: update kernel objects tests
1. Add code change to the test_permission_inheritance() to let it
test that child thread can't access parent thread object. Now that test
tests one more related to it feature.
2. Add new Doxygen tags with informative descriptions about the kernel
objects tests. That will make reading and understanding kernel object
tests code easier.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-16 12:10:31 +02:00
Maksim Masalski
a3621cecd5 tests: copyright message add year to the existing
Instead of replacing of copyright year with the new one,
necessary to add new to the existing one

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-15 13:26:39 +02:00
Maksim Masalski
2893aa0bc1 tests: mem protection new test inherit resource pool
To improve Zephyr tests, I think that it will necessary to have test,
that verifies a child thread inherits resource pool assignment
of their parent.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-15 13:26:39 +02:00
Maksim Masalski
819197fba0 tests: add new semaphore tests
Add new semaphore tests, to test important features like:
-count limit
-semaphore define at compile time
-mutual exclusion

I decided to add new test cases that can improve Zephyr
semaphore testing infrastructure.
For each new test added informative Doxygen description.

New test cases test next important requirements:
1. test_k_sem_correct_count_limit()
That test verifies that semaphore can be taken correctly by a thread,
and taking of semaphore decrements its count as expected.
2. test_k_sem_define()
Explicit ans standalone test to test semaphore can be defined
compile time.
3. test_sem_queue_mutual_exclusion
Test that our system can provide a traditional counting
semaphore abstraction for mutual exclusion.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-15 13:07:46 +02:00
Ying ming
6e0c4c79bc tests: memory allocation: add test case
When a block which is released by function free,
the region would be release to heap memory pool.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-07-14 19:36:56 -04:00
Maureen Helm
5c603d9edf tests: gen_isr_table: Disable gpio on lpcxpresso54114
One of the interrupts used by the gen_isr_table test conflicts with a
gpio interrupt on the lpc54114 soc, so disable gpio for this test on the
corresponding board. We do this for only the m4 core because the test is
not supported on the m0 core.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2020-07-11 08:49:50 -04:00
Enjia Mai
5e9ae9ec76 tests: add test cases for improving testing of mutex
1. Test the priority inheritance mechanism.
2. Test the recursive mutex.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-07-08 23:25:59 -04:00
Maksim Masalski
2053814d7c tests: make code style changes according with review comments
Made light code style changes.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-08 21:59:22 -04:00
Maksim Masalski
6eabee2681 tests: rebase with 2.3 release changes
Rebase using the latest master changes for 2.3 release

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-08 21:59:22 -04:00
Maksim Masalski
416feaab0c tests: resolve shippable errors
During previous commit Shippable let me know about errors
for some boards, resolved them.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-08 21:59:22 -04:00
Maksim Masalski
7808a78417 tests: workqueue tests overhaul adding new tests
During inspection of the workqueue tests, I find out testing gaps.
Decided to add new test cases that can improve Zephyr OS testing
quality.
Added new test cases:
1. test_work_item_supplied_with_func
In docs described that work item supplied with a handler function,
prove that it works.
2. test_process_work_items_fifo
Test that system process work items in first-in, first-out manner.
3. test_sched_delayed_work_item
Verify that delayed work item processed after specific period of time
stated by user.
4. test_workqueue_max_number
Test the limit of number of workqueues created
5. test_cancel_processed_work_item Created test to increase branch
coverage.

Modified existing test cases:
1. test_work_submit_handler updated Doxygen tag, added more detailed
description"

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-08 21:59:22 -04:00
Flavio Ceolin
c4f7faea10 random: Include header where it is used
Unit tests were failing to build because random header was included by
kernel_includes.h. The problem is that rand32.h includes a generated
file that is either not generated or not included when building unit
tests. Also, it is better to limit the scope of this file to where it is
used.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2020-07-08 21:05:36 -04:00
Andrzej Głąbek
8da1736c67 tests/kernel/gen_isr_table: Add special config for nRF5340 and nRF9160
In nRF9160 and application core in nRF5340, not all interrupts with
highest numbers are implemented. Thus, limit the number of interrupts
reported to the test, so that it does not try to use some unavailable
ones.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2020-07-08 12:37:58 +02:00
Andy Ross
fdba8be777 tests/kernel/smp: Fixup IPI test
This test was written to assume that the only IPI handled would be the
one generated by the test, but the scheduler also generates an IPI any
time a thread becomes runnable, and there's no way to lock that out in
an SMP system where the other CPU is going to be doing its own thing
(we can't use "1cpu" because that locks interrupts on the other CPU
and obviously this is a test of an interrupt).

Change the logic to detect that "at least one IPI was received", which
is fine for coverage.  Really a better place for a test like this
would have been tests/kernel/mp, which is a test of the lower level
APIs and runs the other CPU deterministically (i.e. not under the
control of the Zephyr scheduler).

Also some misc fixes:

* Don't busy wait at the start, that's needless.

* Sleep instead of busywaiting after sending the IPI, spinning isn't
  needed here and acts to increase CI load needlessly.

* Declare the cross thread signal variable volatile for correctness
  (though this error seems to have been benign in practice).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-07-07 12:59:33 -04:00
Sandeep Tripathy
36d1bddb41 tests: interrupt: include bcm platform
GICv3 is now support for SGI generation and test case is updated
to use GICv3 apis. bcm958402m2_a72 can be enabled now.

Signed-off-by: Sandeep Tripathy <sandeep.tripathy@broadcom.com>
2020-07-03 12:19:31 -04:00
Enjia Mai
7ac40aabc0 tests: adding test cases for arch-dependent SMP function
Add one another test case for testing both arch_curr_cpu() and
arch_sched_ipi() architecture layer interface.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-07-02 08:42:53 -04:00
Maksim Masalski
223723e8a9 tests: mem protect syscalls update Doxygen tags, fix API, misprints
1. Doxygen tags updates of the existing tests.
2. Fixed use of API K_MSEC in test_syscall_torture
3. Removed misprints

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-07-02 08:26:12 -04:00
Sandeep Tripathy
f54c57effe tests: kernel: interrupt: fix gic sgi priority
GICC_BPR has minimum legal values in secure and non-secure states.
'3' is the minimum BPR value leading to group and sub-group priority
as 'gggg.ssss'. In order to make an IRQ preemptible they need to
be in different priority group.

Hence to be generic priority values should be above '0x0f'.

IRQ0 - default priority  (low prio)
IRQ1 - 0x0   (highest prio)

Signed-off-by: Sandeep Tripathy <sandeep.tripathy@broadcom.com>
2020-07-01 08:02:57 -04:00
Sandeep Tripathy
ca6f04f554 tests: kernel: interrupt: Add gicv3 support
Generate SGI to self using own MPIDR.

Signed-off-by: Sandeep Tripathy <sandeep.tripathy@broadcom.com>
2020-07-01 08:02:57 -04:00
Andy Ross
472b67e124 tests/kernel/smp: Don't wait so long at startup
Sleeping for a full second at startup is needless.  The currently
enabled subsystems on platforms that run this test don't even have any
other threads running at startup, so we're guaranteed the other core
is in idle before we even reach main().  Just a few ms is plenty.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-06-27 08:14:58 -04:00
Nicolas Pitre
ae597c07b6 printk: print %p properly on 32-bit targets
The width for %p on 32-bit targets should be 8 regardless of
CONFIG_PRINTK64. Adjust the test accordingly.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2020-06-27 00:03:58 -04:00
Enjia Mai
d678d7a65f tests: adding test cases for device abstraction
Add three test cases of device abstraction for improving test coverage.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-06-25 17:02:27 -04:00
Ioannis Glaropoulos
422ba1f11b tests: kernel: timer_api: add timer label for this test
Add timer label for this test suite, so it is included
in sanity check runs with -t timer.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-06-24 18:04:17 -07:00
Ioannis Glaropoulos
6209610820 tests: kernel: timer_api: enabling test-suite for Qemu Cortex-M0
After the Qemu Cortex-M0 timer driver rework, we may
enable the test-suite that had been (always) excluded
from running on this platform.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-06-24 18:04:17 -07:00
Ioannis Glaropoulos
cfda90d32f tests: kernel: tickless: re-enabled test-suite for Qemu Cortex-M0
After the Qemu Cortex-M0 timer driver rework, we may
re-enable the test-suite that had been excluded for this
platform.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-06-24 18:04:17 -07:00
Ioannis Glaropoulos
6a3d460916 tests: kernel: common: re-enabled test-cases for Qemu Cortex-M0
After the Qemu Cortex-M0 timer driver rework, we may
re-enable the test-cases that had been skipped for this
platform.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-06-24 18:04:17 -07:00
Andy Ross
973487fdad lib/os: Rework/shrink printk conversions, add 64 bit support
Add support for 64 bit conversions in a uniformly expressable way by
printing values backwards into a buffer on the stack first.  This
allows all operations to work on the low bits of the value and so the
code doesn't need to care (beyond the size of that buffer) about the
word size.  This trick also doesn't care about the specifics of the
base value, so in the process this unifies the decimal and hex printk
conversion code to a single function.

This comes at a mild cost in CPU cycles to the decimal converter and
somewhat higher cost to hex (because it's now doing a full div/mod
operation instead of shifting and masking).  And stack usage has grown
by a few words to hold the temporary.  But the benefits in code size
are substantial (e.g. ~250 bytes of .text on arm32).

Note that this also contains a change to tests/kernel/common to
address what appears to have been a bug in the original converters.
The printk test uses a format string that looks like "%-4x%-2p" and
feeds it the literal arguments "0xABCDEF" and "(char *)42".
Now... clearly both those results are going to overflow the 4 and
2-byte field sizes, so there shouldn't be any whitespace between these
fields.  But the test was written to expect two spaces, inexplicably
(yes, I checked: POSIX-compatible printf implementations don't have
those spaces either).

The new code is definitely doing the right thing, so fix the test
instead.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-06-24 13:43:40 -07:00
Ningx Zhao
d7d2cd5086 tests: queue modifying and adding test case
1.Add a new testcase to verify multiple queues can be defined
2.Add some code comments to describe function performance.

Signed-off-by: Ningx Zhao <ningx.zhao@intel.com>
2020-06-24 20:59:52 +02:00
Enjia Mai
ce31b89e50 tests: adding test cases of spinlock
Add test case for testing achieve mutual exclusion using interrupt
masking, and initialize at runtime.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-06-23 16:14:55 -04:00
Maksim Masalski
f221dfec2f tests: added new doxygen tags for memory protection tests
Added new doxygen tags for tests:
1. test_mem_domain_destroy
2. test_domain_add_part_drop_to_user

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-06-23 12:18:30 -04:00
Maksim Masalski
f25406af99 tests: add new Doxygen tags to threads tests
Reason is that some threads tests have poor description Doxygen
tags. I decided to fix that situation in some tests which understand.

Update Doxygen tags for the next tests:
test_create_new_supervisor_thread_from_user()
test_user_mode_enter()
test_create_new_higher_prio_thread_from_user()
test_create_new_thread_from_user_huge_stacksize()

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-06-23 11:55:26 -04:00
Peter Bigot
219a3ca96d device: provide internal access to static device array
Device objects in Zephyr are currently placed into an array by linker
scripts, making it easy to iterate over all devices if the array
address and size can be obtained.  This has applications in device
power management, but the existing API for this was available only
when that feature was enabled.  It also uses a signed type to hold the
device count.

Provide a new API that is generally available, but marked as internal
since normally applications should not iterate over all devices.  Mark
the PM API approach deprecated.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-23 13:27:14 +02:00
Stephanos Ioannidis
27d42f060d tests: kernel: lifo_usage: Exclude on qemu_arc_em
This test has a very high failure rate on `qemu_arc_em` and needs to be
disabled until a fix is available.

To be addressed in #26163.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-06-21 09:47:24 -04:00
Anas Nashif
6f4f5b1fe5 tests: exclude qemu_arc_hs in lifo_usage test
Fails very frequently in CI, disabling until a fix is available, see

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-06-12 23:22:57 -04:00
Jian Kang
445576c8a2 tests: kernel: Add a new test for providing time duration in milliseconds
Add a new test case to verify whether kernel allow proving time duration
in milliseconds.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
2020-06-11 07:13:23 -04:00
Ying ming
1b1d728a18 tests: atomic operation: add new test cases
add new test cases to illustrate the zephyr OS
support an array of atomic variables, each bit
of which can be modified.

Signed-off-by: Ying ming <mingx.ying@intel.com>
2020-06-10 10:46:28 -04:00
Krzysztof Chruscinski
1b4b9386e5 sys: util: Added separator to FOR_EACH_ macros
Added separator (e.g. comma or semicolon) parameter to FOR_EACH_ family.
Separator is added between macro execution for each argument and not at
the end.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-06-10 11:58:13 +02:00
Anas Nashif
603c24dec9 tests: common: skip bootdelay test on qemu_cortex_m0
Test fails on this one platform, to unblock other changes, skip the test
while the issues is being looked at. This test never ran on this
platform before due to ram restrictions.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-06-09 23:36:16 -04:00
Anas Nashif
ac7756d4b1 tests: kernel: common: rename test boot_delay
rename boot_delay function name for clarity and change doxygen group to
be more generic and part of the init group.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-06-09 23:36:16 -04:00
Anas Nashif
c815b062c6 tests: kernel: remove ram restrictions
Remove all ram restrictions in kernel tests and revisit all tests and
try to make them pass on all platforms.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-06-09 23:36:16 -04:00
Maksim Masalski
82855aa4e0 tests: update doxygen tags for syscalls tests
Reason is that some tests have poor description in Doxygen tags,
decided to fix that situation in some tests which I understand.
Also remove small misprints from some parts of code.

Update Doxygen tags for the next tests:
test_access_kobject_without_init_access
test_thread_without_kobject_permission
test_bad_syscall
test_syscall_invalid_kobject

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-06-09 17:46:23 -04:00
Peter Bigot
31d615eab5 tests: kernel: timer_api: remove extra adjustment to expected result
The converted target value for remaining ticks was increased by one to
match original code, which used a one-sided test.  The current test is
two-sided, so that increment is already present in the allowed 1 tick
error for boards with no slew, and incorporating it into the absolute
error can cause the test to fail.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-09 18:57:31 +02:00
Peter Bigot
9c2c12d10f tests: tickless: fix build error on qemu_cortex_m3
Code compiled only for this platform had an unconverted legacy
sleep delay.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-09 08:14:53 -04:00
YouhuaX Zhu
79481837fe Tests: Adjust code and annotations for poll test cases.
1. Shorten the long function body for test_poll_wait() to
increase readability, split it into below two method:
    test_poll_wait(),
    check_results().

2. Adjust annotations for below poll test cases:
    test_poll_wait(),
    test_poll_cancel(),
    test_poll_threadstate().

Signed-off-by: YouhuaX Zhu <youhuax.zhu@intel.com>
2020-06-09 08:14:01 -04:00
Zhu YouhuaX
1f416d8d0d Tests: Add and modify testcases for pipe.
1. Add a new testcase for defining and initializing pipes at run time.
2. Add details comments for some testcases.

Signed-off-by: Zhu YouhuaX <youhuax.zhu@intel.com>
2020-06-09 08:13:46 -04:00
Alexey Brodkin
b98058ecd0 tests: Exclude qemu_arc{em|hs} in some
See https://app.shippable.com/github/zephyrproject-rtos/zephyr/runs/73233/4/tests

And so until "icount" is implemented in QEMU for ARC we exclude
"tickless_concept" & "timer_api" from sanitycheck tests.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
2020-06-08 16:58:37 -04:00
Kumar Gala
d00d0f1266 samples/tests: Convert use of %ll{u,d} to PRI{u,d}64
Move to using PRIu64/PRId64 instead of %llu/%lld since on
native_posix_64 the uint64_t/int64_t type is defined in terms of 'long
int' and not 'long long int'.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Kumar Gala
a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00
Peter Bigot
06afe554c9 tests: kernel: timer_api: compensate inaccurate conversion
When millisecond/tick conversion is not exact tick delta's are
dependent on the initial tick value.  In those cases exact comparisons
need to also allow an adjacent value.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-05 17:14:48 +02:00
Peter Bigot
b22cef027f tests: kernel: timer_api: compensate for fast clocks
When HFCLK has a slew making it faster than LFCLK the busy wait can
expire before the timer fires.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-05 17:14:48 +02:00
Peter Bigot
365fd524cd tests: kernel: timer_api: use slew for duration timer test
Reduce the duration of the timer test so that it will fire before the
busywait elapses even in the worst case of slew between the tick and
busy-wait clocks.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-05 17:14:48 +02:00
Peter Bigot
ac94ffedce tests: kernel: timer_api: use slew for remaining timer threshold
This test sets a timer using one clock, waits using a second clock,
then sees whether the remaining time is the expected value.  When the
two clocks are skewed the comparison requires a threshold.  Provide a
means to estimate the maximum expected error.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-05 17:14:48 +02:00
Andrew Boie
378024c510 userspace: add z_is_in_user_syscall()
Certain types of system call validation may need to be pushed
deeper in the implementation and not performed in the verification
function. If such checks are only pertinent when the caller was
from user mode, we need an API to detect this situation.

This is implemented by having thread->syscall_frame be non-NULL
only while a user system call is in progress. The template for the
system call marshalling functions is changed to clear this value
on exit.

A test is added to prove that this works.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Peter Bigot
4438b103c2 tests: kernel: mem_protect: futex: convert to new timeout API
Remove use of the legacy timeout API.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-03 17:47:58 +02:00
Peter Bigot
76d8f8f1e2 include: sys: time_units: fix 32-bit near conversion for overflow
Adjusting the input value to allow round to nearest can cause an
overflow which invalidates the expectation that the 32-bit result is
the low 32 bits of the 64-bit result.  If the adjustment overflows do
the full-precision conversion and truncate in the caller.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-06-03 01:49:42 +02:00
Andy Ross
7ff3f8ac1c tests/kernel/queue: Add regression test for CONFIG_POLL race condition
When CONFIG_POLL was set, it was historically true that the queue
could (if a higher priority thread "stole" an insert) return a
spurious NULL instead of continuing to wait on a timeout.

This deliberately exercises that race.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-06-03 01:47:41 +02:00
Andy Ross
99c2d2d047 kernel/queue: Remove interior use of k_poll()
The k_queue data structure, when CONFIG_POLL was enabled, would
inexplicably use k_poll() as its blocking mechanism instead of the
original wait_q/pend() code.  This was actually racy, see commit
b173e4353f.  The code was structured as a condition variable: using
a spinlock around the queue data before deciding to block.  But unlike
pend_current_thread(), k_poll() cannot atomically release a lock.

A workaround had been in place for this, and then accidentally
reverted (both by me!) because the code looked "wrong".

This is just fragile, there's no reason to have two implementations of
k_queue_get().  Remove.

Note that this also removes a test case in the work_queue test where
(when CONFIG_POLL was enabled, but not otherwise) it was checking for
the ability to immediately cancel a delayed work item that was
submitted with a timeout of K_NO_WAIT (i.e. "queue it immediately").
This DOES NOT work with the origina/non-poll queue backend, and has
never been a documented behavior of k_delayed_work_submit_to_queue()
under any circumstances.  I don't know why we were testing this.

Fixes #25904

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-06-03 01:47:41 +02:00
Marc Herbert
debade9121 tests: make find_package(Zephyr...) REQUIRED
... because it is (required).

This makes a difference when building with CMake and forgetting
ZEPHYR_BASE or not registering Zephyr in the CMake package registry.

In this particular case, REQUIRED turns this harmless looking log
statement:

-- Could NOT find Zephyr (missing: Zephyr_DIR)
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- ...
-- ...
-- ...
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:8 (target_sources):
  Cannot specify sources for target "app" which is not built by
  this project.

... into this louder, clearer, faster and (last but not least) final
error:

CMake Error at CMakeLists.txt:5 (find_package):
  Could not find a package configuration file provided by "Zephyr" with
  any of the following names:

    ZephyrConfig.cmake
    zephyr-config.cmake

  Add the installation prefix of "Zephyr" to CMAKE_PREFIX_PATH or set
  "Zephyr_DIR" to a directory containing one of the above files.  If
  "Zephyr" provides a separate development package or SDK, be sure it
  has been installed.

-- Configuring incomplete, errors occurred!

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2020-05-29 10:47:25 +02:00
Ioannis Glaropoulos
79ff37b9cc tests: kernel: stackprot: increase Main stack size for this test
Increase the main thread stack size for this test
to 2048; this increase prevents stacking errors in
the main thread, in several Cortex-M platforms.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-05-28 10:31:05 +02:00
Andrew Boie
4cdaa71444 tests: userspace: check TLS location
Ensure that the TLS region is within the stack object.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-27 19:48:27 +02:00
Alexandre Bourdiol
3152a0d567 tests: kernel: mem_protect: syscalls: configurable faulty address
On nucleo_f429zi and nucleo_f207zg boards,
0xFFFFFFF0 is not a faulty address.
Instead we can use 0x0FFFFFFFF.

Signed-off-by: Alexandre Bourdiol <alexandre.bourdiol@st.com>
2020-05-27 19:29:03 +02:00
Wayne Ren
52992b0658 tests: skip the cpu_idle test for nsim_hs_smp
Because the sleep instruction issue for nsim_hs_smp, idle
loop is used to simulate behavior of sleep, so arch_cpu_idle will
forever loop. This causes cpu idle test loop, then the whole
context test timeouts.

as a fix, skip the cpu_idle test for nsim_hs_smp now.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2020-05-26 17:47:42 +02:00
Peter Bigot
8fbc83c651 tests: timer_api: avoid compounding errors in imprecise conversions
When the timer frequency is not a multiple of 1000 converting between
ticks and milliseconds introduces error.  Avoid propagating the error
by converting divided values rather than dividing converted values.

Also compensate for observed rate differences between the busywait
clock and the timeout clock.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-24 20:28:58 +02:00
Peter Bigot
a44bc7026e tests: timer_api: compensate for fast clocks
A fast timer clock can advance before or after the remaining time
until an event is captured.  Verify the expected relationship between
current and remaining time holds for at least one captured current
time.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-24 20:28:58 +02:00
Peter Bigot
46e402dd6e tests: timer_api: fix for inexact ms/tick conversions
When one millisecond is not an integral number of ticks measuring
durations between tick events will sometimes be less than expected to
correct for error that was accumulated between other events.  Allow
for that in the duration and period comparisons.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-24 20:28:58 +02:00
Peter Bigot
726bff2353 tests: kernel: device: bypass device pm tests
The dummy driver never implemented device power management, so the
fact the not-implemented stub returned success was a false negative.
Verify the expected behavior now, leaving the test code in place for
when somebody provides a non-trivial PM control function.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-05-21 20:32:12 +02:00
Wayne Ren
e0470d0f93 tests: add a workaround for arc emsdp
arc emsdp's console will use irq 108/107 which will
conflict with irqs used in tests (emsdp has 112 irqs),
so add a workaround for emsdp.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2020-05-21 10:59:36 +02:00
Andy Ross
1af8a04fa9 tests/kernel/common: Make test_timeout_order 1cpu
This test works by starting a bunch of poll events, dropping the test
thread priority, calling k_poll(), and assuming that all the timeouts
that fired woke up high priority threads and thus ran before k_poll()
could return.  But that isn't true if you have another CPU that can
run the low priority thread while the last high priority thread
finishes up!

This just isn't SMP-correct.  Mark 1cpu.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-05-19 19:19:51 +02:00
Carles Cufi
c80a75d7d1 Revert "test: kernel: context: Exclude for qemu_cortex_r5 (temporary)"
This reverts commit f87bce135a.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-05-19 17:14:18 +02:00
Vincent Wan
0b12a7b463 tests: timer_api: fix assertion in test_timer_remaining()
This commit fixes the assertion in test_timer_remaining() that checks
whether the remaining ticks on a timer is less than or equal to half of
the timer duration after a busy wait of that time. If the timer
duration corresponds to an odd number of ticks, 1 should be added to
the upper bound given k_timer_remaining_ticks() returns
<ticks til next deadline> - <elapsed ticks>,
and <elapsed ticks> is truncated to closest integer tick count.

For example, if
    dur_ticks = 3277
    <ticks til next deadline> = 3277
    <elapsed ticks> = 1638.5 rounded to 1638

rem_ticks would be 1639, which is 1 greater than dur_ticks/2.

Fixes #25331

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-05-18 11:08:21 +02:00
Wentong Wu
9189acba03 tests: kernel: reduce test interval to save execution time
In Qemu icount mode, busy wait will cause lots of wall time and it's
very easy to get sanitycheck timeout(this case will be successful if
given enough timeout value for sanitycheck), so reduce test interval
to save execution time.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-05-14 13:52:07 +02:00
Wentong Wu
72227574d8 timer: remove QEMU_TICKLESS_WORKAROUND
Qemu icount mode enabled, remove QEMU_TICKLESS_WORKAROUND.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2020-05-14 13:52:07 +02:00
Andrew Boie
3f00daea1e tests: userspace: check for TLS leakage
TLS data set when a thread is in supervisor mode should not
leak if it drops later to user mode.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-13 22:02:48 +02:00
Anas Nashif
ad82b38b8f tests: ztest: prefix tests with test_
Tests should always start with test_, otherwise detection of subtests
will not work through sanitycheck.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-05-13 18:16:07 +02:00
Stephanos Ioannidis
2c3d0b83e3 tests: kernel: context: Fix test_busy_wait timeout
The commit b7e363661d added an additional
busy wait call in the `busy_wait_thread` function -- effectively making
the minimum time required for the thread to exit twice that of the
original implementation.

This commit updates the busy wait thread completion timeout to reflect
that change.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-05-11 21:34:35 +02:00
Meng xianglin
0b1ef3f6bc test: msgq: remove number of cpu restriction
Remove CONFIG_MP_NUM_CPU=1 from test cases of msgq.
For CONFIG_MP_NUM_CPU > 1, start a thread with K_NO_WAIT to get
message from message queue will run immediately on another cpu and
cause message peek failure if there is no message in queue, so put
messages in msgq before start that thread.

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2020-05-09 19:06:53 +02:00
Andrew Boie
b7e363661d tests: context: busy-wait with interrupts locked
This is expected to work on all platforms.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-08 17:44:17 +02:00
Stephanos Ioannidis
004039d08c tests: Rename kernel.fp_sharing
This commit renames the `kernel.fp_sharing` tests to
`kernel.fpu_sharing`, in order to align with the recent
`CONFIG_FP_SHARING` to `CONFIG_FPU_SHARING` renaming.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-05-08 10:58:33 +02:00
Stephanos Ioannidis
728ce61968 tests: Rename kernel.common.stack_protection_arm_fp_sharing
This commit renames the `kernel.common.stack_protection_arm_fp_sharing`
test to `kernel.common.stack_protection_arm_fpu_sharing`, in order to
align with the recent `CONFIG_FP_SHARING` to `CONFIG_FPU_SHARING`
renaming.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-05-08 10:58:33 +02:00
Stephanos Ioannidis
0b930a2195 kconfig: Rename x86 FPU sharing symbols
This commit renames the x86 Kconfig `CONFIG_{EAGER,LAZY}_FP_SHARING`
symbol to `CONFIG_{EAGER,LAZY}_FPU_SHARING`, in order to align with the
recent `CONFIG_FP_SHARING` to `CONFIG_FPU_SHARING` renaming.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-05-08 10:58:33 +02:00
Stephanos Ioannidis
aaf93205bb kconfig: Rename CONFIG_FP_SHARING to CONFIG_FPU_SHARING
This commit renames the Kconfig `FP_SHARING` symbol to `FPU_SHARING`,
since this symbol specifically refers to the hardware FPU sharing
support by means of FPU context preservation, and the "FP" prefix is
not fully descriptive of that; leaving room for ambiguity.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-05-08 10:58:33 +02:00
Abhishek Shah
012472f7d5 boards: arm: Add bcm958402m2_a72 board
Add support for bcm958402m2_a72 board for booting zephyr
on Cortex-A72 core.

Signed-off-by: Abhishek Shah <abhishek.shah@broadcom.com>
2020-05-08 10:46:23 +02:00
Andrew Boie
ac9abb10b8 tests: mem_protect: cleanup
This suite was fairly messy and very unstable on how it re-used
kernel objects.

* Unnecessary ztest_test_pass() or self-aborts removed
* k_thread_join() now used to wait for child thread completion,
  instead of a strange use of a semaphore which was effectively
  a 10ms sleep
* Barriers simplified
* the number of thread objects in kobject.c is now drastically reduced
* test case function names are now descriptive and made static if
  only used in local scope in kobject.c
* SMP no longer disabled

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-07 19:21:16 -04:00
Christopher Friedt
967f7a8bcb tests: kernel: pipe: tests for read_avail write_avail
Tests for issue #25036

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-05-07 19:39:53 +02:00
Andrew Boie
f1b5d9db8e kernel: fix issue with k_thread_join() timeouts
If k_thread_join() was passed with an actual timeout value,
and not K_FOREVER, the blocking thread was not being properly
woken up when the target thread exits. The timeout itself
was never aborted, causing the joining thread to remain
un-scheduled until the timeout expires.

Amend the k_thread_join() test cases to check that the join
completed before the provided timeout period expired.

Fixes: #24744

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-05 11:43:08 -07:00
Kumar Gala
f31a73bb23 tests: kernel: context: Convert to new dts macros
Set the TICK_IRQ on litex and rv32m1 based on DT_IRQN().  For litex we
use DT_NODELABEL(timer0) and on rv32m1 we use DT_ALIAS(system_lptmr) to
determine the timer device.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-30 17:39:27 -04:00
Kumar Gala
b810b4d452 Revert "tests: no need long busy_wait to waste cycles"
This reverts commit 315cba1c40 as it was
causing CI failures for qemu_cortex_m0.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-28 20:34:57 -04:00
Wayne Ren
315cba1c40 tests: no need long busy_wait to waste cycles
* no need long busy_wait to waste cycles, especially in
 CI.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2020-04-28 10:48:01 -07:00
Christopher Friedt
d650f4b494 kernel: pipe: fix !K_NO_WAIT and >= min_xfer bytes transferred
If timeout != K_NO_WAIT, then return immediately when not all
bytes_to_read or bytes_to_write have been transfered, but >=
min_xfer have been transferred.

Fixes #24485

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-04-28 16:14:55 +02:00
Stephanos Ioannidis
0e6ede8929 kconfig: Rename CONFIG_FLOAT to CONFIG_FPU
This commit renames the Kconfig `FLOAT` symbol to `FPU`, since this
symbol only indicates that the hardware Floating Point Unit (FPU) is
used and does not imply and/or indicate the general availability of
toolchain-level floating point support (i.e. this symbol is not
selected when building for an FPU-less platform that supports floating
point operations through the toolchain-provided software floating point
library).

Moreover, given that the symbol that indicates the availability of FPU
is named `CPU_HAS_FPU`, it only makes sense to use "FPU" in the name of
the symbol that enables the FPU.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-04-27 19:03:44 +02:00
Corey Wharton
d873573f76 tests: fp_sharing: Enable build-only tests for RISC-V QEMU platform
Enables build-only tests for the qemu_riscv32 platform.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-04-22 16:39:48 -07:00
Corey Wharton
c8f7cd5462 kconfig: Make the CPU_HAS_FPU_DOUBLE_PRECISION option global.
This option now applies to the RISC-V architecture and is no longer
a ARM only configuration.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-04-22 16:39:48 -07:00
Corey Wharton
a4a334d3f7 tests: fp_sharing: Enable tests for RISC-V architectures
Enable generic and float_disable tests for RISC-V targets that have
CONFIG_CPU_HAS_FPU enabled.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-04-22 16:39:48 -07:00
Corey Wharton
58232d58e0 riscv: Add support for floating point
This change adds full shared floating point support for the RISCV
architecture with minimal impact on threads with floating point
support not enabled.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-04-22 16:39:48 -07:00
Andy Ross
00e2cce1fc tests/kernel/timer/timer_api: Fix static double-conversion goof
The test of the absolute timeout feature was a simple whitebox test
that inspected the generated ticks field of different constructors for
identity.  But it wasn't simple enough, because it was doing a
ticks->ms->ticks conversion (at compile time, sigh) on the input data,
which is obviously lossy on platforms where ticks are shorter than
milliseconds by non-integral factors.

Fix to do the conversion in just one direction.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-22 17:35:10 +02:00
Andy Ross
cc0db43426 tests/kernel/timer/timer_api: Correct tick math for odd freq timers
This test sets a timer, busy waits for half the duration, and then
checks the remaining time is correct.  And it correctly does all its
math in tick precision and aligns to a timer interrupt to eliminate
aliasing due to the tick stride.

But it's waiting using k_busy_wait(), not a timer: "half the duration"
in MICROSECONDS (for k_busy_wait()) is not necessarily representable
as an integer number of TICKS on all platforms.  Because k_busy_wait()
always rounds up, we need one extra tick of buffer on those platforms.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-22 17:35:10 +02:00
Andy Ross
987658dcee tests/kernel: Fill allocation robustly for mpool heap backend
These five tests (mbox_api, mheap_api_concept, msgq_api, pipe_api and
queue) all had test cases where they needed a mem_pool allocation to
FAIL.  And they are all written to assume the behavior of the original
allocator and not the more general k_heap code, which actually
succeeds in a bunch of these cases.

* Even a very small heap saves enough metadata memory for the very
  small minimum block size, and this can be re-used as an allocation.
  So you can't assume a small heap is full.

* Calculating the number of blocks based on "num_blocks * max size /
  minimum size" and allocating them does not fill the heap, because
  the conservative metadata reservation leaves some space left over.

So these have all been modified to "fill" a heap by iteratively
allocating until failure.

Also, this fixes a benign overrun bug in mbox.  The test code would
insert a "big" message by reading past the end of the small message
buffer.  This didn't fail because it happened to be part of an array
of messages and the other ones defined contained the memory read.  But
still.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-14 10:05:55 -07:00
Andy Ross
91cf6651d8 tests/kernel/mem_pool: Split out tests for legacy mem_pool config
The k_heap backend is now the default for mem_pool, so duplicate these
tests across that config so we continue to have coverage for the older
code.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-14 10:05:55 -07:00
Andy Ross
e582bc128a tests/kernel/mem_pool: Adjust tests to work with k_heap backend
The original k_mem_pool tests were a mix of code that tests routine
allocator behavior, the synchronization layer above that, and a
significant amount of code that made low-level assumptions about the
specific memory layout of the original allocator, which doesn't run
out of memory in exactly the same way.

Adjust the expectations as needed for the backend.  A few test cases
were skipped if they were too specific.  Most have been generalized
(for example, iteratively allocating to use up all memory instead of
assuming that it will be empty after N allocations).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-14 10:05:55 -07:00
Anas Nashif
9be6847cc6 tests: critical: change doxygen group
Rename doxygen group to kernel_workqueue_tests

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Anas Nashif
a3ddaf8dbc tests: move critical test under workqueue
This is a workqueue test, so move it where it belongs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Anas Nashif
1825c6f562 tests: put all workqueue test in 1 group
Pun all workqueue tests under 1 doxygen group.

This removes kernel_workqueue_triggered_tests and
kernel_workqueue_delayed_tests doxygen groups.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Anas Nashif
6c8dda4e68 tests: critical: rework test
Cleanup test layout and documentation.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Anas Nashif
b90fafd6a0 kernel: remove unused offload workqueue option
Those are used only in tests, so remove them from kernel Kconfig and set
them in the tests that use them directly.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Stephanos Ioannidis
b73622dff0 tests: kernel: fp_sharing: Use ztest
This commit converts the `fp_sharing` tests to use the ztest framework.

In addition, this commit also introduces a behavioural change to run
the `pi` unit test separately from the `load_store` unit test, in order
to allow more manageable and diagnosable test execution.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-04-10 11:43:05 +02:00
Stephanos Ioannidis
74e43a3103 tests: kernel: fp_sharing: Reorganise tests
The `fp_sharing` testsuite consists of two tests: `load_store` and
`pi`.

This commit reorganises the two tests into separate files and refactors
the common parameters into the `test_common.h` header file.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-04-10 11:43:05 +02:00
Carles Cufi
205cf1595e boards: nrf52810_pca10040: Rename to nrf52dk_nrf52810
The board target for emulation of nRF52810 on nRF5DK, so far
known as nrf52810_pca10040, is renamed to nrf52dk_nrf52810.
Its documentation and all references to its name in the tree are
updated accordingly. Overlay and configuration files specific to
this board are also renamed, to match the new board name.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-04-06 13:09:07 +02:00
Stephanos Ioannidis
3a405409c5 tests: kernel: interrupt: Enable nested interrupt test for Cortex-R
This commit enables nested interrupt test for the Cortex-R platforms
that use the ARM Generic Interrupt Controller (GIC).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-04-02 09:22:38 +02:00
Kumar Gala
a5375ead0c tests: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-31 19:31:20 -05:00
Andy Ross
4c7b77a716 kernel/timeout: Add absolute timeout APIs
Add support for "absolute" timeouts, which are expressed relative to
system uptime instead of deltas from current time.  These allow for
more race-resistant code to be written by allowing application code to
do a single timeout computation, once, and then reuse the timeout
value even if the thread wakes up and needs to suspend again later.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Andy Ross
cfeb07eded kernel/timeout: Enable 64 bit timeout precision
Add a CONFIG_TIMEOUT_64BIT kconfig that, when selected, makes the
k_ticks_t used in timeout computations pervasively 64 bit.  This will
allow much longer timeouts and much faster (i.e. more precise) tick
rates.  It also enables the use of absolute (not delta) timeouts in an
upcoming commit.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Andy Ross
7832738ae9 kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument.  Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created.  This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.

The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.

The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.

Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.

For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided.  When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.

Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions.  These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig.  These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.

k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.

Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate.  Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure.  But k_poll() does not fail
spuriously, so the loop was removed.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Andy Ross
32bb2395c2 timeout: Fix up API usage
Kernel timeouts have always been a 32 bit integer despite the
existence of generation macros, and existing code has been
inconsistent about using them.  Upcoming commits are going to make the
timeout arguments opaque, so fix things up to be rigorously correct.
Changes include:

+ Adding a K_TIMEOUT_EQ() macro for code that needs to compare timeout
  values for equality (e.g. with K_FOREVER or K_NO_WAIT).

+ Adding a k_msleep() synonym for k_sleep() which can continue to take
  integral arguments as k_sleep() moves away to timeout arguments.

+ Pervasively using the K_MSEC(), K_SECONDS(), et. al. macros to
  generate timeout arguments.

+ Removing the usage of K_NO_WAIT as the final argument to
  K_THREAD_DEFINE().  This is just a count of milliseconds and we need
  to use a zero.

This patch include no logic changes and should not affect generated
code at all.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Stephanos Ioannidis
1828ea467a tests: kernel: interrupt: Enable nested interrupt test for Cortex-A
This commit enables nested interrupt test for the Cortex-A platforms
that use the ARM Generic Interrupt Controller (GIC).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 19:24:48 +02:00
Stephanos Ioannidis
9b81938c16 tests: kernel: interrupt: Add nested interrupt test for ARM GIC
This commit adds the nested interrupt testing support for the ARM
Generic Interrupt Controller (GIC).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 19:24:48 +02:00
Stephanos Ioannidis
1b8c8e25ff tests: kernel: interrupt: Clean up prevent_irq test
This commit cleans up the "prevent interruption" test and adds a
documentation comment for it.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 13:53:35 +02:00
Stephanos Ioannidis
6820fdf0fb tests: kernel: interrupt: Clean up dynamic_isr test
This commit cleans up the dynamic ISR test and adds a documentation
comment for it.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 13:53:35 +02:00
Stephanos Ioannidis
06e3e40c0c tests: kernel: interrupt: Explain Cortex-M nested interrupt priorities
This commit adds an explanation comment for the interrupt priorities
used by the Cortex-M nested interrupt test.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 13:53:35 +02:00
Stephanos Ioannidis
e57da829d7 tests: kernel: interrupt: Do not test interrupt nesting on RISC-V
This commit disables the nested interrupt test for the RISC-V platform,
as interrupt nesting is not supported on the current RISV-C
architecture port.

Furthermore, the current `trigger_irq` implementation for RISC-V is
mostly incorrect and cannot be used, so there is no point in leaving
that in the codebase (see #23593).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-27 13:24:35 -04:00
Stephanos Ioannidis
84921c53b1 tests: kernel: interrupt: Rework nested interrupt test
The current nested interrupt test implementation is both buggy and
fundamentally flawed because it does not trigger a higher priority
interrupt from a lower priority interrupt context and relies on the
system timer interrupt, which is not fully governed by the test;
moreover, the current implementation does not properly validate the
test results and can report success if no interrupt is triggered and
serviced at all.

This commit reworks this test to have the following well-defined
and logical procedure:

1. [thread] Trigger IRQ 0 (lower priority)
2. [isr0] Set ISR 0 result token and trigger IRQ 1 (higher priority)
3. [isr1] Set ISR 1 result token and return
4. [isr0] Validate ISR 1 result token and return
5. [thread] Validate ISR 0 result token

The reworked test scenario ensures that the interrupt nesting works
properly and any abnormal conditions are detected (e.g. interrupts not
triggering at all, or ISR 1 not being nested under ISR 0).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-27 13:24:35 -04:00
Stephanos Ioannidis
66a53dd5cd tests: kernel: interrupt: Reorganise tests
This commit re-organises the kernel interrupt tests for consistency.

In addition, it removes any references to the `irq_offload` feature,
which is no longer used by this test.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-27 13:24:35 -04:00
Torsten Rasmussen
407b49b35c cmake: use find_package to locate Zephyr
Using find_package to locate Zephyr.

Old behavior was to use $ENV{ZEPHYR_BASE} for inclusion of boiler plate
code.

Whenever an automatic run of CMake happend by the build system / IDE
then it was required that ZEPHYR_BASE was defined.
Using ZEPHYR_BASE only to locate the Zephyr package allows CMake to
cache the base variable and thus allowing subsequent invocation even
if ZEPHYR_BASE is not set in the environment.

It also removes the risk of strange build results if a user switchs
between different Zephyr based project folders and forgetting to reset
ZEPHYR_BASE before running ninja / make.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Ioannis Glaropoulos
5bd906463d tests: kernel: context: in README, fix text for k_cpu_idle testing
We update README file to correct the text for k_cpu_idle
testing, since now we cover the test for both tickless
and non-tickless kernel configuration.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-23 12:10:46 -07:00
Ioannis Glaropoulos
b9c89c0e7f tests: kernel: context: minor style and indentation fixes
Fix some minor style and indentation issues
in tests/kernel/context/src/main.c.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-23 12:10:46 -07:00
Ioannis Glaropoulos
703e8444af tests: kernel: context: test k_cpu_idle for tickless kernel
We fix the kernel.context test, so it tests the
implementation of k_cpu_idle for tickless kernel.
As most platforms now support tickless kernel by
default, this extension of the test is essential
to get coverage on k_cpu_idle() API.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-23 12:10:46 -07:00
Peter Bigot
42f9d14a3f kernel: deprecate k_uptime_delta_32
The documentation motivates this function by saying it is more
efficient than the core 64-bit version.  This was untrue when
originally added, and is untrue now.  Mark the function deprecated and
replace its sole in-tree use with the trivial equivalent.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-03-23 10:26:05 -04:00
Stephanos Ioannidis
dd75bccaca dts: bindings: Fix xlnx,ttcps binding compat
The `xlnx,ttcps` binding, despite having the file name of
`xlnx,ttcps.yaml`, had the compatible property of `cdns,ttc`.

While it is true that the Xilinx ZynqMP platform embeds the Cadence
Triple Timer Counter (TTC) IP core, its TTC differs from the original
Cadence core in that it implements 32-bit counters, instead of the
16-bit counters defined in the original; hence, the Xilinx variant is
not compatible with the original Cadence version and should be treated
as a different device.

This commit changes the `xlnx,ttcps.yaml` compatible property to
`xlnx,ttcps` for the above reasons.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-21 14:20:17 -04:00
Stephanos Ioannidis
f87bce135a test: kernel: context: Exclude for qemu_cortex_r5 (temporary)
The `tests/kernel/context` test fails for the `qemu_cortex_r5` when the
icount emulation mode is used, because the Xilinx QEMU ignores the WFI
instruction when the icount parameter is specified.

This will be fixed in the Zephyr SDK 0.11.3 and this commit must be
reverted once the CI is updated to use this new SDK version.

For more details, see zephyrproject-rtos/sdk-ng#191.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-21 14:20:17 -04:00
Andrew Boie
2dc2ecfb60 kernel: rename struct _k_object
Private type, internal to the kernel, not directly associated
with any k_object_* APIs. Is the return value of z_object_find().
Rename to struct z_object.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-17 20:11:27 +02:00
Andrew Boie
a33a4b0785 tests: profiling_api: fix comments
This uses log_stack_usage() now.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-14 13:10:19 -04:00
Anas Nashif
5b58e61bcb doc: tests: stack: fix doxygen grouping
Add stack tests to kernel test doxygen group.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-03-14 13:01:03 -04:00
Anas Nashif
527bb7b7e2 doc: tests: futex: fix doxygen grouping
Add tests to kernel test group.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-03-14 13:01:03 -04:00
Martí Bolívar
ededeb2736 doc: fix some errors
I've been seeing these cause errors on the more recent versions of
Doxygen which come with Arch Linux for a while now. Fix these:

error: Illegal format for option TCL_SUBST, no equal sign ('=') specified for item 'YES'
$ZEPHYR_BASE/tests/kernel/mem_protect/futex/src/main.c:461: warning: end of file with unbalanced grouping commands

Just trying to get them out of my local output and as preparation for
whenever they start showing up for Ubuntu.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-03-13 11:23:34 -04:00
Andrew Boie
dc7ac32a94 tests: thread_apis: add k_thread_join() tests
Exercise various scenarios from thread and ISR context.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-13 08:42:43 -04:00
Wayne Ren
3ae7c87eb0 tests: the arc issuse is fixed
the arc issue is fixed, remove the filter

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2020-03-12 13:02:17 -04:00
Luiz Augusto von Dentz
2b466a54da tests: work_q: Add assert if k_delayed_work_submit fails in the handler
This makes the tests actually assert if k_delayed_work_submit fails to
resubmit to ensure that not only the work is executed but also no errors
are reported in such case.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-03-11 09:16:15 -04:00
Andrew Boie
c4fbc08347 kernel: fixup thread monitor locking
The lock in kernel/thread.c was pulling double-duty, protecting
both the thread monitor linked list and also serializing access
to k_thread_suspend/resume functions.

The monitor list now has its own dedicated lock.

The object tracing test has been updated to use k_thread_foreach().

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 16:09:24 -04:00
Andrew Boie
9f0acd44a4 kernel: add APIs for atomic os on pointers
The existing APIs are insufficient on 64-bit systems as atomic_t
is 32-bits wide.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:18:16 -04:00
Andrew Boie
60e0019751 kernel: fix return type for atomic_cas()
In some cases this was a bool, in some cases an integer value
of 1 or 0. Standardize on bool.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:18:16 -04:00
Andrew Boie
06d19213c4 tests: interrupt: fix testcase.yaml
The test itself handles correctly whether gen_isr_table
style dynamic interrupts are supported or not, there's
no need for an alternate scenario.

The tests work fine on riscv32 now, remove the exclusion.
Add a github link as to why Nios II is still excluded.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:14:55 -04:00
Andrew Boie
7eb07d1470 tests: interrupt: fix broken scenario
The author of this test case seems to have been under the
mistaken impression that interrupts are locked in ISRs, which
is untrue.

The only reason this ever passed, anywhere, was a race between
the timer firing and the zassert_not_equal() check in
offload_function. If the busy_wait call is moved after the timer
is started, this fails everywhere.

We do not re-use the timer object from the previous case,
resolving some crashes observed on riscv.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:14:55 -04:00
Andrew Boie
921c628f1e tests: interrupt: use one CPU only
The test tries to mask CPU interrupts and then enable a k_timer,
passing if it didn't fire.

This is totally defeated if the interrupt just fires on another
CPU that doesn't have interrupts masked.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:14:55 -04:00
Wayne Ren
f67592f2e6 tests: enable mpu gap filling tests for arch which supports it
* arc supports mpu gap filling now.
* these tests can be used for any arch which supports mpu gap
  filling.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2020-03-10 11:58:03 +02:00
Ioannis Glaropoulos
61fc061fc4 tests: kernel: userspace: extend bad syscall-ID test-case
Extend the bad syscall-ID test case to cover
erroneously supplied larged unsiged syscall-ID
values.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-07 09:22:23 +02:00
Andrew Boie
bd8a3bba54 tests: syscalls: add torture test
Hammer all CPUs with multiple threads all making system calls
that do memory allocations and buffer validation, in the hopes
that it will help smoke out concurrency issues.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-02-19 12:19:43 -08:00
Anas Nashif
28298fa06a test: object_tracing: account for pre-existing threads
Count existing threads before the test has started to deal with
platforms that have some existing services.

Remove hard-coded accounting for IPM, this is now counted before the
test starts.

Fixes #21756

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-02-19 00:45:29 -05:00
Luiz Augusto von Dentz
3e4ac40149 tests: work_q: Add tests for resubmit from handler
This adds tests to resubmission from work handler.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-17 22:37:26 +02:00
Luiz Augusto von Dentz
038d727c18 kernel: work: Return error if timeout cannot be aborted
This is aligned with the documentation which states that an error shall
be returned if the work has been completed:

  '-EINVAL Work item is being processed or has completed its work.'

Though in order to be able to resubmit from the handler itself it needs
to be able to distinct when the work is already completed so instead of
-EINVAL it return -EALREADY when the work is considered to be completed.

Fixes #22803

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-17 22:37:26 +02:00
Andrew Boie
2c9f42100c tests: syscalls: exclude one case on nsim_sem
This works around an issue with this emulator's configuration where
there is no memory address that can be poked to generate a fault,
it is simulating memory for the entire address space.

Fixes: #22561

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-02-14 09:02:38 -08:00
Stephanos Ioannidis
620f55428d tests: sleep: Increase tick margin for Xilinx QEMU
The Xilinx QEMU, used to emulate the Xilinx ZynqMP platform, is
particularly unstable in terms of timing.

This commit increases the tick margin for the Xilinx ZynqMP platform
from 1 to 5 in order to allow the sleep test to pass with a reasonable
repeatability.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-02-11 08:03:37 -08:00
Stephanos Ioannidis
4a6e3545e9 tests: sleep: Add tick margin definition
This commit introduces the common tick margin definition that can be
used to specify the maximum allowable deviation from the expected
number of ticks.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-02-11 08:03:37 -08:00
Andy Ross
4b670bd4f5 tests/kernel/smp: current CPU is not atomic
This test was whiteboxing the _current_cpu pointer to extract the CPU
ID.  That's actually racy: the thread can be preempted and migrated to
another CPU between the _current_cpu expression and the read of the ID
field.  Do it right.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-02-08 08:51:04 -05:00
Andrew Boie
efc5fe07a2 kernel: overhaul unused stack measurement
The existing stack_analyze APIs had some problems:

1. Not properly namespaced
2. Accepted the stack object as a parameter, yet the stack object
   does not contain the necessary information to get the associated
   buffer region, the thread object is needed for this
3. Caused a crash on certain platforms that do not allow inspection
   of unused stack space for the currently running thread
4. No user mode access
5. Separately passed in thread name

We deprecate these functions and add a new API
k_thread_stack_space_get() which addresses all of these issues.

A helper API log_stack_usage() also added which resembles
STACK_ANALYZE() in functionality.

Fixes: #17852

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-02-08 10:02:35 +02:00
Andy Ross
83d1ca06dc tests/mem_protect/stackprot: Need a delay under SMP
The "alternate thread" test would spawn a thread and then exit the
test, but on SMP that other thread runs asynchronously and it was
possible for the main thread to exit the test entirely before the test
thread had a chance to run (and overflow its stack), leading to
spurious test case failures.

Obviously we can't exactly synchronize to an async crash, so put a
short delay in after spawning the thread.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-02-03 09:31:56 -05:00
Carlo Caione
6f36300219 drivers: timer: Add per-core ARM architected timer
ARM cores may have a per-core architected timer, which provides per-cpu
timers, attached to a GIC to deliver its per-processor interrupts via
PPIs. This is the most common case supported by QEMU in the virt
platform.

This patch introduces support for this timer abstracting the way the
timer registers are actually accessed. This is needed because different
architectures (for example ARMv7-R vs ARMv8-A) use different registers
and even the same architecture (ARMv8-A) can actually use different
timers (ELx physical timers vs ELx virtual timers).

So we introduce the common driver here but the actual SoC / architecture
/ board must provide the three helpers (arm_arch_timer_set_compare(),
arm_arch_timer_toggle(), arm_arch_timer_count()) using an header file
imported through the arch/cpu.h header file.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2020-02-01 08:08:43 -05:00
Jim Shu
e1052a0f8d tests/kernel/fatal: add volatile to prevent compiler optimization
Initialization of local variable 'illegal' can't be optimized, or the
program will jump to the memory contains random value which causes the
unexpected behavior. Add volatile to local variable 'illegal' to prevent
compiler optimization.

Signed-off-by: Jim Shu <cwshu@andestech.com>
2020-01-22 07:08:12 -08:00
Anas Nashif
2711c4e03f tests: test k_sem_init()
Add tests for k_sem_init.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-01-20 17:19:54 -05:00
Anas Nashif
361a84d07f kernel: pipe: runtime error checking
Add runtime error checking to k_pipe_cleanup and k_pipe_get and remove
asserts.
Adapted test which was expecting a fault to handle errors instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-01-20 17:19:54 -05:00
Erwan Gouriou
010e35850e tests/kernel: timer_api: Remove build_only tickless variant
'build_only' directive may not be justified here and
prevent to see issue when running the test.

Similarly to non tickless version exclude qemu_x86_coverage
and qemu_cortex_m0 platforms.
It was actually tested failed on qemu_cortex_m0, no error
reported on qemu_x86_coverage, but removed to be safe on that side
as well.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-01-16 07:43:40 -06:00
Andrew Boie
d3314851df tests: userspace: test syscall irq context
Interrupts should not be locked when servicing a system call,
and the kernel should not think we are in an interrupt handler
either.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-16 08:51:16 +01:00
Andrew Boie
a594ca7c8f kernel: cleanup and formally define CPU start fn
The "key" parameter is legacy, remove it.

Add a typedef for the expected function pointer type.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
6f25384e7a tests: userspace: work around x86_64 bug
Exceptions on x86_64 are incorrectly implemented, and if
a preemptible thread faults, and in its overridden
k_sys_fatal_error_handler() does something which invokes
a scheduling point (such as here where we give semaphores),
the thread will be swapped out on the per-CPU exception stack
and probably explode when it is switched back in.

For now, change the faulting thread priority to co-op so this
doesn't happen.

Workaround for #21462

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
b7160c0ee4 tests: dynamic_thread: disable on x86
This doesn't work properly on x86 unless the dynamic thread
struct allocated gets lucky and is aligned to 16 bytes.
Disabling for now until #17893 is fixed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
8b107a8829 tests: mem_protect: use one cpu
Most of the scenarios in this test case spawn child threads
and expect them to complete before execution proceeds.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
d49f413c54 tests: futex: use one cpu
Nearly all of these cases create a child thread that needs
to complete before the main test proceeds further. If the
child thread runs simultaneously on another CPU, this gets
messed up.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
24ff46c634 tests: userspace: use 1cpu for some cases
This test spawns a child thread and expects it to complete.
Use one CPU for it. Get rid of the useless k_thread_abort()
call and add a k_yield() to ensure the child does its
thing.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Ulf Magnusson
d4ad36e8d6 tests: userspace: Do not assign promptless THREAD_USERSPACE_LOCAL_DATA
Assignments have no effect on promptless symbols. Flagged by
https://github.com/zephyrproject-rtos/zephyr/pull/20742.

This symbol should already be getting enabled if CONFIG_USERSPACE is
enabled, because CONFIG_ERRNO is default y and has

    select THREAD_USERSPACE_LOCAL_DATA if USERSPACE

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-13 19:04:27 +01:00
Peter Bigot
2597df4965 tests: kernel: timer: fix coverity side expression complaint
Capture the value of the volatile variable outside the assert and use
the captured value in the assert.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-07 08:48:25 -05:00
Ulf Magnusson
7e0af9e0b8 kconfig: Remove redundant $ZEPHYR_BASE from 'source's
The $srctree environment variable is already set to point to the Zephyr
root, so no need to do

    source "$(ZEPHYR_BASE)/Kconfig.zephyr"

in samples. Just

    source "Kconfig.zephyr"

works.

(Things would break if $srctree was set to anything else, because every
'source' in the Kconfig files will be relative to it.)

Also add a 'mainmenu' title to the littlefs sample. It shows up at the
top of menuconfig/guiconfig. Source Kconfig.zephyr instead of Kconfig to
avoid overriding it.

As a sidenote, $(FOO) is better $FOO in Kconfig. $FOO is legacy syntax
that Kconfiglib only supports to be compatible with old Linux kernels.
$(FOO) uses the Kconfig preprocessor.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-06 09:48:53 -05:00
Jukka Rissanen
e1b8a2ee7e tests: kernel: poll: Add checks when having zero events
Make sure that we test scenario when number of events is zero.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-01-03 11:26:46 -08:00
Nicolas Pitre
11a1ae5f7a test_pipe_contexts: fix mempool size issue and async pipe coverage
The minimum possible mempool block size is either 8 or 16 for 32-bit or
64-bit targets respectively. Defining BYTES_TO_WRITE to 4 and using that
with K_MEM_POOL_DEFINE() won't produce the expected result i.e. only 1
block at any time could be allocated instead of 4.

Yet, the test does run successfully regardless of the block allocation
loop in tpipe_block_put().

It turns out that the pipe buffer is large enough to consume all the
block data synchronously, meaning that the mempool block is freed right
away and available for the next loop iteration. This also means that the
asynchronous delivery mechanism is never exercized.

Fix both issues by defining PIPE_LEN and BYTES_TO_WRITE in terms of
_MPOOL_MINBLK with the expected factor of 4, and adding a new test
using the half-sized pipe where the pipe buffer gets saturated and
mempool memory blocks are actually queued for asynchronous consumption.

The source data string has to be extended to accommodate larger pipe
sizes too.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-12-20 20:43:01 -05:00
Carlo Caione
aec9a8c4be arch: arm: Move ARM code to AArch32 sub-directory
Before introducing the code for ARM64 (AArch64) we need to relocate the
current ARM code to a new AArch32 sub-directory. For now we can assume
that no code is shared between ARM and ARM64.

There are no functional changes. The code is moved to the new location
and the file paths are fixed to reflect this change.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2019-12-20 11:40:59 -05:00
Andrew Boie
9a9f0ed84a tests: thread_init: disable SMP
This test has a race condition between the start of
its statically initialized threads running on another CPU,
and the assignment of those threads to a memory domain in the
ztest_main() function. Disable SMP for this test.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-18 11:17:33 -08:00
Andrew Boie
a26b9e3dd5 tests: mem_protect: fix cast warning
tc_number is passed to a child thread as a parameter, which is
void *. We want to treat it as an integer, but a direct cast
to int causes a warning on 64-bit platforms; cast to uintptr_t
first to suppress it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-18 11:17:33 -08:00
Andrew Boie
12b76253f6 tests: queue: fix SMP issue
test_queue_supv_to_user() invokes a child thread which does some
work which must take place before the call to k_queue_cancel_wait()
is called by the parent.

However, with SMP enabled, the child thread will just run on another
CPU and we have a race between when child_thread_get() calls
k_queue_get(q, K_FOREVER) and the parent calls k_queue_cancel_wait().
If the parent thread gets there first, the whole test hangs as
the call to k_queue_get(q, K_FOREVER) sits forever.

The fix is to have test_queue_supv_to_user() be a 1cpu test, which
ensures that only one CPU is used.

It's not clear to me why this wasn't causing CI failures on other
SMP targets, but I am able to reproduce reliably on qemu_x86_64
with my user mode patches applied.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-18 11:17:33 -08:00
Mateusz Holenko
93923cb0ba tests: no-multithreading: Disable networking
When networking is selected, building the test
fails with:
undefined reference to `z_impl_k_thread_create'

Signed-off-by: Mateusz Holenko <mholenko@antmicro.com>
2019-12-18 10:35:15 +02:00
Vincent Wan
94140b6816 tests: kernel: gen_isr_table: exclude from testcase.yaml
Excluding this test for cc13x2/cc26x2 platforms where ISR4 is not
available for it to use.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-12-17 13:48:25 -05:00
Alberto Escolar Piedras
0b8678a2b0 samples & tests: Correct main() type
The application main() in Zephyr is defined as having a prototype:
void main(void), as expected by the kernel init (bg_thread_main).

So, correct the different samples and tests that were defined
otherwise.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-12-16 11:27:56 +01:00
Andrew Boie
3b066d4cf5 tests: userspace: fix 64-bit issues
In addition to not assuming all pointers fit in a u32_t,
logic is added to find the privilege mode stack on x86_64
and several error messages now contain more information.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Andrew Boie
3c456fc86a tests: mem_protect: fix corruption issue
This test has a problem, specifically in the scenario for
test_mem_domain_remove_partitions. A low priority thread (10)
is created which is expected to produce an exception. Then
the following happens:

- The thread indeed crashes and ends up in the custom fatal
  error handler, on the stack used for exceptions
- The call to ztest_test_pass() is made
- ztest_test_pass() gives the test_end_signal semaphore
- We then context switch to the ztest main thread which is
  higher priority, leaving the thread that crashed context
  switched out *on the exception stack*
- More tests are run, and some of them also produce exceptions
- Eventually we do a sleep and the original crashed thread is
  swapped in again
- Since several other exceptions have taken place on the
  exception stack since then, resuming context results in
  an unexpected error, causing the test to fail

Only seems to affect arches that have a dedicated stack for
exceptions, like x86_64. For now, increase the priority of
the child thread so it's cleaned up immediately. Longer-term,
this all needs to be re-thought in the test case to make this
less fragile.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Andrew Boie
d27acb9eb6 tests: adjust resource pool sizes for 64-bit
The requests are somewhat larger on 64-bit since we
are allocating structs with pointer members. Increase
these to a larger multiple of the minimum block size.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Andrew Boie
69d47c170e tests: mem_protect: don't cast pointers to u32_t
Use uintptr_t instead. Fixes some 64-bit issues.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Andrew Boie
b5c681071a kernel: don't use u32_t for data sizes
Use a size_t instead.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Kumar Gala
a8171db6a6 doc: Fix warnings associated with 'unbalanced grouping commands'
Builds of docs with doxygen 1.8.16 has a number of warnings of the form:
'warning: unbalanced grouping commands'.  Fix those warnings be either
balancing the group command or removing it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-12 12:39:35 -06:00
Peter A. Bigot
c326661ee6 kernel: init: provide access to kernel startup state
Device initialization may require use of generic services such as
starting up power rails, some of which may be controlled by GPIOs on
an external controller that can't be used until full kernel services
are available.  Generic services can check k_is_in_isr() and mediate
their behavior that way, but currently have no way to determine that
the kernel is not available.

Provide a function that indicates whether initialization is still in
pre-kernel stages where no kernel services are available.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-12-11 14:45:40 -08:00
Ulf Magnusson
984bfae831 global: Remove leading/trailing blank lines in files
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.

Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.

Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-11 19:17:27 +01:00
Anas Nashif
1d25eba4fd tests: obj tracing: fix counting
We break out of the while loop on a 2 count then we assert on 2, this
seems to never fail. Count to the end and then assert.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-12-10 10:40:16 -05:00
Anas Nashif
5d94b89512 tests: fifo: assert of NULL from k_fifo_get
Fix Null pointer dereferences.

Fixes #20877
Coverity CID: 205823

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-12-10 10:39:59 -05:00
Kumar Gala
24ae1b1aa7 include: Fix use of <misc/FOO.h> -> <sys/FOO.h>
Fix #include <misc/FOO.h> as misc/FOO.h has been deprecated and
should be #include <sys/FOO.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Anas Nashif
8dd6cd8ec4 tests: kernel: split pending testing
Split long test into 3 sections, once for each object being tested.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-12-09 15:53:44 -05:00
Anas Nashif
70758c4374 tests: fix test identifiers
The seasonal overhaul of test identifiers aligning the terms being used
and creating a structure. This is hopefully the last time we do this,
plan is to document the identifiers and enforce syntax.

The end-goal is to be able to generate a testsuite description from the
existing tests and sync it frequently with the testsuite in Testrail.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-12-09 15:53:44 -05:00
Erwan Gouriou
065a2cb08c tests/kernel: timer_api: Enable Test userspace
timer_api requires TEST_USERSPACE activation which is missing
in tickless configuration of the test.
Enable flag in prj_tickless.cnf

Fixes #20904


Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-12-09 16:40:07 +01:00
Peter Bigot
7e71164cc6 tests: kernel: timer: add test for starvation
Add a test that repeatedly reschedules a timer before it expires, and
has no other timers active.  If the timer internal state overflows due
to counter wrap either the uptime or the tick counter may appear to go
backwards.  The test runs until it fails, or until a specified amount
of measured time has passed.

This test is build-only for automated test programs as the default
limit to pass is one hour, and some platforms may require an even
longer period.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-12-02 15:28:12 +01:00
Ioannis Glaropoulos
7dc061871d tests: kernel: add kernel and sleep tags in tests
Adding kernel tag in tests/kernel/early_sleep and sleep tag
in tests/kernel/sleep. So both early_sleep and sleep suites
have the same tags.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-26 13:34:30 -06:00
Andy Ross
b2435d856a tests/kernel/threads/thread_apis: Add k_thread_suspend() edge cases
Add test cases to make sure that a thread that suspends itself stops
executing immediately, and that a thread suspended while sleeping does
not wake up unexpectedly when its timeout expires.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-25 19:12:05 -05:00
Alberto Escolar Piedras
77006e896b tests: metaIRQ: Ensure counts are not changing in assert evaluation
Coverity's analysis is not happy about using a volatile variable
in an assert, even if the assert is not optionally compiled in.
Avoid the issue by loading the value in an automatic varible before
using it in the assert.

CID: 206016
CID: 206018
CID: 206019
CID: 206021
Fixes: #20968
Fixes: #20966
Fixes: #20965
Fixes: #20963

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-11-25 16:50:04 -05:00
Peter Bigot
e5af53a32f tests: kernel: critical: add output to support diagnostics
As implemented this test runs for 20 s with no output, which makes it
difficult to identify the cause of failure.  Add output indicating
progress, and emit diagnostics a particular failure observed on iMX
boards.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-11-19 15:22:01 -05:00
Wolfgang Puffitsch
138be8e3d8 tests: Add test for MetaIRQ preemption of cooperative thread
Test that meta-IRQ returns to the cooperative thread it interrupted,
and not to whichever thread is highest priority at that point.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-11-15 17:10:36 -05:00
Anas Nashif
28ac1634ef tests: stack: consolidate tests
consolidate both stack test applications into one.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Anas Nashif
7e6cd374ac tests: stack: move stack_usage into stack
Just call it stack instead of stack_usage, preprate for consolidation of
test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Anas Nashif
b396759984 tests: semaphore: consolidate semaphore tests
No need to have two tests for the same thing, just put everything in one
test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Anas Nashif
834b7744ec tests: semaphore: cleanup assert messages
Remove redundant message from asserts.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Anas Nashif
e0f677649a tests: semaphore: cleanup asserts
Remove newline from asserts.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Ioannis Glaropoulos
01a5ef2b9c tests: stack_random: fix reading volatile variable
Fix coverity issue 20534: read the status of a volatile
variable in an ASSERT statement via a stack variable
declared and defined for this purpose.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-12 07:07:01 -06:00
Peter Bigot
5f34700133 kernel: move time_units into sys subdirectory
This isn't something the user will ever include directory, so take
steps to hide it.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-11-08 18:37:46 -05:00
Andrew Boie
d2b8922fa3 kernel: allow threads to sleep forever
Previously, passing K_FOREVER to k_sleep() would return
immediately.

Forever is a long time. Even if woken up at some point,
we still had forever to sleep, so return K_FOREVER in this
case.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-09 00:36:34 +01:00
Andrew Boie
e09a0255da kernel: sychronize irq_offload() access
Entering irq_offload() on multiple CPUs can cause
difficult to debug/reproduce crashes. Demote irq_offload()
to non-inline (it never needed to be inline anyway) and
wrap the arch call in a semaphore.

Some tests which were unnecessarily killing threads
have been fixed; these threads exit by themselves anyway
and we won't leave the semaphore dangling.

The definition of z_arch_irq_offload() moved to
arch_interface.h as it only gets called by kernel C code.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-08 15:16:43 -08:00
Andy Ross
8892406c1d kernel/sys_clock.h: Deprecate and convert uses of old conversions
Mark the old time conversion APIs deprecated, leave compatibility
macros in place, and replace all usage with the new API.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-08 11:08:58 +01:00
Andy Ross
a63a3e2e48 tests/kernel/timer/timer_api: Add tests for the new conversion routines
The new conversion API has a ton of generated utilities.  Test it via
enumerating each one of them and throwing a selection of both
hand-picked and random numbers at it.  Works by using slightly
different math to compute the expected result and assuming that we
don't have symmetric bugs in both.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-08 11:08:58 +01:00
Andrew Boie
4f77c2ad53 kernel: rename z_arch_ to arch_
Promote the private z_arch_* namespace, which specifies
the interface between the core kernel and the
architecture code, to a new top-level namespace named
arch_*.

This allows our documentation generation to create
online documentation for this set of interfaces,
and this set of interfaces is worth treating in a
more formal way anyway.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-07 15:21:46 -08:00
Ioannis Glaropoulos
40fbff6c8f tests: kernel: mem_protect: run tests with ARMV8-M MPU gap filling
We add a new test-case for the mem_protect and userspace tests,
to test the ARMv8-M MPU driver without the skipping of full SRAM
partitioning (i.e. gap filling).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-07 09:41:54 -08:00
Andrew Boie
ec3aafbf78 printk: print pointers on 64-bit properly
Needs a min-width of 16, not 8, for 64-bit.
Some indentation oddities fixed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-06 17:50:34 -08:00
Stephanos Ioannidis
2d7460482d headers: Refactor kernel and arch headers.
This commit refactors kernel and arch headers to establish a boundary
between private and public interface headers.

The refactoring strategy used in this commit is detailed in the issue

This commit introduces the following major changes:

1. Establish a clear boundary between private and public headers by
  removing "kernel/include" and "arch/*/include" from the global
  include paths. Ideally, only kernel/ and arch/*/ source files should
  reference the headers in these directories. If these headers must be
  used by a component, these include paths shall be manually added to
  the CMakeLists.txt file of the component. This is intended to
  discourage applications from including private kernel and arch
  headers either knowingly and unknowingly.

  - kernel/include/ (PRIVATE)
    This directory contains the private headers that provide private
   kernel definitions which should not be visible outside the kernel
   and arch source code. All public kernel definitions must be added
   to an appropriate header located under include/.

  - arch/*/include/ (PRIVATE)
    This directory contains the private headers that provide private
   architecture-specific definitions which should not be visible
   outside the arch and kernel source code. All public architecture-
   specific definitions must be added to an appropriate header located
   under include/arch/*/.

  - include/ AND include/sys/ (PUBLIC)
    This directory contains the public headers that provide public
   kernel definitions which can be referenced by both kernel and
   application code.

  - include/arch/*/ (PUBLIC)
    This directory contains the public headers that provide public
   architecture-specific definitions which can be referenced by both
   kernel and application code.

2. Split arch_interface.h into "kernel-to-arch interface" and "public
  arch interface" divisions.

  - kernel/include/kernel_arch_interface.h
    * provides private "kernel-to-arch interface" definition.
    * includes arch/*/include/kernel_arch_func.h to ensure that the
     interface function implementations are always available.
    * includes sys/arch_interface.h so that public arch interface
     definitions are automatically included when including this file.

  - arch/*/include/kernel_arch_func.h
    * provides architecture-specific "kernel-to-arch interface"
     implementation.
    * only the functions that will be used in kernel and arch source
     files are defined here.

  - include/sys/arch_interface.h
    * provides "public arch interface" definition.
    * includes include/arch/arch_inlines.h to ensure that the
     architecture-specific public inline interface function
     implementations are always available.

  - include/arch/arch_inlines.h
    * includes architecture-specific arch_inlines.h in
     include/arch/*/arch_inline.h.

  - include/arch/*/arch_inline.h
    * provides architecture-specific "public arch interface" inline
     function implementation.
    * supersedes include/sys/arch_inline.h.

3. Refactor kernel and the existing architecture implementations.

  - Remove circular dependency of kernel and arch headers. The
   following general rules should be observed:

    * Never include any private headers from public headers
    * Never include kernel_internal.h in kernel_arch_data.h
    * Always include kernel_arch_data.h from kernel_arch_func.h
    * Never include kernel.h from kernel_struct.h either directly or
     indirectly. Only add the kernel structures that must be referenced
     from public arch headers in this file.

  - Relocate syscall_handler.h to include/ so it can be used in the
   public code. This is necessary because many user-mode public codes
   reference the functions defined in this header.

  - Relocate kernel_arch_thread.h to include/arch/*/thread.h. This is
   necessary to provide architecture-specific thread definition for
   'struct k_thread' in kernel.h.

  - Remove any private header dependencies from public headers using
   the following methods:

    * If dependency is not required, simply omit
    * If dependency is required,
      - Relocate a portion of the required dependencies from the
       private header to an appropriate public header OR
      - Relocate the required private header to make it public.

This commit supersedes #20047, addresses #19666, and fixes #3056.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-11-06 16:07:32 -08:00
Wayne Ren
f8edd95422 tests: Fix the compile warning for arc
the following compile warning will fail the CI:

/zephyr/tests/kernel/fp_sharing/generic/src/float_regs_arc_gcc.h:
41:8: error: /unused variable 'temp' [-Werror=unused-variable]

/zephyr/tests/kernel/fp_sharing/generic/src/float_regs_arc_gcc.h:
75:8: error: /unused variable 'temp' [-Werror=unused-variable]

cc1: all warnings being treated as errors

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-10-30 09:28:28 +01:00
Daniel Leung
b7eb04b300 x86: consolidate x86_64 architecture, SoC and boards
There are two set of code supporting x86_64: x86_64 using x32 ABI,
and x86 long mode, and this consolidates both into one x86_64
architecture and SoC supporting truly 64-bit mode.

() Removes the x86_64:x32 architecture and SoC, and replaces
   them with the existing x86 long mode arch and SoC.
() Replace qemu_x86_64 with qemu_x86_long as qemu_x86_64.
() Updates samples and tests to remove reference to
   qemu_x86_long.
() Renames CONFIG_X86_LONGMODE to CONFIG_X86_64.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-10-25 17:57:55 -04:00
Maksim Masalski
6882d97531 tests: new updated names for the kernel tests
After run Sanitycheck script I found out that some test cases
have the same test case name in the test result .xml file.
To get rid of it, I decided to change test cases names
for the kernel tests.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2019-10-24 06:25:53 -04:00
Maksim Masalski
d85b45b072 tests: updated names for the arch interrupt tests
Test case arch.interrupt have same test case name
for different architectures. To get rid of it,
I decided to change test cases names.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2019-10-23 23:13:13 -04:00
peng1 chen
f20084ff1c Code Coverage: Fix the issue of function code coverage in thread.c
The k_thread_state_str is a new function added into
kernel/thread.c recently which was used to return
the human friendly thread state, so it hasn't been
called by other existing code.
In order to improve the function code coverage, we
just replace the "th->base.thread_state & _THREAD_PENDING"
code by using k_thread_state_str function in
tests/kernel/sched/preempt/src/main.c, because
k_thread_state_str function is realized by judging
the thread_state member to return the thread state.

Signed-off-by: peng1 chen <peng1.chen@intel.com>
2019-10-23 19:16:24 -07:00
Andrei Gansari
b5ed5af8c8 tests: schedule_api adapt to slow ticks
This test case is has a tolerance of 1ms, but systems with a tick slower
than 1000 ticks/sec may spil outside the 1ms tolerance.
Tolerance adapts to system's ticks/sec, e.g. QEMU targets have
100ticks/sec -> tolerance is 10ms.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2019-10-22 23:06:41 -04:00
Andrei Gansari
65fbfbbbff tests: scheduler_api removed MPS2 workaround
CONFIG_SOC_SERIES_MPS2 specific test workaround is removed
to use systick drives as tickless.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2019-10-22 23:06:41 -04:00
Maksim Masalski
9f26f7d3d4 tests: updated names for the kernel tests
After run Sanitycheck script I found out that test cases
had the same test case name in the test result .xml file.
For board itodk in .xml file was duplicated kernel.common test.
To get rid of it, I decided to change test cases names
for the kernel tests, contained name kernel.common.
Now only one test has kernel.common test name,
and will be no duplicated test cases names in the future.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2019-10-22 22:55:35 -04:00
Stephanos Ioannidis
5806787ae1 tests: kernel: Fix incorrect interrupt controller type inference.
The current implementation of kernel interrupt tests incorrectly
infers NVIC, which is specific to Cortex-M, from CONFIG_ARM.

This commit fixes such incorrect NVIC inferences by using
CONFIG_CPU_CORTEX_M instead of CONFIG_ARM.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-10-22 15:07:52 -07:00
Wayne Ren
482b993b88 tests: add the case for ARC in yaml
* add the case for ARC in yaml after dynamic and direct irq are
  supported
* fix the bug that index in sw_isr_table should have a offset of
  CONFIG_GEN_IRQ_START_VECTOR

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-10-21 09:06:17 -07:00
Ioannis Glaropoulos
9375aaebe6 tests: kernel: fatal: add a test-case for arbitrary error reason
We add a test-case in kernel/fatal test suite, to test that
the application developer can induce a SW-generated exception
with any 'reason' value.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-10-16 11:22:48 +02:00
Ioannis Glaropoulos
04c334ad1b tests: kernel: userspace: replace inline assembly with C code
We replace an inline assembly block of code with CMSIS
functions, to make it portable to ARMv6-M architecture.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-10-15 10:06:48 -07:00
Andrew Boie
b7d41a2a94 tests: move boot_page_table test
This is x86-specific.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Andrew Boie
06d3e958a7 tests: move x86_mmu_api test
This is x86-specific.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Andrew Boie
31620b90e2 x86: refactor mmustructs.h
The struct definitions for pdpt, pd, and pt entries has been
removed:

 - Bitfield ordering in a struct is implementation dependent,
   it can be right-to-left or left-to-right
 - The two different structures for page directory entries were
   not being used consistently, or when the type of the PDE
   was unknown
 - Anonymous structs/unions are GCC extensions

Instead these are now u64_t, with bitwise operations used to
get/set fields.

A new set of inline functions for fetcing various page table
structures has been implemented, replacing the older macros.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Andrew Boie
ab4d647e6d x86: mmu: get rid of x86_page_entry_data_t typedef
This hasn't been necessary since we dropped support for 32-bit
non-PAE page tables. Replace it with u64_t and scrub any
unnecessary casts left behind.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Andrew Boie
e3ab43580c x86: move mmustructs.h
This will be used for both 32-bit and 64-bit mode.
This header gets pulled in by x86's arch/cpu.h, so put
it in include/arch/x86/.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Nicolas Pitre
923a909db8 tests/mem_pool_threadsafe: use actual minimum mempool block size
On 64-bit targets, the minimum possible mempool block size is not 8
but 16. With a max block size of 32, the mempool allocator cannot
split it into 4 sub-blocks, reducing the available memory allocations
to that original 32-byte block only.

To get the same allocation patterns and test behavior whether it is
built for a 32-bit or 64-bit architecture, let's define BLK_SIZE_MIN
and BLK_SIZE_MAX in terms of _MPOOL_MINBLK instead of literal values.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-10-09 17:45:40 -05:00