Commit graph

503 commits

Author SHA1 Message Date
Anas Nashif 345735d0a8 tests: remove CONFIG_ZTEST_NEW_API in all tests
Remove all usage of CONFIG_ZTEST_NEW_API from tests and sample as this
is now enabled by default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Anas Nashif e19f21cb27 kernel: move z_is_thread_essential out of public kernel header
This is a private API to the kernel, so move out of kernel.h

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-09-30 18:43:28 +02:00
Manuel Argüelles 3923cda6d8 tests: kernel: syscalls: use default faulty address for s32z270dc2
Before Picolibc was made default, this board needed a custom test
faulty address. Now this address does not produce a fault anymore so
switch back to the default faulty address.

Fixes #63270

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-09-29 20:34:51 +03:00
Daniel Leung d47b1c05f3 kernel: userspace: add k_object_is_valid()
This adds a function k_object_is_valid() to check if a kernel
object exists, of certain type, and has been initialized.
This replaces the same (or very similar) code that has been
copied from kernel into the network subsystem.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-09-28 17:28:43 -04:00
Anas Nashif ceb42a688e kernel: remove reference to non existing z_thread_heap_assign
we have no z_thread_heap_assign, was suppoosed to reference
k_thread_heap_assign.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-09-17 07:59:30 -04:00
Daniel Leung 3441c70117 tests: mem_protect/mem_protect: reuse child thread and stack
This reuses the child_thread variable and child_stack acorss
test suites.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-09-15 09:26:26 +02:00
Daniel Leung 4bebb65491 tests: mem_protect/mem_protect: fix number of kobjects to test
In test_kobject_perm_error, there are 13 kobjects to test but
the loop only do 12. So amend the code to test all 13 kobjects.

Also remove the parameter of tid to child thread as the child
thread is not using it.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-09-15 09:26:26 +02:00
Gerard Marull-Paretas 9c961571a2 modules: cmsis: move glue code to modules/cmsis
The CMSIS module glue code was part of arch/ directory. Move it to
modules/cmsis, and provide a single entry point for it: cmsis_core.h.
This entry header will include the right CMSIS header (M or A/R).

To make this change possible, CMSIS module Kconfig/CMake are declared as
external, allowing us to add a new Zephyr include directory.

All files including CMSIS have been updated.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-08-24 13:20:21 +02:00
Jaxson Han d1a3b2631c tests: kernel: mem_protect: Increase stack size for 64BIT plat
Some 64 bit platforms do not have MMU, however the 64 bit platfoms need
a larger stack. This testcase fails with non-MMU 64 bit platform e.g.
v8r64 platform due to the stack overflow. To fix this issue, set 2k
stack for all 64 bit platforms (CONFIG_64BIT) as this is likely a common
issue for all non-MMU 64 bit platforms.

Signed-off-by: Jaxson Han <jaxson.han@arm.com>
2023-08-21 13:27:07 +02:00
Manuel Argüelles 5d3d4eb8b0 tests: syscalls: add faulty address for s32z270dc2_r52 boards
Default faulty address does not generate the expected fault on the
s32z270dc2_r52 boards.

