Commit Graph

124 Commits

Author SHA1 Message Date
Piotr Mienkowski 41c10d4f66 ztest: fix ztest thread priority in cooperative mode
By default ztest thread is running at the priority `-1`. This value is
invalid when the testcase is running in cooperative mode only. Set
default ztest thread priority to `-2` if this is the case. The fix is
modeled on the approach used to define the default
`MAIN_THREAD_PRIORITY`.

Signed-off-by: Piotr Mienkowski <piotr.mienkowski@gmail.com>
2021-04-21 08:10:36 -05:00
Henry Wang 7d88c3b79d tests: Add missing timestamp_serialize() for Armv8-R aarch64
This commit fixes the build error: "error implementation of
timestamp_serialize() not provided for your CPU target" for
fvp_baser_aemv8r tests.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
2021-04-13 07:47:44 -04:00
Anas Nashif 0ec3774bde userspace: rename _is_user_context -> k_is_user_context
This functions is being called across the tree, no reason why it should
not be a public API.

The current usage violates a few MISRA rules.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-04-01 05:34:17 -04:00
Carlo Caione 3539c2fbb3 arm/arm64: Make ARM64 a standalone architecture
Split ARM and ARM64 architectures.

Details:

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

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

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-03-30 08:18:23 -04:00
Eugeniy Paltsev d7b8d798c0 testsuite: generalize timestamp_serialize for all ARC CPUs
Generalize timestamp_serialize defenition for all ARC CPUs
instead of ARCv2 only.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
2021-03-25 07:23:02 -04:00
Reto Schneider c59cf6008b tests: ztest: Fix assert hook dependency
Without this fix, ztest_set_assert_valid() can only be used when
CONFIG_ZTEST_FATAL_HOOK is set.

Signed-off-by: Reto Schneider <reto.schneider@husqvarnagroup.com>
2021-03-22 15:59:25 -04:00
Anas Nashif 1aca2fbf4f ztest: fix header guard
rename __ZTEST_H__ -> ZEPHYR_TESTSUITE_INCLUDE_ZTEST_H_

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2021-03-22 13:46:03 -04:00
Andrew Boie acda9bf9ce linker-tool-gcc: revise for MMU support
We need to do a few things differently if we are to support
a virtual memory map, i.e. CONFIG_MMU where CONFIG_KERNEL_VM_BASE
is not the same as CONFIG_SRAM_BASE_ADDRESS.

 - All sections must be specified with a VMA and LMA, where
   VMA is the virtual address and LMA is the physical memory
   location.
 - All sections must be specified with ALIGN_WITH_INPUT to
   keep VMAs and LMAs synchronized

To do this, the existing linker macros need some adjustment:

 - GROUP_LINK_IN undefined when CONFIG_KERNEL_VM_BASE is not
   the same as CONFIG_SRAM_BASE_ADDRESS.
 - New macro GROUP_ROM_LINK_IN for text/rodata sections
 - New macro GROUP_NOLOAD_LINK_IN for bss/noinit sections
 - Implicit ALIGN_WITH_INPUT for all sections

GROUP_FOLLOWS_AT is unused anywhere in the kernel for years
now and has been removed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-03-16 15:03:44 -04:00
Enjia Mai 2c5e2c2394 tests: ztest: provide test execution times per ztest testcase
Add execution time for testing result of each ztest testcase as:

START - test_sem_multi_take_timeout_diff_sem
PASS - test_sem_multi_take_timeout_diff_sem in 2.54 seconds

Fix #32137.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-03-11 07:52:17 -05:00
Jan Van Winkel 4a9a49a185 ztest: Added support to return data via mock
Added support to mock framework to return data via function parameters

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2021-03-09 07:09:13 -05:00
Ioannis Glaropoulos 1d55f94a32 testsuite: only enable TEST_ARM_CORTEX_M when building tests
Add a dependency on TEST_ARM_CORTEX_M switch, so it
only gets switched on when building tests, not samples,
as originally intended.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2021-03-01 14:33:26 +03:00
Alexander Wachter 0c1877a999 ztest: fix z_assert_within() bounds
zassert_within should also compare on equality instead
of only greater/lower.
example:
zassert_within(1,1,0); // should return true
zassert_within(1,2,1); // should return true

Signed-off-by: Alexander Wachter <alexander@wachter.cloud>
2021-02-17 06:32:02 -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
Kumar Gala 3befd7d45f cleanup: rename sanitycheck references to twister
Cleanup references to sanitycheck that should now be twister.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2021-01-14 07:50:52 -06:00
Enjia Mai a420cb4fd5 tests: ztest: add a common fatal and assert hook for special purpose
This is in order to reduce the redundancy code writing for fatal and
assert handler for error case testing. They can be used both in kernel
and userspace, and are also SMP safe.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-01-13 09:05:31 -05:00
Jingru Wang d1665d32f4 gcov: Add coverage support for arc nsim platform
* add toolchain abstraction for coverage
* add select HAS_COVERAGE_SUPPORT to kconfig
* port gcov linker code to CKake for arc
* give user permission to gcov bss section
* expand the size of iccm and dccm to 1M

