Commit graph

2597 commits

Author SHA1 Message Date
Eric Johnson
0916c58c68 tests: kernel: timer: timer_api: Correct one-shot typo
Fixed typos for one-shot to match Zephyr docs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-03-03 10:38:29 +01:00
Enjia Mai
702f89d885 tests: common: add test case for testing errno
Add test case for testing errno, shows it works properly.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-03-02 14:29:58 -05:00
Meng xianglin
80ec588e46 test: thread_api: refine test coverage of thread_api
Add new test cases for some interfaces in thread.c

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes #32572

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-11 14:47:40 -05:00
Andy Ross
95bcba5946 tests/kernel/thread_stack: Fix KERNEL_COHERENCE interactions
Thread stack memory on coherence platforms needs to be linked into a
special section (so it can be cached).

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

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

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

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

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-02-05 08:29:44 -05:00
Andy Ross
4d4a636555 tests/kernel/common: Skip the printk test when not applicable
When CONFIG_LOG_PRINTK is set, the printk hook mechanism doesn't exist
and this test can't pass.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2021-02-03 20:56:14 -05:00
Andy Ross
782c121dd3 tests/sched/deadline: Fix precision rollover
The deadline scheduler as of commit ef626571b2 ("kernel/sched:
Optimize deadline comparison") got an optimization that requires that
the the cycle difference of the deadline time of the "first" and
"last" runnable thread never be higher than 2^31.

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

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

Fixes #31508

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

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

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

Fixes #30434

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

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

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

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

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

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

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

Convert to ticks first before computing the cycle delay needed.

Fixes #29705

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

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

Additionlly, removed LOG_ENABLE_FANCY_OUTPUT_FORMATTING which is no
longer in use.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes #31333

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Just remove it.

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

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

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

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

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

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

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

Fixes #29519

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

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

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

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

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

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

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2020-12-16 14:26:55 +01:00
Watson Zeng
0bc64a7946 tests: tls: add toolchain filter
tls rely on both arch has tls and toolchain support tls, add filter:
CONFIG_TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE for
some tests enabled tls.

Signed-off-by: Watson Zeng <zhiwei@synopsys.com>
2020-12-15 11:22:38 +01:00
Ioannis Glaropoulos
4f4dd9f29f tests: mem_protect: exclude nRF5340 DK from the gap filling test
Modify test .yaml file, to allow the .gap_filling test
variant to execute only on cortex-m33 platforms with
sufficient number of MPU regions. Copy pasting the
configuration from mem_protect/userspace test.

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

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

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

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

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

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

and use PM_ as the prefix for all PM related Kconfigs

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes #24358

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

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

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

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

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

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

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

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2020-12-01 10:14:35 -06:00
Anas Nashif
98981ec05e tests: kernel: do not build on all platforms
build_on_all here was supposed to be a smoke test to test building on
all platforms, it should not be used for more than 1 just test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-11-30 13:10:32 -08:00
Trond Einar Snekvik
7986f94275 kernel: Add K_DELAYED_WORK_DEFINE
Adds a K_DELAYED_WORK_DEFINE, matching the K_WORK_DEFINE macro, with
accompanying Z_DELAYED_WORK_INITIALIZER macro.

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

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

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

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

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

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

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-11-18 08:02:08 -05:00
Meng xianglin
e696c65de1 test: context: Refine descriptions for some test cases
Add or refine comments for some test cases for readability

Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
2020-11-17 22:11:45 -05:00
Enjia Mai
a9bacf552c tests: improve test case descriptions of some interrupt APIs
To add some test case descriptions for testing irq_lock(), irq_unlock()
, irq_enable(), irq_disable().

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

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

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

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

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

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-11-13 14:53:55 -08:00
Martin Åberg
d2409ec0f7 tests: Big endian support in bitfield test
The BIT_INDEX() macro assumed little-endian. This commit adds
big-endian support, conditioned on the preprocessor define
CONFIG_BIG_ENDIAN.

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

Update options and expected results for formatting test.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-11-13 06:38:01 -05:00
Wentong Wu
6221439fbd tests: kernel: syscalls: add more than 6 arguments syscall test case
Add more than 6 arguments syscall test case.

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

Fixes #29654

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

These two tests have been drastically simplified and
combined.

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

Delete this unnecessary test.

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

test_mark_thread_exit_uninitialized no longer occurs twice.

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

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

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

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

Along the way the test code was simplified.

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

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

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

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

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

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

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

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

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

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

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

This reverts commit a4f1a5f58f.

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

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

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

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

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

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

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

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

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

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

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

Also validates some unsuccessful cancel return values.

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

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

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

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

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

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

Fix that by disabling optimization on these functions.

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

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

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

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

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

Add volatile to avoid that.

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

Fixes #28589

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

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

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

New tests for memory domains and partitions:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes #28549

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

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

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

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

Coverity-CID: 212956
Fixes: #27837.

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

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

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

Fixes #28319

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            pos = p_o + 1

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

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

                pos += 1

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

            start = pos
            break

        if irq < 0:
            break

    return db

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

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

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

        subprocess.run(cmd)

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

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

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

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

Finally, some files needed manual fixes such.

Fixes #27399

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

Fixes #27399

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

Fixes #27399

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

A coccinelle rule is used for this:

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

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

Fixes #27399

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

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

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

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

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

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

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

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

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

Fixes #27645
Fixes #27646
Fixes #27648

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

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

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

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

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

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

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

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

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

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

Fixes #26997
Fixes #26998

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

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

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

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

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

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

Fixes: #26984

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

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

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

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

And grep/sed rules for macros:

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

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

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

Fixes #27397

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

@r_device_config@
struct device *D;
@@

D->
-	config_info
+	config

And 2 grep/sed rules for macros:

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

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

Fixes #27397

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

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

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

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

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

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

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

Tested on qemu_x86, qemu_x86_64, reel_board, and iotdk

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

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

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

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

Two new arch defines are introduced:

- ARCH_KERNEL_STACK_GUARD_SIZE
- ARCH_KERNEL_STACK_OBJ_ALIGN

New public declaration macros:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Added detailed Doxygen tag with information about the test

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Also some misc fixes:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

To be addressed in #26163.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A test is added to prove that this works.

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

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

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

This deliberately exercises that race.

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

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

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

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

Fixes #25904

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

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

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

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

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

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

    ZephyrConfig.cmake
    zephyr-config.cmake

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

-- Configuring incomplete, errors occurred!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes #25331

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Fixes: #24744

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

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-30 17:39:27 -04:00
Kumar Gala
b810b4d452 Revert "tests: no need long busy_wait to waste cycles"
This reverts commit 315cba1c40 as it was
causing CI failures for qemu_cortex_m0.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-04-28 20:34:57 -04:00
Wayne Ren
315cba1c40 tests: no need long busy_wait to waste cycles
* no need long busy_wait to waste cycles, especially in
 CI.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2020-04-28 10:48:01 -07:00
Christopher Friedt
d650f4b494 kernel: pipe: fix !K_NO_WAIT and >= min_xfer bytes transferred
If timeout != K_NO_WAIT, then return immediately when not all
bytes_to_read or bytes_to_write have been transfered, but >=
min_xfer have been transferred.

Fixes #24485

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2020-04-28 16:14:55 +02:00
Stephanos Ioannidis
0e6ede8929 kconfig: Rename CONFIG_FLOAT to CONFIG_FPU
This commit renames the Kconfig `FLOAT` symbol to `FPU`, since this
symbol only indicates that the hardware Floating Point Unit (FPU) is
used and does not imply and/or indicate the general availability of
toolchain-level floating point support (i.e. this symbol is not
selected when building for an FPU-less platform that supports floating
point operations through the toolchain-provided software floating point
library).

Moreover, given that the symbol that indicates the availability of FPU
is named `CPU_HAS_FPU`, it only makes sense to use "FPU" in the name of
the symbol that enables the FPU.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-04-27 19:03:44 +02:00
Corey Wharton
d873573f76 tests: fp_sharing: Enable build-only tests for RISC-V QEMU platform
Enables build-only tests for the qemu_riscv32 platform.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-04-22 16:39:48 -07:00
Corey Wharton
c8f7cd5462 kconfig: Make the CPU_HAS_FPU_DOUBLE_PRECISION option global.
This option now applies to the RISC-V architecture and is no longer
a ARM only configuration.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-04-22 16:39:48 -07:00
Corey Wharton
a4a334d3f7 tests: fp_sharing: Enable tests for RISC-V architectures
Enable generic and float_disable tests for RISC-V targets that have
CONFIG_CPU_HAS_FPU enabled.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-04-22 16:39:48 -07:00
Corey Wharton
58232d58e0 riscv: Add support for floating point
This change adds full shared floating point support for the RISCV
architecture with minimal impact on threads with floating point
support not enabled.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-04-22 16:39:48 -07:00
Andy Ross
00e2cce1fc tests/kernel/timer/timer_api: Fix static double-conversion goof
The test of the absolute timeout feature was a simple whitebox test
that inspected the generated ticks field of different constructors for
identity.  But it wasn't simple enough, because it was doing a
ticks->ms->ticks conversion (at compile time, sigh) on the input data,
which is obviously lossy on platforms where ticks are shorter than
milliseconds by non-integral factors.

Fix to do the conversion in just one direction.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-22 17:35:10 +02:00
Andy Ross
cc0db43426 tests/kernel/timer/timer_api: Correct tick math for odd freq timers
This test sets a timer, busy waits for half the duration, and then
checks the remaining time is correct.  And it correctly does all its
math in tick precision and aligns to a timer interrupt to eliminate
aliasing due to the tick stride.

But it's waiting using k_busy_wait(), not a timer: "half the duration"
in MICROSECONDS (for k_busy_wait()) is not necessarily representable
as an integer number of TICKS on all platforms.  Because k_busy_wait()
always rounds up, we need one extra tick of buffer on those platforms.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-22 17:35:10 +02:00
Andy Ross
987658dcee tests/kernel: Fill allocation robustly for mpool heap backend
These five tests (mbox_api, mheap_api_concept, msgq_api, pipe_api and
queue) all had test cases where they needed a mem_pool allocation to
FAIL.  And they are all written to assume the behavior of the original
allocator and not the more general k_heap code, which actually
succeeds in a bunch of these cases.

* Even a very small heap saves enough metadata memory for the very
  small minimum block size, and this can be re-used as an allocation.
  So you can't assume a small heap is full.

* Calculating the number of blocks based on "num_blocks * max size /
  minimum size" and allocating them does not fill the heap, because
  the conservative metadata reservation leaves some space left over.

So these have all been modified to "fill" a heap by iteratively
allocating until failure.

Also, this fixes a benign overrun bug in mbox.  The test code would
insert a "big" message by reading past the end of the small message
buffer.  This didn't fail because it happened to be part of an array
of messages and the other ones defined contained the memory read.  But
still.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-14 10:05:55 -07:00
Andy Ross
91cf6651d8 tests/kernel/mem_pool: Split out tests for legacy mem_pool config
The k_heap backend is now the default for mem_pool, so duplicate these
tests across that config so we continue to have coverage for the older
code.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-14 10:05:55 -07:00
Andy Ross
e582bc128a tests/kernel/mem_pool: Adjust tests to work with k_heap backend
The original k_mem_pool tests were a mix of code that tests routine
allocator behavior, the synchronization layer above that, and a
significant amount of code that made low-level assumptions about the
specific memory layout of the original allocator, which doesn't run
out of memory in exactly the same way.

Adjust the expectations as needed for the backend.  A few test cases
were skipped if they were too specific.  Most have been generalized
(for example, iteratively allocating to use up all memory instead of
assuming that it will be empty after N allocations).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-04-14 10:05:55 -07:00
Anas Nashif
9be6847cc6 tests: critical: change doxygen group
Rename doxygen group to kernel_workqueue_tests

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Anas Nashif
a3ddaf8dbc tests: move critical test under workqueue
This is a workqueue test, so move it where it belongs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Anas Nashif
1825c6f562 tests: put all workqueue test in 1 group
Pun all workqueue tests under 1 doxygen group.

This removes kernel_workqueue_triggered_tests and
kernel_workqueue_delayed_tests doxygen groups.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Anas Nashif
6c8dda4e68 tests: critical: rework test
Cleanup test layout and documentation.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Anas Nashif
b90fafd6a0 kernel: remove unused offload workqueue option
Those are used only in tests, so remove them from kernel Kconfig and set
them in the tests that use them directly.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-12 18:42:27 -04:00
Stephanos Ioannidis
b73622dff0 tests: kernel: fp_sharing: Use ztest
This commit converts the `fp_sharing` tests to use the ztest framework.

In addition, this commit also introduces a behavioural change to run
the `pi` unit test separately from the `load_store` unit test, in order
to allow more manageable and diagnosable test execution.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-04-10 11:43:05 +02:00
Stephanos Ioannidis
74e43a3103 tests: kernel: fp_sharing: Reorganise tests
The `fp_sharing` testsuite consists of two tests: `load_store` and
`pi`.

This commit reorganises the two tests into separate files and refactors
the common parameters into the `test_common.h` header file.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-04-10 11:43:05 +02:00
Carles Cufi
205cf1595e boards: nrf52810_pca10040: Rename to nrf52dk_nrf52810
The board target for emulation of nRF52810 on nRF5DK, so far
known as nrf52810_pca10040, is renamed to nrf52dk_nrf52810.
Its documentation and all references to its name in the tree are
updated accordingly. Overlay and configuration files specific to
this board are also renamed, to match the new board name.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-04-06 13:09:07 +02:00
Stephanos Ioannidis
3a405409c5 tests: kernel: interrupt: Enable nested interrupt test for Cortex-R
This commit enables nested interrupt test for the Cortex-R platforms
that use the ARM Generic Interrupt Controller (GIC).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-04-02 09:22:38 +02:00
Kumar Gala
a5375ead0c tests: Convert to new DT_INST macros
Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-31 19:31:20 -05:00
Andy Ross
4c7b77a716 kernel/timeout: Add absolute timeout APIs
Add support for "absolute" timeouts, which are expressed relative to
system uptime instead of deltas from current time.  These allow for
more race-resistant code to be written by allowing application code to
do a single timeout computation, once, and then reuse the timeout
value even if the thread wakes up and needs to suspend again later.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Andy Ross
cfeb07eded kernel/timeout: Enable 64 bit timeout precision
Add a CONFIG_TIMEOUT_64BIT kconfig that, when selected, makes the
k_ticks_t used in timeout computations pervasively 64 bit.  This will
allow much longer timeouts and much faster (i.e. more precise) tick
rates.  It also enables the use of absolute (not delta) timeouts in an
upcoming commit.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Andy Ross
7832738ae9 kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API
functions were accepting a millisecond timeout argument.  Instead of
forcing milliseconds everywhere (which are often not integrally
representable as system ticks), do the conversion to ticks at the
point where the timeout is created.  This avoids an extra unit
conversion in some application code, and allows us to express the
timeout in units other than milliseconds to achieve greater precision.

The existing K_MSEC() et. al. macros now return initializers for a
k_timeout_t.

The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t
values, which means they cannot be operated on as integers.
Applications which have their own APIs that need to inspect these
vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to
test for equality.

Timer drivers, which receive an integer tick count in ther
z_clock_set_timeout() functions, now use the integer-valued
K_TICKS_FOREVER constant instead of K_FOREVER.

For the initial release, to preserve source compatibility, a
CONFIG_LEGACY_TIMEOUT_API kconfig is provided.  When true, the
k_timeout_t will remain a compatible 32 bit value that will work with
any legacy Zephyr application.

Some subsystems present timeout (or timeout-like) values to their own
users as APIs that would re-use the kernel's own constants and
conventions.  These will require some minor design work to adapt to
the new scheme (in most cases just using k_timeout_t directly in their
own API), and they have not been changed in this patch, instead
selecting CONFIG_LEGACY_TIMEOUT_API via kconfig.  These subsystems
include: CAN Bus, the Microbit display driver, I2S, LoRa modem
drivers, the UART Async API, Video hardware drivers, the console
subsystem, and the network buffer abstraction.

k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant
provided that works identically to the original API.

Most of the changes here are just type/configuration management and
documentation, but there are logic changes in mempool, where a loop
that used a timeout numerically has been reworked using a new
z_timeout_end_calc() predicate.  Also in queue.c, a (when POLL was
enabled) a similar loop was needlessly used to try to retry the
k_poll() call after a spurious failure.  But k_poll() does not fail
spuriously, so the loop was removed.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Andy Ross
32bb2395c2 timeout: Fix up API usage
Kernel timeouts have always been a 32 bit integer despite the
existence of generation macros, and existing code has been
inconsistent about using them.  Upcoming commits are going to make the
timeout arguments opaque, so fix things up to be rigorously correct.
Changes include:

+ Adding a K_TIMEOUT_EQ() macro for code that needs to compare timeout
  values for equality (e.g. with K_FOREVER or K_NO_WAIT).

+ Adding a k_msleep() synonym for k_sleep() which can continue to take
  integral arguments as k_sleep() moves away to timeout arguments.

+ Pervasively using the K_MSEC(), K_SECONDS(), et. al. macros to
  generate timeout arguments.

+ Removing the usage of K_NO_WAIT as the final argument to
  K_THREAD_DEFINE().  This is just a count of milliseconds and we need
  to use a zero.

This patch include no logic changes and should not affect generated
code at all.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Stephanos Ioannidis
1828ea467a tests: kernel: interrupt: Enable nested interrupt test for Cortex-A
This commit enables nested interrupt test for the Cortex-A platforms
that use the ARM Generic Interrupt Controller (GIC).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 19:24:48 +02:00
Stephanos Ioannidis
9b81938c16 tests: kernel: interrupt: Add nested interrupt test for ARM GIC
This commit adds the nested interrupt testing support for the ARM
Generic Interrupt Controller (GIC).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 19:24:48 +02:00
Stephanos Ioannidis
1b8c8e25ff tests: kernel: interrupt: Clean up prevent_irq test
This commit cleans up the "prevent interruption" test and adds a
documentation comment for it.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 13:53:35 +02:00
Stephanos Ioannidis
6820fdf0fb tests: kernel: interrupt: Clean up dynamic_isr test
This commit cleans up the dynamic ISR test and adds a documentation
comment for it.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 13:53:35 +02:00
Stephanos Ioannidis
06e3e40c0c tests: kernel: interrupt: Explain Cortex-M nested interrupt priorities
This commit adds an explanation comment for the interrupt priorities
used by the Cortex-M nested interrupt test.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-31 13:53:35 +02:00
Stephanos Ioannidis
e57da829d7 tests: kernel: interrupt: Do not test interrupt nesting on RISC-V
This commit disables the nested interrupt test for the RISC-V platform,
as interrupt nesting is not supported on the current RISV-C
architecture port.

Furthermore, the current `trigger_irq` implementation for RISC-V is
mostly incorrect and cannot be used, so there is no point in leaving
that in the codebase (see #23593).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-27 13:24:35 -04:00
Stephanos Ioannidis
84921c53b1 tests: kernel: interrupt: Rework nested interrupt test
The current nested interrupt test implementation is both buggy and
fundamentally flawed because it does not trigger a higher priority
interrupt from a lower priority interrupt context and relies on the
system timer interrupt, which is not fully governed by the test;
moreover, the current implementation does not properly validate the
test results and can report success if no interrupt is triggered and
serviced at all.

This commit reworks this test to have the following well-defined
and logical procedure:

1. [thread] Trigger IRQ 0 (lower priority)
2. [isr0] Set ISR 0 result token and trigger IRQ 1 (higher priority)
3. [isr1] Set ISR 1 result token and return
4. [isr0] Validate ISR 1 result token and return
5. [thread] Validate ISR 0 result token

The reworked test scenario ensures that the interrupt nesting works
properly and any abnormal conditions are detected (e.g. interrupts not
triggering at all, or ISR 1 not being nested under ISR 0).

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-27 13:24:35 -04:00
Stephanos Ioannidis
66a53dd5cd tests: kernel: interrupt: Reorganise tests
This commit re-organises the kernel interrupt tests for consistency.

In addition, it removes any references to the `irq_offload` feature,
which is no longer used by this test.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-27 13:24:35 -04:00
Torsten Rasmussen
407b49b35c cmake: use find_package to locate Zephyr
Using find_package to locate Zephyr.

Old behavior was to use $ENV{ZEPHYR_BASE} for inclusion of boiler plate
code.

Whenever an automatic run of CMake happend by the build system / IDE
then it was required that ZEPHYR_BASE was defined.
Using ZEPHYR_BASE only to locate the Zephyr package allows CMake to
cache the base variable and thus allowing subsequent invocation even
if ZEPHYR_BASE is not set in the environment.

It also removes the risk of strange build results if a user switchs
between different Zephyr based project folders and forgetting to reset
ZEPHYR_BASE before running ninja / make.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Ioannis Glaropoulos
5bd906463d tests: kernel: context: in README, fix text for k_cpu_idle testing
We update README file to correct the text for k_cpu_idle
testing, since now we cover the test for both tickless
and non-tickless kernel configuration.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-23 12:10:46 -07:00
Ioannis Glaropoulos
b9c89c0e7f tests: kernel: context: minor style and indentation fixes
Fix some minor style and indentation issues
in tests/kernel/context/src/main.c.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-23 12:10:46 -07:00
Ioannis Glaropoulos
703e8444af tests: kernel: context: test k_cpu_idle for tickless kernel
We fix the kernel.context test, so it tests the
implementation of k_cpu_idle for tickless kernel.
As most platforms now support tickless kernel by
default, this extension of the test is essential
to get coverage on k_cpu_idle() API.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-23 12:10:46 -07:00
Peter Bigot
42f9d14a3f kernel: deprecate k_uptime_delta_32
The documentation motivates this function by saying it is more
efficient than the core 64-bit version.  This was untrue when
originally added, and is untrue now.  Mark the function deprecated and
replace its sole in-tree use with the trivial equivalent.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-03-23 10:26:05 -04:00
Stephanos Ioannidis
dd75bccaca dts: bindings: Fix xlnx,ttcps binding compat
The `xlnx,ttcps` binding, despite having the file name of
`xlnx,ttcps.yaml`, had the compatible property of `cdns,ttc`.

While it is true that the Xilinx ZynqMP platform embeds the Cadence
Triple Timer Counter (TTC) IP core, its TTC differs from the original
Cadence core in that it implements 32-bit counters, instead of the
16-bit counters defined in the original; hence, the Xilinx variant is
not compatible with the original Cadence version and should be treated
as a different device.

This commit changes the `xlnx,ttcps.yaml` compatible property to
`xlnx,ttcps` for the above reasons.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-21 14:20:17 -04:00
Stephanos Ioannidis
f87bce135a test: kernel: context: Exclude for qemu_cortex_r5 (temporary)
The `tests/kernel/context` test fails for the `qemu_cortex_r5` when the
icount emulation mode is used, because the Xilinx QEMU ignores the WFI
instruction when the icount parameter is specified.

This will be fixed in the Zephyr SDK 0.11.3 and this commit must be
reverted once the CI is updated to use this new SDK version.

For more details, see zephyrproject-rtos/sdk-ng#191.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-21 14:20:17 -04:00
Andrew Boie
2dc2ecfb60 kernel: rename struct _k_object
Private type, internal to the kernel, not directly associated
with any k_object_* APIs. Is the return value of z_object_find().
Rename to struct z_object.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-17 20:11:27 +02:00
Andrew Boie
a33a4b0785 tests: profiling_api: fix comments
This uses log_stack_usage() now.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-14 13:10:19 -04:00
Anas Nashif
5b58e61bcb doc: tests: stack: fix doxygen grouping
Add stack tests to kernel test doxygen group.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-03-14 13:01:03 -04:00
Anas Nashif
527bb7b7e2 doc: tests: futex: fix doxygen grouping
Add tests to kernel test group.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-03-14 13:01:03 -04:00
Martí Bolívar
ededeb2736 doc: fix some errors
I've been seeing these cause errors on the more recent versions of
Doxygen which come with Arch Linux for a while now. Fix these:

error: Illegal format for option TCL_SUBST, no equal sign ('=') specified for item 'YES'
$ZEPHYR_BASE/tests/kernel/mem_protect/futex/src/main.c:461: warning: end of file with unbalanced grouping commands

Just trying to get them out of my local output and as preparation for
whenever they start showing up for Ubuntu.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-03-13 11:23:34 -04:00
Andrew Boie
dc7ac32a94 tests: thread_apis: add k_thread_join() tests
Exercise various scenarios from thread and ISR context.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-13 08:42:43 -04:00
Wayne Ren
3ae7c87eb0 tests: the arc issuse is fixed
the arc issue is fixed, remove the filter

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2020-03-12 13:02:17 -04:00
Luiz Augusto von Dentz
2b466a54da tests: work_q: Add assert if k_delayed_work_submit fails in the handler
This makes the tests actually assert if k_delayed_work_submit fails to
resubmit to ensure that not only the work is executed but also no errors
are reported in such case.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-03-11 09:16:15 -04:00
Andrew Boie
c4fbc08347 kernel: fixup thread monitor locking
The lock in kernel/thread.c was pulling double-duty, protecting
both the thread monitor linked list and also serializing access
to k_thread_suspend/resume functions.

The monitor list now has its own dedicated lock.

The object tracing test has been updated to use k_thread_foreach().

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 16:09:24 -04:00
Andrew Boie
9f0acd44a4 kernel: add APIs for atomic os on pointers
The existing APIs are insufficient on 64-bit systems as atomic_t
is 32-bits wide.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:18:16 -04:00
Andrew Boie
60e0019751 kernel: fix return type for atomic_cas()
In some cases this was a bool, in some cases an integer value
of 1 or 0. Standardize on bool.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:18:16 -04:00
Andrew Boie
06d19213c4 tests: interrupt: fix testcase.yaml
The test itself handles correctly whether gen_isr_table
style dynamic interrupts are supported or not, there's
no need for an alternate scenario.

The tests work fine on riscv32 now, remove the exclusion.
Add a github link as to why Nios II is still excluded.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:14:55 -04:00
Andrew Boie
7eb07d1470 tests: interrupt: fix broken scenario
The author of this test case seems to have been under the
mistaken impression that interrupts are locked in ISRs, which
is untrue.

The only reason this ever passed, anywhere, was a race between
the timer firing and the zassert_not_equal() check in
offload_function. If the busy_wait call is moved after the timer
is started, this fails everywhere.

We do not re-use the timer object from the previous case,
resolving some crashes observed on riscv.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:14:55 -04:00
Andrew Boie
921c628f1e tests: interrupt: use one CPU only
The test tries to mask CPU interrupts and then enable a k_timer,
passing if it didn't fire.

This is totally defeated if the interrupt just fires on another
CPU that doesn't have interrupts masked.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-10 10:14:55 -04:00
Wayne Ren
f67592f2e6 tests: enable mpu gap filling tests for arch which supports it
* arc supports mpu gap filling now.
* these tests can be used for any arch which supports mpu gap
  filling.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2020-03-10 11:58:03 +02:00
Ioannis Glaropoulos
61fc061fc4 tests: kernel: userspace: extend bad syscall-ID test-case
Extend the bad syscall-ID test case to cover
erroneously supplied larged unsiged syscall-ID
values.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2020-03-07 09:22:23 +02:00
Andrew Boie
bd8a3bba54 tests: syscalls: add torture test
Hammer all CPUs with multiple threads all making system calls
that do memory allocations and buffer validation, in the hopes
that it will help smoke out concurrency issues.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-02-19 12:19:43 -08:00
Anas Nashif
28298fa06a test: object_tracing: account for pre-existing threads
Count existing threads before the test has started to deal with
platforms that have some existing services.

Remove hard-coded accounting for IPM, this is now counted before the
test starts.

Fixes #21756

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-02-19 00:45:29 -05:00
Luiz Augusto von Dentz
3e4ac40149 tests: work_q: Add tests for resubmit from handler
This adds tests to resubmission from work handler.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-17 22:37:26 +02:00
Luiz Augusto von Dentz
038d727c18 kernel: work: Return error if timeout cannot be aborted
This is aligned with the documentation which states that an error shall
be returned if the work has been completed:

  '-EINVAL Work item is being processed or has completed its work.'

Though in order to be able to resubmit from the handler itself it needs
to be able to distinct when the work is already completed so instead of
-EINVAL it return -EALREADY when the work is considered to be completed.

Fixes #22803

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
2020-02-17 22:37:26 +02:00
Andrew Boie
2c9f42100c tests: syscalls: exclude one case on nsim_sem
This works around an issue with this emulator's configuration where
there is no memory address that can be poked to generate a fault,
it is simulating memory for the entire address space.

Fixes: #22561

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-02-14 09:02:38 -08:00
Stephanos Ioannidis
620f55428d tests: sleep: Increase tick margin for Xilinx QEMU
The Xilinx QEMU, used to emulate the Xilinx ZynqMP platform, is
particularly unstable in terms of timing.

This commit increases the tick margin for the Xilinx ZynqMP platform
from 1 to 5 in order to allow the sleep test to pass with a reasonable
repeatability.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-02-11 08:03:37 -08:00
Stephanos Ioannidis
4a6e3545e9 tests: sleep: Add tick margin definition
This commit introduces the common tick margin definition that can be
used to specify the maximum allowable deviation from the expected
number of ticks.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-02-11 08:03:37 -08:00
Andy Ross
4b670bd4f5 tests/kernel/smp: current CPU is not atomic
This test was whiteboxing the _current_cpu pointer to extract the CPU
ID.  That's actually racy: the thread can be preempted and migrated to
another CPU between the _current_cpu expression and the read of the ID
field.  Do it right.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-02-08 08:51:04 -05:00
Andrew Boie
efc5fe07a2 kernel: overhaul unused stack measurement
The existing stack_analyze APIs had some problems:

1. Not properly namespaced
2. Accepted the stack object as a parameter, yet the stack object
   does not contain the necessary information to get the associated
   buffer region, the thread object is needed for this
3. Caused a crash on certain platforms that do not allow inspection
   of unused stack space for the currently running thread
4. No user mode access
5. Separately passed in thread name

We deprecate these functions and add a new API
k_thread_stack_space_get() which addresses all of these issues.

A helper API log_stack_usage() also added which resembles
STACK_ANALYZE() in functionality.

Fixes: #17852

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-02-08 10:02:35 +02:00
Andy Ross
83d1ca06dc tests/mem_protect/stackprot: Need a delay under SMP
The "alternate thread" test would spawn a thread and then exit the
test, but on SMP that other thread runs asynchronously and it was
possible for the main thread to exit the test entirely before the test
thread had a chance to run (and overflow its stack), leading to
spurious test case failures.

Obviously we can't exactly synchronize to an async crash, so put a
short delay in after spawning the thread.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-02-03 09:31:56 -05:00
Carlo Caione
6f36300219 drivers: timer: Add per-core ARM architected timer
ARM cores may have a per-core architected timer, which provides per-cpu
timers, attached to a GIC to deliver its per-processor interrupts via
PPIs. This is the most common case supported by QEMU in the virt
platform.

This patch introduces support for this timer abstracting the way the
timer registers are actually accessed. This is needed because different
architectures (for example ARMv7-R vs ARMv8-A) use different registers
and even the same architecture (ARMv8-A) can actually use different
timers (ELx physical timers vs ELx virtual timers).

So we introduce the common driver here but the actual SoC / architecture
/ board must provide the three helpers (arm_arch_timer_set_compare(),
arm_arch_timer_toggle(), arm_arch_timer_count()) using an header file
imported through the arch/cpu.h header file.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2020-02-01 08:08:43 -05:00
Jim Shu
e1052a0f8d tests/kernel/fatal: add volatile to prevent compiler optimization
Initialization of local variable 'illegal' can't be optimized, or the
program will jump to the memory contains random value which causes the
unexpected behavior. Add volatile to local variable 'illegal' to prevent
compiler optimization.

Signed-off-by: Jim Shu <cwshu@andestech.com>
2020-01-22 07:08:12 -08:00
Anas Nashif
2711c4e03f tests: test k_sem_init()
Add tests for k_sem_init.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-01-20 17:19:54 -05:00
Anas Nashif
361a84d07f kernel: pipe: runtime error checking
Add runtime error checking to k_pipe_cleanup and k_pipe_get and remove
asserts.
Adapted test which was expecting a fault to handle errors instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-01-20 17:19:54 -05:00
Erwan Gouriou
010e35850e tests/kernel: timer_api: Remove build_only tickless variant
'build_only' directive may not be justified here and
prevent to see issue when running the test.

Similarly to non tickless version exclude qemu_x86_coverage
and qemu_cortex_m0 platforms.
It was actually tested failed on qemu_cortex_m0, no error
reported on qemu_x86_coverage, but removed to be safe on that side
as well.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2020-01-16 07:43:40 -06:00
Andrew Boie
d3314851df tests: userspace: test syscall irq context
Interrupts should not be locked when servicing a system call,
and the kernel should not think we are in an interrupt handler
either.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-16 08:51:16 +01:00
Andrew Boie
a594ca7c8f kernel: cleanup and formally define CPU start fn
The "key" parameter is legacy, remove it.

Add a typedef for the expected function pointer type.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
6f25384e7a tests: userspace: work around x86_64 bug
Exceptions on x86_64 are incorrectly implemented, and if
a preemptible thread faults, and in its overridden
k_sys_fatal_error_handler() does something which invokes
a scheduling point (such as here where we give semaphores),
the thread will be swapped out on the per-CPU exception stack
and probably explode when it is switched back in.

For now, change the faulting thread priority to co-op so this
doesn't happen.

Workaround for #21462

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
b7160c0ee4 tests: dynamic_thread: disable on x86
This doesn't work properly on x86 unless the dynamic thread
struct allocated gets lucky and is aligned to 16 bytes.
Disabling for now until #17893 is fixed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
8b107a8829 tests: mem_protect: use one cpu
Most of the scenarios in this test case spawn child threads
and expect them to complete before execution proceeds.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
d49f413c54 tests: futex: use one cpu
Nearly all of these cases create a child thread that needs
to complete before the main test proceeds further. If the
child thread runs simultaneously on another CPU, this gets
messed up.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Andrew Boie
24ff46c634 tests: userspace: use 1cpu for some cases
This test spawns a child thread and expects it to complete.
Use one CPU for it. Get rid of the useless k_thread_abort()
call and add a k_yield() to ensure the child does its
thing.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-01-13 16:35:10 -05:00
Ulf Magnusson
d4ad36e8d6 tests: userspace: Do not assign promptless THREAD_USERSPACE_LOCAL_DATA
Assignments have no effect on promptless symbols. Flagged by
https://github.com/zephyrproject-rtos/zephyr/pull/20742.

This symbol should already be getting enabled if CONFIG_USERSPACE is
enabled, because CONFIG_ERRNO is default y and has

    select THREAD_USERSPACE_LOCAL_DATA if USERSPACE

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-13 19:04:27 +01:00
Peter Bigot
2597df4965 tests: kernel: timer: fix coverity side expression complaint
Capture the value of the volatile variable outside the assert and use
the captured value in the assert.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-07 08:48:25 -05:00
Ulf Magnusson
7e0af9e0b8 kconfig: Remove redundant $ZEPHYR_BASE from 'source's
The $srctree environment variable is already set to point to the Zephyr
root, so no need to do

    source "$(ZEPHYR_BASE)/Kconfig.zephyr"

in samples. Just

    source "Kconfig.zephyr"

works.

(Things would break if $srctree was set to anything else, because every
'source' in the Kconfig files will be relative to it.)

Also add a 'mainmenu' title to the littlefs sample. It shows up at the
top of menuconfig/guiconfig. Source Kconfig.zephyr instead of Kconfig to
avoid overriding it.

As a sidenote, $(FOO) is better $FOO in Kconfig. $FOO is legacy syntax
that Kconfiglib only supports to be compatible with old Linux kernels.
$(FOO) uses the Kconfig preprocessor.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-01-06 09:48:53 -05:00
Jukka Rissanen
e1b8a2ee7e tests: kernel: poll: Add checks when having zero events
Make sure that we test scenario when number of events is zero.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-01-03 11:26:46 -08:00
Nicolas Pitre
11a1ae5f7a test_pipe_contexts: fix mempool size issue and async pipe coverage
The minimum possible mempool block size is either 8 or 16 for 32-bit or
64-bit targets respectively. Defining BYTES_TO_WRITE to 4 and using that
with K_MEM_POOL_DEFINE() won't produce the expected result i.e. only 1
block at any time could be allocated instead of 4.

Yet, the test does run successfully regardless of the block allocation
loop in tpipe_block_put().

It turns out that the pipe buffer is large enough to consume all the
block data synchronously, meaning that the mempool block is freed right
away and available for the next loop iteration. This also means that the
asynchronous delivery mechanism is never exercized.

Fix both issues by defining PIPE_LEN and BYTES_TO_WRITE in terms of
_MPOOL_MINBLK with the expected factor of 4, and adding a new test
using the half-sized pipe where the pipe buffer gets saturated and
mempool memory blocks are actually queued for asynchronous consumption.

The source data string has to be extended to accommodate larger pipe
sizes too.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-12-20 20:43:01 -05:00
Carlo Caione
aec9a8c4be arch: arm: Move ARM code to AArch32 sub-directory
Before introducing the code for ARM64 (AArch64) we need to relocate the
current ARM code to a new AArch32 sub-directory. For now we can assume
that no code is shared between ARM and ARM64.

There are no functional changes. The code is moved to the new location
and the file paths are fixed to reflect this change.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2019-12-20 11:40:59 -05:00
Andrew Boie
9a9f0ed84a tests: thread_init: disable SMP
This test has a race condition between the start of
its statically initialized threads running on another CPU,
and the assignment of those threads to a memory domain in the
ztest_main() function. Disable SMP for this test.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-18 11:17:33 -08:00
Andrew Boie
a26b9e3dd5 tests: mem_protect: fix cast warning
tc_number is passed to a child thread as a parameter, which is
void *. We want to treat it as an integer, but a direct cast
to int causes a warning on 64-bit platforms; cast to uintptr_t
first to suppress it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-18 11:17:33 -08:00
Andrew Boie
12b76253f6 tests: queue: fix SMP issue
test_queue_supv_to_user() invokes a child thread which does some
work which must take place before the call to k_queue_cancel_wait()
is called by the parent.

However, with SMP enabled, the child thread will just run on another
CPU and we have a race between when child_thread_get() calls
k_queue_get(q, K_FOREVER) and the parent calls k_queue_cancel_wait().
If the parent thread gets there first, the whole test hangs as
the call to k_queue_get(q, K_FOREVER) sits forever.

The fix is to have test_queue_supv_to_user() be a 1cpu test, which
ensures that only one CPU is used.

It's not clear to me why this wasn't causing CI failures on other
SMP targets, but I am able to reproduce reliably on qemu_x86_64
with my user mode patches applied.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-18 11:17:33 -08:00
Mateusz Holenko
93923cb0ba tests: no-multithreading: Disable networking
When networking is selected, building the test
fails with:
undefined reference to `z_impl_k_thread_create'

Signed-off-by: Mateusz Holenko <mholenko@antmicro.com>
2019-12-18 10:35:15 +02:00
Vincent Wan
94140b6816 tests: kernel: gen_isr_table: exclude from testcase.yaml
Excluding this test for cc13x2/cc26x2 platforms where ISR4 is not
available for it to use.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-12-17 13:48:25 -05:00
Alberto Escolar Piedras
0b8678a2b0 samples & tests: Correct main() type
The application main() in Zephyr is defined as having a prototype:
void main(void), as expected by the kernel init (bg_thread_main).

So, correct the different samples and tests that were defined
otherwise.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-12-16 11:27:56 +01:00
Andrew Boie
3b066d4cf5 tests: userspace: fix 64-bit issues
In addition to not assuming all pointers fit in a u32_t,
logic is added to find the privilege mode stack on x86_64
and several error messages now contain more information.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Andrew Boie
3c456fc86a tests: mem_protect: fix corruption issue
This test has a problem, specifically in the scenario for
test_mem_domain_remove_partitions. A low priority thread (10)
is created which is expected to produce an exception. Then
the following happens:

- The thread indeed crashes and ends up in the custom fatal
  error handler, on the stack used for exceptions
- The call to ztest_test_pass() is made
- ztest_test_pass() gives the test_end_signal semaphore
- We then context switch to the ztest main thread which is
  higher priority, leaving the thread that crashed context
  switched out *on the exception stack*
- More tests are run, and some of them also produce exceptions
- Eventually we do a sleep and the original crashed thread is
  swapped in again
- Since several other exceptions have taken place on the
  exception stack since then, resuming context results in
  an unexpected error, causing the test to fail

Only seems to affect arches that have a dedicated stack for
exceptions, like x86_64. For now, increase the priority of
the child thread so it's cleaned up immediately. Longer-term,
this all needs to be re-thought in the test case to make this
less fragile.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Andrew Boie
d27acb9eb6 tests: adjust resource pool sizes for 64-bit
The requests are somewhat larger on 64-bit since we
are allocating structs with pointer members. Increase
these to a larger multiple of the minimum block size.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Andrew Boie
69d47c170e tests: mem_protect: don't cast pointers to u32_t
Use uintptr_t instead. Fixes some 64-bit issues.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Andrew Boie
b5c681071a kernel: don't use u32_t for data sizes
Use a size_t instead.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-12 14:48:42 -08:00
Kumar Gala
a8171db6a6 doc: Fix warnings associated with 'unbalanced grouping commands'
Builds of docs with doxygen 1.8.16 has a number of warnings of the form:
'warning: unbalanced grouping commands'.  Fix those warnings be either
balancing the group command or removing it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-12 12:39:35 -06:00
Peter A. Bigot
c326661ee6 kernel: init: provide access to kernel startup state
Device initialization may require use of generic services such as
starting up power rails, some of which may be controlled by GPIOs on
an external controller that can't be used until full kernel services
are available.  Generic services can check k_is_in_isr() and mediate
their behavior that way, but currently have no way to determine that
the kernel is not available.

Provide a function that indicates whether initialization is still in
pre-kernel stages where no kernel services are available.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-12-11 14:45:40 -08:00
Ulf Magnusson
984bfae831 global: Remove leading/trailing blank lines in files
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.

Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.

Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-11 19:17:27 +01:00
Anas Nashif
1d25eba4fd tests: obj tracing: fix counting
We break out of the while loop on a 2 count then we assert on 2, this
seems to never fail. Count to the end and then assert.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-12-10 10:40:16 -05:00
Anas Nashif
5d94b89512 tests: fifo: assert of NULL from k_fifo_get
Fix Null pointer dereferences.

Fixes #20877
Coverity CID: 205823

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-12-10 10:39:59 -05:00
Kumar Gala
24ae1b1aa7 include: Fix use of <misc/FOO.h> -> <sys/FOO.h>
Fix #include <misc/FOO.h> as misc/FOO.h has been deprecated and
should be #include <sys/FOO.h>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-12-10 08:39:37 -05:00
Anas Nashif
8dd6cd8ec4 tests: kernel: split pending testing
Split long test into 3 sections, once for each object being tested.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-12-09 15:53:44 -05:00
Anas Nashif
70758c4374 tests: fix test identifiers
The seasonal overhaul of test identifiers aligning the terms being used
and creating a structure. This is hopefully the last time we do this,
plan is to document the identifiers and enforce syntax.

The end-goal is to be able to generate a testsuite description from the
existing tests and sync it frequently with the testsuite in Testrail.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-12-09 15:53:44 -05:00
Erwan Gouriou
065a2cb08c tests/kernel: timer_api: Enable Test userspace
timer_api requires TEST_USERSPACE activation which is missing
in tickless configuration of the test.
Enable flag in prj_tickless.cnf

Fixes #20904


Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-12-09 16:40:07 +01:00
Peter Bigot
7e71164cc6 tests: kernel: timer: add test for starvation
Add a test that repeatedly reschedules a timer before it expires, and
has no other timers active.  If the timer internal state overflows due
to counter wrap either the uptime or the tick counter may appear to go
backwards.  The test runs until it fails, or until a specified amount
of measured time has passed.

This test is build-only for automated test programs as the default
limit to pass is one hour, and some platforms may require an even
longer period.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-12-02 15:28:12 +01:00
Ioannis Glaropoulos
7dc061871d tests: kernel: add kernel and sleep tags in tests
Adding kernel tag in tests/kernel/early_sleep and sleep tag
in tests/kernel/sleep. So both early_sleep and sleep suites
have the same tags.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-26 13:34:30 -06:00
Andy Ross
b2435d856a tests/kernel/threads/thread_apis: Add k_thread_suspend() edge cases
Add test cases to make sure that a thread that suspends itself stops
executing immediately, and that a thread suspended while sleeping does
not wake up unexpectedly when its timeout expires.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-25 19:12:05 -05:00
Alberto Escolar Piedras
77006e896b tests: metaIRQ: Ensure counts are not changing in assert evaluation
Coverity's analysis is not happy about using a volatile variable
in an assert, even if the assert is not optionally compiled in.
Avoid the issue by loading the value in an automatic varible before
using it in the assert.

CID: 206016
CID: 206018
CID: 206019
CID: 206021
Fixes: #20968
Fixes: #20966
Fixes: #20965
Fixes: #20963

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-11-25 16:50:04 -05:00
Peter Bigot
e5af53a32f tests: kernel: critical: add output to support diagnostics
As implemented this test runs for 20 s with no output, which makes it
difficult to identify the cause of failure.  Add output indicating
progress, and emit diagnostics a particular failure observed on iMX
boards.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-11-19 15:22:01 -05:00
Wolfgang Puffitsch
138be8e3d8 tests: Add test for MetaIRQ preemption of cooperative thread
Test that meta-IRQ returns to the cooperative thread it interrupted,
and not to whichever thread is highest priority at that point.

Signed-off-by: Wolfgang Puffitsch <wopu@demant.com>
2019-11-15 17:10:36 -05:00
Anas Nashif
28ac1634ef tests: stack: consolidate tests
consolidate both stack test applications into one.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Anas Nashif
7e6cd374ac tests: stack: move stack_usage into stack
Just call it stack instead of stack_usage, preprate for consolidation of
test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Anas Nashif
b396759984 tests: semaphore: consolidate semaphore tests
No need to have two tests for the same thing, just put everything in one
test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Anas Nashif
834b7744ec tests: semaphore: cleanup assert messages
Remove redundant message from asserts.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Anas Nashif
e0f677649a tests: semaphore: cleanup asserts
Remove newline from asserts.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-11-15 08:04:52 -05:00
Ioannis Glaropoulos
01a5ef2b9c tests: stack_random: fix reading volatile variable
Fix coverity issue 20534: read the status of a volatile
variable in an ASSERT statement via a stack variable
declared and defined for this purpose.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-12 07:07:01 -06:00
Peter Bigot
5f34700133 kernel: move time_units into sys subdirectory
This isn't something the user will ever include directory, so take
steps to hide it.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-11-08 18:37:46 -05:00
Andrew Boie
d2b8922fa3 kernel: allow threads to sleep forever
Previously, passing K_FOREVER to k_sleep() would return
immediately.

Forever is a long time. Even if woken up at some point,
we still had forever to sleep, so return K_FOREVER in this
case.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-09 00:36:34 +01:00
Andrew Boie
e09a0255da kernel: sychronize irq_offload() access
Entering irq_offload() on multiple CPUs can cause
difficult to debug/reproduce crashes. Demote irq_offload()
to non-inline (it never needed to be inline anyway) and
wrap the arch call in a semaphore.

Some tests which were unnecessarily killing threads
have been fixed; these threads exit by themselves anyway
and we won't leave the semaphore dangling.

The definition of z_arch_irq_offload() moved to
arch_interface.h as it only gets called by kernel C code.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-08 15:16:43 -08:00
Andy Ross
8892406c1d kernel/sys_clock.h: Deprecate and convert uses of old conversions
Mark the old time conversion APIs deprecated, leave compatibility
macros in place, and replace all usage with the new API.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-08 11:08:58 +01:00
Andy Ross
a63a3e2e48 tests/kernel/timer/timer_api: Add tests for the new conversion routines
The new conversion API has a ton of generated utilities.  Test it via
enumerating each one of them and throwing a selection of both
hand-picked and random numbers at it.  Works by using slightly
different math to compute the expected result and assuming that we
don't have symmetric bugs in both.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-11-08 11:08:58 +01:00
Andrew Boie
4f77c2ad53 kernel: rename z_arch_ to arch_
Promote the private z_arch_* namespace, which specifies
the interface between the core kernel and the
architecture code, to a new top-level namespace named
arch_*.

This allows our documentation generation to create
online documentation for this set of interfaces,
and this set of interfaces is worth treating in a
more formal way anyway.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-07 15:21:46 -08:00
Ioannis Glaropoulos
40fbff6c8f tests: kernel: mem_protect: run tests with ARMV8-M MPU gap filling
We add a new test-case for the mem_protect and userspace tests,
to test the ARMv8-M MPU driver without the skipping of full SRAM
partitioning (i.e. gap filling).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-07 09:41:54 -08:00
Andrew Boie
ec3aafbf78 printk: print pointers on 64-bit properly
Needs a min-width of 16, not 8, for 64-bit.
Some indentation oddities fixed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-06 17:50:34 -08:00
Stephanos Ioannidis
2d7460482d headers: Refactor kernel and arch headers.
This commit refactors kernel and arch headers to establish a boundary
between private and public interface headers.

The refactoring strategy used in this commit is detailed in the issue

This commit introduces the following major changes:

1. Establish a clear boundary between private and public headers by
  removing "kernel/include" and "arch/*/include" from the global
  include paths. Ideally, only kernel/ and arch/*/ source files should
  reference the headers in these directories. If these headers must be
  used by a component, these include paths shall be manually added to
  the CMakeLists.txt file of the component. This is intended to
  discourage applications from including private kernel and arch
  headers either knowingly and unknowingly.

  - kernel/include/ (PRIVATE)
    This directory contains the private headers that provide private
   kernel definitions which should not be visible outside the kernel
   and arch source code. All public kernel definitions must be added
   to an appropriate header located under include/.

  - arch/*/include/ (PRIVATE)
    This directory contains the private headers that provide private
   architecture-specific definitions which should not be visible
   outside the arch and kernel source code. All public architecture-
   specific definitions must be added to an appropriate header located
   under include/arch/*/.

  - include/ AND include/sys/ (PUBLIC)
    This directory contains the public headers that provide public
   kernel definitions which can be referenced by both kernel and
   application code.

  - include/arch/*/ (PUBLIC)
    This directory contains the public headers that provide public
   architecture-specific definitions which can be referenced by both
   kernel and application code.

2. Split arch_interface.h into "kernel-to-arch interface" and "public
  arch interface" divisions.

  - kernel/include/kernel_arch_interface.h
    * provides private "kernel-to-arch interface" definition.
    * includes arch/*/include/kernel_arch_func.h to ensure that the
     interface function implementations are always available.
    * includes sys/arch_interface.h so that public arch interface
     definitions are automatically included when including this file.

  - arch/*/include/kernel_arch_func.h
    * provides architecture-specific "kernel-to-arch interface"
     implementation.
    * only the functions that will be used in kernel and arch source
     files are defined here.

  - include/sys/arch_interface.h
    * provides "public arch interface" definition.
    * includes include/arch/arch_inlines.h to ensure that the
     architecture-specific public inline interface function
     implementations are always available.

  - include/arch/arch_inlines.h
    * includes architecture-specific arch_inlines.h in
     include/arch/*/arch_inline.h.

  - include/arch/*/arch_inline.h
    * provides architecture-specific "public arch interface" inline
     function implementation.
    * supersedes include/sys/arch_inline.h.

3. Refactor kernel and the existing architecture implementations.

  - Remove circular dependency of kernel and arch headers. The
   following general rules should be observed:

    * Never include any private headers from public headers
    * Never include kernel_internal.h in kernel_arch_data.h
    * Always include kernel_arch_data.h from kernel_arch_func.h
    * Never include kernel.h from kernel_struct.h either directly or
     indirectly. Only add the kernel structures that must be referenced
     from public arch headers in this file.

  - Relocate syscall_handler.h to include/ so it can be used in the
   public code. This is necessary because many user-mode public codes
   reference the functions defined in this header.

  - Relocate kernel_arch_thread.h to include/arch/*/thread.h. This is
   necessary to provide architecture-specific thread definition for
   'struct k_thread' in kernel.h.

  - Remove any private header dependencies from public headers using
   the following methods:

    * If dependency is not required, simply omit
    * If dependency is required,
      - Relocate a portion of the required dependencies from the
       private header to an appropriate public header OR
      - Relocate the required private header to make it public.

This commit supersedes #20047, addresses #19666, and fixes #3056.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-11-06 16:07:32 -08:00
Wayne Ren
f8edd95422 tests: Fix the compile warning for arc
the following compile warning will fail the CI:

/zephyr/tests/kernel/fp_sharing/generic/src/float_regs_arc_gcc.h:
41:8: error: /unused variable 'temp' [-Werror=unused-variable]

/zephyr/tests/kernel/fp_sharing/generic/src/float_regs_arc_gcc.h:
75:8: error: /unused variable 'temp' [-Werror=unused-variable]

cc1: all warnings being treated as errors

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-10-30 09:28:28 +01:00
Daniel Leung
b7eb04b300 x86: consolidate x86_64 architecture, SoC and boards
There are two set of code supporting x86_64: x86_64 using x32 ABI,
and x86 long mode, and this consolidates both into one x86_64
architecture and SoC supporting truly 64-bit mode.

() Removes the x86_64:x32 architecture and SoC, and replaces
   them with the existing x86 long mode arch and SoC.
() Replace qemu_x86_64 with qemu_x86_long as qemu_x86_64.
() Updates samples and tests to remove reference to
   qemu_x86_long.
() Renames CONFIG_X86_LONGMODE to CONFIG_X86_64.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-10-25 17:57:55 -04:00
Maksim Masalski
6882d97531 tests: new updated names for the kernel tests
After run Sanitycheck script I found out that some test cases
have the same test case name in the test result .xml file.
To get rid of it, I decided to change test cases names
for the kernel tests.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2019-10-24 06:25:53 -04:00
Maksim Masalski
d85b45b072 tests: updated names for the arch interrupt tests
Test case arch.interrupt have same test case name
for different architectures. To get rid of it,
I decided to change test cases names.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2019-10-23 23:13:13 -04:00
peng1 chen
f20084ff1c Code Coverage: Fix the issue of function code coverage in thread.c
The k_thread_state_str is a new function added into
kernel/thread.c recently which was used to return
the human friendly thread state, so it hasn't been
called by other existing code.
In order to improve the function code coverage, we
just replace the "th->base.thread_state & _THREAD_PENDING"
code by using k_thread_state_str function in
tests/kernel/sched/preempt/src/main.c, because
k_thread_state_str function is realized by judging
the thread_state member to return the thread state.

Signed-off-by: peng1 chen <peng1.chen@intel.com>
2019-10-23 19:16:24 -07:00
Andrei Gansari
b5ed5af8c8 tests: schedule_api adapt to slow ticks
This test case is has a tolerance of 1ms, but systems with a tick slower
than 1000 ticks/sec may spil outside the 1ms tolerance.
Tolerance adapts to system's ticks/sec, e.g. QEMU targets have
100ticks/sec -> tolerance is 10ms.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2019-10-22 23:06:41 -04:00
Andrei Gansari
65fbfbbbff tests: scheduler_api removed MPS2 workaround
CONFIG_SOC_SERIES_MPS2 specific test workaround is removed
to use systick drives as tickless.

Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
2019-10-22 23:06:41 -04:00
Maksim Masalski
9f26f7d3d4 tests: updated names for the kernel tests
After run Sanitycheck script I found out that test cases
had the same test case name in the test result .xml file.
For board itodk in .xml file was duplicated kernel.common test.
To get rid of it, I decided to change test cases names
for the kernel tests, contained name kernel.common.
Now only one test has kernel.common test name,
and will be no duplicated test cases names in the future.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2019-10-22 22:55:35 -04:00
Stephanos Ioannidis
5806787ae1 tests: kernel: Fix incorrect interrupt controller type inference.
The current implementation of kernel interrupt tests incorrectly
infers NVIC, which is specific to Cortex-M, from CONFIG_ARM.

This commit fixes such incorrect NVIC inferences by using
CONFIG_CPU_CORTEX_M instead of CONFIG_ARM.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-10-22 15:07:52 -07:00
Wayne Ren
482b993b88 tests: add the case for ARC in yaml
* add the case for ARC in yaml after dynamic and direct irq are
  supported
* fix the bug that index in sw_isr_table should have a offset of
  CONFIG_GEN_IRQ_START_VECTOR

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-10-21 09:06:17 -07:00
Ioannis Glaropoulos
9375aaebe6 tests: kernel: fatal: add a test-case for arbitrary error reason
We add a test-case in kernel/fatal test suite, to test that
the application developer can induce a SW-generated exception
with any 'reason' value.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-10-16 11:22:48 +02:00
Ioannis Glaropoulos
04c334ad1b tests: kernel: userspace: replace inline assembly with C code
We replace an inline assembly block of code with CMSIS
functions, to make it portable to ARMv6-M architecture.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-10-15 10:06:48 -07:00
Andrew Boie
b7d41a2a94 tests: move boot_page_table test
This is x86-specific.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Andrew Boie
06d3e958a7 tests: move x86_mmu_api test
This is x86-specific.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Andrew Boie
31620b90e2 x86: refactor mmustructs.h
The struct definitions for pdpt, pd, and pt entries has been
removed:

 - Bitfield ordering in a struct is implementation dependent,
   it can be right-to-left or left-to-right
 - The two different structures for page directory entries were
   not being used consistently, or when the type of the PDE
   was unknown
 - Anonymous structs/unions are GCC extensions

Instead these are now u64_t, with bitwise operations used to
get/set fields.

A new set of inline functions for fetcing various page table
structures has been implemented, replacing the older macros.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Andrew Boie
ab4d647e6d x86: mmu: get rid of x86_page_entry_data_t typedef
This hasn't been necessary since we dropped support for 32-bit
non-PAE page tables. Replace it with u64_t and scrub any
unnecessary casts left behind.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Andrew Boie
e3ab43580c x86: move mmustructs.h
This will be used for both 32-bit and 64-bit mode.
This header gets pulled in by x86's arch/cpu.h, so put
it in include/arch/x86/.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-14 11:49:39 -07:00
Nicolas Pitre
923a909db8 tests/mem_pool_threadsafe: use actual minimum mempool block size
On 64-bit targets, the minimum possible mempool block size is not 8
but 16. With a max block size of 32, the mempool allocator cannot
split it into 4 sub-blocks, reducing the available memory allocations
to that original 32-byte block only.

To get the same allocation patterns and test behavior whether it is
built for a 32-bit or 64-bit architecture, let's define BLK_SIZE_MIN
and BLK_SIZE_MAX in terms of _MPOOL_MINBLK instead of literal values.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-10-09 17:45:40 -05:00
Nicolas Pitre
0125cabec7 test_pipe_contexts: don't free memory blocks handed to k_pipe_block_put
Documentation for k_pipe_block_put() says:

  This routine writes the data contained in a memory block to pipe.
  Once all of the data in the block has been written to the pipe,
  it will free the memory block.

Therefore it is wrong to free the memory block within the test code.
When the mempool allocator is instrumented to detect double-free
instances, this case is signaled right away.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-10-09 11:15:46 -07:00
Peter Bigot
e28f330a8e coccinelle: standardize k_thread create/define calls with integer timeouts
Re-run with updated script to convert integer literal delay arguments
to k_thread_create and K_THREAD_DEFINE to use the standard timeout
macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Peter Bigot
6e5db350b2 coccinelle: standardize k_sleep calls with integer timeouts
Re-run with updated script to convert integer literal delay arguments to
k_sleep to use the standard timeout macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Peter Bigot
3423d8b2a4 coccinelle: standardize k_mbox_data_block_get call with timeout
Re-run with updated script to convert integer literal delay arguments to
k_mbox_data_block_get to use the standard timeout macros.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-09 08:38:10 -04:00
Charles E. Youse
12287985fb tests/kernel/smp: make 64-bit clean
Just housekeeping around the casting between void * arguments to
thread functions and integer types.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-10-07 19:46:55 -04:00
Andy Ross
d042a3dac7 tests/kernel/mp: Update the MP test to run on emulated platforms
This was a very early test and got bitrotten inside a esp32-only
whitelist.  Make it run generically.

SMP must be forced off by the test (it's commonly a platform default).

Add a build-time failure when the configuration is single-CPU, for
clarity.

Filter the test likewise so it runs on all supported systems.

Also, the key argument to the CPU startup function is vestigial and
the test was being too strict by requiring it to be non-zero.

Finally, the qemu command line needs to predicate the "-smp" argument
on CONFIG_MP_NUM_CPUS and not just CONFIG_SMP so we have an extra CPU
to test against.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-10-06 12:53:28 -04:00
Andy Ross
6214f81fed tests/kernel/spinlock: No need to use MP API anymore
This test was written very early.  Spinlocks are required for SMP
implementation.  They couldn't be tested in terms of it, so the test
used the low level MP API instead.  But of course that breaks if SMP
is actually working and the CPU is already started.

No need for that now.  Just spawn a thread like any other, and filter
the test to run only on SMP systems.

Fixes #19319

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-10-06 12:53:28 -04:00
Anas Nashif
41a72e4c00 tests: smp: do not whitelist, use filter
Whitelisting is bad, new platforms with this capability would be
missed..

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-10-05 16:13:36 -07:00
Andrew Boie
f0ddbd7eee x86: abstract toplevel page table pointer
This patch is a preparatory step in enabling the MMU in
long mode; no steps are taken to implement long mode support.

We introduce struct x86_page_tables, which represents the
top-level data structure for page tables:

- For 32-bit, this will contain a four-entry page directory
  pointer table (PDPT)
- For 64-bit, this will (eventually) contain a page map level 4
  table (PML4)

In either case, this pointer value is what gets programmed into
CR3 to activate a set of page tables. There are extra bits in
CR3 to set for long mode, we'll get around to that later.

This abstraction will allow us to use the same APIs that work
with page tables in either mode, rather than hard-coding that
the top level data structure is a PDPT.

z_x86_mmu_validate() has been re-written to make it easier to
add another level of paging for long mode, to support 2MB
PDPT entries, and correctly validate regions which span PDPTE
entries.

Some MMU-related APIs moved out of 32-bit x86's arch.h into
mmustructs.h.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-10-04 15:53:49 -07:00
Peter Bigot
66c8756956 coccinelle: standardize kernel API timeout arguments
Re-run with updated script to detect missed cases.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-04 16:23:57 -04:00
Piotr Zięcik
19d8349aa5 kernel: Introduce k_work_poll
This commit adds new k_work_poll interface. It allows to
submit given work to a workqueue automatically when one of the
watched pollable objects changes its state.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-10-04 17:15:17 +02:00
Peter Bigot
ab91eef23b coccinelle: standardize kernel API timeout arguments
Use the int_literal_to_timeout Coccinelle script to convert literal
integer arguments for kernel API timeout parameters to the standard
timeout value representations.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-10-03 11:55:44 -07:00
Andy Ross
bbd910b2e2 tests/kernel/sched/schedule_api: Filter for MULTIQ platforms
This test requires more than 32 static priorities by default, and
doesn't run with the multiq scheduler without a special configuration.
That used to be specified per-platform, but got moved to a separate
test case a while back.

This broke non-default platforms like qemu_cortex_m3 which use
SCHED_MULTIQ as their default backend.  Put a filter in place instead
of going back to per-platform changes.

Fixes #19437

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-10-03 07:26:10 -04:00
Stephanos Ioannidis
b3d6ac2e37 tests: timer_api: Fix duplicate timestamp update.
Remove duplicate "tdata.timestamp" update in duration_expire; this
value is already updated by k_uptime_delta.

Besides simply removing duplicate value update, this commit also
addresses the intermittent assertion failure that is caused by
updating "tdata.timestamp" at a later time than the actual execution
of the k_uptime_delta function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-10-02 21:07:49 -04:00
Ioannis Glaropoulos
85afd0f797 boards: arm: qemu_cortex_m0: filter out a couple of failing tests
We filter out the following kernel tests
- tickless_concept
- timer_api
from the set of tests running on QEMU Cortex-M0 platform,
as the tests consistently fail on QEMU. In addition, we
add a workaround for kernel/interrupt test, so it can
successfully execute on QEMU Cortex-M0.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-10-02 21:06:54 -04:00
Jan Van Winkel
7c07093f66 kernel: tests: Increased TX/RX buf size in pipe test
Increased TX/RX buffer size by one in pipe test to prevent buffer
overrun.

Some test will transfer one byte more then the number of bytes
supported by the pipe, in case the buffer size is the same as the
size of the pipe this will result in a buffer overrun.
Tools such as address sanitizer would detect this overrun and fail the
test.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-10-01 17:56:02 -04:00
Jan Van Winkel
b3ce7cb1c8 kernel: tests: Added header with common declarations
Added header file containing common declarations for tstack,
tstack_size and tdata.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-10-01 09:16:01 -04:00
Andrew Boie
fe031611fd kernel: rename main/idle thread/stacks
The main and idle threads, and their associated stacks,
were being referenced in various parts of the kernel
with no central definition. Expose these in kernel_internal.h
and namespace with z_ appropriately.

The main and idle threads were being defined statically,
with another variable exposed to contain their pointer
value. This wastes a bit of memory and isn't accessible
to user threads anyway, just expose the actual thread
objects.

Redundance MAIN_STACK_SIZE and IDLE_STACK_SIZE defines
in init.c removed, just use the Kconfigs they derive
from.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-09-30 15:25:55 -04:00
Andrew Boie
e1ec59f9c2 kernel: renamespace z_is_in_isr()
This is part of the core kernel -> architecture interface
and is appropriately renamed z_arch_is_in_isr().

References from test cases changed to k_is_in_isr().

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-09-30 15:25:55 -04:00
Anas Nashif
1caab558a1 tests: move intmath test to be unit tests
Move to a unit test, no need to build this for every platform we have.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-09-27 15:23:26 -04:00
Anas Nashif
e9156e04b4 tests: move list test to be unit tests
Move to a unit test, no need to build this for every platform we have.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-09-27 15:23:26 -04:00
Andy Ross
d1200d2155 tests: Never disable SMP
Disabling SMP mode for certain tests was a one-release thing, done to
avoid having to triage every test independently (MANY are not
SMP-safe), and with the knowledge that it was probably hiding bugs in
the kernel.

Turn it on pervasively.  Tests are treated with a combination of
flagging specific cases as "1cpu" where we have short-running tests
that can be independently run in an otherwise SMP environment, and via
setting CONFIG_MP_NUM_CPUS=1 where that's not possible (which still
runs the full SMP kernel config, but with only one CPU available).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-26 16:54:06 -04:00
Andy Ross
49398cfbf6 tests/kernel/sched/schedule_api: Relax preemption order constraints
This test was testing for an undocumented and somewhat hyperspecific
behavior: when a process reaches a reschedule point and yields to a
higher priority thread, and there is another equal priority thread
active, which thread gets to run when the higher priority thread
finishes its work?  The original scheduler (because it leaves the
older thread in place in the list) implements the preemption like an
interrupt and returns to the original thread, despite the fact that
this then resets is time slice quantum unfairly.  In SMP mode, where
the current threads cannot live in the active list, the thread gets
added back to the end of the queue and the other thread runs.  In
effect, in UP mode "yield" and "reschedule" mean very slightly
different things where in SMP they act the same.

We don't document either behavior, as it happens.  Relax the test
constraints by adding a single deliberate k_yield() to unify behavior.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-26 16:54:06 -04:00
Anas Nashif
fc4cb492b5 tests: build kernel/common on all platforms, always
To catch more potential issues with PRs, build common kernel tests
in addition to the synchronization sample which does not run any tests.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-09-25 12:56:32 -04:00
Peter Bigot
d2ad8fca48 tests: exclude platforms with limited flash
Platforms with limited flash are now failing to link.  Add or increase
flash requirements for test cases to exclude the ones that will fail.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-09-23 17:49:46 -07:00
Vincent Wan
2930d000ff tests/kernel/sleep: relax upper bound for TI CC13X2/CC26X2 RTC
The RTC on TI CC13X2/CC26X2 is a 32 KHz clock for which the minimum
compare delay is 3 ticks. When using it as the system clock, we need
to relax the upper bound to ensure the test succeeds.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-09-19 13:43:10 -05:00
Anas Nashif
7912f24bf3 tests: timer_api: exclude qemu_x86_coverage
Test keeps failing when coverage is enabled.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-09-19 09:22:09 -04:00
Vincent Wan
d2edfa2347 tests: fatal: allocate timer outside of stack
In stack_sentinel_timer(), the timer should not be allocated on the
stack. If it gets added to the list of timeouts by k_timer_start,
then an unexpected exception may occur when the timer expires since it
may have been overwritten.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-09-18 13:27:30 +08:00
Charles E. Youse
3038209695 drivers/timer/hpet.c: migrate to devicetree
This driver was still using CONFIG_* values to determine its address,
IRQ, etc. Add a binding for an "intel,hpet" device and migrate this
driver to devicetree.

Fixes: #18657

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-09-17 22:37:09 +08:00
Jan Van Winkel
0ae378e92e tests: kernel: Suppress warnings in intmath tests
Suppress integer overflow warning generated by the check macros
NEG_CHECK and ROLLOVER_CHECK in intmath tests

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-09-17 11:27:19 +02:00
Andrew Boie
c4befd50ab tests: increase min_ram for two tests
These two tests were right at the knife edge of 16kb
on riscv64, and were not building with logging enabled
on that platform.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-09-12 05:17:39 -04:00
Andrew Boie
7819a5a9a8 tests: profiling_api: increase idle stack size
This test for some reason wants to validate that
k_stack_analyze() works when called from the idle thread,
but with a default idle stack size of 256 this just results
in crashes.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-09-12 05:17:39 -04:00
Andy Ross
4723def90d tests/kernel/mem_protect/syscalls: Add cases to test 64 bit arguments
Add some simple tests of the new code generation for syscalls with 64
bit arguments.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-12 11:31:50 +08:00
Andy Ross
6564974bae userspace: Support for split 64 bit arguments
System call arguments, at the arch layer, are single words.  So
passing wider values requires splitting them into two registers at
call time.  This gets even more complicated for values (e.g
k_timeout_t) that may have different sizes depending on configuration.
This patch adds a feature to gen_syscalls.py to detect functions with
wide arguments and automatically generates code to split/unsplit them.

Unfortunately the current scheme of Z_SYSCALL_DECLARE_* macros won't
work with functions like this, because for N arguments (our current
maximum N is 10) there are 2^N possible configurations of argument
widths.  So this generates the complete functions for each handler and
wrapper, effectively doing in python what was originally done in the
preprocessor.

Another complexity is that traditional the z_hdlr_*() function for a
system call has taken the raw list of word arguments, which does not
work when some of those arguments must be 64 bit types.  So instead of
using a single Z_SYSCALL_HANDLER macro, this splits the job of
z_hdlr_*() into two steps: An automatically-generated unmarshalling
function, z_mrsh_*(), which then calls a user-supplied verification
function z_vrfy_*().  The verification function is typesafe, and is a
simple C function with exactly the same argument and return signature
as the syscall impl function.  It is also not responsible for
validating the pointers to the extra parameter array or a wide return
value, that code gets automatically generated.

This commit includes new vrfy/msrh handling for all syscalls invoked
during CI runs.  Future commits will port the less testable code.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-09-12 11:31:50 +08:00
Andrew Boie
9df9994572 x86: fix XIP SOC support and defaults
XIP support in x86 was something of a mess. This
patch does the following:

- Generic ia32 SOC no longer defines a "flash" region
  as generic X86 devices don't have a microcontroller-
  like concept of flash. The same has been done for apollo_lake.
- Generic ia32 and apollo_lake SOCs starts memory at 1MB.
- Generic ia32 SOC may optionally have CONFIG_XIP enabled.
  The board definition must provide a flash region definition
  that gets exposed as DT_PHYS_LOAD_ADDR.
- Fixed definitions for RAM/ROM source addresses in ia32's
  linker.ld when XIP is turned off.
- Support for enabling XIP on apollo_lake SOC removed, there's
  no use-case.
- acrn and gpmrb boards have flash and XIP related definitions
  removed.
- qemu_x86 has a fake flash region added, immediately after system
  RAM, for use when XIP is enabled. This used to be in the ia32 SOC.
  However, the default for qemu_x86 is to now have XIP disabled.
- Fixed tests/kernel/xip to run by default on boards that enable
  XIP by default, plus an additional test to exercise XIP on
  qemu_x86 (which supports it but has XIP switched off by default)

The overall effect of this patch is to:

- Remove XIP configuration for SOC/boards where it does not make
  any sense to have it
- Support testing XIP on qemu_x86 via tests/kernel/xip, but leave
  it off by default for other tests, to ensure it doesn't bit-rot
  and that the system works in both scenarios.
- XIP remains an available feature for boards that need it.

Fixes: #18956

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-09-11 21:11:38 -04:00
Ioannis Glaropoulos
ee74098450 tests: exclude twr_ke18f platform from several user mode tests
Several user mode tests cannot run on twr_ke18f because
either the platform does not have a sufficient number of
MPU regions required for the tests, or, the tests also
require HW stack protection (which has been, by default,
excluded in user mode tests for twr_ke18f board). We
excluded the board from all those tests.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-03 16:44:22 +02:00
Ioannis Glaropoulos
31f8b6f17d tests: kernel: replace CONFIG_USERSPACE with CONFIG_TEST_USERSPACE
This commit replaces several CONFIG_USERSPACE=y
settings with CONFIG_TEST_USERSPACE=y. This allows
the test sub-system Kconfig structure to control
the settings of USERSPACE and HW_STACK_PROTECTION
in the various tests suites.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-09-03 16:44:22 +02:00
Ioannis Glaropoulos
c18ff87c69 tests: kernel: interrupt: stop excluding ARM platforms
As we have re-worked the test code, and the test-case can run
on Cortex-M platforms on any available and implemented NVIC
IRQ lines, we do not need to exclude these ARM boards anymore.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-08-29 13:05:12 +02:00
Ioannis Glaropoulos
e128f3c5d9 tests: kernel: interrupt: make test work with any available NVIC IRQ
This commit re-works the test for the ARM architecture,
so that it can work with any available NVIC IRQ, not
bound to use the last 2 NVIC lines. It makes use of
the dynamic IRQ feature.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-08-29 13:05:12 +02:00
Jukka Rissanen
7c2f063625 tests: kernel: Add unit test for sys_put|get_le64()
Make sure sys_put|get_le64() works as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-28 09:39:56 +02:00
Jukka Rissanen
753600fa71 tests: kernel: Add unit test for sys_put|get_le32()
Make sure sys_put|get_le32() works as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-28 09:39:56 +02:00
Jukka Rissanen
6b1e44a3ed tests: kernel: Add unit test for sys_put|get_le16()
Make sure sys_put|get_le16() works as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-28 09:39:56 +02:00
Jukka Rissanen
a7a5e6912f tests: kernel: Add unit test for sys_put|get_be16()
Make sure sys_put|get_be16() works as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-28 09:39:56 +02:00
Jukka Rissanen
0587b7ecb5 tests: kernel: Add unit test for sys_put|get_be32()
Make sure sys_put|get_be32() works as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-28 09:39:56 +02:00
Jukka Rissanen
0dcc637e7d tests: kernel: Add unit test for sys_put_be64()
Make sure sys_put_be64() works as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-28 09:39:56 +02:00
Jukka Rissanen
bbac6e5ca0 tests: kernel: Add unit test for sys_get_be64()
Make sure sys_get_be64() works as expected.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-08-28 09:39:56 +02:00
Wentong Wu
9d1da7866c tests: kernel: fix unhandled return values.
Fix unhandled return values as most other places handled in this
file, fix coverity issue 203507.

Fixes: #18445.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-08-27 10:01:38 -04:00
Wentong Wu
de4dcb5731 tests: kernel: fix unhandled return values.
Fix unhandled return values as most other places handled in this
file, fix coverity issue 203454.

Fixes: #18443.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-08-27 10:01:38 -04:00
Peter Bigot
243ea2a1e1 tests/kernel/sleep: relax upper bound to support additional delays
Nordic platforms measure ticks in cycles of a 32 KiHz clock for which
the minimum compare delay is 2 ticks.  The test assumed an upper bound
of four ticks delay per loop iteration, resulting from alignment at
various layers.  This delay is met on Nordic for tick rates at or below
16384, but is too short for the default 32768 Hz tick rate.

Instrumentation confirms that the usleep test loop body on Nordic at 32
KiHz ticks takes 3 ticks as the optimum delay, only when a debug probe
is active.  In other circumstances it can take either 5 or 6 ticks,
depending on timer alignment and stability.

Relax the upper bound for platforms using this system timer at the
highest rate.

Closes #17965.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-08-23 14:43:31 +02:00
Andy Ross
b5908fd89d tests/kernel/interrupt: Add a simple dynamic interrupt test
Platforms which use the GEN_SW_ISR mechanism for interrupt handling
can make use of a really simple whitebox trick for verifying that it
worked (i.e. that the pointer and argument get placed in the table
correctly).

Easy and simple way to get some coverage for dynamic IRQs, which is
currently entirely missing.  Long term we'll want to replace this with
a test that uses the API directly and chooses an arch-specific vector
to set, and triggers it using arch-specific code, but that's quite a
bit more effort and for now we need to land patches to
z_irq_connect_dynamic() which show test coverage.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-22 17:53:51 -04:00
Andrew Boie
db48d3e22a sys_sem: add build time definition macros
We need a SYS_SEM_DEFINE() that works just like
K_SEM_DEFINE().

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-08-22 07:38:56 -05:00
Andy Ross
8cdbd1cd0b tests/kernel/common: Fix dead code in sflist test
An inverted comparison typo led to the final loop in the sflist being
skipped.  Fix so that it actually runs.

(Odd that it took a static analysis tool to detect this, the loop
expressions are all constants, I'm surprised gcc didn't see it while
doing unrolling analysis).

Fixes #18437

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-22 07:07:31 -04:00
Andy Ross
ca82230780 tests/kernel/fp_sharing: Fix static analysis warning
Can't use a volatile variable in something that the tool thinks is an
optional assert, because the read is treated as a side effect.

Fixes #18438
Fixes #18439

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-22 07:07:31 -04:00
Andy Ross
28fc46ee09 tests/kernel/sched/schedule_api: Fix static analysis volatile warning
We were testing the value of a volatile variable inside a zassert,
which static analysis doesn't like.  In principle, it might be
volatile because it's an MMIO register or something and the read is a
side effect, and an assertion will be optionally compiled.  (Except
here the value is just regular memory marked volatile for
threadsafety, and zassert will never be elided in a test, but the tool
doesn't know that).

Refactor a little so we always read the variable in a way the tool can
detect is consistent.

Fixes #18446

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-08-21 15:53:50 +02:00
Andrew Boie
f31e492440 tests: fatal: increase robustness
We now verify, for every crash, that the expected thread
crashed with the expected reason.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-08-19 15:38:51 -05:00
Carles Cufi
ac442203bb tests: kernel: mutex: Require 32kB RAM when building with USERSPACE
The sys_mutex test doesn't seem to fit in 24kB of RAM anymore,
when building with user mode support (CONFIG_USERSPACE=y). We,
therefore, restrict it to platforms that have 32KB or more of
RAM. We also filter the test with ARCH_HAS_USERSPACE explicitly.

The alternative setup of the sys_mutex test, i.e. without user
mode support (CONFIG_TEST_USERSPACE=n) continues to build for
platforms with less than 32k of RAM.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-08-15 20:01:05 -05:00
Wayne Ren
c78be56f0f tests: enable hsdk and nsim_hs_smp for smp test
ARC now supports SMP, enable the kernel/smp test
for arc platforms

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-08-11 21:18:38 +02:00
Wendy Liang
4ef9d4b6bf timer: Add Xilinx ZynqMP PS ttc timer
Add Xilinx PS ttc timer for Xilinx ZynqMP platform.

Signed-off-by: Wendy Liang <wendy.liang@xilinx.com>
2019-08-09 22:50:50 +02:00
Wayne Ren
73df065616 tests: remove the exception for arc
the tested feature is supported now, remove the exception

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-08-09 20:11:58 +02:00
Ioannis Glaropoulos
8dc83c1d94 tests: several tweaks for passing tests on qemu
This commit includes tweaks in several tests, so
that the tests can be passing on ARM QEMU targets,
mps2_an385 and mps2_an521 with Qemu 4.x release.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-08-08 21:56:45 +02:00
Nicolas Pitre
af1510d3bb tests: fatal: make sure the illegal insn occupies a full word
... and is properly aligned. This may make a difference on
64-bit targets.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-08-07 08:12:56 -05:00
Andrew Boie
f2422f1f19 tests: clean up fatal error handlers
- k_sys_fatal_error_handler() can return on all platforms,
  indicating that the faulting thread should be aborted.
- Hang the system for unexpected faults instead of trying
  to keep going, we have no idea whether the system is even
  runnable.

Prevents infinite crash loops during tests.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-08-06 19:32:22 -07:00
Yasushi SHOJI
1fe8269399 test: kernel: sched: Add a test for nested scheduler lock
Add a new test for unlocking nested scheduler lock.  Make sure that
k_sched_unlock() isn't unconditionally a preemption point.

Signed-off-by: Yasushi SHOJI <y-shoji@ispace-inc.com>
2019-08-06 10:19:50 +02:00
Andrew Boie
8014e075f4 x86: use per-thread page tables
Previously, context switching on x86 with memory protection
enabled involved walking the page tables, de-configuring all
the partitions in the outgoing thread's memory domain, and
then configuring all the partitions in the incoming thread's
domain, on a global set of page tables.

We now have a much faster design. Each thread has reserved in
its stack object a number of pages to store page directories
and page tables pertaining to the system RAM area. Each
thread also has a toplevel PDPT which is configured to use
the per-thread tables for system RAM, and the global tables
for the rest of the address space.

The result of this is on context switch, at most we just have
to update the CR3 register to the incoming thread's PDPT.

The x86_mmu_api test was making too many assumptions and has
been adjusted to work with the new design.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-08-05 13:25:50 +02:00
Nicolas Pitre
1f4b5ddd0f riscv32: rename to riscv
With the upcoming riscv64 support, it is best to use "riscv" as the
subdirectory name and common symbols as riscv32 and riscv64 support
code is almost identical. Then later decide whether 32-bit or 64-bit
compilation is wanted.

Redirects for the web documentation are also included.

Then zephyrbot complained about this:

"
New files added that are not covered in CODEOWNERS:

dts/riscv/microsemi-miv.dtsi
dts/riscv/riscv32-fe310.dtsi

Please add one or more entries in the CODEOWNERS file to cover
those files
"

So I assigned them to those who created them. Feel free to readjust
as necessary.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-08-02 13:54:48 -07:00
Wayne Ren
8b04c7de13 arch: arc: optimize the float support
* enable float support
* implement z_arch_float_disable
* add arc support in fp_sharing test

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-08-01 18:09:35 -07:00
Ioannis Glaropoulos
1b97691713 tests: kernel: userspace: fix test skipping for ARC
This commit is a hotfix. It makes sanitycheck happy by fixing
the way we can temporarily exclude some tests in the userspace
test suite for the ARC architecture.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-30 10:12:47 -07:00
Anas Nashif
578ae40761 boards: remove quarl_se_c1000
This board and SoC was discontinued some time ago and is currently not
maintained in the zephyr tree.
Remove all associated configurations and variants from the tree.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-07-29 21:30:25 -07:00
Anas Nashif
a597c86c30 boards: remove galileo board
This board and SoC was discontinued some time ago and is currently not
maintained in the zephyr tree.
Remove all associated configurations and variants from the tree.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-07-29 21:30:25 -07:00
Andrew Boie
55fce980d7 tests: z_except_reason() policy from usermode
User mode should be able to successfully induce a kernel
oops, or stack check fail fatal error. The latter is
required by compiler stack canaries.

User mode should not be able to induce a kernel panic, or
fake some other kind of exception.

Currently supported on ARM and x86 platforms.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-29 11:08:49 -07:00
Andrew Boie
96571a8c40 kernel: rename NANO_ESF
This is now called z_arch_esf_t, conforming to our naming
convention.

This needs to remain a typedef due to how our offset generation
header mechanism works.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-25 15:06:58 -07:00
Andrew Boie
fe8d75acbf arm: fix exception reason code for bad syscall
ARM was reporting as a CPU exception and not a kernel
oops.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-25 15:06:58 -07:00
Andrew Boie
71ce8ceb18 kernel: consolidate error handling code
* z_NanoFatalErrorHandler() is now moved to common kernel code
  and renamed z_fatal_error(). Arches dump arch-specific info
  before calling.
* z_SysFatalErrorHandler() is now moved to common kernel code
  and renamed k_sys_fatal_error_handler(). It is now much simpler;
  the default policy is simply to lock interrupts and halt the system.
  If an implementation of this function returns, then the currently
  running thread is aborted.
* New arch-specific APIs introduced:
  - z_arch_system_halt() simply powers off or halts the system.
* We now have a standard set of fatal exception reason codes,
  namespaced under K_ERR_*
* CONFIG_SIMPLE_FATAL_ERROR_HANDLER deleted
* LOG_PANIC() calls moved to k_sys_fatal_error_handler()

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-25 15:06:58 -07:00
Wentong Wu
d4e580c6c9 tests: add test cases for sys_sem
add test cases for sys_sem data structure.

Fixes: #15139.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-07-24 10:12:25 -07:00
Piotr Zięcik
285bfa7f62 tests: work_queue_api: Fix k_delayed_work_remaining_get() test
Existing test checking value returned by k_delayed_work_remaining_get()
verified two cases:

1) The k_delayed_work_remaining_get() should return 0 for non-submitted
   work.

2) The k_delayed_work_remaining_get() should return value greater or
   equal to the timeout value of just submitted work.

Unfortunately, the second check is not correct. The value returned
by the k_delayed_work_remaining_get() just after submitting delayed
work should be:

- Equal to timeout of the submitted work if no timer interrupt was
  executed between submitting work and checking remaining time.

  OR

- Less than timeout of the submitted work if a timer interrupt was
  executed between submitting work and checking remaining time.

This commit changes the test accordingly taking under account the
error caused by back and forth conversion between ms and ticks.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-07-23 13:54:39 +02:00
Ioannis Glaropoulos
6c4fdc61ef tests: kernel: fp_sharing: increase robustness of float_disable test
This commit make the float_disable test suite more robust
for fast CPUs, by replacing k_sleep(1) with k_yield(), as
the mechanism to trigger thread swap-out during the test
execution. In the wake of using k_yield(), the test, now,
fixes the priorities of all testing threads to 0, making
the test behavior more deterministic with respect to
thread scheduling. The patch doesn't change the functional
behavior of the test.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-19 12:11:38 +02:00
Andrew Boie
15b1196e58 tests: force stack canaries off for two user tests
Stack canaries require that the z_libc_partition be added to
the memory domain, otherwise user thread access to the
stack canary value will result in an MPU/MMU fault.

These tests define their own domains to test specific userspace
features. Adding another partition to them would be invasive,
would potentially break some platforms with a limited number
of MPU regions, and these tests are not designed to validate
stack canaries anyway, we have other tests for that.

Fixes: #17595

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-17 09:32:07 -07:00
Nicolas Pitre
6609c12516 tests: enable native_posix_64 testing
Whenever conditions are applied to native_posix, they should apply to
native_posix_64 too.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-16 10:41:11 -07:00
Nicolas Pitre
0aa796cbaa print format: adjust specifiers to be compatible with a 64-bit build
The size_t type is either compatible with an int on 32-bit target, or
a long on 64-bit targets. It could even be a long even on some 32-bit
targets. Let's use the z qualifier in the printf format to be compatible
with whatever flavor in use.

In case of pointers, let's just use %p with pointers directly and
avoid casts altogether.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-11 20:12:26 -07:00
Ioannis Glaropoulos
3b28297003 tests: kernel: critical: alternative test-case for SAM SoCs with WDT
In SAM SoCs Watchdog is selected by default and runs
with some default configuration, unless the build sets
CONFIG_WDT_DISABLE_AT_BOOT. As the tests/kernel/critical
takes relatively large amount of time to complete, the
watchdog (that is never fed in the test) will eventually
trigger a reset. As a result the test keeps restarting
continuously and never completes. We want to run the
test on SAM SoCs, so we do the following:
- filter our the SAM SoCs with the SAM WDT from the
  default build
- introduce an alternative test-case for these SoCs
  with the additional CONFIG_WDT_DISABLE_AT_BOOT
  option set.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-11 11:26:01 -05:00
Ioannis Glaropoulos
4476ae00d2 tests: kernel: fp_sharing: add test for k_float_disable
This commit contributes the basic testing for
k_float_disable() API, for ARM and x86 ARCHes.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-10 13:44:02 -07:00
Ioannis Glaropoulos
3d3a8c554f tests: kernel: fp_sharing: move fp_sharing test
Make fp_sharing a 'parent' test suite directory, and
rename the original fp_sharing test into
tests/kernel/fp_sharing/generic. In this
way more FP-related tests can be grouped
together in the same test directory.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-10 13:44:02 -07:00
Ioannis Glaropoulos
3717c6b3dc tests: arch: x86: move static_idx under tests/arch/x86
Move the x86-specific static_idx test under
tests/arch/x86 subdirectory.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-09 09:53:44 -07:00
Ioannis Glaropoulos
14797354c4 tests: kernel: move arm-specific kernel tests under tests/arch/arm
This commit moves the arm-specific tests in 'tests/arch/arm'
subdirectory.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-09 09:53:44 -07:00
Anas Nashif
528a2de290 tests: schedule_api: minor cleanup
rename test function and move #if to the start of the line.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-07-04 10:04:27 -04:00
Nicolas Pitre
922c7ec546 test/msgq: adjust overflow test for 64-bit targets
This is testing size_mul_overflow() in z_impl_k_msgq_alloc_init() so
make sure OVERFLOW_SIZE_MSG is large enough even on 64-bit targets.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-04 07:22:43 -04:00
Charles E. Youse
b4316fef48 arch/x86: eliminate arch/x86/include/asm_inline.h
Over time, this has been reduced to a few functions dealing solely
with floating-point support, referenced only from core/ia32/float.c.
Thus they are moved into that file and the header is eliminated.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-07-03 20:01:17 -04:00
Charles E. Youse
7c2d7d7b69 arch/x86: move arch/x86/include/mmustructs.h to ia32/mmustructs.h
For now, only the 32-bit subarchitecture supports memory protection.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-07-03 20:01:17 -04:00
Nicolas Pitre
39cd2ebef7 malloc: make sure returned memory is properly aligned
The accounting data stored at the beginning of a memory block used by
malloc must push the returned memory address to a word boundary. This
is already the case on 32-bit systems, but not on 64-bit systems where
e.g. struct k_mem_block_id still has a size of 4.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-03 14:17:29 -07:00
Andrew Boie
3c8fa37a10 tests: fp_sharing: properly dump coverage data
This was dumping coverage before the test code even ran.
Ideally, this gets re-written to use ztest, but meanwhile
place a dummy main thread which sleeps forever, and dump
coverage once the test succeeds.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-03 07:19:49 -07:00
Andrew Boie
65e658b578 tests: fatal: test failed assertion
Covers assert_post_action() which was previously uncovered.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-02 22:57:14 -04:00
Andy Ross
03164a7802 tests/kernel/workq/work_queue: Fix for fast/non-standard tick rates
This test was written to properly align its millisecond-measured wait
time and assumed that there would be no other overhead.  In fact on
fast tick rate systems (or even ones where the alignment computation
doesn't provide the needed padding as "slop") that's not quite enough
time to complete the full test.  There are cycles between the sleep
calls that need to be accounted for, and aren't.

Just give it one extra work item of time before failing.  We aren't
testing work queue timing precision here, just evaluation semantics.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Andy Ross
5238f5b97e tests/kernel/early_sleep: Fix for fast ticks
"50" ticks is fine with 100 Hz timer precision but way too short to
survive the conversion to milliseconds on fast, non-decimal tick
rates.  Make it half a second, which was the original intent.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Andy Ross
fc392a2c75 tests/kernel/tickless/tickless_concept: Force 100 Hz ticks
This test was written to assume ~100 Hz ticks in ways that are
difficult to fix.  It wants to sleep for periods on the order of the
TICKLESS_IDLE_THRESH kconfig, which is extremely small on high tick
rate systems and (on nRF in particular) does not have a cleanly
divisible representation in milliseconds.

Fixing precision issues by cranking the idle threshold up on a
per-system basis seems like an abuse, as that is what we want to be
testing in the first place.  Just let the test run at the tick rate it
has always expected.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Andy Ross
b1280108a2 tests/kernel/sleep: Fix usleep test for fast ticks
The logic about minimal sleep sizes due to "tick" aliasing was
correct, but drivers also have similar behavior with "cycle" aliasing
too.  When cycles are 3-4 orders of magnitude faster than ticks, it's
undetectable noise.  But now on nRF they're exactly the same and we
need to correct for that, essentially doubling the number of ticks a
usleep() might wait for.

The logic here was simply too strict, basically.  Fast tick rates
can't guarantee what the test promised.

Note that this relaxes the test bounds on the other side of the
equation too: it's no longer an error to usleep() for only one tick
(i.e. an improved sleep/timeout implementation no longer gets detected
as a test failure).

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Andy Ross
f4803bf117 tests/kernel/context: Fix sleep test for fast ticks
The sleep test was checking that the sleep took no longer than "2
ticks" longer than requested.  But "2 ticks" for fast tick rate
configurations can be "zero ms", and for aliasing reasons it's always
possible to delay for 1 unit more than requested (becuase you can
cross a millisecond/tick/whatever boundary in your own code on either
side of the sleep).  So that "slop" value needs to be no less than
1ms.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Andy Ross
8bd8663bb3 tests/kernel/common: Fix uptime delta test for fast ticks
The test for the k_uptime_delta utilities was calling it in a loop and
waiting for the uptime to advance.  But the code was specifically
wanting it to advance 5ms or more at one go, which clearly isn't going
to work for a tick rate above 200 Hz.

The weird thing is that the test knew this and even commented about
the limitation.  Which seems silly: it's perfectly fine for the clock
to advance just a single millisecond.  That's correct behavior too.
Let's test for that, and it will work everywhere.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Andy Ross
e019dac776 tests/kernel/sched/schedule_api: Fix slice time test for fast ticks
When ticks are sub-millisecond, the math produces minimum and maximum
values for the slice duration test that are equal.  But because of
aliasing across tick boundaries, it's always possible (for any time
period, nothing specific to time slicing here) to measure one tick
more than an intended duration.  So make sure there's always at least
a range of 1ms.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Andy Ross
f288d1e4a7 tests: samples: Apps shouldn't set tick rate
Tick rate is becoming a platform tunable in the tickless world.  Some
apps were setting it due to requirements of drivers or subsystems (or
sometimes for reasons that don't make much sense), but the dependency
goes the other way around now: board/soc/arch level code is
responsible for setting tick rates that work with their devices.

A few tests still use hard-configured tick rates, as they have
baked-in assumptions (like e.g. "a tick will be longer than a
millisecond") that need to be addressed first.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Andy Ross
b696c3e469 tests/kernel/mem_pool: Fix timeout units
This code was clearly written to assume that the timeout argument to
k_mem_pool_alloc() was in ticks and not ms.  Adjust to what appears to
have been the intent.  It was working as intended (i.e waiting one or
1/10th of a second) only on systems where the default tick rate was
100 Hz.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Nicolas Pitre
ace11bbefd mempool: make sure max block size isn't smaller than minimum allowed
If maxsize is smaller than _MPOOL_MINBLK, then Z_MPOOL_LVLS() will be 0.
That means the loop in z_sys_mem_pool_base_init() that initializes the
block free list for the nonexistent level 0 will corrupt whatever memory
at the location the zero-sized struct sys_mem_pool_lvl array was
located. And the corruption happens to be done with a perfectly legit
memory pool block address which makes for really nasty bugs to solve.

This is more likely on 64-bit systems due to _MPOOL_MINBLK being twice
the size of 32-bit systems.

Let's prevent that with a build-time assertion on maxsize when defining
a memory pool, and adjust the affected test accordingly.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-02 19:41:20 -07:00
Charles E. Youse
930e6af999 arch/x86: move include/arch/x86/segmentation.h to ia32/segmentation.h
This header is currently IA32-specific, so move it into the subarch
directory and update references to it.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-07-02 19:30:00 -04:00
Charles E. Youse
dff016b53c arch/x86: move include/arch/x86/arch.h to ia32/arch.h
Making room for the Intel64 subarch in this tree. This header is
32-bit specific and so it's relocated, and references rewritten
to find it in its new location.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-07-02 19:30:00 -04:00
Charles E. Youse
6f3009ecf0 arch/x86: move include/arch/x86/asm.h to include/arch/x86/ia32/asm.h
This file is 32-bit specific, so it is moved into the ia32/ directory
and references to it are updated accordingly.

Also, SP_ARG* definitions are no longer used, so they are removed.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-07-02 19:30:00 -04:00
Andrew Boie
b52abfe225 tests: schedule_api: cover priority checks
Some cases, such as for the idle thread, were uncovered.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-02 18:44:11 -04:00
Andrew Boie
38129ce1a6 kernel: fix CONFIG_THREAD_NAME from user mode.
This mechanism had multiple problems:

- Missing parameter documentation strings.
- Multiple calls to k_thread_name_set() from user
  mode would leak memory, since the copied string was never
  freed
- k_thread_name_get() returns memory to user mode
  with no guarantees on whether user mode can actually
  read it; in the case where the string was in thread
  resource pool memory (which happens when k_thread_name_set()
  is called from user mode) it would never be readable.
- There was no test case coverage for these functions
  from user mode.

To properly fix this, thread objects now have a buffer region
reserved specifically for the thread name. Setting the thread
name copies the string into the buffer. Getting the thread name
with k_thread_name_get() still returns a pointer, but the
system call has been removed. A new API k_thread_name_copy()
is introduced to copy the thread name into a destination buffer,
and a system call has been provided for that instead.

We now have full test case coverge for these APIs in both user
and supervisor mode.

Some of the code has been cleaned up to place system call
handler functions in proximity with their implementations.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-01 16:29:45 -07:00
Ioannis Glaropoulos
f3f3dc8768 tests: kernel: fatal: run test for ARMv8-M with MPU stack guards
HW stack protection in ARMv8-M is implemented by default
with the built-in stack guard mechanism. Therefore, by
default all tests for ARMv8-M will use the built-in stack
overflow mechanism (CONFIG_BUILTIN_STACK_GUARD is set in
tests). However, we would like have some coverage on the
MPU stack guard mechanism for ARMv8-M. The added test case
manually disables BUILTIN_STACK_GUARD and enables the
MPU_STACK_GUARD option, to provide that test coverage.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-01 12:54:20 -07:00
Ioannis Glaropoulos
e8f2d86d94 tests: remove redundant CONFIG_HW_STACK_PROTECTION=y setting
CONFIG_TEST_HW_STACK_PROTECTION is set by default in tests,
and that one selects HW_STACK_PROTECTION option. Therefore,
we do not need to set that one explicitly in the test project
configuration files. We clean up some redundant occurrences of
CONFIG_HW_STACK_PROTECTION=y from the tree.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-07-01 12:54:20 -07:00
Andrew Boie
058ebe69c3 tests: common: add tests for extra sflist APIs
sflists have a couple APIs related to sfnodes that aren't
present for slists. There were uncovered, write some tests
for them.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-01 08:25:25 -07:00
Andrew Boie
a744501a7d kernel: test coverage for sflist
We were testing all the slist APIs, but not the sflist
variant. Make a copy of the slist tests for sflist,
with the names properly changed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-01 08:25:25 -07:00
Andrew Boie
b6e4f91069 lib: os: fix slist code coverage
Some of the slist APIs were only being indirectly exercised;
add to the slist test case to cover everything explicitly.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-01 08:25:25 -07:00
Andrew Boie
8753becbe1 kernel: delete k_futex_init()
There's no need for a system call for this; futexes live in
user memory and the initialization bit is ignored.

It's sufficient to just do an atomic_set().

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-01 08:15:10 -07:00
Andrew Boie
06d7746cd2 kernel: cover k_array_index_sanitize()
Needed an explicit test for this function for code
coverage purposes; we were relying indirectly on
other code using it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-30 09:22:09 -04:00
Andrew Boie
e8092894a1 tests: futex: improve coverage
Error cases weren't being tested; bring up coverage for
kernel/futex.c up to 100% file/function/branch.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-30 09:18:47 -04:00
Andrew Boie
0b0294d682 kernel: cover k_usleep() from user mode
No test was exercising the k_usleep() system call, run
the test case as a user thread to fix code coverage.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-29 20:55:07 -07:00
Andrew Boie
ca3549d9f5 tests: sys_mutex: improve code coverage
Test error cases and alternative implementation to bring code
coverage up to 100% file / 100% line.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-29 13:31:14 -07:00
Anas Nashif
5b0aa794b2 cleanup: include/: move misc/reboot.h to power/reboot.h
move misc/reboot.h to power/reboot.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
efb8df5366 cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
0c9e280547 cleanup: include/: move misc/mutex.h to sys/mutex.h
move misc/mutex.h to sys/mutex.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
08ee8b09ba cleanup: include/: move misc/mempool.h to sys/mempool.h
move misc/mempool.h to sys/mempool.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
ee9dd1a54a cleanup: include/: move misc/dlist.h to sys/dlist.h
move misc/dlist.h to sys/dlist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
5d001f3e41 cleanup: include/: move misc/byteorder.h to sys/byteorder.h
move misc/byteorder.h to sys/byteorder.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
190e368275 cleanup: include/: move power.h to power/power.h
move power.h to power/power.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif
e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Ioannis Glaropoulos
bceca79804 tests: kernel: fatal: check stack overflow of FP capable threads
Test the HW stack protection feature for threads that are
pre-tagged as FPU users, when building with support for FP
shared registers mode (CONFIG_FP_SHARING=y).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-27 18:07:03 -07:00
Ioannis Glaropoulos
1dd2796b6f tests: kernel: add simple test for the ramfunc feature
This commit contributes a simple test for
the ARM RAMFUNC feature.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-27 12:44:20 -07:00
Charles E. Youse
ad409f4bce tests/kernel/context: add case for CONFIG_APIC_TIMER
Test needs trivial modification to account for new APIC timer code.
Eventually CONFIG_APIC_TIMER_IRQ, CONFIG_LOAPIC_TIMER_IRQ, etc. will
be consolidated into one CONFIG_TIMER_IRQ to reduce the noise a bit.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-27 07:20:54 -04:00
Ioannis Glaropoulos
1e29d40e87 tests: kernel: arm runtime nmi: add arm tag
Add the arm tag to tests/kernel/arm_runtime_nmi test.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-26 09:55:13 -04:00
Ioannis Glaropoulos
e5c0e3caa1 tests: kernel: submit a simple test for zero-latency irqs
The commit contributes a simple test for the Zero-Latency
IRQ feature (CONFIG_ZERO_LATENCY_IRQS=y) for ARM platforms.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-26 09:55:13 -04:00
Nicolas Pitre
659fa0d57d lifo/fifo: first word is not always first 4 bytes
The first word is used as a pointer, meaning it is 64 bits on 64-bit
systems. To reserve it, it has to be either a pointer, a long, or an
intptr_t. Not an int nor an u32_t.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-26 09:08:42 -04:00
Andy Ross
c0630346c8 Revert "tests: tickless_concept: Fix slicing time measurement"
Unfortunately this seems to have introduced spurious failures on (at
least) qemu_x86 and qemu_xtensa.

The change limits the timeslice tolerance to +/- 1ms, which isn't
necessarily correct when the tick rate is less than 1ms (though it
will probably work on deterministic hardware as long as the system is
hitting the target at exactly the right tick), and isn't even
theoretically achievable on emulation environments where timing
granularity is limited by the host scheduling quantum.

What this needs to do is check the deadline is off by at most one
tick, and trust the platform integration to have set the tick rate
appropriately.

(I do worry that the earlier version of the test was trying to set the
limit at half the TICKLESS_IDLE_THRESHOLD, though -- that seems weird,
and hints that maybe the test is trying to do something more
elaborate?)

Fixes #17063.

This reverts commit 62c71dc4d8.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-06-26 09:59:47 +02:00
Andrew Boie
643f86f1f2 tests: thread_apis: exercise some system calls
We had no system call coverage for k_thread_suspend
and k_thread_resume.

Some unnecessary cleanup tasks in the test case have
been removed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-25 22:45:09 -04:00
Andrew Boie
ffd182a04b tests: device: cover device_get_binding()
We had no coverage for invoking this from a system call.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-25 22:44:14 -04:00
Andrew Boie
848221812f tests: userspace: cover z_object_recycle()
We didn't have code coverage for this function anywhere
except indirectly through some network tests; exercise it
in the suite of userspace tests.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-25 17:28:19 -07:00
Andrew Boie
d053ba59ac tests: dynamic_thread: cover thread_idx_free()
Address a coverage gap in kernel/userspace.
Unfortunately, in the process of fixing this, a bug was
discovered, see #17023.

This test is user mode specific, filter the testcase
on whether userspace is available instead of ifdefing
the code.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-25 17:28:19 -07:00
Andrew Boie
777336ef38 tests: userspace: cover missing/bad syscalls
We were missing code coverage for bad or unimplemented
system call IDs.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-25 17:28:19 -07:00
Andrew Boie
31c4cc54fa tests: common: cover k_cycle_get_32() syscall
We had plenty of coverage for k_cycle_get(), but not its
32-bit variant. Run a case in user mode so that the system
call handler gets covered.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-25 17:22:52 -07:00
Charles E. Youse
3dc7c7a6ea drivers/interrupt_controller/mvic.c: remove MVIC interrupt controller
The Quark D2000 is the only x86 with an MVIC, and since support for
it has been dropped, the interrupt controller is orphaned. Removed.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-25 08:06:43 -04:00
Wentong Wu
a30162be35 tests: add futex test cases
add futex test cases.

Fixes: #14493.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-06-24 15:38:21 -07:00
Ioannis Glaropoulos
0180b94afd tests: kernel: fatal: add explicit test case for ARM and FP Sharing mode
For the ARM architecture we would like to test the HW
Stack Protection feature when building with support for
FP shared registers mode (CONFIG_FP_SHARING=y), as a
means of increasing coverage.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-24 13:26:47 -07:00
Ioannis Glaropoulos
723aae9503 tests: kernel: mem_protect: use correct define for MEM_REGION_ALLOC
For ARM architecture, use Z_THREAD_MIN_STACK_ALIGN to define
MEM_REGION_ALLOC in tests/kernel/mem_protect/mem_protect/.
STACK_ALIGN takes into account MPU stack guard alignment
requirements. However, application memory partitions do not
require MPU stack guards, therefore, the alignment requirements
are not applicable here.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-24 10:16:57 -07:00
Kumar Gala
2910b5eac1 tests/kernel/context: Fix TICK_IRQ define for RV32M1 lptmr_timer
We missed converting DT_OPENISA_RV32M1_LPTMR_SYSTEM_LPTMR_IRQ to
DT_OPENISA_RV32M1_LPTMR_SYSTEM_LPTMR_IRQ_0.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-06-21 16:17:05 -05:00
Anas Nashif
f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Ioannis Glaropoulos
8004082389 tests: kernel: fatal: add explicit no user-mode test case
We would like to test the HW stack protection feature in ARM
builds with no user-mode support, i.e. CONFIG_USERSPACE=n. For
that we add a new test-case in tests/kernel/fatal test suite.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-19 09:07:57 -07:00
Andrew Boie
6020a50092 tests: schedule_api: skip test assert if COVERAGE
This test case is so timing sensitive that gathering code
coverage data screws up the results.

Since this is an abnormal execution environment anyway,
just skip the assertions if CONFIG_COVERAGE=y.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-19 08:42:50 -04:00
Andrew Boie
03f22773c5 tests: schedule_api: test syscalls from usermode
We didn't have any coverage of the system call handlers for
k_wakeup() and k_is_preempt().

Increase RAM requirements due to stack alignment constraints
on MPU platforms when user mode is enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-19 08:42:50 -04:00
Andrew Boie
b5d3ba4634 tests: schedule_api: exercise SCHED_MULTIQ
This option should work on any arch, don't reserve
this just for native_posix.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-19 08:42:50 -04:00
Andrew Boie
a3eb8c4ade tests: schedule_api: fix extern tstacks
Fix how the tstacks array was declared extern so this
actually compiles on all platforms with user mode enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-19 08:42:50 -04:00
Ulf Magnusson
eba81c6e54 yaml: Remove redundant document separators
YAML document separators are needed e.g. when doing

  $ cat doc1.yaml doc2.yaml | <parser>

For the bindings, we never parse concatenated documents. Assume we don't
for any other .yaml files either.

Having document separators in e.g. base.yaml makes !include a bit
confusing, since the !included files are merged and not separate
documents (the merging is done in Python code though, so it makes no
difference for behavior).

The replacement was done with

    $ git ls-files '*.yaml' | \
        xargs sed -i -e '${/\s*\.\.\.\s*/d;}' -e 's/^\s*---\s*$//'

First pattern removes ... at the end of files, second pattern clears a
line with a lone --- on it.

Some redundant blank lines at the end of files were cleared with

    $ git ls-files '*.yaml' | xargs sed -i '${/^\s*$/d}'

This is more about making sure people can understand why every part of a
binding is there than about removing some text.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-06-19 10:40:10 +02:00
Andrew Boie
94b9640a9c tests: poll: expand userspace coverage
The syscall handler for k_poll() returns error values
instead of killing the caller for various bad arguments,
cover these cases.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-18 09:08:01 -04:00
Andrew Boie
682a53db28 tests: queue: test k_queue_alloc_*pend()
These were never getting called anywhere from user mode,
except for k_queue_alloc_append(), but only by virtue of
some workqueue tests.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-18 09:08:01 -04:00
Andrew Boie
d87a90e4b9 tests: mutex_api: run in user mode
Addresses coverage gaps. Some changes were made so that exited
threads do not have k_thread_abort() called on them.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-18 09:08:01 -04:00
Nicolas Pitre
2b32059a61 printk: make it 64-bit compatible
On 64-bit systems the most notable difference is due to longs and
pointers being 64-bit wide. Therefore there must be a distinction
between ints and longs. Similar to the prf.c case, this patch properly
implements the h, hh, l, ll and z length modifiers as well as some small
cleanups.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-17 10:28:44 -07:00
Ioannis Glaropoulos
f4f2b13126 tests: kernel: fatal: add HW stack check for priv stack
This commit adds a test in tests/kernel/fatal test-suite, which checks
that the HW stack overflow detection works as expected during a user
thread system call.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-17 10:27:52 -07:00
Ioannis Glaropoulos
02a3c52084 tests: kernel: userspace: correct address of thread priv stack start
In ARM architecture z_priv_stack_find() returns the start of a
thread's privilege stack; we do not need to subtract the length
of a (possible) stack guard. This commit corrects the assigning
of the start address of a thread privilege stack in
test/kerne/mem_protect/mem_protect/userspace.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-17 09:47:21 -07:00
Charles E. Youse
c2c85a2a48 arch/x86/Kconfig: remove CONFIG_ISA_IA32
This option is set iff CONFIG_X86 is set, thus it provides no useful
information. Remove the option and replace references with CONFIG_X86.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-14 05:49:13 -04:00
Nicolas Pitre
3d51f7c266 k_stack: make it 64-bit compatible
The k_stack data type cannot be u32_t on a 64-bit system as it is
often used to store pointers. Let's define a dedicated type for stack
data values, namely stack_data_t, which can be adjusted accordingly.
For now it is defined to uintptr_t which is the integer type large
enough to hold a pointer, meaning it is equivalent to u32_t on 32-bit
systems and u64_t on 64-bit systems.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-14 05:46:29 -04:00
Ioannis Glaropoulos
9f8044e6b5 tests: kernel: fp_sharing: call k_float_disable() for ARM
We can now invoke k_float_disable(.) for ARM platforms,
too, since we introduced the function as a cross-arch
system call.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-12 09:17:45 -07:00
Nicolas Pitre
6311766d9a pointer-type args: cast appropriately to be 64-bit compatible
Using void pointers as universal arguments is widely used. However, when
compiling a 64-bit target, the compiler doesn't like when an int is
converted to a pointer and vice versa despite the presence of a cast.
This is due to a width mismatch between ints (32 bits) and pointers
(64 bits). The trick is to cast to a widening integer type such as
intptr_t and then cast to
void*.

When appropriate, the INT_TO_POINTER macro is used instead of this
double cast to make things clearer. The converse with POINTER_TO_INT
is also done which also serves as good code annotations.

While at it, remove unneeded casts to specific pointer types from void*
in the vicinity, and move to typed variable upon function entry to make
the code cleaner.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-12 08:20:52 -07:00
Nicolas Pitre
1f35774407 memslab/mempool: make tests 64-bit compatible
Minimum block size is 2x larger on 64-bit systems, so let's simply
double all size params. This won't change the validity of those tests
on 32-bit systems. Alignment tests are also adjusted for wider pointers.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-11 09:38:06 -07:00
Andrew Boie
324ae6fd56 tests: tickless_concept: disable for coverage
This test is already flaky, but becomes even flakier when
coverage is enabled.

Disable until we put a stake through the QEMU timing issues
being worked on in #14173.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-06 09:29:12 -07:00
Piotr Zięcik
a45ce52253 tests: timer_api: Fix timer synchronization
The test_timer_periodicity waits for first timer expiration
in order to extract timer firing time. The wait is performed
using k_timer_status_sync() API call, which blocks thread
until timer expiration. However if the timer expired before
call the this function, it will return immediately, triggering
test failure.

This commit adds the second call to the k_timer_status_sync()
to ensure that the following part of the test will be executed
as soon as possible after timer expiration.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-06-06 09:31:26 -04:00
Anas Nashif
2fb19fcbdd style: samples/tests: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Andy Ross
ed5185ba12 tests/kernel/fatal: Fix wait-for-interrupt delay in stack check test
Contrary to the comment in code, this test is NOT, in fact, compiled
with a traditional ticked kernel.  Spinning won't work reliably
because interrupts won't necessarily be delivered when you expect.
This test case would fail spuriously as I moved things around when
debugging.

Doing it right (using a k_timer in this case) is actually less code
anyway.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-06-03 12:03:48 -07:00
Andy Ross
e6af0f8caa arch/*: Add z_arch_irq_unlocked() predicate and test
It's useful to be able to inspect the key returned from
z_arch_irq_unlock() to see if interrupts were enabled at the point
where z_arch_irq_lock() was called.  Architectures tend to represent
this is a simple way that doesn't require platform assembly to
inspect.

Adds a simple test to kernel/common that validates this predicate with
a nested lock.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-06-03 12:03:48 -07:00
Ioannis Glaropoulos
13a587756c tests: kernel: userspace: explicitly declare function for the test
In the wake of moving the internal API header arm_core_mpu_dev.h
into arch/arm/cortex_m/mpu, we need to explicitly declare the
arm_core_mpu_disable() function in the userspace test. Note that
arm_core_mpu_disable() (as any other function in this internal
API) is not supposed to be called directly by kernel/application
functions; an exception is allowed in this test suite, so we are
able to test the MPU disabling functionality.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-05-30 09:00:05 -05:00
Marc Herbert
4afcc0f8af sanitycheck: CONFIG_TEST_USERSPACE / userspace tag cleanup
- Delete CONFIG_TEST_USERSPACE=n no-ops because it's the default
since commit 7b1ee5cf13

- Some tests have a "userspace" tag pretending to TEST_USERSPACE but
don't and vice versa: fix missing or spurious "userspace" tags in
testcase.yaml files.

Tests have a _spurious_ "userspace" tag when they PASS this command
cause none should pass:

  ./scripts/sanitycheck --tag=userspace -p qemu_x86 \
      --extra-args=CONFIG_TEST_USERSPACE=n  \
      --extra-args=CONFIG_USERSPACE=n | tee userspace.log

All tests run by this command must either fail to build or fail to run
with some userspace related error. Shortcut to look at all test
failures:

 zephyr_failure_logs() {
     awk '/see.*log/ {print $2}' "$@"
 }

Tests _missing_ "userspace" tag FAIL to either build or to run with some
userspace related error when running this:

  ./scripts/sanitycheck --exclude=userspace -p qemu_x86 \
      --extra-args=CONFIG_TEST_USERSPACE=n  \
      --extra-args=CONFIG_USERSPACE=n | tee excludeuserspace.log

Note the detection methods above are not 100% perfect because some
flexible tests like tests/kernel/queue/src/main.c evade them with #ifdef
CONFIG_USERSPACE smarts. Considering they never break, it is purely the
test author's decision to include or not such flexible tests in the
"userspace" subset.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-05-30 08:45:39 -04:00
Henrik Brix Andersen
c3ccbbbdc3 tests: kernel: common: add missing userspace tag
Add missing userspace tag to the kernel/common test suite.

Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
2019-05-26 08:56:08 -04:00
Piotr Zięcik
ba4eae14dd tests: test_sched_timeslice_reset: Fix slice time measurement
The time measurement based on k_uptime_delta() might be not accurate
for some values of CONFIG_SYS_CLOCK_TICKS_PER_SEC. This commit
introduces measurement based on k_cycle_get_32(), which is more
precise.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-05-23 09:28:58 -04:00
Piotr Zięcik
62c71dc4d8 tests: tickless_concept: Fix slicing time measurement
The time measurement based on k_uptime_delta() might be not accurate
for some values of CONFIG_SYS_CLOCK_TICKS_PER_SEC. This commit
introduces measurement based on k_cycle_get_32(), which is more
precise.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-05-23 09:28:58 -04:00
Piotr Zięcik
86f012d27c tests: timer_api: Fix test for SYS_CLOCK_TICKS_PER_SEC != 100
This commit changes the timer_api test in order to take under account
fact that timeouts used in the test might not be aligned to tick
boundary.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-05-23 09:28:58 -04:00
Charles E. Youse
9ab293b919 tests/kernel/sleep: add tests for k_usleep() API
Test that k_usleep() allows sleep durations near the limit of what
the platform's tick rate will allow.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-05-21 23:09:16 -04:00
Wentong Wu
fc3270d09c tests: kernel: increase stack buffer when code coverage enabled
increase stack buffer when code coverage enabled.

Fixes: #15794.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-05-16 09:29:55 -07:00
Filip Kokosinski
c0c3cdfc57 drivers: timer: add LiteX timer driver
Add LiteX timer driver with bindings for this device.

Signed-off-by: Filip Kokosinski <fkokosinski@internships.antmicro.com>
Signed-off-by: Mateusz Holenko <mholenko@antmicro.com>
2019-05-15 12:52:16 -05:00
Ryan QIAN
46289bed0c tests: change the min_ram for mbedtls and mem_protect
- Change the min_ram to 36K, since they can't be built on RT1015 which
has 32K ram.

Signed-off-by: Ryan QIAN <jianghao.qian@nxp.com>
2019-05-14 12:23:42 -05:00
Andrew Boie
9485172677 tests: stackprot: don't set main stack size
This test uses ztest anyway, the default should be fine
just like any other test running under ztest.

k_thread_create() uses a lot of stack, and the main
stack size is very small if ztest is enabled. Do it in
another ztest task instead.

We don't need to mess with the main thread's priority,
just have the alt thread run cooperatively.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-03 13:30:16 -07:00
Andrew Boie
5f0ee9d350 tests: timer_api: run in user mode
We didn't have any coverage of the timer APIs in user
mode.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 18:01:06 -07:00
Andrew Boie
1d4cc154b0 tests: pipe: fix error with optimization disabled
The various struct pipe_sequence were not located in memory
accessible to user mode. With optimization turned on, they
weren't in memory at all, but with code coverage enabled
the arrays were actually being read, resulting in memory
access failures from user mode.

Fix them by placing in ROM, they never get modified.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 07:22:37 -04:00
Daniel Leung
a404bb76ee tests/kernel/device: extends test for code coverage
device_get_binding() compares pointers first before doing strcmp().
However, enabling coverage forces -O0 to disable any compiler
optimizations. There would be multiple copies of the same string,
and the code pathing doing pointer comparsion would not be tested
at all. So add this flag to merge string constants such that
the pointer comparison would be exercised.

This also adds a bad driver which fails initialization. This is
to make sure that execution path is covered.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-05-01 10:38:03 -04:00
Siddharth Chandrasekaran
b070bbd888 tests: kernel: Exclude platforms stm32_min_dev_*
Exclude the two variants of smt32_min_dev (stm32_min_dev_black and
stm32_min_dev_blue) from kernel tests.

Signed-off-by: Siddharth Chandrasekaran <siddharth@embedjournal.com>
2019-04-26 03:34:45 -07:00
Ioannis Glaropoulos
01a2bebc83 tests: kernel: mem_protect: protection: fix test-case filter
The test is to run for boards that have memory protection
enabled; having MPU capabilities on the SoC level is not
sufficient (the user, or the board itself, might not enable
memory protection support). This commit applies that policy
to the mem_protect/protection test suite.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-04-23 13:04:22 -07:00
Daniel Leung
3fa90938fe tests/kernel/schedule_api: also test without time slicing
This extends the schedule_api test to cover situations when
time slicing is disabled.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-04-18 12:26:52 -04:00
Wentong Wu
8646a8e4f5 tests/kernel/mem_protect/stackprot: stack size adjust
revert commit 3e255e968 which is to adjust stack size
on qemu_x86 platform for coverage test, but break other
platform's CI test.

Fixes: #15379.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-04-12 10:06:43 -04:00
Wentong Wu
22c9646b97 tests: adjust stack size for mps2_an385's coverage test
for SDK 0.10.0, it consumes more stack size when coverage
enabled, so adjust stack size to fix stack overflow issue.

Fixes: #15206.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-04-11 17:59:39 -04:00
Wentong Wu
3e255e968a tests: adjust stack size for qemu_x86's coverage test
for SDK 0.10.0, it consumes more stack size when coverage
enabled, so adjust stack size to fix stack overflow issue.

Fixes: #15206.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-04-11 17:59:39 -04:00
Ioannis Glaropoulos
e2969e5de0 tests: kernel: fp_sharing: minor fix in #ifdef expression
We need to use the ARMV7_M_ARMV8_M_FP Kconfig symbol,
which denotes the Floating-Point capabilities, instead
of the option that signifies the Cortex-M variant. Fix
is of minor importance, as long as the #ifdef block
remains empty.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-04-10 10:59:46 -04:00
Andrew Boie
7387b56c61 tests: add nsim special cases for two tests
The NSIM emulator has severe performance issues when
the MPU registers are reprogrammed on context switch.
Disable runtime reprogramming of the MPU for these
platforms on these two tests, which have a lot of context
switch thrashing. This is done by ensuring userspace
and hardware stack overflow detection via guard areas
is disabled.

I have assurances from the ARC team that the tests run fine
on real hardware and this is an emulation issue.

For 1.15, this will be completely resolved by optimizing
MPU region gap-filling to not take place during context
switch time, which will drastically reduce the number of
MPU registers poked during context switch on nsim_sem.

Meanwhile, for 1.14 we ensure that no runtime reprogramming
of the MPU is done for these tests.

Fixes: #14642

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-09 19:38:32 -04:00
Anas Nashif
a520266e44 tests: remove unused defaults.tc
This file is not used and was originally added to support TCF hardware
testing. We use harness now.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 10:26:27 -04:00
Anas Nashif
3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Andrew Boie
7b1ee5cf13 tests: CONFIG_TEST_USERSPACE now off by default
Unlike CONFIG_HW_STACK_PROTECTION, which greatly helps
expose stack overflows in test code, activating
userspace without putting threads in user mode is of
very limited value.

Now CONFIG_TEST_USERSPACE is off by default. Any test
which puts threads in user mode will need to set
CONFIG_TEST_USERSPACE.

This should greatly increase sanitycheck build times
as there is non-trivial build time overhead to
enabling this feature. This also allows some tests
which failed the build on RAM-constrained platforms
to compile properly.

tests/drivers/build_all is a special case; it doesn't
put threads in user mode, but we want to ensure all
the syscall handlers compile properly.

Fixes: #15103 (and probably others)

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-06 14:30:42 -04:00
Andrew Boie
027b6aaf89 tests: set userspace tag for all tests that use it
This lets us quickly filter tests that exercise userspace
when developing it.

Some tests had a whitelist with qemu_cortex_m3; change
this to mps2_an385, which is the QEMU target with an
MPU enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-06 14:30:42 -04:00
Andrew Boie
ad71c2fc44 tests: poll: reduce memory usage
We can re-use thread/stack objects between cases, no
need to have separate ones.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-06 14:30:42 -04:00
Anas Nashif
ed139948a5 license: add missing licences to source code
Add missing license to source code files.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-05 23:45:51 -04:00
Andrew Boie
4e5c093e66 kernel: demote K_THREAD_STACK_BUFFER() to private
This macro is slated for complete removal, as it's not possible
on arches with an MPU stack guard to know the true buffer bounds
without also knowing the runtime state of its associated thread.

As removing this completely would be invasive to where we are
in the 1.14 release, demote to a private kernel Z_ API instead.
The current way that the macro is being used internally will
not cause any undue harm, we just don't want any external code
depending on it.

The final work to remove this (and overhaul stack specification in
general) will take place in 1.15 in the context of #14269

Fixes: #14766

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-05 16:10:02 -04:00
Wentong Wu
b991962a2e tests: adjust stack size for qemu_x86 and mps2_an385's coverage test
for SDK 0.10.0, it consumes more stack size when coverage enabled
on qemu_x86 and mps2_an385 platform, adjust stack size for most of
the test cases, otherwise there will be stack overflow.

Fixes: #14500.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-04-04 08:23:13 -04:00
Wentong Wu
1214736be5 tests: disable kernel.sched.preempt and kernel.poll on nrf52810_pca10040
on platform nrf52810_pca10040, the remaining sram space is not enough
to build test cases kernel.sched.preempt and kernel.poll, temporary
exclude nrf52810_pca10040 on that two cases, will open them when issue
is fixed.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-04-04 08:23:13 -04:00
Patrik Flykt
7c0a245d32 arch: Rename reserved function names
Rename reserved function names in arch/ subdirectory. The Python
script gen_priv_stacks.py was updated to follow the 'z_' prefix
naming.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt
97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Andrew Boie
14db4eedff tests: userspace: check stack buffer access
The stack information stored in the thread->stack_info
fields need to represent the actual writable area for
its associated thread. Perform various tests to ensure
that the various reported and specified values are in
agreement.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:48:20 -04:00
Andrew Boie
c8aee7b413 sys_mem_pool: use sys_mutex
Permission management no longer necessary, the former
parameter for the mutex is now simply ignored.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:47:45 -04:00
Andrew Boie
f8b6276780 tests: repurpose one of the mutex tests
We have two redundant mutex tests. Repurpose one
of them to excerise sys_mutex instead.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:47:45 -04:00
Andrew Boie
468c47bb83 tests: thread_apis: fix failure on ARC
This test is only trying to prove that k_thread_foreach() works,
it has nothing to do with stacks. Remove the stack checks
completely.

Fixes: #15044

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-02 20:11:19 -04:00
Flavio Ceolin
96659ac83b tests: fp_sharing: Fix build error
k_disable_float is only available in X86 when LAZY_FP_SHARING is
set. Adding this condition before using this function.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-04-02 11:31:22 -04:00
Andrew Boie
dea4394ef4 tests: fatal: fix sentinel timer IRQ checking
Tickless kernel is now always disabled, ensuring that when
the kernel's tick count changes, we really did get a timer
interrupt.

The test now awaits a change in tick count instead of busy
waiting for an arbitrary time period.

Fixes: #15013

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-29 22:13:40 -04:00
Patrik Flykt
21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt
24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Anas Nashif
006b97de13 tests: no-multithreading: do not report success twice
We are reporting success twice, once by calling macro directly, and once
by using ztest test_main().

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-26 20:09:07 -04:00
Wayne Ren
6b5bed6aa9 arch: arc: fix the handling of stack check exception
stack check exception may come out with other protection
vilation, e.g. MPU read/write. So the possible paramter
will be 0x02 | [0x4 | 0x8].

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-03-26 14:34:39 -04:00
Piotr Mienkowski
a3082e49a1 power: modify HAS_STATE_SLEEP_ Kconfig options
Add SYS_POWER_ prefix to HAS_STATE_SLEEP_, HAS_STATE_DEEP_SLEEP_
options to align them with names of power states they control.
Following is a detailed list of string replacements used:
s/HAS_STATE_SLEEP_(\d)/HAS_SYS_POWER_STATE_SLEEP_$1/
s/HAS_STATE_DEEP_SLEEP_(\d)/HAS_SYS_POWER_STATE_DEEP_SLEEP_$1/

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-03-26 13:27:55 -04:00
Piotr Mienkowski
17b08ceca5 power: clean up system power managment function names
This commit cleans up names of system power management functions by
assuring that:
- all functions start with 'sys_pm_' prefix
- API functions which should not be exposed to the user start with '_'
- name of the function hints at its purpose

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-03-26 13:27:55 -04:00
Piotr Mienkowski
204311d004 power: rename Low Power States to Sleep States
There exists SoCs, e.g. STM32L4, where one of the low power modes
reduces CPU frequency and supply voltage but does not stop the CPU. Such
power modes are currently not supported by Zephyr.

To facilitate adding support for such class of power modes in the future
and to ensure the naming convention makes it clear that the currently
supported power modes stop the CPU this commit renames Low Power States
to Slep States and updates the documentation.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-03-26 13:27:55 -04:00
Flavio Ceolin
f1741dab6c tests: mbox: Check k_mbox_get return
Coverity was complaining that this function was not being checked only
in a specific case.

Coverity CID: 183066

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-23 20:13:12 -04:00
Andy Ross
61065b3235 tests: samples: Re-enable SMP on a few tests
The 14 individual cases that use these four config files are now
passing reliably when SMP is enabled, after the "Mark sleeping threads
suspended" scheduler fix.  Turn it back on.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-23 19:28:15 -04:00
Andy Ross
09fdd814df tests/kernel/smp: Give time for a wakeup to take effect
For obvious performance reasons, scheduler state changes (other than
aborting a thread) do not cause synchronous interrupts on the other
CPU.  Doing a k_thread_wakeup() means that the current CPU will run it
synchronously if it's high priority, but if you want to see it run on
the other cores you need to wait for them to reach a scheduling point
on their own.

The test was written to assume that k_thread_wakeup() is synchronous,
but that's not right, and it needs to spin a bit.  This bug was always
present in the test, but masked by a bug in the way that k_sleep() was
handled on SMP.  See #9506.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-23 19:28:15 -04:00
Andy Ross
4f04f6486d tests: More SMP disablement
A few more test cases that are measurably unreliable when run in SMP.
For the most part these work most of the time (though the semaphore
one was pretty borderline -- I measured about 25% failures), but are
measurably unstable against the backdrop of known qemu instability.
Something is clearly going on and we need to come back to these to fix
threadsafety issues.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-20 11:33:29 -05:00
Daniel Leung
91eb147452 tests: kernel/smp: whitelist qemu_x86_64 for testing
Add qemu_x86_64 to the platform whitelist so that this will actually
be built and tested with sanitycheck.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-18 17:57:54 -04:00
Daniel Leung
96ccb913e4 tests: kernel/smp: fixed missing 'z_' renaming
There was a missing 'z_' renaming to
z_is_thread_prevented_from_running which would have caused
sanitycheck to fail but it is not being built at the moment.
Fix this first.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-18 17:57:54 -04:00
Andrew Boie
b3eb510f5c kernel: fix atomic ops in user mode on some arches
Most CPUs have instructions like LOCK, LDREX/STREX, etc which
allows for atomic operations without locking interrupts that
can be invoked from user mode without complication. They typically
use compiler builtin atomic operations, or custom assembly
to implement them.

However, some CPUs may lack these kinds of instructions, such
as Cortex-M0 or some ARC. They use these C-based atomic
operation implementations instead. Unfortunately these require
grabbing a spinlock to ensure proper concurrency with other
threads and ISRs. Hence, they will trigger an exception when
called from user mode.

For these platforms, which support user mode but not atomic
operation instructions, the atomic API has been exposed as
system calls.

Some of the implementations in atomic_c.c which can be instead
expressed in terms of other atomic operations have been removed.

The kernel test of atomic operations now runs in user mode to
prove that this works.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-18 09:18:00 -04:00
Andy Ross
5a56ee5605 tests/kernel/fifo/fifo_usage: Disable SMP
This test isn't SMP-safe and won't pass reliably on x86_64 by default
(though it does pass often enough to get CI passes on most things, it
fails spuriously in ways that aren't timing related).  Turn off the
second CPU.  Fixes #14501

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-15 19:42:59 +01:00
Andy Ross
c4e2f1b217 tests/kernel/mem_pool/mem_pool_threadsafe: Reduce tick rate
Qemu just can't handle 1000 Hz ticks.  On our CI machines, CONFIG_HZ
on the host (which is the limit of timing precision for things like
idle wakeups and signal delivery, both of which qemu seems to use for
timing) is 250.  When the mismatch gets this large, we start seeing
artifacts like interrupts being delivered "in the past" (i.e. code
sees a z_clock_elapsed() value of "2" ticks before getting a
z_clock_announce() call for "1").

As it happens, this test doesn't actually require timing with that
precision, it just wants "lots of context switching" to exercise the
threadsafety of the mem_pool APIs.  So decrease the tick rate to the
100Hz default, but put a loop counter in the worker threads to force
them to do 10x more work, keeping the number of preemptions constant.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-15 05:50:43 +01:00
Ramakrishna Pallala
e1639b5345 device: Extend device_set_power_state API to support async requests
The existing device_set_power_state() API works only in synchronous
mode and this is not desirable for devices(ex: Gyro) which take
longer time (few 100 mSec) to suspend/resume.

To support async mode, a new callback argument is added to the API.
The device drivers can asynchronously suspend/resume and call the
callback function upon completion of the async request.

This commit adds the missing callback parameter to all the drivers
to make it compliant with the new API.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2019-03-14 14:26:15 +01:00
Kumar Gala
6ef55b0942 tests: kernel: context: Fix build issue with RV32M1_LPTMR_TIMER
We needed to add support for the RV32M1_LPTMR_TIMER to the test so its
knows what the IRQ of the timer is.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-13 17:02:05 -05:00
Andy Ross
05c1263ebd tests/kernel/smp: Clean up "guess waiting" on SMP thread exit
The various tests would all do a "wait for threads to exit" step
before checking the results, but this was implemented with a simple
busy wait that turns out to need careful tuning (because there was
busy waiting in the threads).

Rather than try to synchronize this, white box the issue (it's a low
level SMP test, after all) by spinning on the thread states directly
watching for the kernel to flag them dead.  The downside here is that
if the process fails for some reason we'll get a hang and a timeout
reported from sanitycheck and not a synchronous ztest assertion.  But
in return, successful tests run much faster and I don't need to worry
about how to tune them for IPI latency on different platforms.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-13 19:15:20 +01:00
Andy Ross
829f6639da tests/kernel/smp: Remove test_wakeup_pending_threads case
This case was predicated on a mistake.  The behavior of k_wakeup() has
always been NOT to wake up threads that are "pending" on a wait queue,
only ones blocked on a timeout in k_sleep().  As written, this test
case could never pass.

(Really there's no good reason for that.  It seems reasonable to me to
expect wakeup to work symmetrically, and the docs are sort of
ambiguous on the subject.  But the code in k_wakeup() is clear:
threads flagged pending get an early exit and the call becomes a
noop.)

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-13 19:15:20 +01:00
Andy Ross
5697dd7980 tests/kernel/smp: Honor TEST_EXTRA_STACKSIZE
There was a test-created thread that wasn't including this.  It's a
huge stack and doesn't overflow (though I thought briefly that it
was), but it's a rule that we need to have that buffer and I'm trying
to fix these as I find them.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-13 19:15:20 +01:00
Patrik Flykt
4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Charles E. Youse
78b98ae895 tests/xip: exclude Minnowboard from test (does not do XIP)
Minnowboard should not run the XIP test as it doesn't execute-in-place.
Updated the test specification to exclude Minnowboard.

Fixes #14099.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-03-07 20:31:31 -05:00
Arnaud Pouliquen
97f4265c12 tests: fix compilation error for printk
Fix multiple definitions of `ram_console'. The ram_console
array is already defined in drivers/console/ram_console.c.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@st.com>
2019-03-06 18:15:06 -05:00
Maksim Masalski
b324f35e61 macros: deleted macros SECONDS(), MSEC(), USEC()
Changed everywhere these macros to the K_MSEC(), K_SECONDS()

Signed-off-by: Maksim Masalski <maxxliferobot@gmail.com>
2019-03-04 19:04:21 -05:00
Piotr Zierhoffer
8642be070c m2gl025_miv: Ignore lifo_usage tests
These tests fail on hardware. An appropriate issue will be filed on
GitHub, but it doesn't make sense to hold the CI from going green.

Fixes #13960.

Signed-off-by: Piotr Zierhoffer <pzierhoffer@antmicro.com>
2019-03-04 12:39:09 -05:00
Andrew Boie
8207801c9b tests: userspace: remove unused partition
No data was ever being put in part2.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-04 08:05:16 -08:00
Andrew Boie
92da519d45 tests: userspace: add some more scenarios
We want to show that performing various memory domain
operations, and then either dropping to user mode, or
swapping to a user thread in the same domain, has the
correct memory policy for the user context.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-03 23:44:13 -05:00
Charles E. Youse
d51ee67cbe tests/timer_api: revert testcase configuration
My test tag 'flarp' got through in the last commit.  Removed.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-03-01 14:53:33 -08:00
Charles E. Youse
fbf4c7eea0 tests/timer_api: revert testcase configuration
Removing the build_only option for tickless broke CI (for reasons
unrelated to the new tests I added in the prior commit).

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-03-01 14:53:33 -08:00
Charles E. Youse
0ad4022e51 kernel/timeout: fix k_timer_remaining_get() when tickless
In some circumstances (e.g., a tickless kernel), k_timer_remaining_get()
would not account for time passed that didn't involve clock interrupts.
This adds a simple fix for that, and adds a test case.  In addition, the
return value of k_timer_remaining_get() is clamped at 0 in the case of
overdue timers and the API description is adjusted to reflect this.

Fixes: #13353

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-03-01 14:53:33 -08:00
Andy Ross
f085928ab0 tests/kernel/fifo/fifo_timeout: Tick alignment for oversensitive timing
This test was written to wait on a fifo with a timeout, return, and
check the timing between the start and end using k_cycle_get_32() to
see that it didn't run long.  But timeouts expire on tick boundaries,
and so if tick expires between the start of the test and the entry to
k_fifo_get(), the timeout will take one full tick longer than expected
due to aliasing.

As it happened this passed everywhere except nRF (whose cycle timer is
32 kHz and thus more susceptible to coarser aliasing like this), and
even there it passed for a while until the spinlock validation layer
went in and added just enough time to the userspace code paths
(i.e. the code between the start time fetch and the point where the
fifo blocks takes longer) to open the window and push us over the
limit.

The workaround here is just to add a k_sleep(1) call, which is
guaranteed to block and wake up synchronously at the next tick.

Fixes #13289

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-03-01 19:45:39 +01:00
Andy Ross
fc3ca95ba7 tests: Mass SMP disablement on non-SMP-safe tests
(Chunk 2 of 3 - this patch was split across pull requests to address
CI build time limitations)

Zephyr has always been a uniprocessor system, and its kernel tests are
rife with assumptions and outright dependence on single-CPU operation
(for example: "low priority threads will never run until this high
priority thread blocks" -- not true if there's another processor to
run it!)

About 1/3 of our tests fail right now on x86_64 when dual processor
operation is made default.  Most of those can probably be recovered on
a case-by-case basis with simple changes (and a few of them might
represent real bugs in SMP!), but for now let's make sure the full
test suite passes by turning the second CPU off.  There's still plenty
of SMP coverage in the remaining cases.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 12:47:12 -08:00
Ioannis Glaropoulos
ca3b6c680f tests: kernel: fatal: remove #ifdefs for ARM platforms
This commit removes the #ifdefs for ARM platforms in
tests/kernel/fatal/main.c, as all the tests suite can be
executed for platforms supporting the ARM and the NXP MPU.
Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-28 11:57:25 -08:00
Andy Ross
3f4aa6316c tests/kernel/sched/schedule_api: Restore spinning for timer alignment
Commit 0cc362f873 ("tests/kernel: Simplify timer spinning") was
added to work around a qemu bug with dropped interrupts on x86_64.
But it turns out that the tick alignment that the original
implementation provided (fundamentally, it spins waiting on the timer
driver to report tick changes) was needed for correct operation on
nRF52.

The effectively revert that commit (and refactors all the spinning
into a single utility) and replaces it with a workaround targeted to
qemu on x86_64 only.  Fixes #11721

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 13:06:48 -06:00
Andy Ross
a334ac2045 tests: Mass SMP disablement on non-SMP-safe tests
(Chunk 1 of 3 - this patch was split across pull requests to address
CI build time limitations)

Zephyr has always been a uniprocessor system, and its kernel tests are
rife with assumptions and outright dependence on single-CPU operation
(for example: "low priority threads will never run until this high
priority thread blocks" -- not true if there's another processor to
run it!)

About 1/3 of our tests fail right now on x86_64 when dual processor
operation is made default.  Most of those can probably be recovered on
a case-by-case basis with simple changes (and a few of them might
represent real bugs in SMP!), but for now let's make sure the full
test suite passes by turning the second CPU off.  There's still plenty
of SMP coverage in the remaining cases.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 13:02:20 -06:00
Andy Ross
fe04adf99b lib/os: Conditionally eliminate alloca/VLA usage
MISRA rules (see #9892) forbid alloca() and family, even though those
features can be valuable performance and memory size optimizations
useful to Zephyr.

Introduce a MISRA_SANE kconfig, which when true enables a gcc error
condition whenever a variable length array is used.

When enabled, the mempool code will use a theoretical-maximum array
size on the stack instead of one tailored to the current pool
configuration.

The rbtree code will do similarly, but because the theoretical maximum
is quite a bit larger (236 bytes on 32 bit platforms) the array is
placed into struct rbtree instead so it can live in static data (and
also so I don't have to go and retune all the test stack sizes!).
Current code only uses at most two of these (one in the scheduler when
SCHED_SCALABLE is selected, and one for dynamic kernel objects when
USERSPACE and DYNAMIC_OBJECTS are set).

This tunable is false by default, but is selected in a single test (a
subcase of tests/kernel/common) for coverage.  Note that the I2C and
SPI subsystems contain uncorrected VLAs, so a few platforms need to be
blacklisted with a filter.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 10:06:35 -08:00
Ioannis Glaropoulos
7926cf24b6 tests: kernel: arm_irq_vector_table: extend the test for nRF9160
This commit extends the arm_irq_vector_table test,
so it can run successfully in nRF9160-based platforms.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-28 18:17:03 +01:00
Ioannis Glaropoulos
1e74007606 tests: kernel: arm_irq_vector_table: add clock ISR in the IRQ vector
This commit adds the Clock Control Interrupt Service
Routine into the customized vector table, when building
for nRF52X-based platforms. As a result, the interrupts
generated by the clock control will not interfere with
the test.

Fixes #13823.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-28 18:17:03 +01:00
Ioannis Glaropoulos
3dc81a40bc tests: kernel: arm_irq_vector_table: minor typo and style fixes
Minor typo and style fixes in the test logging, stressing
that the test is applicable for Cortex-M MCUs, in general.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-28 18:17:03 +01:00
Ioannis Glaropoulos
bc902954e4 tests: kernel: arm_irq_vector_table: refactor custom IRQ settings
In order to make this test easy to extend for additional
Cortex-M-based platforms, we apply the following minor
refactoring to the test:
- we introduce the _ISR_OFFSET macro to denote the offset
  inside the interrupts' vector table (starting from IRQ
  line 0) of the first manually installed ISR.
- we move the asserts that ensure the validity of the custom
  vector table to build-time and place them in the beginning
  of the text, outside source code.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-28 18:17:03 +01:00
Andy Ross
a4614372f9 tests: Mass SMP disablement on non-SMP-safe tests
(Chunk 3 of 3 - this patch was split across pull requests to address
CI build time limitations)

Zephyr has always been a uniprocessor system, and its kernel tests are
rife with assumptions and outright dependence on single-CPU operation
(for example: "low priority threads will never run until this high
priority thread blocks" -- not true if there's another processor to
run it!)

About 1/3 of our tests fail right now on x86_64 when dual processor
operation is made default.  Most of those can probably be recovered on
a case-by-case basis with simple changes (and a few of them might
represent real bugs in SMP!), but for now let's make sure the full
test suite passes by turning the second CPU off.  There's still plenty
of SMP coverage in the remaining cases.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-27 14:22:06 -08:00
Cinly Ooi
2810b88971 tests: Enable kernel.device tests for qemu_x86_64
Reworked platform_whitelist to enable the "test kernel.device" for
qemu_x86_64

kernel.device.pm is not yet enabled for qemu_x86_64 because
there is a link error

   undefined symbol `_DEVICE_STRUCT_SIZEOF'
   referenced in expression

Signed-off-by: Cinly Ooi <cinly.ooi@intel.com>
2019-02-26 22:55:40 -08:00
Andrew Boie
feab37096b libc: fix CONFIG_STDOUT_CONSOLE semantics
The intent of this Kconfig is to allow libc stdout
functions like printf() to send their output to the
active console driver instead of discarding it.

This somehow evolved into preferring to use
printf() instead of printk() for all test case output
if enabled. Libc printf() implementation for both
minimal libc and newlib use considerably more stack
space than printk(), with nothing gained by using
them.

Remove all instances where we are conditionally
sending test case output based on this config, enable
it by default, and adjust a few tests that disabled
this because they were blowing stack.

printk() and vprintk() now work as expected for
unit_testing targets, they are just wrappers for
host printf().

Fixes: #13701

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-26 08:00:33 -06:00
Piotr Mienkowski
f04a4c9deb power: rename CPU_LPS_n power states
CPU_LPS_n name used to indicate a low power state is cryptic and
incorrect. The low power states act on the whole SoC and not exclusively
on the CPU. This patch renames CPU_LPS_n states to LOW_POWER_n. Also
HAS_ pattern for Kconfig options is used in favor of a non standard
_SUPPORTED. Naming of deep sleep states was adjusted accordingly.

Following is a detailed list of string replacements used:
s/SYS_POWER_STATE_CPU_LPS_(\d)_SUPPORTED/HAS_STATE_LOW_POWER_$1/
s/SYS_POWER_STATE_CPU_LPS_(\d)/SYS_POWER_STATE_LOW_POWER_$1/
s/SYS_POWER_STATE_DEEP_SLEEP_(\d)_SUPPORTED/HAS_STATE_DEEP_SLEEP_$1/

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-02-26 02:30:13 +01:00
Piotr Mienkowski
c75187587b power: simplify SYS_POWER_*_SUPPORTED Kconfig options
This commit removes dependency on SYS_POWER_LOW_POWER_STATES_SUPPORTED,
SYS_POWER_DEEP_SLEEP_STATES_SUPPORTED Kconfig options. Power management
SYS_POWER_LOW_POWER_STATES, SYS_POWER_DEEP_SLEEP_STATES options depend
now directly on specific power states supported by the given SoC. This
simplifies maintenance of SoC Kconfig files.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2019-02-26 02:30:13 +01:00
Andrew Boie
4ce652e4b2 userspace: remove APP_SHARED_MEM Kconfig
This is an integral part of userspace and cannot be used
on its own. Fold into the main userspace configuration.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-23 07:43:55 -05:00
Anas Nashif
e88752f5fe tests: stacks: increase STACK_LEN to 4
Test was failing on nios2 with:

../app/libapp.a(test_stack_contexts.c.obj): in function `tstack_pop':
/home/galak/git/zephyr/tests/kernel/stack/stack_api/src/test_stack_contexts.c:31:
warning: unable to reach (null) (at 0x004002f4) from the global pointer
(at 0x004082fc) because the offset (-32776) is out of the allowed range,
-32678 to 32767

Fixes #13595

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-22 23:10:22 -05:00
Andrew Boie
45631c30ca tests: stackprot: run in user mode
Ensure that stack canaries work properly in user mode.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-22 18:50:43 -05:00
Ioannis Glaropoulos
67aee1f1f6 tests: kernel: userspace: fix test for non-secure builds
This commit fixes a test in kernel/mem_protect/userspace,
which was attempting to read from an address that was not
necessarily within the image memory range, causing faults
in ARM TrustZone-enabled builds.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-22 12:32:26 -06:00
Piotr Zięcik
81c1d37c89 test: kernel: device.pm: Do not enable system-level PM. It is not used.
This commit disables system-level power management in the device power
management test as it is not used.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-02-19 13:25:36 -05:00
Piotr Zięcik
63b0df645e power: Clean up power state names
Some of power states used numerical suffix while otthers not.
This commit adds proper suffix to all power state names.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>

f
2019-02-19 13:25:36 -05:00
Piotr Zięcik
c45961daae power: Rework OS <-> Application interface
This commit simplifies OS <-> Application interface controlling power
management. In the previous approach application-based PM required
overriding sys_suspend() and sys_resume() functions. As these functions
actually implemented power state change, in such case application
basically had to provide own implementation of all PM-related stuff,
which was not portable and hard to maintain.

This commit changes this scheme: The sys_suspend() and sys_resume()
are now system functions while the application could either use
built-in power management policies or provide its own. All details
of power mode switching are now handled by the OS.

Also, this commit cleans up the Kconfig options related to system-level
power management grouping them under common CONFIG_SYS_PM_ prefix.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-02-19 13:25:36 -05:00
Andrew Boie
4ae33f0b55 tests: fatal: refactor and add user mode tests
We weren't testing whether stack overflows in user mode
were correctly reported.

A more aggressive stack overflow logic is enabled if
HW-based stack overflow detection is enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-15 09:48:37 -05:00
Andrew Boie
2cfeba8507 x86: implement interrupt stack trampoline
Upon hard/soft irq or exception entry/exit, handle transitions
off or onto the trampoline stack, which is the only stack that
can be used on the kernel side when the shadow page table
is active. We swap page tables when on this stack.

Adjustments to page tables are now as follows:

- Any adjustments for stack memory access now are always done
  to the user page tables

- Any adjustments for memory domains are now always done to
  the user page tables

- With KPTI, resetting a page now clears the present bit

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie
f093285345 x86: modify MMU APIs for multiple page tables
Current set of APIs and macros assumed that only one set
of page tables would ever be in use.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Kumar Gala
1f59e9e825 tests: kernel: gen_isr_table: Exclude platforms test isnt valid on
The test assumes that the last to IRQ number will be free, this isn't a
valid assumption and now that we detect multiple ISRs registering for
the some IRQ line, we see failures because of this assumption on some
platforms.  Exclude those platforms from this test for the time being.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-12 15:35:29 -05:00
Piotr Zięcik
7a49356c77 power: Fix naming of Kconfig options controlling low power states
The SYS_POWER_LOW_POWER_STATE_SUPPORTED and SYS_POWER_LOW_POWER_STATE
suggests one low power state but these options control multiple
low power state. This commit uses plural in the names to indicate
that.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-02-12 07:46:32 -05:00
Andy Ross
d653e6868e tests/kernel/schedule_api: Bump stack size and unify stacks
The new spinlock validation features combined with spinlockification
have increased stack usage a bit in CONFIG_ASSERT builds, but this is
a good feature we want to keep.  This test was bumping into limits, so
increase the size from 512 to 640 bytes.

Unfortunately, this is also a huge test that creates a LOT of those
stacks across different test cases, so that minor bump blows us past
the 64k SRAM limit on a bunch of boards.  So unify all those stacks
that are only ever used in one case at a time so the memory can be
shared.  Now there's one fixed stack, named "tstack", and one array
"tstacks".  Much smaller.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-08 14:49:39 -05:00
Andy Ross
1bf9bd04b1 kernel: Add _unlocked() variant to context switch primitives
These functions, for good design reason, take a locking key to
atomically release along with the context swtich.  But there's still a
common pattern in code to do a switch unconditionally by passing
irq_lock() directly.  On SMP that's a little hurtful as it spams the
global lock.  Provide an _unlocked() variant for
_Swap/_reschedule/_pend_curr for simplicity and efficiency.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-08 14:49:39 -05:00
Andy Ross
aa6e21c24c kernel: Split _Swap() API into irqlock and spinlock variants
We want a _Swap() variant that can atomically release/restore a
spinlock state in addition to the legacy irqlock.  The function as it
was is now named "_Swap_irqlock()", while _Swap() now refers to a
spinlock and takes two arguments.  The former will be going away once
existing users (not that many!  Swap() is an internal API, and the
long port away from legacy irqlocking is going to be happening mostly
in drivers) are ported to spinlocks.

Obviously on uniprocessor setups, these produce identical code.  But
SMP requires that the correct API be used to maintain the global lock.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-08 14:49:39 -05:00
Piotr Zięcik
d02e3ebd4c power: Eliminate SYS_PM_* power states.
The power management framework used two different abstractions
to describe power states. The SYS_PM_* given coarse information
what kind of power state (low power or deep sleep) was used,
while the SYS_POWER_STATE_* abstraction provided information
about particular power mode.

This commit removes the SYS_PM_* abstraction as the same
information is already carried in SYS_POWER_STATE_*.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2019-02-08 09:07:00 -05:00
Andrew Boie
41f6011c36 userspace: remove APPLICATION_MEMORY feature
This was never a long-term solution, more of a gross hack
to get test cases working until we could figure out a good
end-to-end solution for memory domains that generated
appropriate linker sections. Now that we have this with
the app shared memory feature, and have converted all tests
to remove it, delete this feature.

To date all userspace APIs have been tagged as 'experimental'
which sidesteps deprecation policies.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andrew Boie
525065dd8b tests: convert to use app shared memory
CONFIG_APPLICATION_MEMORY was a stopgap feature that is
being removed from the kernel. Convert tests and samples
to use the application shared memory feature instead,
in most cases using the domain set up by ztest.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andrew Boie
84c808918b tests: set CONFIG_MAX_THREAD_BYTES for a few tests
Some tests instantiate a lot of thread objects. These
were not tagged with __kernel, and
CONFIG_APPLICATION_MEMORY was enabled, so the kernel was
not adding them to the kernel object database.

However, with CONFIG_APPLICATION_MEMORY disabled, this
overflowed the default max number of thread objects (16).
Increase the max to 32 for these particular tests.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andrew Boie
62a6f87139 tests: remove app_memory test
CONFIG_APPLICATION_MEMORY is being removed from
Zephyr.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andrew Boie
889b2377ef tests: userspace: remove extra_sections
This is unnecessary.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andrew Boie
8bfd8457ea tests: mem_protect: fix Kconfig
We want CONFIG_APPLICATION_MEMORY specifically disabled
for this test, but it was being transitively selected by
CONFIG_TEST_USERSPACE which defaults to on for CONFIG_TEST.

Turn it off so that disabling application memory in the
config actually has an effect.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Kumar Gala
5ef93aa639 tests: kernel: interrupt: Exclude platforms test isnt valid on
The test assumes that the last to IRQ numbers will be free, this isn't a
valid assumption and now that we detect multiple ISRs registering for
the some IRQ line, we see failures because of this assumption on some
platforms.  Exclude those platforms from this test for the time being.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-07 15:58:43 -05:00
Anas Nashif
177df596d3 tests: irq_offload: remove irq_offload test
This is now part of kernel/common.
Forgot to remove it in d0bcf27eab

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-06 10:10:42 -05:00
Andrew Boie
2d9bbdf5f3 x86: remove support for non-PAE page tables
PAE tables introduce the NX bit which is very desirable
from a security perspetive, back in 1995.

PAE tables are larger, but we are not targeting x86 memory
protection for RAM constrained devices.

Remove the old style 32-bit tables to make the x86 port
easier to maintain.

Renamed some verbosely named data structures, and fixed
incorrect number of entries for the page directory
pointer table.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-05 20:51:21 -08:00
Anas Nashif
d0bcf27eab tests: common: move irq_offload test to common
This is a small test that can be easily integrated into the common set
of tests we have already.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-05 20:40:07 -05:00
Anas Nashif
d35f1150f3 tests: common: move boot_delay test to common
This is a small test that can be easily integrated into the common set
of tests we have already.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-05 20:40:07 -05:00
Anas Nashif
3f27247617 tests: common: move errno test to common
This is a small test that can be easily integrated into the common set
of tests we have already.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-05 20:40:07 -05:00
Ioannis Glaropoulos
2782a00a00 tests: kernel: interrupt: group IRQ line number selection together
This commit moves the definition of IRQ_LINE(..) macro from
interrupt.h into nested_irq.c, and adds some inline comments
documenting the use of it.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-04 20:50:59 -05:00
Andy Ross
54dd1a3cf1 tests/threads/thread_apis: Add test for CPU mask API
Very simple test for thread CPU masks.  While this is a SMP feature,
the implementation doesn't actually depend on SMP so we can test it
right here in the thread_apis test.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-01 21:37:24 -05:00
Andy Ross
eda4c027da misc/dlist: Swap insertion API for a faster one
The sys_dlist_insert_*() functions had a behavior where a NULL
argument for the insertion position to sys_dlist_insert_after/before()
was interpreted as "the end of the list".  We never used that
convention (except in one spot internal to dlist.h which was not
itself used anywhere), and of course already have an API for appending
and prepending to a list.

In practice this was a performance disaster.  The NULL check is
virtually never provable statically by the compiler, so that test and
branch is present always.  And worse, the check and call to another
function was pushing this beyond the complexity limit for gcc to
inline a function (at -Os optimization anyway), forcing us to use
function calls for what should be a ~8 instruction sequence.  The
upshot is that dlist insertions were 2-3x slower than they needed to
be.

Deprecate these older APIs and introduce a new sys_dlist_insert() call
which can be much better optimized.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-01 15:57:21 -05:00
Anas Nashif
a93651085e boards: remove pulpino board
This board is unmaintained and unsupported. It is not known to work and
has lots of conditional code across the tree that makes code
unmaintainable.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-31 22:47:18 -05:00
Andrew Boie
c253a686bf app_shmem: auto-initialize partitions
There are no longer per-partition initialization functions.
Instead, we iterate over all of them at boot to set up the
derived k_mem_partitions properly.

Some ARC-specific hacks that should never have been applied
have been removed from the userspace test.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-01-30 23:15:51 -05:00
Andrew Boie
85e1fcb02a app_shmem: renamespace and document
The public APIs for application shared memory are now
properly documented and conform to zephyr naming
conventions.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-01-30 15:43:58 -08:00
Andrew Boie
f278f31da1 app_shmem: delete parallel API for domains
The app shared memory macros for declaring domains provide
no value, despite the stated intentions.

Just declare memory domains using the standard APIs for it.

To support this, symbols declared for app shared memory
partitions now are struct k_mem_partition, which can be
passed to the k_mem_domain APIs as normal, instead of the
app_region structs which are of no interest to the end
user.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-01-29 11:11:49 -08:00
Johan Hedberg
e405fc41f2 atomic: Add atomic_set_bit_to() API
Several places in the code have constructions like this:

	if (bool_variable) {
		atomic_set_bit(flags, FLAG);
	} else {
		atomic_clear_bit(flags, FLAG);
	}

To reduce the amount of code for such situations, introduce a new
atomic_set_bit_to() helper which lets you condense the above five
lines to a single one:

	atomic_set_bit_to(flags, FLAG, bool_variable);

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2019-01-25 17:35:44 -05:00
Peter A. Bigot
d40b8ce1fb sys: dlist: Add sys_dnode_is_linked
The original implementation allows a list to be corrupted by list
operations on the removed node.  Existing code attempts to avoid this by
using external state to determine whether a node is in a list, but this
is fragile and fails when the state that holds the flag value is changed
after the node is removed, e.g. in preparation for re-using the node.

Follow Linux in invalidating the link pointers in a removed node.  Add
API so that detection of particpation in a list is available at the node
abstraction.

This solution relies on the following steady-state invariants:
* A node (as opposed to a list) will never be adjacent to itself in a
  list;
* The next and prev pointers of a node are always either both null or
  both non-null.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-01-23 20:46:49 +01:00
Andrzej Głąbek
37fbff6179 drivers: nrf: Adjust clock_control and timer drivers for nRF9160
Minor adjustments are done to the nRF clock_control and rtc_timer
drivers to make them usable on nRF9160 as well.
The arm_irq_vector_table test code is modified only because it uses
the function that has been renamed in the nrf_rtc_timer driver.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-01-21 10:13:34 +01:00
Andrew Boie
970758408b printk: don't print incorrect 64-bit integers
printk is supposed to be very lean, but should at least not
print garbage values. Now when a 64-bit integral value is
passed in to be printed, 'ERR' will be reported if it doesn't
fit in 32-bits instead of truncating it.

The printk documentation was slightly out of date, this has been
updated.

Fixes: #7179

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-01-18 08:23:15 -08:00
Andrew Boie
dfeed647f5 printk: fix printing 64-bit hex values
These were being truncated to 32-bits, and only 8
hex digits were supported.

An extraneous printk() at the beginning of the test
which was not being tested in any way has been removed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-01-17 14:59:03 -06:00
Peter A. Bigot
bfad9721d2 kernel: remove k_alert API
This API was used in only one place in non-test code.  See whether we
can remove it.

Closes #12232

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-01-16 21:34:07 -05:00
Adithya Baglody
25572f3b85 tests: Dont run coverage for select test cases.
Disabled the CONFIG_COVERAGE for benchmarks and other tests.
This is needed because it interferes with normal behavior of the
test case.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-16 06:12:33 -05:00
Adithya Baglody
516bf34df5 tests: Increase the stack size by CONFIG_TEST_EXTRA_STACKSIZE.
These tests need to use stack size as a function of
CONFIG_TEST_EXTRA_STACKSIZE. These test will fail when
CONFIG_COVERAGE is enabled.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2019-01-16 06:12:33 -05:00
Andy Ross
f033d542ad tests: samples: Disable newlib tests on x86_64
This builds with a host compiler, not one from the SDK, and so no
newlib library is available.  There is work to enable newlib detection
at and above the cmake level.  This patch can be reverted when that
lands.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Andy Ross
0cc362f873 tests/kernel: Simplify timer spinning
There is actually nothing wrong with this test code idiom.  But it's
tickling a qemu emulator bug with the hpet driver and x86_64[1].  The
rapidly spinning calls to k_uptime_get_32() need to disable
interrupts, read timer hardware state and enable them.  Something goes
wrong in qemu with this process and the timer interrupt gets lost.
The counter blows right past the comparator without delivering its
interrupt, and thus the interrupt won't be delivered until the counter
is next reset in idle after exit from the busy loop, which is
obviously too late to interrupt the timeslicing thread.

Just replace the loops with a single call to k_busy_wait().  The
resulting code ends up being much simpler anyway.  An added bonus is
that we can remove the special case handling for native_posix (which
was an entirely unrelated thing, but with a similar symptom).

[1] But oddly not the same emulated hardware running with the same
driver under the same qemu binary when used with a 32 bit kernel.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Andy Ross
870e8188a8 tests/kernel/sched/schedule_api: Honor TEST_EXTRA_STACKSIZE
Stacks created by tests should add this amount so thread-hungry
architectures can tune it.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Andy Ross
31e79a791e tests/kernel/mem_protect/stackprot: Whitelist x86_64
This architecture doesn't support stack canaries.  In fact the gcc
-fstack-protect features don't seem to be working at all.  I'm
guessing it's an x32 ABI mismatch?

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Andy Ross
b69d0da82d arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().

The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.

Limitations:

+ Right now the SDK lacks an x86_64 toolchain.  The build will fall
  back to a host toolchain if it finds no cross compiler defined,
  which is tested to work on gcc 8.2.1 right now.

+ No x87/SSE/AVX usage is allowed.  This is a stronger limitation than
  other architectures where the instructions work from one thread even
  if the context switch code doesn't support it.  We are passing
  -no-sse to prevent gcc from automatically generating SSE
  instructions for non-floating-point purposes, which has the side
  effect of changing the ABI.  Future work to handle the FPU registers
  will need to be combined with an "application" ABI distinct from the
  kernel one (or just to require USERSPACE).

+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
  of all memory.  No MMU/USERSPACE support yet.

+ We are building with -mno-red-zone for stack size reasons, but this
  is a valuable optimization.  Enabling it requires automatic stack
  switching, which requires a TSS, which means it has to happen after
  MMU support.

+ The OS runs in 64 bit mode, but for compatibility reasons is
  compiled to the 32 bit "X32" ABI.  So while the full 64 bit
  registers and instruction set are available, C pointers are 32 bits
  long and Zephyr is constrained to run in the bottom 4G of memory.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Andy Ross
0f075753b8 tests/kernel/threads/thread_apis: Fix include hygine
These files were relying on _thread_essential_set() from
kernel_internal.h, but not including it directly.  New architectures
won't transitively include things the same way.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Adithya Baglody
4c1667fbfa tests: Updated all the tests which use k_thread_access_grant.
With the new implementation we do not need a NULL terminated list
of kobjects. Therefore the list will only contain valid entries
of kobjects.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2019-01-03 12:35:14 -08:00
Andy Ross
b748d5219a tests/kernel/timer_api: Synchronize racy subtest
The test_timer_periodicity test is racy and subject to initial state
bugs.  The operation of that test is to:

1. Start a timer with a known period
2. Take the current time with k_uptime_get()
3. Wait for the timer to fire with k_timer_status_sync()
4. Check that the current time minus start time is the period

But that's wrong, because a tick expiring between any of the first
three steps is going to skew the math (i.e. the timer will have
started on a different tick than the "start time").

And taking an interrupt lock around the process can't fix the issue,
because in the tickless world we live in k_uptime_get() is actually a
realtime quanity based on a hardware counter and doesn't rely on
interrupt delivery.

Instead, use another timer object to synchronize the test start to a
driver tick, ensuring that even if the race is unfixable the initial
conditions are always correct.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-03 12:29:02 -05:00
Anas Nashif
5060ca6a30 cmake: increase minimal required version to 3.13.1
Move to latest cmake version with many bug fixes and enhancements.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-01-03 11:51:29 -05:00
Anas Nashif
74a74bb6b8 power: rename api sys_soc -> sys_
sys_soc is just redundant, just call APIs with sys_*.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-28 16:16:28 -05:00
Anas Nashif
9151fbebf2 power: rename APIs and removing leading _
Remove leading underscore from PM APIs. _ was used for internal APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-12-28 16:16:28 -05:00
Spoorthi K
e62e54bdcd tests: interrupt: Change IRQ priorities in test
Keeping IRQ0 priority as 1 and IRQ1 priority as 0
so that system timer which of priority 0 in ARC
will be interrupted by IRQ1 of same priority.
In ARM, system timer is of priority 1, hence
making ISR0 priority as 2 and ISR1 priority as 1.
Thus system timer will always be interrupted by
ISR1 in both the architectures.

Fixes: #12147

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-12-21 21:04:36 +01:00
Spoorthi K
82f73bd5e3 tests: nested_irq: Fix k_busy_wait usage and interrupt priority
k_busy_wait() call used in test expects time in us, but the test
is specifying wait in ms.

Also the test fails on NRF5 platform as the test hardcodes the
interrupts priority to 0 and 1 and assumes system timer to be of
priority 0 which is not the case in NRF5 platforms as per
@pizi-nordic where system timer is at priority 1. Hence changing
test interrupts to 1 and 2.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-12-11 13:36:52 -05:00
Andrew Boie
5f793cc25c tests: mem_pool_api: reduce stack usage
Some arches were getting a stack overflow in ISR context.

Fixes: #9777

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-12-07 20:09:47 -05:00
Ioannis Glaropoulos
e8e5c388b4 test: kernel: userspace: add include for arm core mpu
In the wake of dfa7a354ff2a31fea8614b3876b051aadc30b242, where
the inclusions for MPU APIs were clean-up, we need to directly
include arm_core_mpu_dev.h in the userspace test suite, which
invokes arm_core_mpu_enable/disable(), directly. The same is
already done for ARC MPU.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-12-05 15:15:07 -05:00
Patrik Flykt
440b535602 tests: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Andrew Boie
2b1d54e897 kernel: add user mode work_q capability
This allows for workqueues to be started in user mode.
No additional kernel objects or system calls are defined
other than starting the workqueue in user mode; for
permission purposes the embedded queue and thread objects
are sufficient.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-11-29 09:21:18 -08:00
Andrew Boie
3ced428f2f tests: don't enable application memory
This shouldn't be enabled unless the test case is
specifically testing the feature.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-11-28 15:33:11 -08:00
Piotr Mienkowski
970aef2905 kernel: ensure System Power Managment enables Tickless Idle.
System Power Management is only supported in Tickless Idle mode.
This patch modifies Kconfig dependencies to ensure System Power
Management option selects Tickless Idle one.

Fixes: #11046

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2018-11-21 23:16:35 -05:00
Andrew Boie
3aa59a6eed tests: test dynamic IRQ APIs
The gen_isr_table test now tries to install two dynamic
IRQ handlers.

RISCV32 has a workaround due to limited number of SW
triggerable interrupts that can be configured.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-11-20 09:30:34 -05:00
Spoorthi K
06fa2e6764 tests: msgq: Modify test to verify k_msgq_peek
Verify k_msgq_peek() API functionality by
modifying existing test suite.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-11-19 22:43:04 -05:00
Andy Ross
39b2a09f38 drivers/timer: New xtensa timer with tickless support
Rewritten Xtensa CCOUNT driver along the lines of all the other new
drivers.  The new API permits much smaller code.

Notably: The Xtensa counter is a 32 bit up-counter with a comparator
register.  It's in some sense the archetype of this kind of timer as
it's the simplest of the bunch (everything else has quirks: NRF is
very slow and 24 bit, HPET has a runtime frequency detection, RISC-V
is 64 bit...).  I should have written this one first.

Note also that this includes a blacklist of the xtensa architecture on
the tests/driver/ipm test.  I'm getting spurious failures there where
a k_sem_take() call with a non-zero timeout is being made out of the
console output code in interrupt context.  This seems to have nothing
to do with the timer; I suspect it's because the old timer drivers
would (incorrectly!) call z_clock_announce() in non-interrupt context
in some contexts (e.g. "expiring really soon").  Apparently this test
(or something in the IPM or Xtensa console code) was somehow relying
on that on Xtensa.  But IPM is a Quark thing and there's no particular
reason to run this test there.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross
ea35343eb1 tests/kernel/interrupt: Shrink very long k_busy_wait() argument
This test was written with an outrageously long timeout of 25 seconds.
That blows right through the 32 bit cycle counter on qemu_cortex_m3[1]
and produces an essentially random delay instead of the desired
number, causing a hang with the new SysTick driver in tickless mode.

Push the number down so it doesn't overflow.  The root cause, though,
is that k_busy_wait() can take arguments it can't handle.  It ought to
have an outer loop or something so that it can spin for INT_MAX
milliseconds correctly.

[1] Which has a 12MHz clock rate.  Many hardware implementations are
much faster still.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross
4b305e1a25 tests/kernel/context: Limit no-tick-during-irq-load to !TICKLESS
When TICKLESS_KERNEL is enabled, the current time in ticks is based on
a hardware counter and not interrupt delivery (which is the whole
point of tickless), so irq-locking does not prevent time from
advancing.  Disable this test in that configuration.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Andy Ross
0f444c84e5 drivers/timer: Add a standard workaround for known qemu issues
Qemu doesn't like tickless.  By default[1] it tries to be realtime as
vied by the host CPU -- presenting read values from hardware cycle
counters and interrupt timings at the appropriate real world clock
times according to whatever the simulated counter frequency is.  But
when the host system is loaded, there is always the problem that the
qemu process might not see physical CPU time for large chunks of time
(i.e. a host OS scheduling quantum -- generally about the same size as
guest ticks!) leading to lost cycles.

When those timer interrupts are delivered by the emulated hardware at
fixed frequencies without software intervention, that's not so bad:
the work the guest has to do after the interrupt generally happens
synchronously (because the qemu process has just started running) and
nothing notices the dropout.

But with tickless, the interrupts need to be explicitly programmed by
guest software!  That means the driver needs to be sure it's going to
get some real CPU time within some small fraction of a Zephyr tick of
the right time, otherwise the computations get wonky.

The end result is that qemu tends to work with tickless well on an
unloaded/idle run, but not in situations (like sanitycheck) where it
needs to content with other processes for host CPU.

So, add a flag that drivers can use to "fake" tickless behavior when
run under qemu (only), and enable it (only!) for the small handful of
tests that are having trouble.

[1] There is an -icount feature to implement proper cycle counting at
the expense of real-world-time correspondence.  Maybe someday we might
get it to work for us.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-11-13 17:10:07 -05:00
Alberto Escolar Piedras
f1da7abc75 tests: kernel: context: Bugfix for POSIX arch in TICKLESS
In the POSIX architecture, with the inf_clock "SOC", time does
not pass while the CPU is running. Tests that require time to pass
while busy waiting should call k_busy_wait() or in some other way
set the CPU to idle. This test was setting the CPU to idle while
waiting for the next time slice. This is ok if the system tick
(timer) is active and awaking the CPU every system tick period.
But when configured in tickless mode that is not the case, and the
CPU was set to sleep for an indefinite amount of time.
This commit fixes it by using k_busy_wait(a few microseconds) inside
that busy wait loop instead.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-11-13 09:19:03 -05:00
Alberto Escolar Piedras
0682a51686 tests: kernel: sched: Bugfix for POSIX arch in TICKLESS
In the POSIX architecture, with the inf_clock "SOC", time does
not pass while the CPU is running. Tests that require time to pass
while busy waiting should call k_busy_wait() or in some other way
set the CPU to idle. This test was setting the CPU to idle while
waiting for the next time slice. This is ok if the system tick
(timer) is active and awaking the CPU every system tick period.
But when configured in tickless mode that is not the case, and the
CPU was set to sleep for an indefinite amount of time.
This commit fixes it by using k_busy_wait(a few microseconds) inside
that busy wait loop instead.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-11-13 09:19:03 -05:00
Alberto Escolar Piedras
018073b359 tests: kernel: tickless: Bugfix for POSIX arch in TICKLESS
In the POSIX architecture, with the inf_clock "SOC", time does
not pass while the CPU is running. Tests that require time to pass
while busy waiting should call k_busy_wait() or in some other way
set the CPU to idle. This test was setting the CPU to idle while
waiting for the next time slice. This is ok if the system tick
(timer) is active and awaking the CPU every system tick period.
But when configured in tickless mode that is not the case, and the
CPU was set to sleep for an indefinite amount of time.
This commit fixes it by using k_busy_wait(a few microseconds) inside
that busy wait loop instead.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-11-13 09:19:03 -05:00
Alberto Escolar Piedras
74e9ee967a tests: kernel: common: Bugfix for POSIX arch in TICKLESS
In the POSIX architecture, with the inf_clock "SOC", time does
not pass while the CPU is running. Tests that require time to pass
while busy waiting should call k_busy_wait() or in some other way
set the CPU to idle. This test was setting the CPU to idle while
waiting for the next time slice. This is ok if the system tick
(timer) is active and awaking the CPU every system tick period.
But when configured in tickless mode that is not the case, and the
CPU was set to sleep for an indefinite amount of time.
This commit fixes it by using k_busy_wait(a few microseconds) inside
that busy wait loop instead.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-11-13 09:19:03 -05:00
Alberto Escolar Piedras
bdc0a20f4e tests: sched: schedule_api: Bugfix for POSIX arch in TICKLESS
In the POSIX architecture, with the inf_clock "SOC", time does
not pass while the CPU is running. Tests that require time to pass
while busy waiting should call k_busy_wait() or in some other way
set the CPU to idle. This test was setting the CPU to idle while
waiting for the next time slice. This is ok if the system tick
(timer) is active and awaking the CPU every system tick period.
But when configured in tickless mode that is not the case, and the
CPU was set to sleep for an indefinite amount of time.
This commit fixes it by using k_busy_wait(a few microseconds) inside
that busy wait loop instead.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-11-13 09:19:03 -05:00
Niranjhana N
6316d774f2 tests: kernel: test force suspend of device
Add test for the force suspend of device by
setting state to device_set_power_state API.

Signed-off-by: Niranjhana N <niranjhana.n@intel.com>
2018-11-10 13:50:42 -05:00
Ioannis Glaropoulos
ff5d942db8 tests: kernel: userspace: minor typo fixes
Some minor style and typo fixes in
tests/kernel/mem_protect/userspace/src/main.c.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-06 16:14:41 -05:00
Flavio Ceolin
aecd4ecb8d kernel: Change k_poll_signal api
k_poll_signal was being used by both, struct and function. Besides
this being extremely error prone it is also a MISRA-C violation.
Changing the function to contain a verb, since it performs an action
and the struct will be a noun. This pattern must be formalized and
followed and across the project.

MISRA-C rules 5.7 and 5.9

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
Flavio Ceolin
a406b88fca kernel: Remove duplicated identifier
There was an struct and a variable called _kernel. This is error prone
and a MISRA-C violation. It is changing the struct to have a unique
identifier.

MISRA-C rule 5.8

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-04 11:37:24 -05:00
Kumar Gala
9db7175e67 tests: Remove board.h include
We either don't need board.h in the test or we should be include soc.h
instead.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:15:18 +01:00
Alberto Escolar Piedras
847b7ccbcc tests: kernel tickless: Bugfix for POSIX arch in TICKLESS
In the POSIX architecture, with the inf_clock "SOC", time does
not pass while the CPU is running. Tests that require time to pass
while busy waiting should call k_busy_wait() or in some other way
set the CPU to idle. This test was setting the CPU to idle while
waiting for the next time slice. This is ok if the system tick
(timer) is active and awaking the CPU every system tick period.
But when configured in tickless mode that is not the case, and the
CPU was set to sleep for an indefinite amount of time.
This commit fixes it by using k_busy_wait(a few microseconds) inside
that busy wait loop instead.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-31 19:43:10 -04:00
Alberto Escolar Piedras
574fc953e2 tests: sleep: Bugfix for POSIX arch in TICKLESS
In the POSIX architecture, with the inf_clock "SOC", time does
not pass while the CPU is running. Tests that require time to pass
while busy waiting should call k_busy_wait() or in some other way
set the CPU to idle. This test was setting the CPU to idle while
waiting for the next time slice. This is ok if the system tick
(timer) is active and awaking the CPU every system tick period.
But when configured in tickless mode that is not the case, and the
CPU was set to sleep for an indefinite amount of time.
This commit fixes it by using k_busy_wait(a few microseconds) inside
that busy wait loop instead.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-31 19:43:10 -04:00
Alberto Escolar Piedras
a57ddef003 tests: sched: schedule_api: Bugfix for POSIX arch in TICKLESS
In the POSIX architecture, with the inf_clock "SOC", time does
not pass while the CPU is running. Tests that require time to pass
while busy waiting should call k_busy_wait() or in some other way
set the CPU to idle. This test was setting the CPU to idle while
waiting for the next time slice. This is ok if the system tick
(timer) is active and awaking the CPU every system tick period.
But when configured in tickless mode that is not the case, and the
CPU was set to sleep for an indefinite amount of time.
This commit fixes it by using k_busy_wait(a few microseconds) inside
that busy wait loop instead.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-10-31 19:43:10 -04:00
Spoorthi K
a94f97b4b3 tests: kernel: Validate set thread name to current thread
Enhance test to validate a scenario where k_thread_name_set()
    with NULL as thread ID should set thread name to current
    thread.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-10-29 10:17:10 -04:00
Adithya Baglody
24b89f12eb tests: sched: schedule_api: Increase the minimum ram needed.
This test was failing on nrf52810_pca10040 due to lack of RAM.
It was a side effect of increasing the privilege stack size.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-10-28 11:43:32 -04:00
Reto Schneider
7eabab2f5d samples, tests: Use semi-accurate project names
When using an IDE (e.g. Eclipse, Qt Creator), the project name gets
displayed. This greatly simplifies the navigation between projects when
having many of them open at the same time. Naming every project "NONE"
defeats this functionality.

This patch tries to use sensible project names while not duplicating
too much of what is already represented in the path. This is done by
using the name of the directory the relevant CMakeLists.txt file is
stored in. To ensure unique project names in the samples (and again, in
the tests folder) folder, small manual adjustments have been done.

Signed-off-by: Reto Schneider <code@reto-schneider.ch>
2018-10-27 21:31:25 -04:00
Anas Nashif
d3ed3f11fa tests: interrupt: disable riscv32
This is a new test and we have riscv32 failing on that all of the
sudden. Disabling while we look into it and identify if that is a
testcase issue or not.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-16 21:27:23 -04:00
Andy Ross
a715a5fc57 tests/kernel/context: Skip test_kernel_cpu_idle when tickless
This test was written to assume that on idle the CPU would wake up on
the next tick boundary because of the timer interrupt.  No such
interrupt arrives in tickless mode and it hangs forever.

A more whiteboxy test involving setting a clock timout will have to be
written for this feature if we want to keep it on tickless systems.
Alternatively we could move this test out of tests/kernel/context and
always disable tickless.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross
4f02dd1407 tests/kernel/context: Disable test_kernel_interrupts when tickless
The theory behind this test seems to be that taking an IRQ lock should
prevent the advance of the kernel's tick counter.  That works on
traditional timers only.  In tickless mode the timer hardware/driver
is expected to be able to give us an answer for time independent of
interrupt delivery, so the test fails spuriously.  The "bug" detected
is a feature of tickless!

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross
cfe62038d2 kernel: Checkpatch fixups
I was pretty careful, but these snuck in.  Most of them are due to
overbroad string replacements in comments.  The pull request is very
large, and I'm too lazy to find exactly where to back-merge all of
these.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross
af7bf89ed2 tests/kernel: Bump stack size for mem_protect/stackprot
This test needs just a tiny bit of extra stack.  512 bytes isn't
enough on x86 with the most recent set of timer patches.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross
7aae75bd1c idle: Fix tickless timeout behavior
If the idle code was detecting that it needed to sleep for less than
CONFIG_SYS_TICKLESS_IDLE_THRESH, then it would never call
z_clock_set_timeout() at all, which means that the system would never
wake up unless it already had a timeout scheduled!  Apparently we
lacked a test case to detect this condition.

Honestly this seems like a crazy feature to me.  There's no benefit in
delivering needless tick announcements.  If the system has the
capacity to enter deeper sleep for long timeouts, that's already
exposed via the PM APIs, the timer subsystem needn't be involved.
But... we actually have a test (tickless_concept) that looks at this,
so support it for now and consider deprecation later.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross
317178b88f sys_clock: Fix unsafe tick count usage
The system tick count is a 64 bit quantity that gets updated from
interrupt context, meaning that it's dangerously non-atomic and has to
be locked.  The core kernel clock code did this right.

But the value was also exposed to the rest of the universe as a global
variable, and virtually nothing else was doing this correctly.  Even
in the timer ISRs themselves, the interrupts may be themselves
preempted (most of our architectures support nested interrupts) by
code that wants to set timeouts and inspect system uptime.

Define a z_tick_{get,set}() API, eliminate the old variable, and make
sure everyone uses the right mechanism.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross
b2e4283555 sys_clock: Make sys_clock_hw_cycles_per_tick() a proper API
This was another "global variable" API.  Give it function syntax too.
Also add a warning, because on nRF devices (at least) the cycle clock
runs in kHz and is too slow to give a precise answer here.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Andy Ross
220d4f8347 sys_clock.h: Make "global variable" APIs into proper functions
The existing API defined sys_clock_{hw_cycles,ticks}_per_sec as simple
"variables" to be shared, except that they were only real storage in
certain modes (the HPET driver, basically) and everywhere else they
were a build constant.

Properly, these should be an API defined by the timer driver (who
controls those rates) and consumed by the clock subsystem.  So give
them function syntax as a stepping stone to get there.

Note that this also removes the deprecated variable
_sys_clock_us_per_tick rather than give it the same treatment.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-10-16 15:03:10 -04:00
Anas Nashif
621f75bfa7 tests: remove bat_commit, replace core with kernel
bat_commit is an old and obsolete tag that has not been maintained over
time and was supposed to serve a purpose that is obsolete now. Also
rename core tag with kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-16 09:17:51 -04:00
Anas Nashif
91cdb35584 tests: fatal: fix condition for NXP MPU
Fixed condition and wrong Kconfig name, shoud be CONFIG_CPU_HAS_NXP_MPU
instead of only CPU_HAS_NXP_MPU.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-15 09:07:43 -04:00
Ajay Kishore
2a103ea674 tests: add tests to validate interrupt nesting feature
This test is intended to verify the interrupt nesting.
Interrupt nesting feature allows an ISR to be preempted
in mid-execution if a higher priority interrupt is signaled.
The lower priority ISR resumes execution once the higher
priority ISR has completed its processing.

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-10-10 19:59:47 -04:00
Ulf Magnusson
92ef8582b9 Kconfig: Remove redundant $(ZEPHYR_BASE) from 'source's
The $srctree environment variable gives the path relative to which
'(o)source' statements work (the current directory is used if $srctree
is unset). It is set to $ZEPHYR_BASE in cmake/kconfig.cmake, so there's
no need to qualify the source of Kconfig.zephyr in sample Kconfig files
(or in external projects).

All 'source's in Zephyr assume that the Zephyr root directory is used as
the srctree as well, and would break otherwise.

Remove the $(ZEPHYR_BASE)s to make it clearer that all 'source'
statements work relative to the Zephyr root. There was some user
confusion on IRC.

Also explain how things work in the documentation.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-10-10 11:28:27 -05:00
Ioannis Glaropoulos
52b729a6a4 arch: arm: fix mem domain sample/test for ARMv8-M access permissions
This commit updates the mem_domain_apis_test sample and the
mem_protect test, so they can compile and execute in ARMv8-M
platforms, which do not support the P_RW_U_RO access permissions
combination (privileged read/write, unprivileged read-only). The
modification consists of, simply, selecting a different access
permission (P_RO_U_RO) when building for ARMv8-M MPUs with the
unmodified ARM MPU architecture.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-10-09 19:33:24 -04:00
Anas Nashif
0a0c8c831f kernel: move to new logger
Use the new logger framework for kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 17:49:12 -04:00
Rajavardhan Gundi
fa77e400aa tests/kernel: fifo_timeout: Remove wake-up order checking
There is no guarantee of wake-up order when multiple threads
are woken up on the same tick. Hence, modified the tests
accordingly.

Fixes #8159.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-10-02 14:06:50 -07:00
Mark Ruvald Pedersen
d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Anas Nashif
f6e7e98909 tests: test k_thread_name_set
Basic test for new API: k_thread_name_set.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-27 08:58:55 +05:30
Sebastian Bøe
72e7bfa680 cmake: Remove unnecessary KCONFIG_ROOT configuration
It is no longer necessary to set the KCONFIG_ROOT variable when the
KConfig file is in the application root directory.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-09-21 13:37:21 -04:00
Ajay Kishore
22d653fd20 tests: sched: Use SCHED_MULTIQ for native posix platform
To improve the code coverage on native posix, adding CONFIG_SCHED_MULTIQ
for scheduler api tests.

Extracting a separate prj_native_posix.conf file for the scheduler test,
which validates the "multi queue" scheduler on native posix.

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-09-21 08:50:13 -04:00
Adithya Baglody
0e11792f4e tests: userspace: Incorrect location to the privileged stack.
The test case was supposed to access the privileged stack area
but instead it was accessing the stack guard region.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 20:35:25 -04:00
Adithya Baglody
b19f3ec2ba tests: mem_protect: mem_protect: Update the stack size.
This patch updates the alignment for the memory domain partitions.
Also update the stack size for qemu_cortex_m3.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 20:35:25 -04:00
Adithya Baglody
44057a197f tests: kernel: pipe : Update the stack size.
Now the stack size is a function of CONFIG_TEST_EXTRA_STACKSIZE.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 20:35:25 -04:00
Adithya Baglody
a8f2675604 tests: userspace: Update the required stack size for mps2_an385
Increasing the stack size to 1024.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 20:35:25 -04:00
Piotr Zięcik
1c16cfcc30 arch: arm: Make ARM_MPU the sole option controlling MPU usage
This commit removes all MPU-related (ARM_CORE_MPU and NXP_MPU)
options exept ARM_MPU, which becomes master switch controlling
MPU support on ARM.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-09-20 14:16:50 +02:00
Kumar Gala
05272d62b3 tests: mem_protect: syscalls: set CONFIG_USERSPACE in prj.conf
Set CONFIG_USERSPACE in the prj.conf to ensure its set, right now
getting CONFIG_USERSPACE depends on tests/Kconfig setting it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-09-18 17:03:57 -04:00
Flavio Ceolin
da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Ajay Kishore
75780a8135 tests: pipe: Enhance tests to improve code coverage
This test is intended to validate k_pipe_alloc_init()
and k_pipe_cleanup(), when CONFIG_USERSPACE is not defined.
Also added test to validate pending reader and pending writer
feature in pipe.

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-09-14 09:06:31 -04:00
Ulf Magnusson
d713033d5c Kconfig: Use new preprocessor syntax for env. variables
With the new Kconfig preprocessor (described in
https://github.com/torvalds/linux/blob/master/Documentation/kbuild/
kconfig-macro-language.txt), the syntax for expanding environment
variables is $(FOO) rather than $FOO.

$(FOO) is a general preprocessor variable expansion, which falls back to
environment variables if the variable isn't set (like in Make). It can
also be used in prompts, 'comment's, etc.

The old syntax will probably be supported forever in Kconfiglib for
backwards compatibility, but might as well make it consistent now that
people might start using the preprocessor more.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-09-11 19:17:25 -04:00
Andy Ross
a7e5d2f02e tests/kernel/sched/deadline: Disable CONFIG_BT
The BT threads are interfering with the main thread priority selection
and the test fails semi-spuriously on NRF5x boards with "threads ran
too soon" (i.e. not an EDF failure per se, but the fact that the new
threads at K_LOWEST_APPLICATION_PRIO are running instead of the test
thread).  This is a reasonable workaround for testing the
SCHED_DEADLINE ordering behavior, though.

Fixes #9843

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-09-08 08:43:06 -04:00
Andy Ross
02aa980042 tests: Add kernel/sched/deadline test for EDF validation
Simple test for CONFIG_SCHED_DEADLINE.  It creates a bunch of threads
at randome deadlines but within the same priority, and validates that
they run in the correct order.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-09-06 14:26:22 -04:00
Anas Nashif
c8402bc3ce tests: preempt: increase stack size for test
Failed with:

Running test suite suite_preempt
===================================================================
starting test - test_preempt
***** Stack Check Fail! *****
Current thread ID = 0x0040019c
eax: 0x00400254, ebx: 0x00400254, ecx: 0x004002b0, edx: 0x00000001
esi: 0x004001f8, edi: 0x00401080, ebp: 0x00408024, esp: 0x00408000
eflags: 0x00000046 cs: 0x0008
call trace:
eip: 0x00002115
     0x000021b8 (0x40019c)
     0x00002685 (0x4001f8)
     0x00004f65 (0x401120)
     0x00005187 (0x401120)
     0x000051c2 (0x40019c)
     0x000052be (0xffffffff)
     0x00005bab (0x246)
     0x000019c4 (0x400078)
Fatal fault in thread 0x0040019c! Aborting.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-31 11:14:39 -04:00
Anas Nashif
af17c195b4 tests: syscalls: ignore faults, they are intentional
We are blowing up the kernel here intentionally, so ignore the faults on
some platforms.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-30 15:05:30 -04:00
Andy Ross
2f95e2400f tests/kernel/threads/no-multithreading: Disable USERSPACE
Building with !MULTITHREADING is designed for bootloaders and similar
minimal-functionality use cases.  It's pathologically silly to combine
it with MMU drivers and address space partitioning, even though on
some architectures that technically works (on ARM, it seems not to).

The test intent was to disable this originally, but it turns out that
doesn't work.  There is a TEST_USERSPACE kconfig symbol that also
needs to be explicitly turned off, otherwise it will reselect
USERSPACE against our wishes.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-30 13:29:09 -04:00
Paul Sokolovsky
14742d79fe tests: k_poll: Add testcase to poll fifo which gets k_fifo_cancel_wait
In this case k_poll() returns -EINTR, while still fills in event
states.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-08-30 09:28:29 -04:00
Maureen Helm
3e41864e25 tests: gen_isr_table: Add barriers after triggering the irq
Fixes the gen_isr_table kernel test on mimxrt1050_evk by using data and
instruction synchronization barriers instead of disabling compiler
optimization on arm platforms. According to [1] section 4.5, "if a
pended interrupt request needs to be recognized immediately after being
enabled in the NVIC, add a DSB instruction and then an ISB instruction"

[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dai0321a/BIHJDAAE.html

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-08-29 18:48:42 -04:00
Daniel Leung
4a2ba0dd04 tests/kernel: pipes: add tests for smaller pipe buffers
This adds some test cases where the pipe buffer is smaller than
the size of data being pushed through the pipe.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-08-29 15:57:28 -04:00
Wayne Ren
3f2f6dda1a tests: a fix for ARC and MPU VER 3
For ARC MPU version 3, the defined partitions are not added to MPU
when appmem_init_app_memory is doning app_bss_zero().

So need to disable mpu first to allow appmem_init_app_memory to
access all partitions.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-08-28 13:57:50 -04:00
Anas Nashif
d2b4d8f049 tests: thread_api: increase stack for test
Add more stack for this test, it was failing and hidden by sanitycheck
(which needs to be fixed somewhere else).

Fixes #9664

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-27 18:41:22 -04:00
Ajay Kishore
f17b111e39 tests: kernel: init: Fix integer overflow issue
Cast the msec to nsec conversion macro with u64_t to fix the
integer overflow issue.

Fixes #9135

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-08-26 18:47:08 -07:00
Adithya Baglody
871cc3232f tests: kernel: sched: schedule_api: Increase stack size.
The stack size was way too less. Increasing the size to minimum
of 512 for all platforms.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-08-24 07:03:34 -07:00
Spoorthi K
2a72f500cb tests: smp: Modify test to verify thread delay
Improved test with thread delay and removed few prints.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-20 17:51:07 -07:00
Ajay Kishore
8c456f755d tests: mempool: Enhance tests to improve code coverage
Assisning system heap to the current thread.
And validate allocation and free memory from the same system
heap memory pool.

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-08-19 13:09:35 -07:00
Anas Nashif
ce88792a6e tests: fp_sharing: use filter
use CONFIG_ARMV7_M_ARMV8_M_FP as filter instead of platform_whitelist.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-19 12:26:13 -07:00
Adithya Baglody
f3e0566650 tests: kernel: fp_sharing: Added support for Cortex-M7
Added required macros to get the test case working with a
cortex-M7.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-08-19 12:26:13 -07:00
Ajay Kishore
47889cd12c tests: fatal: Add description and RTM links
Add doxygen groups, description and RTM links for
fatal test cases

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-08-17 06:18:21 -07:00
Flavio Ceolin
0866d18d03 irq: Fix irq_lock api usage
irq_lock returns an unsigned int, though, several places was using
signed int. This commit fix this behaviour.

In order to avoid this error happens again, a coccinelle script was
added and can be used to check violations.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-16 19:47:41 -07:00
Spoorthi K
1c721217df tests: smp: Additional tests to verify SMP functionality
Add tests to verify SMP functionality

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-16 15:48:40 -07:00
Praful Swarnakar
94acc18b3e coverage: tests: poll: Add test to validate multiple polling threads
Add testcase for validating poll events by manipultaing thread
state to improve code coverage. Also, add multiple threads to
wait on same event.

Signed-off-by: Praful Swarnakar <praful.swarnakar@intel.com>
2018-08-16 15:31:43 -07:00
Sebastian Bøe
55ee53ce91 cmake: Prepend 'cmake_minimum_required()' into 'app' build scripts
Prepend the text 'cmake_minimum_required(VERSION 3.8.2)' into the
application and test build scripts.

Modern versions of CMake will spam users with a deprecation warning
when the toplevel CMakeLists.txt does not specify a CMake
version. This is documented in bug #8355.

To resolve this we include a cmake_minimum_required() line into the
toplevel build scripts. Additionally, cmake_minimum_required is
invoked from within boilerplate.cmake. The highest version will be
enforced.

This patch allows us to afterwards change CMake policy CMP000 from OLD
to NEW which in turn finally rids us of the verbose warning.

The extra boilerplate is considered more acceptable than the verbosity
of the CMP0000 policy.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-08-15 04:06:50 -07:00
Piotr Zięcik
5b3a7ed740 tests: kernel: Do not use exact time in timing checks.
This commit replaces exact time compassion by a range check, allowing
the tests to pass on platforms which needs rounding in __ticks_to_ms()
and _ms_to_ticks().

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-08-14 07:18:44 -07:00
Ajay Kishore
4cc2866358 tests: FIFO: Add description and RTM links
Add doxygen groups, description and RTM links for
FIFO test cases

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-08-13 12:35:10 -07:00
Ajay Kishore
648477c6ed tests: static_idt: Add description and RTM links
Add doxygen groups, description and RTM links for
static idt test cases

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-08-13 12:34:11 -07:00
Spoorthi K
a54a887a70 tests: kernel: Add doxygen groups
Add doxygen groups for kernel test cases

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-13 07:02:21 -07:00
Spoorthi K
db9f6a9094 tests: obj_tracing: Enhance object tracing test
Enhance object tracing test to improve code coverage
of kernel object initialization.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-13 06:39:01 -07:00
Praful Swarnakar
68bde79ee5 tests: kernel: device: Add RTM link, description and doxygen group
Add RTM links, description and doxygen group for device test cases.

Signed-off-by: Praful Swarnakar <praful.swarnakar@intel.com>
2018-08-10 04:06:42 -07:00
Ajay Kishore
b3f4d6b057 tests: lifo: Add description and RTM links
Add doxygen groups, description and RTM links for
lifo test cases

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-08-10 04:03:59 -07:00
Ajay Kishore
dec8b9e559 tests: msgq: Add description and RTM links
Add doxygen groups, description and RTM links for
msgq test cases

Signed-off-by: Ajay Kishore <ajay.kishore@intel.com>
2018-08-10 04:03:16 -07:00
Spoorthi K
234f48e1ef tests: userspace: Add description and doxygen links
Add description and doxygen links to userspace test cases

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-10 03:55:44 -07:00
Spoorthi K
6910f15fcf tests: protection: Add description and doxygen group
Add description and doxygen groups for protection
test cases

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-10 03:55:44 -07:00
Spoorthi K
b32b39af05 tests: userspace: Remove extra call to same testcase
The test read_kobject_user_pipe() is called twice in
the test suite. There is no need of calling same test
twice. Removing the extra call.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-10 03:54:43 -07:00
Spoorthi K
0975663e3f tests: x86_mmu_api: Add description and doxygen groups
Add description, RTM links and doxygen groups for
x86_mmu_api test cases.

Signed-off-by: Spoorthi K <spoorthi.k@intel.com>
2018-08-10 03:53:57 -07:00