Commit graph

512 commits

Author SHA1 Message Date
Adithya Baglody 9fad6d9fcd tests: x86_mmu_api: Fixed testcase crash.
Running this testcase on qemu without userspace enabled it
crashes. The testcase was modifing page table information
of the bss region. This in turn caused some variables to be
inaccessible. Fixed it by moving the page manipulation to a
different location.

GH-5646

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-01-18 09:19:06 -08:00
Alberto Escolar Piedras 9851b1ac21 tests: kernel/context support other posix boards
Make it possible to run in other posix boards.
By default, if the POSIX board does not define the TICK_IRQ
just run without that part of the test, printing a note.
The place where other POSIX boards should define it, is also
clear, and should be easy to keep those lines free from merge
conflicts in the future.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-01-15 18:42:09 -05:00
Anas Nashif f88f57b5c2 tests: obj_tracing: disable BT for this test
BT does use a semaphore, which does cause the count of sempahores to
fail, disable BT here to only keep locally created objects.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-15 18:31:47 -05:00
Andrew Boie dff0cb2d65 tests: userbuffer_validate: move and rename
What this test actually does is verify internal APIs for manipulating
the MMU specifically on the X86. It is not compatible with other arches.
Moved to live with the rest of the memory protection tests.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-01-12 13:22:10 -05:00
Anas Nashif 5f42cb1b12 tests: mem_protect: fix README and adapt for cmake
Use built-in macro for build instructions.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-11 12:50:14 -05:00
Adithya Baglody 34b8b3b5ee tests: kernel: fatal: x86: Fixed the issue with stack alignment.
The test case used a stack which was not aligned to 4kB. Hence an
assert was catching this issue.

GH-5539

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-01-09 08:22:05 -05:00
Anas Nashif 829598be2b tests: add CONFIG_TEST for marking tests
Mark tests with CONFIG_TEST to allow for test specific setup and
configuration.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-08 10:03:57 -05:00
Anas Nashif 3858b3c85f tests: minor cleanup of test file headers
Create a doxygen header

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-08 08:08:45 -05:00
Anas Nashif 51e93dd105 tests: remove empty test header
Empty file with no value...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-08 08:08:45 -05:00
Anas Nashif 9b20fa22ac tests: static_idt: do not include test cmake
We should not include test/CMakeLists.txt directly, it is included by
cmake already.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-08 08:08:45 -05:00
Punit Vara 72a5f06ceb tests: obj_tracing: Convert legacy test to ztest
Use ztest API in legacy test to support ztest
framework and also update README according to new
output.

Signed-off-by: Punit Vara <punit.vara@intel.com>
2018-01-05 07:21:32 -05:00
Anas Nashif d872010f93 tests: test sys_kernel_version_get()
Basic test for sys_kernel_version_get verifying macros work correctly
and we get the expected version parts using the macros.

Fixes #4777

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-04 13:29:03 -05:00
Anas Nashif c263f2a208 tests: timer_api: remove build_only, exclude arches
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-28 20:24:29 -05:00
Anas Nashif 38e40427ec tests: kernel: move build test out of kernel
This test has nothing related to kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-28 20:24:29 -05:00
Alberto Escolar Piedras 04c7620580 native: blacklisted 3 testcases
The following 3 testcases are blacklisted for the POSIX
arch / simple_process BOARD:
* tests/drivers/ipm : won't compile due to missing
   __stdout_hook_install()  [part of minimal libc]
  (POSIX arch uses the native libc)
* tests/kernel/mem_protect/stackprot : will crash
  "natively" when trying to corrupt the stack and therefore
  will fail the testcase. The current understanding is that
  the POSIX arch should let the native OS handle faults,
  so they can be debugged with the native tools.