Signed-off-by: Jingru Wang <jingru@synopsys.com>
2021-01-12 07:16:19 -05:00
Marko Poljanić 2b92ae308b coverage: C++ fix loop in gcov_coverage_dump
During coverage reports generation in C++ code gcov_coverage_dump()
function would get stuck in endless loop. Fix by checking list head
pointer with current list pointer.

Signed-off-by: Marko Poljanić <mpoljanic@gmail.com>
2021-01-10 16:59:47 -05:00
Enjia Mai 8d5a22c3c1 tests: enable the code coverage report for qemu_x86_64
Enable the code coverage report for qemu_x86_64 platform.
See issue #17991 please.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2021-01-05 10:32:38 -08: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 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
Kumar Gala cc0c58c3af tests: coverage: GCOV counter value changed in GCC10.
Updated the GCOV_COUNTERS value, without which the coverage data
was corrupted when gcc 10.2 was used.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-11-18 22:17:58 -05:00
Martin Åberg 5d38a006a5 sparc: Add testsuite support
This commit provides the timestamp_serialize() define for the SPARC
architecture.

Co-authored-by: Nikolaus Huber <nikolaus.huber.melk@gmail.com>
Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
2020-11-13 14:53:55 -08:00
Andrew Boie 95bbc742ba kernel: move kernel object APIs to own header
Part of an effort to break up the gigantic kernel.h.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-10-12 12:21:46 -04:00
Anas Nashif 6f729383a8 tests: timestamp: minor cleanup
Minor cleanup and fixes.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-09-05 13:28:38 -05:00
Peter Bigot 9024669a67 testsuite: fix unittest cross-language flags
Unit tests may include C++ code, so ensure the compiler flags are
consistent to avoid link errors.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-31 11:02:35 -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
Jingru Wang dae250472f gcov: Add coverage support for arc qemu platform
* add toolchain abstraction for coverage
* add select HAS_COVERAGE_SUPPORT to kconfig
* port gcov linker code to CKake for arc

Signed-off-by: Jingru Wang <jingru@synopsys.com>
2020-08-26 12:32:39 +02:00
Anas Nashif 1d60a3e86f ztest: set thread name
If thread names are enabled, set thread name for the ztest thread for
tracing purposes.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-08-24 13:21:12 +02:00
Simon Glass c5d85e175f subsys/testsuite: Add an assert for a zero return code
Many functions signal success by returning a return code of zero. Add
an assertion for this.

Some functions can return a positive value to indicate success, where
they want to convey some information. This is not handled by this
assert function.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-08-19 19:20:35 -04:00
Peter Bigot dfb9f11be3 ztest: make arc/cpu.h override C++ safe
This override header declares structures and inline functions, which
must be given C language linkage to avoid conflicting declaration
errors with other headers.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-12 16:39:37 -05:00
Jett Rink 63283621ea ztest: clean up comments, strings, and interface
Clean up comment typos and wording for expect data functions.

Add a cast to (void *) to match convention set in expect value;
this allows the caller to avoid casting on every single call.

Signed-off-by: Jett Rink <jettrink@google.com>
2020-08-05 15:05:44 -04:00
Jett Rink 03c0990275 ztest: fix failure when exceeding mock parameter count
If you tried to use more mock parameters than were set in
CONFIG_ZTEST_PARAMETER_COUNT, you would get a random seg fault somewhere
unrelated to the mocking parameter as we would use memory past an array
bounds.

Signed-off-by: Jett Rink <jettrink@google.com>
2020-08-05 15:05:44 -04:00
Jett Rink a6e1706269 ztest: increase default mock parameter count
If one enables mocking, then they most likely want more than 1 mockable
or verifiable parameter by default. Bump the default number of mockable
parameters to 10 to handle most cases without needing to touch an
additional Kconfig option.

Signed-off-by: Jett Rink <jettrink@google.com>
2020-08-05 15:05:44 -04:00
Andrew Boie 9598a5fbff ztest: use kernel stack for cpuhold
These threads don't run in user mode, save some memory if
userspace is not enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-08-05 13:21:38 +02:00
Carles Cufi 244f826e3c cmake: remove _if_kconfig() functions
This set of functions seem to be there just because of historical
reasons, stemming from Kbuild. They are non-obvious and prone to errors,
so remove them in favor of the `_ifdef()` ones with an explicit
`CONFIG_` condition.

Script used:

git grep -l _if_kconfig | xargs sed -E -i
"s/_if_kconfig\(\s*(\w*)/_ifdef(CONFIG_\U\1\E \1/g"

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-08-01 12:35:20 +02: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
David Leach 87e02c62bd subsys/testsuite: Fix coverity null dereference warning
Coverity is not able to detect that the call to ztest_test_fail()
will not return so it emits a warning on a later access to
param. Add a return; after the call so coverity won't complain.

