Commit graph

336 commits

Author SHA1 Message Date
Joshua Lilly b3cba84dcd testsuite: coverage: allow access to gcov internals
This allows external applications wishing to report coverage data over
different interfaces the ability to do so by exposing the gcov list.

Signed-off-by: Joshua Lilly <jgl@meta.com>
2023-11-29 04:59:47 -08:00
Greter Raffael 774858c6dc ztest: Add comfort functions for non-zero return codes
Many functions return non-zero return codes on errors. I added an assert
for the case, when a function is expected to fail. It is just a
shorthand for `zassert_not_equal(0, ret);`, analogous to
`zassert_ok`, introduced in c5d85e175f.

I also added the corresponding `zassume_nok` and `zexpect_nok`.

Signed-off-by: Greter Raffael <rgreter@baumer.com>
2023-11-04 07:39:46 -04:00
Benedikt Schmidt c5b252d8f1 testssuite: fix thread function signatures
Fix thread function signatures to avoid stack corruption on thread exit.

Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
2023-10-30 12:24:34 +01:00
Piotr Kosycarz bc8b7dd6dd testsuite: coverage: allow gcov data dump directly on console
When there is no buffer for gcov hex data,
dump them directly to console.
This saves RAM which can be used to hold more gcov data.

Reduce number of gcov hex data send by console -
do not send space between every two digits.

Signed-off-by: Piotr Kosycarz <piotr.kosycarz@nordicsemi.no>
2023-10-25 09:57:15 +02:00
Flavio Ceolin c166685fcf ztest: Do not abort k_current_get from ISR
Do not abort k_current_get() from ISR.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-24 09:04:42 +02:00
Flavio Ceolin 564adad952 treewide: Add CODE_UNREACHABLE after k_thread_abort(current)
Compiler can't tell that k_thread_abort() won't return and issues a
warning unless we tell it that control never gets this far.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-24 09:04:42 +02:00
Anas Nashif 719fee2bbc doc: ztest: adapt ztest docs
Remove remaining usage and documenation of dropped kconfig that is now
the default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Anas Nashif 996c8457d7 ztest: remove old ztest api
Remove old Ztest API entirely. New API is the now the default.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Anas Nashif 01281ed8af ztest: enable ZTEST_NEW_API by default
Enable by default so we can remove kconfigs from tests/samples and keep
things working as before.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-10-20 15:04:29 +02:00
Flavio Ceolin e7bd10ae71 random: Rename random header
rand32.h does not make much sense, since the random subsystem
provides more APIs than just getting a random 32 bits value.

Rename it to random.h and get consistently with other
subsystems.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2023-10-10 14:23:50 +03:00
Joshua Lilly f51575212b testsuite: coverage: extend code coverage to include risc-v
This PR adds regions for gcov symbols in bss to enable gcov
functionality for risc-v

Signed-off-by: Joshua Lilly <jgl@meta.com>
2023-09-26 23:32:45 -04:00
Jordan Yates ca5931065c testsuite: boards: unit_testing: default HCI bus
Be explicit about the HCI backend that Bluetooth unit tests require.
Some unit tests depend on `BT_HAS_HCI_VS`, so also enable that.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-09-25 16:43:42 +02:00
Hake Huang acf3755d1c ztest_new: add CONFIG_ZTEST_NO_YIELD to ztest_new
Rather than yielding to idle thread, keep the part awake.
So debugger can still access it,
since some SOCs cannot be debugged in low power states.

Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
2023-09-18 06:50:08 -04:00
Gerard Marull-Paretas d4ffef507c testsuite: busy_sim: use POST_KERNEL
Devices should be initialized in pre/post-Kernel.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
2023-09-15 16:04:19 +02:00
Prashanth S 05fe627d79 drivers: interrupt-controller: Add VIM Interrupt Controller support
Add TI VIM (Vectored Interrupt Manager) interrupt controller support.
VIM is a TI specific custom interrupt controller for ARM cores.
In J721E soc, VIM aggregates interrupts to Cortex R5 cores.

TRM for J721e https://www.ti.com/lit/zip/spruil1
File: spruil1c.pdf
VIM: section 6.3.3.6