Signed-off-by: Manuel Argüelles <manuel.arguelles@nxp.com>
2023-08-16 15:04:14 +02:00
Daniel Leung 174caf0c10 tests: kernel: renames shadow variables
Renames	shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:12 +00:00
Flavio Ceolin 2bb6ad76ec tests: stackprot: New test to check canaries behavior
Adding a new simple test that checks that canaries values
are different between threads when CONFIG_STACK_CANARIES_TLS
is enabled.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-08-08 19:08:04 -04:00
Flavio Ceolin 0f2d0ca40d tests: stackprot: Test canaries in TLS
Add a new test to enable stack canaries in TLS.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-08-08 19:08:04 -04:00
Anas Nashif b835b02136 tests: cleanup metadata and filtering
- Add integration_platforms to avoid excessive filtering
- Make sure integration platforms are actually part of the filter
- Fix some tags and test meta data

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-06-13 09:38:27 -04:00
Declan Snyder 670e2a28fb tests: userspace: Support mimxrtXXX_evk_cm33
RT685 and RT494 ran out of mpu regions to do this test,
so add board overlays to disable the USB SRAM MPU
region definition because it is not needed for this test.

Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
2023-06-01 19:02:58 -04:00
Keith Packard 091948a5a9 tests: Increase a couple of test stack sizes
mem_protect and sprintf stacks both need to be slightly larger than
currently defined in order to avoid stack overflow when using picolibc.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-06-01 13:43:25 -04:00
Daniel Leung c9b5326270 tests: kernel/userspace: add a test for kernel only thread
This adds a test to make sure kernel only threads cannot go
into user mode: doing so would result in kernel panic.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-05-25 16:30:26 -04:00
Anas Nashif 5d8c8f3838 tests: sys_sem: cleanup test metadata
Remove definition of testcases in yaml file, those are now detected from
binary.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-05-25 04:44:11 -04:00
Carlo Caione 6f3a13d974 barriers: Move __ISB() to the new API
Remove the arch-specific ARM-centric __ISB() macro and use the new
barrier API instead.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-05-24 13:13:57 -04:00
Carlo Caione cb11b2e84b barriers: Move __DSB() to the new API
Remove the arch-specific ARM-centric __DSB() macro and use the new
barrier API instead.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-05-24 13:13:57 -04:00
Anas Nashif c5d798173c tests: improve filtering and use integration_platforms
Use integration platforms to limit scope in CI.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-05-24 07:50:50 -04:00
Gerard Marull-Paretas 93b63df762 samples, tests: convert string-based twister lists to YAML lists
Twister now supports using YAML lists for all fields that were written
as space-separated lists. Used twister_to_list.py script. Some artifacts
on string length are due to how ruamel dumps content.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-10 09:52:37 +02:00
Keith Packard bfa6a44746 tests,samples: Fix picolibc malloc arena settings
With picolibc moving to using the common malloc implementation, samples and
tests with picolibc-specific settings need to switch to using the common
malloc settings instead.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-05-09 01:29:16 +09:00
Rick Tsao 1a51f6d45d tests: mem_protect: Add support for configurable granularity of PMP
Redefine MEM_REGION_ALLOC to make memory domain align with granularity
of PMP.

Signed-off-by: Rick Tsao <rick592@andestech.com>
2023-04-06 11:50:43 +02:00
Daniel Leung e35733d2ff tests: mem_protect/syscalls: print FAILED when faulting
If there are any CPU exceptions, printing a failed message
would allow twister to stop early instead of waiting for
timeout.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-27 20:13:22 -04:00
Daniel Leung 4a39c0c49f tests: mem_protect/sys_sem: print FAILED when faulting
If there are any CPU exceptions, printing a failed message
would allow twister to stop early instead of waiting for
timeout.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-27 20:13:22 -04:00
Daniel Leung 97fe4833d8 tests: mem_protect: remove code to recover spinlock
The variable need_recover_spinlock is always set to false so
the spinlock recovery code is effectively no-op. So remove
everything related to the variable.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-03-24 09:04:13 +01:00
Daniel Leung 116998c677 tests: kernel: print FAILED when wrong faults caught
For some kernel tests, faults and exceptions are expected.
They are caught and the test would continue if the reasons
for faults are as expected. However, when the unexpected
reasons are encountered, the code simply prints a message
and calls k_fatal_halt(). When running under twister,
these messages are not the expected failed messages so
twister will spin till timeout although the execution
has already been halted. This adds another printk() before
halt to signal twister that the test has failed and bails
early.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-02-21 18:06:44 -05:00
Daniel Leung d650d76d62 tests: mem_protect/mem_protect: join thread at end of test...
...test_inherit_resource_pool. This waits for the newly created
threads to finish before moving on to the next test. This fixes
an issue on qemu_x86_tiny where there would be a double fault
after all tests have run.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-02-21 18:06:44 -05:00
Nicolas Pitre 3c440af975 riscv: pmp: provision for implementations with partial PMP support
Looks like some implementors decided not to implement the full set of
PMP range matching modes. Let's rearrange the code so that any of those
modes can be disabled.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-02-20 10:57:11 +01:00
Kumar Gala 5605da129b tests: kernel: mem_protect: stackprot: Dont inline check_input
When building with LLVM on qemu_x86 we see the compiler ends up
inlining the check_input function.  This breaks the stack overflow
that the test is trying to generate, so mark the check_input()
function as noinline to fix the issue.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-02-19 20:47:44 -05:00
Evgeniy Paltsev e0de642d0a ARC: qemu: disable test where we trigger ARC QEMU bug #54720
Disable tests/kernel/mem_protect/syscalls for qemu_arc_em where
we trigger ARC QEMU bug which cause illegal instruction exception
on perfectly valid ARC code.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2023-02-17 08:50:37 +09:00
Keith Packard fb193e2d3d tests/mem_protect: Use minimal libc for kernel.memory_protection
This test has trouble on qemu_x86_tiny and randomly generates a Double
Fault error. I couldn't get it to reliably run with picolibc as a Double
Fault usually occured before the test completed.