* samples/cpp_synchronization : it is not possible
  to build cpp code yet on top of the posix arch

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras 4494fc93f0 tests: kernel/threads/scheduling fix for native arch
A couple of infinite wait loops fixed for posix arch

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras 59423b2435 test: kernel/critical fix for posix arch
Added small delay in each iteration of the critical_loop
loop for the posix arch:
For this arch this loop and critical_rtn would otherwise
run in 0 time and therefore the test would never finish.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras ccae2bbcd6 test: timer use k_busy_wait()
test/timer/timer_api use k_busy_wait to implement the
tests' busy_wait_ms, for archs which require a different
type of busy waiting

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras 8c9118c2ab test: sleep: fix for posix arch
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras 6f0facc29d test: kernel/tickless fix for native
tests/kernel/tickless/tickless_concept fix in
infinite wait loops for POSIX ARCH

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras ebd87d872d tests: kernel/common : fix for native
fix in busy waits in test/kernel/common for the POSIX
arch

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras c0a5aa6aa3 test: workq : fix for native arch
replaced manual busy wait loop in test with
k_busy_wait()

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras 5f18271ba7 test: sprintf fix for POSIX arch
POSIX arch is not limited to 200 chars in sprintf

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras 309b000eab test: kernel/fatal changes for POSIX
For the POSIX arch we rely on the native OS to handle
segfaults, and stack overflows.
So that we can debug them with normal native tools.
Therefore these 2 are ifdef'ed for this arch in this test

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras 83978989c1 tests: kernel/context posix arch support
allow to compile with posix arch

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif 274ad46a84 kernel: move posix header to posix/
Having posix headers in the default include path causes issues with the
posix port. Move to a sub-directory to avoid any conflicts.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif e2122cbf89 lib: move ring_buffer from misc/ to lib/
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-15 20:02:01 -05:00
Stephen Smalley e3fe3ebb3f tests/kernel/mem_protect/userspace: test access to other thread stack
Add tests of the ability to read or write the stack of another thread.
Use semaphores for explicit synchronization of the start and end of the
other thread to ensure that the attempted stack access occurs while the
thread is alive.  This ensures that the MMU/MPU has been configured at
least once to allow userspace access to the stack, and that any
removal of access upon thread termination has not yet occurred.  This
therefore should exercise changing the MMU/MPU configuration to remove
access to the other thread's stack when switching back to our
thread.

Tested on qemu_x86 (pass) and on frdm_k64f (with and without the ARM
userspace patches; with them, the tests pass; without, they fail as
expected).  Also, as with most of the other tests, if you replace
ztest_user_unit_test() with ztest_unit_test(), then the tests fail as
expected.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-12-14 09:08:19 -08:00
Anas Nashif 23f81eeb42 tests/samples: fixed yaml syntax
Use a map directory, avoid the list which makes parsing a bit
cumbersome.

Fixes #5109

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-11 14:47:08 -05:00
Andy Gross c242c78ec0 tests: kernel: mem_protect: Adjust priv exec tests
This patch removes the extraneous priv_insn test as it is a duplicate
of the following test that writes to the control register.  For ARM,
unprivileged contexts which access control registers does not result
in a fault.  It results in no modification of the register, so we have
to check that a modification occurred.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2017-12-11 10:53:12 -08:00
Andy Gross 6ffdb84b86 tests: kernel: mem_protect: Fix stack size calc
This patch fixes the calculation of the privileged stack portion.  The
ztest threads have a stack size of 2048.  The privileged area resides in
the lowest 512 bytes.  So use the definition of the stack size to get to
the right area.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2017-12-11 10:53:12 -08:00
Anas Nashif f46c0c2472 kconfig: remove deprecated DEBUG_TRACING_KERNEL_OBJECTS
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-09 08:48:51 -06:00
Adithya Baglody a54c1f516f tests: mem_pool: Fixed memory pool test case failure on quark d2000.
Due to insufficient ISR stack memory the irq offload was
corrupting the memory.

GH-4766

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-12-08 07:29:17 -05:00
Anas Nashif abbaac9189 cleanup: remove nanokernel/nano leftovers
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-05 09:44:23 -06:00
Akhilesh Kumar Upadhyay 149c341ec6 tests: kernel: x86 : App to validate x86 specific boot time page table
Testcase developed to validate x86 specific boot time page table faults.

