Commit graph

503 commits

Author SHA1 Message Date
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
Daniel Leung 2ffd49310a tests: mem_protect/mem_protect: more tables for QEMU Cortex A53
For qemu_cortex_a53 on the mem_protect test, the test
test_mem_domain_init_fail() fails due to not having enough
translation tables. However, since ARM64 MMU asserts on such
condition, and k_mem_domain_init() also asserts when fails,
there is no way to distinguish these two assertions at runtime,
thus the test was considered passing. Fix this by allocating
a few more tables so the test will actually fail on
k_mem_domain_init().

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-11-22 12:45:22 -05: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
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
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
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 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
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 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 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
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 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
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 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 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
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
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
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 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 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 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 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
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
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
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
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
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
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
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
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