Fixes #25790

Signed-off-by: David Leach <david.leach@nxp.com>
2020-07-24 21:51:14 -04:00
David Leach 48f7f11998 subsys/ztest: Suppress Coverity warning
Coverity warnings on dead loop code. We know this can
occur if the NUM_CPUHOLD is defined as zero which occurs
when CONFIG_SMP is false.

Fixes #20516
Fixes #20517

Signed-off-by: David Leach <david.leach@nxp.com>
2020-07-24 21:51:14 -04:00
Anas Nashif be0dff6844 test: remove TEST_SHELL
No need for this now, all shells are enabled if CONFIG_SHELL is set.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-06-24 21:37:12 -04:00
Christoph Reiter 88765ad328 testsuite: Align testsuite output
Makes the output easier to read for humans.

Signed-off-by: Christoph Reiter <christoph.reiter@infineon.com>
2020-06-22 14:56:39 -04: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
Simon Glass 4b2c413e13 subsys/testsuite: Shorten the assertion messages
At present these can be very long since they include the full path of
the filename with the error.

    Assertion failed at /home/sglass/cosarm/zephry/zephyrproject/
	zephyr/tests/drivers/flash_simulator/src/main.c:102:
	test_write_read: (0 not equal to rc)

Reduce the length by omitting the current directory (where the tests
are being run) from the output:

    Assertion failed at tests/drivers/flash_simulator/src/main.c:102:
	test_write_read: (0 not equal to rc)

This improves usability for people running tests locally.

Signed-off-by: Simon Glass <sjg@chromium.org>
2020-05-13 16:23:39 +02:00
Jukka Rissanen 34b7a6c81c testsuite: Allow user to override minimal logging
The testsuite was always forcing minimal logging. This is problematic
as it does not allow user to see full logging string. Allow user to
override the minimal logging if needed, the default is still to
enable minimal logging.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2020-05-07 23:47:55 -05:00
Andrew Boie 1ff066548a ztest: end tests more robustly
If a ztest test case creates child thread(s), and one of the
descendent threads invokes ztest_test_pass(), ztest_test_fail(),
or ztest_thread_skip(), only that descendent thread will be
aborted.

Then ztest will try to run the next scenario on the ztest_thread
which is already in use. This was causing corruption issues on
SMP systems, and possibly other subtle, hard-to-debug
situations.

This patch ensures that ztest_thread is always dead before
re-using it, as run_test() now attempts to join on it instead
of using a semaphore.

The ztest_test_* functions now ensure that the ztest_thread
is always aborted, in addition to the current thread.

This isn't perfect. If the testcase spawned other threads,
they will keep running. The most robust way to fix this is to
iterate over all non-essential threads in the system and abort
them. Unfortunately, Zephyr doesn't have a facility to do
this safely.

It would also be simpler to re-use thread objects if
k_thread_create() could detect whether the thread was already
active and abort it, but this is currently not possible
since k_thread_create() can be used with uninitialzed
thread object memory and no checks are possible. This
may be improved in the future, see #23030.

Fixes: #22738
Partial fix for: #24713

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-05-07 19:21:16 -04:00
Marek Porwisz d9f8a6f8e9 subsys/testsuite: Extended mocking API to support arrays
I was missing mocking api to compare data under an address pointed
by a parameter as some functions may copy buffers before passing
further.
Created ztest_expect_data and ztest_check_expected_data.

Signed-off-by: Marek Porwisz <marek.porwisz@nordicsemi.no>
2020-05-04 12:00:02 +02:00
Anas Nashif 051602f4f3 sanitycheck: support coverage with unit tests
Fix setting coverage for unit tests and link against gcov when coverage
is enabled.

Fixes #24674

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2020-04-29 09:01:06 -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
Torsten Rasmussen d7862cf776 cmake: using ${ZEPHYR_BASE} instead of $ENV{ZEPHYR_BASE}
With the introduction of ZephyrConfig.cmake all parts of CMake code
should rely on the CMake ZEPHYR_BASE variable instead of the environment
setting.

This ensures that after the first CMake invocation, then all subsequent
invocation in same build folder will use same zephyr base.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Stephanos Ioannidis a033683783 arch: arm: aarch32: Rename `cortex_r` to `cortex_a_r`
This commit renames the `cortex_r` directory under the AArch32 to
`cortex_a_r`, in preparation for the AArch32 Cortex-A support.

The rationale for this renaming is that the Cortex-A and Cortex-R share
the same base design and the difference between them, other than the
MPU vs. MMU, is minimal.

Since most of the architecture port code and configurations will be
shared between the Cortex-A and Cortex-R architectures, it is
advantageous to have them together in the same directory.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2020-03-26 11:20:36 +01:00