Signed-off-by: Prashanth S <slpp95prashanth@yahoo.com>
2023-09-04 10:53:09 +02:00
Alberto Escolar Piedras 9c0b12947e tests: interrupt util: Fix for native/posix targets
This utility header was accessing directly the interrupt
controller HW models, but those are not an interface one
can expect to not change, or to be avaliable in different
targets.
Instead we change it to use the APIs we have a contract
about, that is, the ones all POSIX arch boards are
expected to provide.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-09-01 09:54:27 +02:00
Nick Ward 2d65acca3a drivers: gpio: use gpio_is_ready_dt helper function
Update `struct gpio_dt_spec` use with gpio_is_ready_dt()

Signed-off-by: Nick Ward <nix.ward@gmail.com>
2023-08-28 08:48:35 -05:00
Alberto Escolar Piedras fd27bed45e cmake/toolchain: Support LLVM source profiling/coverage for native boards
Add a a new source coverage for native builds
and new kconfig choice of COVERAGE mode to select which:
* COVERAGE_NATIVE_GCOV: what we had until now with native builds
* COVERAGE_NATIVE_SOURCE: a new LLVM source coverage mode
* COVERAGE_GCOV: the old COVERAGE_GCOV (embedded gcov data generation).

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-08-28 10:35:21 +02:00
Gerard Marull-Paretas 9c961571a2 modules: cmsis: move glue code to modules/cmsis
The CMSIS module glue code was part of arch/ directory. Move it to
modules/cmsis, and provide a single entry point for it: cmsis_core.h.
This entry header will include the right CMSIS header (M or A/R).

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

All files including CMSIS have been updated.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-08-24 13:20:21 +02:00
Daniel Leung 7c91228896 ztest: rename shadow variables
This renames the shadow variables found by -Wshadow.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-08-10 08:14:12 +00:00
Al Semjonovs dee493d311 ztest: Fix test statistics reporting
Flaky tests give innacurate test summary indicating a misleading
passing test suite.  Add new status for flaky tests.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2023-08-09 07:38:22 -04:00
Anas Nashif 37da312439 Revert "ztest: Fix test statistics reporting"
This reverts commit 2af5ac8fbb.

Failures are not being captured correctly now:

 - PASS - [test_c_lib.test_strtoul] duration = 0.001 seconds
 - PASS - [test_c_lib.test_strxspn] duration = 0.001 seconds
 - FAIL - [test_c_lib.test_that_fails] duration = 0.002 seconds
 - PASS - [test_c_lib.test_time] duration = 0.001 seconds
 - PASS - [test_c_lib.test_tolower_toupper] duration = 0.001 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-08-07 15:40:24 -04:00
Al Semjonovs 2af5ac8fbb ztest: Fix test statistics reporting
Flaky tests give innacurate test summary indicating a misleading
passing test suite.  Add new status for flaky tests.

Signed-off-by: Al Semjonovs <asemjonovs@google.com>
2023-08-03 11:08:47 -04:00
Nicolas Pitre 52e2f83185 kernel/timeout: introduce the timepoint API
This is meant as a substitute for sys_clock_timeout_end_calc()

Current sys_clock_timeout_end_calc() usage opens up many bug
possibilities due to the actual timeout evaluation's open-coded nature.

Issue ##50611 is one example.

- Some users store the returned value in a signed variable, others in
  an unsigned one, making the comparison with UINT64_MAX (corresponding
  to K_FOREVER) wrong in the signed case.

- Some users compute the difference and store that in a signed variable
  to compare against 0 which still doesn't work with K_FOREVER. And when
  this difference is used as a timeout argument then the K_FOREVER
  nature of the timeout is lost.

- Some users complexify their code by special-casing K_NO_WAIT and
  K_FOREVER inline which is bad for both code readability and binary
  size.

Let's introduce a better abstraction to deal with absolute timepoints
with an opaque type to be used with a well-defined API.
The word "timeout" was avoided in the naming on purpose as the timeout
namespace is quite crowded already and it is preferable to make a
distinction between relative time periods (timeouts) and absolute time
values (timepoints).