I spent a couple of hours attempting to track this down and found that it
happens when code pages for the main thread get unmapped because the
qemu_x86_tiny intentionally offers very few available PTEs.

Work around this by just using the minimal libc for this test.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-01-30 23:46:55 +00:00
Keith Packard 6738e8e9df tests/x86/mem_protect: Disable picolibc heap for demand paging tests
These tests don't need any libc heap and currently fail when one is
available.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-01-30 23:46:55 +00:00
Jordan Yates 839ca44f80 Revert "tests: update expected exception codes"
This reverts commit d8ac658578.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-01-27 18:09:32 +09:00
Jordan Yates d8ac658578 tests: update expected exception codes
Update expected exception codes for Cortex-M, Cortex-R and Cortex-A
CPUs.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-01-12 10:01:05 +01:00
Flavio Ceolin e31f4de09e tests: obj_validation: Call setup function
The setup function for object validation test was defined
but no called.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-01-10 19:23:57 -05:00
Fabio Baltieri 5c32300861 yamllint: fix all yamllint truthy errors
Fix all thruthy errors detected by yamllint:

yamllint -f parsable -c .yamllint $( find -regex '.*\.y[a]*ml' ) | \
  grep '(truthy)'

This only accepts true/false for boolean properties. Seems like python
takes all sort of formats:

https://github.com/yaml/pyyaml/blob/master/lib/yaml/constructor.py#L224-L235

But the current specs only mention "true" or "false"

https://yaml.org/spec/1.2.2/#10212-boolean

Which is the standard yamllint config.

Excluding codeconv and workflow files, as some are using yes/no instead
in the respective documentation.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-01-04 01:16:45 +09:00
Hein Wessels 3210541c86 toolchain: gcc: rename popcount to avoid conflict with C++20
The macro conflicts with the C++20 feature std::popcount

fixes zephyrproject-rtos/zephyr#53421

Signed-off-by: Hein Wessels <heinwessels93@gmail.com>
2023-01-03 11:06:45 +01:00
Evgeniy Paltsev 7b4fc1d6d2 tests: re-enable tests which were disabled due to ARC QEMU issues
Re-enable several mem_protect tests which were disabled due to
issues in ARC QEMU (which are fixed and fixes were propagated to
Zephyr SDK)

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2022-12-08 16:59:15 +09:00
Anas Nashif ba7d730e9b tests/samples: use integration_plaforms in more tests/samples
integration_platforms help us control what get built/executed in CI and
for each PR submitted. They do not filter out platforms, instead they
just minimize the amount of builds/testing for a particular
tests/sample.
Tests still run on all supported platforms when not in integration mode.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-29 16:03:23 +01:00
Anas Nashif 808266a493 tests: use ignore_fault field instead of tags
Use dedicated field in the yaml file instead of mixing this testing
feature with tags.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-11-25 06:38:05 -05:00
Daniel Leung 75fd531164 tests: mem_map: test if z_phys_unmap reclaim memory correctly
This adds a test to see if z_phys_unmap() can reclaim memory
correctly, so that the next z_phys_map() re-uses the same
address (with identical input arguments).

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-11-17 15:56:04 +00:00
Enjia Mai 0d5555e728 tests: kernel: mem_protect: fix incorrect skip on mem_map test
The mem_map test was skipped on all the phsical x86 boards when
running twister to test them. This error happens when migrating
the new ztest. Remove the incorrect platform allow to fix this
error.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-11-09 09:25:08 +00:00
Keith Packard 82352fda28 tests/mem_protect/userspace: Disable picolibc malloc heap
Reduces MPU partition usage when building with picolibc

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-11-08 10:44:36 +01:00
Keith Packard 71bf8623e3 tests/mem_map: Disable picolibc malloc heap
Reduces MPU partition usage when building with picolibc

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-11-08 10:44:36 +01:00
Keith Packard 62b0ef376b tests/kernel: Delay between thread creation in stack random test
This avoids problems when using timers for random numbers; run too fast and
all the values are the same.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-11-08 10:44:36 +01:00
Daniel Leung 65f6e3a4e3 tests: mem_map: compare just written data too in mapped_rw
After writing to mapped_rw, we should also check if the backing
buffer has the correct data. Or we could have a situation where
on systems that need explicit cache controls, the newly updated
mapped_rw is cached but the backing buffer still contain old
data. Comparing the backing buffer to mapped_ro does not really
matter in this case as the content would certain match.