Signed-off-by: Akhilesh Kumar Upadhyay <akhilesh.kumarx.upadhyay@intel.com>
2017-12-05 08:12:45 -05:00
Akhilesh Kumar Upadhyay 3d612b7a8b x86: mmu: kernel: Validate existing APIs
Testcase developed x86mmu specific, to validate
existing  APIs. This checks for the PDE/PTE set
on the address and returns if some violation occurs or not.

Signed-off-by: Akhilesh Kumar Upadhyay <akhilesh.kumarx.upadhyay@intel.com>
2017-12-04 11:26:39 -05:00
Kumar Gala a2caf36103 kernel: Remove deprecated k_mem_pool_defrag code
Remove references to k_mem_pool_defrag and any related bits associated
with mem_pool defrag that don't make sense anymore.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-11-28 15:23:22 -05:00
Stephen Smalley 24076abc6d tests/kernel/mem_protect/userspace: test that _k_neg_eagain is in rodata
Explicitly test that _k_neg_eagain is in rodata.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-11-28 12:29:13 -05:00
Stephen Smalley 2055d7545e tests/kernel/mem_protect/userspace: Add userspace protection tests
This is still work-in-progress, but putting it up in case it is
helpful to people working in this area and for early comments.

Add a set of tests to validate the expected security properties
of threads created with K_USER when CONFIG_USERSPACE=y.  This can
be used as a regression test for architectures that already implement
this support and as a validation test for others.

I considered incorporating these tests into the existing protection
test, but decided against it since protection does not enable or rely
upon CONFIG_USERSPACE for its existing tests and passes on everything
that provides MPU or MMU support, even without full userspace support.

I also considered incorporating these tests into the existing
obj_validation test, but decided against it since obj_validation only
tests the object validation/permission logic, does not run any user
mode threads (or strictly depend on that support), and passes
on both x86 and arm today, unlike these tests.  That said, I have no
strong objections if it would be preferable to fold these into it
(and perhaps rename it to be more general).

The current tests implemented in this test program verify the following
for a thread created with K_USER:

is_usermode: is running in usermode
priv_insn: cannot invoke privileged insns directly
write_control: cannot write to control registers
disable_mmu_mpu: cannot disable memory protections (MMU/MPU)
read_kernram: cannot read from kernel RAM
write_kernram: cannot write to kernel RAM
write_kernro: cannot write to kernel rodata
write_kerntext: cannot write to kernel text
read_kernel_data: cannot read __kernel-marked data
write_kernel_data: cannot write __kernel-marked data
read_kernel_stack: cannot read the kernel/privileged stack
write_kernel_stack: cannot write the kernel/privileged stack
pass_user_object: cannot pass a non-kernel object to a syscall
pass_noperms_object: cannot pass an object to a syscall without a grant
start_kernel_thread: cannot start a kernel (non-user) thread

Some of the tests overlap and could possibly be dropped, but it
seems harmless to retain them.  The particular targets of read/write
tests are arbitrary other than meeting the test criteria and can be
changed (e.g. in data, rodata, or text) if desired to avoid coupling
to kernel implementation details that may change in the future.

On qemu_x86, all of the tests pass.  And, if you replace all
occurrences of ztest_user_unit_test() with ztest_unit_test(), then
all of the tests fail (i.e. when the tests are run in kernel mode,
they all fail as expected).  On frdm_k64f presently (w/o the arm
userspace patches), all of the tests fail except for write_kernro and
write_kerntext, as expected.

ToDo:
- Verify that a user thread cannot access data in another memory domain.
- Verify that a user thread cannot access another thread's stack.
- Verify that a user thread cannot access another thread's kobject.
- Verify that k_thread_user_mode_enter() transitions correctly.
- Verify that k_object_access_revoke() is enforced.
- Verify that syscalls return to user mode upon completion.
- Verify that a user thread cannot abuse other svc calls (ARM-specific).
- Other suggested properties we should be testing?

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-11-28 12:29:13 -05:00
Stephen Smalley 48475ef69b tests/kernel/mem_protect/protection: fix test_main arguments
test_main() takes no arguments, so this was causing a fault
after returning from test_main due to the stack canary checking.