A few stacks are also adjusted as they were too tight on X86.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2023-07-25 09:12:26 +02:00
Alberto Escolar Piedras 913920a06f ztests: Enable native specific functionality with embedded libCs
When building with the native simulator instead of attempting to
call directly to the host libC, use the trampolines provided
by the runner.
In this way we can build this code even if we are building
Zephyr with an embedded C library.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-07-13 07:44:11 -04:00
Alberto Escolar Piedras 56dc20eb1d Kconfig: Tidy up dependants of NATIVE_APPLICATION
So they depend or select on the right NATIVE_BUILD
instead of NATIVE_APPLICATION.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-07-05 07:01:19 -04:00
Yuval Peress 8e5cae7fa3 ztest: Allow 'before' functions to run in privilaged mode
When writing a test suite, it's more common to want the 'before'
hook to run in privilaged mode, even when the test is run in userspace.
Reconfigure ztest to first run the test thread callback in privilaged
mode and only enter userspace after the test rule and suite's 'before'
functions ran.

Signed-off-by: Yuval Peress <peress@google.com>
2023-06-23 12:30:46 -04:00
Alberto Escolar Piedras b4b2eaae35 ztests: Build POSIX arch extra functionality only if possible
The extra ztest functionality for the posix arch
requires the host libC. Disable it if we are
building with an embedded libC.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-06-23 09:05:00 +02:00
Daniel Leung e734911c96 ztest: syscalls: use zephyr_syscall_header
This adds a few line use zephyr_syscall_header() to include
headers containing syscall function prototypes.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2023-06-17 07:57:45 -04:00
Gerard Marull-Paretas 49ec35fe5e testsuite: group all test-related APIs under 'testing'
Before this change we had 2 top-level Doxygen entries for Testing APIs:

- Zephyr tests
- Zephyr testing suite

This patch creates a single top-level group to contain ZTest and FFF
extensions.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-31 14:39:29 -04:00
Lukasz Mrugala fe3f5816b8 testsuite: Docstring typo fix
Word 'platform' misspelled as 'platorm'.

Signed-off-by: Lukasz Mrugala <lukaszx.mrugala@intel.com>
2023-05-29 14:34:33 -04:00
Anas Nashif c0469e6bbd ztest: deprecate old ztest API
Deprecate old ztest APIs.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-05-28 11:35:12 -04:00
Alberto Escolar Piedras 0ae060d174 drivers: Console: Move all posix arch boards to same driver
All posix arch boards are required to provide the same
tracing/print API.
So, instead of having a different driver for native_posix and the
bsim boards, let's have a common one which uses this API.
This in turn results in the printk strings being printed in
the same underlaying backend as before with individual drivers.

A part from this, the native_posix console driver was a full
backend for the now long gone Zephyr console shell
(named legacy_shell from 527256501f
until it was retired in fd0b7f7767).
The whole input handling in this driver was dead code
(since 140a8d0c8a)

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2023-05-26 12:57:41 +02:00
Carlo Caione 6f3a13d974 barriers: Move __ISB() to the new API
Remove the arch-specific ARM-centric __ISB() macro and use the new
barrier API instead.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2023-05-24 13:13:57 -04:00
Fabio Baltieri b9ea2c2705 build: downgrade the no optimization ztest error to warning
The current approach of failing the build on ztest with no optimization
broke coverage builds, and generally raised some concerns about being
too aggressive.

Downgrade the error to a warning and rework the option to inhibit the
warning, while also dropping it automatically for POSIX (that are not
really affected by stack size) and coverage run (that always runs with
no optimization).