Also, this moves the mapping of mapped_ro earlier so that we
map both mapped_rw and mapped_ro because data manipulation.

And that we also need to verify the values of the backing and
mapped buffers.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-11-05 19:56:57 +01:00
Daniel Leung 97b89b659b tests: mem_map: fix potential out-of-bound for test buffer
There is an assumption on test_page buffer that the MMU page
size is 4kb so that there is a 8kb buffer for read/write.
However, page size may not be 4kb on all architectures.
We need to make sure the test buffer is large enough for
the read/write test.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-11-05 19:56:57 +01:00
Daniel Leung 4f2b7c693e tests: sys_sem: no k_thread_access_grant call if not userspace
The sys_sem.nouser test does not enable userspace which makes
k_thread_access_grant() no-op. However, XCC would still emit
LOOP instructions for the for-loop. Since there is nothing
to do, the XCC assembler complains about it being an empty
loop and errors out. So guard the k_thread_access_grant()
calls so they are only compiled if userspace is enabled.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-11-05 08:29:01 -04:00
Kumar Gala b5ec4109d3 tests: mem_protect: syscalls: Convert CONFIG_MP_NUM_CPUS handling
Move runtime checks to use arch_num_cpus() and build checks
to use CONFIG_MP_MAX_NUM_CPUS.  This is to allow runtime
determination of the number of CPUs in the future.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-31 17:09:06 +01:00
Kumar Gala fc95ec98dd smp: Convert #if to use CONFIG_MP_MAX_NUM_CPUS
Convert CONFIG_MP_NUM_CPUS to CONFIG_MP_MAX_NUM_CPUS as we work on
phasing out CONFIG_MP_NUM_CPUS.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-20 22:04:10 +09:00
Kumar Gala 4f0166088c tests: move to using CONFIG_MP_MAX_NUM_CPUS
For tests that set CONFIG_MP_NUM_CPUS, switch to using
CONFIG_MP_MAX_NUM_CPUS instead as we work to phase out
CONFIG_MP_NUM_CPUS.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2022-10-20 22:04:10 +09:00
Meng xianglin 7f37facddf tests: mem_protect: sys_sem: move a test case to new ztest API
move test case test_sem_take_timeout_fails() to new ztest API

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2022-09-22 16:42:51 +00:00
Michał Barnaś dae8efa692 ztest: remove the obsolete NULL appended to zassert macros
This commit removes the usage of NULL parameter as message in
zassert_* macros after making it optional

Signed-off-by: Michał Barnaś <mb@semihalf.com>
2022-09-09 07:05:38 -04:00
Gerard Marull-Paretas 79e6b0e0f6 includes: prefer <zephyr/kernel.h> over <zephyr/zephyr.h>
As of today <zephyr/zephyr.h> is 100% equivalent to <zephyr/kernel.h>.
This patch proposes to then include <zephyr/kernel.h> instead of
<zephyr/zephyr.h> since it is more clear that you are including the
Kernel APIs and (probably) nothing else. <zephyr/zephyr.h> sounds like a
catch-all header that may be confusing. Most applications need to
include a bunch of other things to compile, e.g. driver headers or
subsystem headers like BT, logging, etc.

The idea of a catch-all header in Zephyr is probably not feasible
anyway. Reason is that Zephyr is not a library, like it could be for
example `libpython`. Zephyr provides many utilities nowadays: a kernel,
drivers, subsystems, etc and things will likely grow. A catch-all header
would be massive, difficult to keep up-to-date. It is also likely that
an application will only build a small subset. Note that subsystem-level
headers may use a catch-all approach to make things easier, though.