Before, the test run ends with:
PROJECT EXECUTION SUCCESSFUL
***** CPU Page Fault (error code 0x00000011)
Supervisor thread executed address 0x00400000
PDE: 0x027 Present, Writable, User, Execute Enabled
PTE: 0x80000000267 Present, Writable, User, Execute Disable
Current thread ID = 0x00401080
Faulting segment:address = 0x0008:0x00400000
eax: 0x00000000, ebx: 0x00000000, ecx: 0x0040b19c, edx: 0x000056df
esi: 0x00000000, edi: 0x00000000, ebp: 0x000051c0, esp: 0x0040b1d8
eflags: 0x246
Caught system error -- reason 6

After, the test run ends with:
PROJECT EXECUTION SUCCESSFUL

Reported-by: Joshua Domagalski <jedomag@tycho.ncsc.mil>
Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-11-27 13:11:42 -08:00
Punit Vara c7fd8e6343 tests: sleep: convert legacy test to ztest
This patch do following things :
- fix checkpatch warnings
- replace conditions with ztest apis wherever necessary

Signed-off-by: Punit Vara <punit.vara@intel.com>
2017-11-15 09:27:07 -05:00
Punit Vara 9c1622a64a tests: tickless: Make use of ztest framework
Add appropriate ztest APIs to make this legacy test case to
use ztest framework.

Signed-off-by: Punit Vara <punit.vara@intel.com>
2017-11-15 09:25:17 -05:00
Punit Vara 21510d4350 tests: pending: Make use of ztest framework
Add appropriate ztest APIs to make this legacy test case to
use ztest framework.

Signed-off-by: Punit Vara <punit.vara@intel.com>
2017-11-15 09:25:17 -05:00
Punit Vara 33bd43b468 tests: mutex: convert legacy test to ztest
Make legacy test case use of ztest apis to support
ztest framework.

Reduce ztest stack size to 512 otherwise region 'SRAM'
will overflow for nucleo board.

Signed-off-by: Punit Vara <punit.vara@intel.com>
2017-11-15 09:23:42 -05:00
Kumar Gala 805d69c288 tests: protection: Fix building on ARC
Added a case for ARC in the test so it builds.  ARC MPU has execute
permision bit so we can enable the NO_EXECUTE_SUPPORT testing.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-11-15 08:49:53 -05:00
Andrew Boie 02d6c11f1d tests: mheap_api_concept: test k_calloc()
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-14 12:50:10 -08:00
Punit Vara 4a9a0e209a tests: context: convert legacy test to ztest
Use ztest apis in legacy test to support ztest
framework.

Signed-off-by: Punit Vara <punit.vara@intel.com>
2017-11-14 10:02:43 -08:00
Punit Vara eeb4cd24ab tests: work_queue: Convert legacy test to ztest
Make use of ztest apis to support ztest framework.

Signed-off-by: Punit Vara <punit.vara@intel.com>
2017-11-14 10:02:02 -08:00
Punit Vara 1604a9351f tests: timer_monotonic: Migrate legacy test to ztest
Use ztest macros and apis in legacy test to support ztest
framework.

Signed-off-by: Punit Vara <punit.vara@intel.com>
2017-11-14 09:50:12 -08:00
Andy Ross a9f0f445ba tests/kernel/pipe: fix uninitialized semaphore
The end_sema k_sem was only initialized on one of the several paths
that used it, leading to some crazy clobber-the-run-queue behavior
that was dependent on linkage order (see the linked bug) when end_sema
and the pipe object were made non-static..

Adding a k_sem_init() call fixes the corrupt issue, but really the
right thing is to use the DEFINE macro, so do that instead.  Note that
that the initializer changes the linkage order too (by putting the
semaphore in a separate segment), so... yeah, it's actually impossible
to prove that this patch in isolation resolves the issue seen without
manual validation.

Issue: https://github.com/zephyrproject-rtos/zephyr/issues/4366

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2017-11-14 09:47:19 -08:00