Will reconsider this down the road if we still see issues filed for the
tests broken with no optimization and no further tuning.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-05-23 14:51:24 +00:00
Fabio Baltieri f5830f3c3f ztest: error out when building tests with no compiler optimizations
Many tests are known to fail when built and no compiler optimizations.
Add a CMake check to error out when building a ztest based test with no
optimization, ask not file issues about it but also adds an opt-out
option to bypass the error for tests are actually designed to work in
this setup.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-05-22 12:25:43 -04:00
Gerard Marull-Paretas dacb3dbfeb iterable_sections: move to specific header
Until now iterable sections APIs have been part of the toolchain
(common) headers. They are not strictly related to a toolchain, they
just rely on linker providing support for sections. Most files relied on
indirect includes to access the API, now, it is included as needed.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-05-22 10:42:30 +02:00
Dmitrii Golovanov 63fc307404 tests: ztress: Extend ZTRESS_EXECUTE() description
Add more details on the number of thread contexts possible
for ZTRESS_EXECUTE().

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2023-05-09 08:47:53 -04:00
Dmitrii Golovanov 130652efbd tests: ztest: ztress: Fix out-of-bounds at ztress_execute
Fix ztress_execute() out-of-bounds in case it is called with timer
and for maximum number of threads allowed (CONFIG_ZTRESS_MAX_THREADS).

Signed-off-by: Dmitrii Golovanov <dmitrii.golovanov@intel.com>
2023-05-09 08:47:53 -04:00
Stine Åkredalen 938c59c063 ztest: mock: fix failed test printed message.
Corrected printed message on failing test with expected or received
NULL pointer in ztest_check_expected_data.

Signed-off-by: Stine Åkredalen <stine.akredalen@nordicsemi.no>
2023-04-14 12:39:52 -04:00
Gerard Marull-Paretas 667eeb11fb shell: fix MISRA 5.7 violations on struct shell
MISRA Rule 5.7 requires uniqueness of tag identifiers. Shell is
frequently problematic because many code uses `const struct shell
*shell`. This causes CI noise every time one of these shell files is
edited, so let's update all of them with `const struct shell *sh`
instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-14 12:21:08 +02:00
Keith Packard 0b90fd5adf samples, tests, boards: Switch main return type from void to int
As both C and C++ standards require applications running under an OS to
return 'int', adapt that for Zephyr to align with those standard. This also
eliminates errors when building with clang when not using -ffreestanding,
and reduces the need for compiler flags to silence warnings for both clang
and gcc.

Most of these changes were automated using coccinelle with the following
script:

@@
@@
- void
+ int
main(...) {
	...
-	return;
+	return 0;
	...
}

Approximately 40 files had to be edited by hand as coccinelle was unable to
fix them.

Signed-off-by: Keith Packard <keithp@keithp.com>
2023-04-14 07:49:41 +09:00
Gerard Marull-Paretas cb067800b4 ztest: mock: fix UNNECESSARY_INT compliance issue
Fix checkpatch issue: UNNECESSARY_INT: Prefer 'unsigned long' over
'unsigned long int' as the int is unnecessary

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 16:42:29 +02:00
Gerard Marull-Paretas 4863c5f05b sys/util: extend usage of DIV_ROUND_UP
Many areas of Zephyr divide and round up without using the DIV_ROUND_UP
macro. Make use of it, so that we make use of a tested system macro and
at the same time we make code more readable.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 16:42:29 +02:00
Gerard Marull-Paretas a5fd0d184a init: remove the need for a dummy device pointer in SYS_INIT functions
The init infrastructure, found in `init.h`, is currently used by:

- `SYS_INIT`: to call functions before `main`
- `DEVICE_*`: to initialize devices

They are all sorted according to an initialization level + a priority.
`SYS_INIT` calls are really orthogonal to devices, however, the required
function signature requires a `const struct device *dev` as a first
argument. The only reason for that is because the same init machinery is
used by devices, so we have something like:

```c
struct init_entry {
	int (*init)(const struct device *dev);
	/* only set by DEVICE_*, otherwise NULL */
	const struct device *dev;
}
```

As a result, we end up with such weird/ugly pattern:

```c
static int my_init(const struct device *dev)
{
	/* always NULL! add ARG_UNUSED to avoid compiler warning */
	ARG_UNUSED(dev);
	...
}
```

This is really a result of poor internals isolation. This patch proposes
a to make init entries more flexible so that they can accept sytem
initialization calls like this:

```c
static int my_init(void)
{
	...
}
```

This is achieved using a union:

```c
union init_function {
	/* for SYS_INIT, used when init_entry.dev == NULL */
	int (*sys)(void);
	/* for DEVICE*, used when init_entry.dev != NULL */
	int (*dev)(const struct device *dev);
};

struct init_entry {
	/* stores init function (either for SYS_INIT or DEVICE*)
	union init_function init_fn;
	/* stores device pointer for DEVICE*, NULL for SYS_INIT. Allows
	 * to know which union entry to call.
	 */
	const struct device *dev;
}
```

This solution **does not increase ROM usage**, and allows to offer clean
public APIs for both SYS_INIT and DEVICE*. Note that however, init
machinery keeps a coupling with devices.

**NOTE**: This is a breaking change! All `SYS_INIT` functions will need
to be converted to the new signature. See the script offered in the
following commit.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

init: convert SYS_INIT functions to the new signature

Conversion scripted using scripts/utils/migrate_sys_init.py.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

manifest: update projects for SYS_INIT changes

Update modules with updated SYS_INIT calls:

- hal_ti
- lvgl
- sof
- TraceRecorderSource

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: devicetree: devices: adjust test

Adjust test according to the recently introduced SYS_INIT
infrastructure.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>

tests: kernel: threads: adjust SYS_INIT call

Adjust to the new signature: int (*init_fn)(void);

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-12 14:28:07 +00:00
Kumar Gala c09e8fae23 twister: Use pyelf to extract symbol information
For ztest twister would parse the symbol information that was
generated as part of the build (zephyr.symbols).  However the format
of the zephyr.symbols files is highly dependant on the toolchain.

Move to using pyelf to parse the symbol information directly from
zephyr.elf instead so that this works regardless of toolchain.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-04-08 18:37:52 +02:00
Anas Nashif ef1a589f61 ztest: add macro for custom testcase result
Some cases, especially those dealing with faults need to inject output
manually, so provied a macro for special case.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2023-04-05 10:27:28 +02:00
Gregory Shue 5623f54a35 fff: Add fff_extensions.h, RETURN_HANDLED_CONTEXT()
Add supplementary header <zephyr/fff_extensions.h>.  Add macro
to fff_extensions.h for simplifying definition of custom fake functions
needing call-unique information for producing desired output data.
When an array of custom fake context structures is defined and
the return field within the first structure instance is registered
with the standard SET_RETURN_SEQ() macro of FFF, the
RETURN_HANDLED_CONTEXT() macro provides the inverse logic to
recover the context structure for this called instance. The body of
the custom fake handler is provided to the RETURN_HANDLED_CONTEXT()
macro for appropriate execution and access to the custom fake
parameters.

A test suite is also provided to verify macro implementation and
illustrate usage. It is at:
zephyr/tests/subsys/testsuite/fff_fake_contexts/

This code was verified by:

1. (Pass) west build -p always \
            -b unit_testing tests/subsys/testsuite/fff_fake_contexts/ && \
         ./build/testbinary
2. (Pass) west build -p always \
            -b native_posix tests/subsys/testsuite/fff_fake_contexts/ && \
         ./build/zephyr/zephyr.exe
3. (Pass) ./scripts/twister -p unit_testing \
            -T tests/subsys/testsuite/fff_fake_contexts/
4. (Pass) ./scripts/twister -p native_posix \
            -T tests/subsys/testsuite/fff_fake_contexts/
5. (Pass) cd doc && build html-fast

Fix #55246

Signed-off-by: Gregory Shue <gregory.shue@legrand.com>
2023-03-16 13:43:33 -04:00
Aaron Massey 107cb86bb3 ztest: Add initial zexpect API for delayed failing
Add the zexpect API, inspired by GoogleTest's EXPECT API. This API reports
test failures while allowing test execution to continue. This enables test
reports to show more than a singule failing property on a failing test.

Signed-off-by: Aaron Massey <aaronmassey@google.com>
2023-02-23 20:34:39 +01:00
Fabio Baltieri 9b30667c77 build: drop LEGACY_INCLUDE_PATH support
LEGACY_INCLUDE_PATH has been defaulting to "n" and marked as deprecated
in both v3.2 and v3.3. Drop the option entirely for v3.4.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2023-02-21 15:06:48 +01:00