NOTE: This patch is **NOT** removing the header, just removing its usage
in-tree. I'd advocate for its deprecation (add a #warning on it), but I
understand many people will have concerns.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-09-05 16:31:47 +02:00
Enjia Mai 7dcab41b4c tests: kernel: move the sys_sem test to new ztest API
Migrate the testsuite tests/kernel/mem_protect/sys_sem to the
new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-08-19 20:44:49 +00:00
Enjia Mai 00fedc2eb2 tests: kernel: move the test demand_paging to new ztest API
Migrate the testsuite tests/kernel/mem_protect/demand_paging to
the new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-08-19 20:44:49 +00:00
Enjia Mai 7684f46b7f tests: kernel: move the memory protection test to new ztest API
Migrate the testsuite tests/kernel/mem_protect/mem_protect to
the new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-08-19 20:44:49 +00:00
Enjia Mai 8ea5cea4a7 tests: kernel: move the userspace test to new ztest API
Migrate the testsuite tests/kernel/mem_protect/userspace to the
new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-08-19 20:44:49 +00:00
Enjia Mai 09abe3b6a6 tests: kernel: move the test futex to new ztest API
Migrate the testsuite tests/kernel/mem_protect/futex to the
new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-08-19 20:44:49 +00:00
Daniel Leung fd8ffdb833 boards: qemu_x86_tiny: enable support for coverage
This adds the bits so that we can use qemu_x86_tiny for
coverage, as this is currently the only board that can do
demand paging.

This uses the board revision as a way to specify the RAM
size as coverage requires more memory available to store
the coverage data. By piggybacking onto board revision,
this avoids adding another board config just for coverage.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-08-18 17:23:18 +02:00
Peter Mitsis 029035cbea tests: Add CONFIG_PIPES to tests that use pipes
Use of pipes is now configurable. All tests that use pipes must enable
that feature. (Note: no sample projects currently use pipes.)

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2022-08-17 19:31:25 +02:00
Fabio Baltieri def230187b test: fix more legacy #include paths
Add a bunch of missing "zephyr/" prefixes to #include statements in
various test and test framework files.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2022-08-02 16:41:41 +01:00
Johann Fischer d66e047e5b tests: use unsigned int for irq_lock()
irq_lock() returns an unsigned integer key.
Generated by spatch using semantic patch
scripts/coccinelle/irq_lock.cocci

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
2022-07-14 14:37:13 -05:00
Enjia Mai 4a3184441c tests: kernel: mem_protect: move the obj validation test to new ztest
Migrate the testsuite tests/kernel/mem_protect/obj_validation
to the new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-07-14 10:29:33 +02:00
Enjia Mai a3d834ed2b tests: kernel: mem_protect: move the syscalls test to new ztest
Migrate the testsuite tests/kernel/mem_protect/syscalls to
the new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-07-14 10:29:33 +02:00
Enjia Mai 72d4ac27ad tests: kernel: mem_protect: move the protection test to new ztest
Migrate the testsuite tests/kernel/mem_protect/protection to
the new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-07-14 10:29:33 +02:00
Enjia Mai 4df4646aa1 tests: kernel: mem_protect: move the stack random test to new ztest
Migrate the testsuite tests/kernel/mem_protect/stack_random to the new
ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-07-14 10:29:33 +02:00
Enjia Mai b479838e0a tests: kernel: mem_protect: move the stack protection test to new ztest
Migrate the testsuite tests/kernel/mem_protect/stackprot to the new
ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-07-14 10:29:33 +02:00
Enjia Mai 87f0b58efe tests: kernel: mem_protect: move the mem map test to new ztest API
Migrate the testsuite tests/kernel/mem_protect/mem_map to the new
ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-07-14 10:29:33 +02:00
Andrei Emeltchenko 66cfe4f430 tests: mem_protect: Fix checking wrong variable
At the moment zassert_is_null() is checking value which is always NULL.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2022-06-30 12:37:14 -05:00
Keith Packard 2263708c73 tests/mem_protect: Increase MPU sizes for qemu_cortex_a53
When running with picolibc, we need more MPU resources for these
tests. Get rid of picolibc malloc arena too.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-06-30 10:33:24 +02:00
Stephanos Ioannidis 2904b0020e tests: kernel: stack_random: Disable -Wdangling-pointer warning
This commit selectively disables the dangling pointer warning
(`-Wdangling-pointer`) for the compilation of the `alternate_thread`
function because it deliberately makes use of a dangling pointer in
order to test stack randomisation.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-06-17 10:18:26 +02:00
Daniel Leung a9972f3d99 tests: mem_protect/mem_map: enable userspace on qemu_x86_tiny
Due to qemu_x86_tiny having very small defined SRAM area,
enabling userspace results in not having enough free physical
pages to run the tests. So make the memory a bit larger so
we can actually test memory mapping with userspace.

Fixes #46398

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-06-13 12:12:42 +02:00
Carlo Caione 63fa264c22 tests: mem_protect/mem_map: qemu_x86_tiny: Exclude userspace testing
There are no enough free pages to run the test with userspace enabled on
qemu_x86_tiny. Disable it.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-06-10 09:48:23 +02:00
Carlo Caione f094542d64 tests: mem_protect/mem_map: Test also K_MEM_PERM_USER
The tests is currently testing all the memory mapping parameters but
K_MEM_PERM_USER. Add a test case to test that as well.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-06-10 09:48:23 +02:00
Nicolas Pitre 6051ea7d3c riscv: clarify stack size and alignment parameters
The StackGuard area is used to save the esf and run the exception code
resulting from a StackGuard trap. Size it appropriately.

Remove redundancy, clarify documentation, etc.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-05-18 10:54:53 +02:00
Guo Lixin 80b2d7722d tests: add filter of configs to avoid mismatch test running
Some test suites have different test case lists in test_main(), that
conforms to different test scenarios defined in testcase.yaml. We
use if statement to decide which test case list should run under
specific config.
But for thoses boards who do not support those configs, we will run test
cases on the other side of the if statement even if it has deviated from
the original test scenario.
So add filter to avoid test scenario running under mismatch config.

Signed-off-by: Guo Lixin <lixinx.guo@intel.com>
2022-05-16 22:49:34 -04:00
Anas Nashif 84410f57b2 tests: mem_protect: define testcases in yaml
Define all testcases in the yaml for consistency and issue parsing
them during setup.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-05-13 12:16:57 -04:00
Gerard Marull-Paretas ade7ccb918 tests: migrate includes to <zephyr/...>
In order to bring consistency in-tree, migrate all tests to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 20:02:14 +02:00
Nicolas Pitre 2fece49a14 riscv: pmp: switch over to the new implementation
Add the appropriate hooks effectively replacing the old implementation
with the new one.

Also the stackguard wasn't properly enforced especially with the
usermode combination. This is now fixed.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-04-29 15:30:00 +02:00
Keith Packard 6f9f8c1e32 samples, tests: Add z_libc_partition to all test domains
When a memory domain is initialized, the z_libc_partition must be
included so that critical libc-related data can be accessed.

On ARM processors without TPIDRURO when THREAD_LOCAL_STORAGE is enabled,
this includes the TLS base pointer, which is used for several
thread-local variables in the kernel.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-04-28 11:09:01 +09:00
Keith Packard 19c8956946 tests: Disable HW stack protection for some mpu tests
When active, z_libc_partition consumes an MPU region which leaves too
few for some MPU tests. Free up one by disabling HW stack protection.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-04-28 11:09:01 +09:00
Keith Packard b03b2e0403 tests/kernel/mem_protect: Check for thread_userspace_local_data
When using THREAD_LOCAL_STORAGE the thread_userspace_local_data stuff
isn't used, so these tests wouldn't build.

Signed-off-by: Keith Packard <keithp@keithp.com>
2022-04-28 11:09:01 +09:00
Carlo Caione 82451951cf tests: Misc test fixes for fvp_base_revc_2xaemv8a
Fix several tests for the fvp_base_revc_2xaemv8a board.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-04-26 09:00:18 +02:00
Stephanos Ioannidis 97064045d2 tests: kernel: syscall: Exclude for qemu_arc_em
This commit excludes the kernel syscall test for the `qemu_arc_em`
platform because this test may fail with the ARC QEMU 6.2 on certain
host systems.

Refer to the following issues for more details:

* foss-for-synopsys-dwc-arc-processors/qemu#66
* zephyrproject-rtos/zephyr#44862

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-04-19 09:15:06 -04:00
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Carles Cufi e83a13aabf kconfig: Rename the TEST_EXTRA stack size option to align with the rest
All stack sizes should end with STACK_SIZE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-02-22 08:23:05 -05:00
Carles Cufi 4b8f1c04ab kconfig: Rename the ZTEST stack size option to align with the rest
All stack sizes should end with STACK_SIZE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-02-22 08:23:05 -05:00
David Leach fdea2a628b tests: mem_protect: ensure allocated objects are initialized
K_OBJ_MSGQ, K_OBJ_PIPE, and K_OBJ_STACK objects have pointers
to additional memory that can be allocated. The k_obj_alloc()
returns these objects as uninitialized so when they are freed
there are random opportunities for freeing invalid memory
and causing random faults.

Signed-off-by: David Leach <david.leach@nxp.com>
2022-02-21 20:43:47 -05:00
David Leach a0737e687c tests: mem_protect: avoid allocating K_OBJ_MSGQ in userspace.
The K_OBJ_MSGQ object is unitialized so when the thread cleanup occurs
after an expected fault for invalid access the test case can randomly
fault again because the cleanup of the thread will sometimes attempt
to free invalid buffer_start pointer in the msgq object.

Fixes #42705

Signed-off-by: David Leach <david.leach@nxp.com>
2022-02-21 20:43:47 -05:00
Jim Shu e2d67d60ba tests: mem_protect: enlarge heap size of RISCV64
Because k_thread size in RISCV64 is near 512 bytes, (num_of_thread *
256) bytes heap size is not enough. Enlarge heap size in RISCV64
to the (num_of_thread * 1024) bytes like x86_64 and ARM64.

Signed-off-by: Jim Shu <cwshu09@gmail.com>
2022-01-18 13:11:36 -05:00
Daniel Leung 8f7f62869a tests: remove @return doc for void functions
For functions returning nothing, there is no need to document
with @return, as Doxgen complains about "documented empty
return type of ...".

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2022-01-12 16:02:16 -05:00
Carles Cufi cfbaac6733 tests: kernel: Fix address-of-packed-mem warning
The warning below appears once -Waddress-of-packed-mem is enabled:

/__w/zephyr/zephyr/tests/kernel/mem_protect/userspace/src/main.c: In
function 'test_main':
/__w/zephyr/zephyr/tests/kernel/mem_protect/userspace/src/main.c:1024:17:
error: converting a packed 'k_thread_stack_t' {aka 'struct
z_thread_stack_element'} pointer (alignment 1) to a 'struct
z_x86_thread_stack_header' pointer (alignment 4096) may result in an
unaligned pointer value [-Werror=address-of-packed-member]
 1024 |  hdr = ((struct z_x86_thread_stack_header *)ztest_thread_stack);

To avoid the warning, use an intermediate void * variable.

More info in #16587.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2021-12-10 14:08:59 +01:00
Lixin Guo 51cd1fcde6 tests: syscall: fix low value of CONFIG_MAX_THREAD_BYTES
Failed to build tests/kernel/mem_protect/syscalls on fvp_baser_aemv8r_smp
because the default value of CONFIG_MAX_THREAD_BYTES is too low.
So manually set the value to 5 in test case's prj.conf file.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-12-09 19:46:25 -05:00
Lixin Guo c02d39ea57 tests: userspace: add support for K_OBJ_CONDVAR
add support for K_OBJ_CONDVAR in test_alloc_kobjects()
This improves the code coverage.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-12-06 08:06:45 -05:00
Lixin Guo 350a13566e tests: userspace: add support for validating invalid objects
test userspace API with invalid kernel objects.
This improves code coverage.

Signed-off-by: Lixin Guo <lixinx.guo@intel.com>
2021-12-06 08:06:45 -05:00
Daniel Leung bb595a85f1 kernel: mem_domain: add/remove partition funcs to return errors
This changes both k_mem_domain_add_partition() and
k_mem_domain_remove_partition() to return errors instead of
asserting when errors are encountered. This gives the application
chance to recover.

The arch_mem_domain_parition_add()/_remove() will be modified
later together with all the other arch_mem_domain_*() changes
since the architecture code for partition addition and removal
functions usually cannot be separately changed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-11-22 12:45:22 -05:00
Daniel Leung fb91ce2e21 kernel: mem_domain: init function to return error values
This changes k_mem_domain_init() to return error values
instead of asserting when errors are encountered.
This gives applications a chance to recover if needed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-11-22 12:45:22 -05:00