Commit Graph

186 Commits

Author SHA1 Message Date
Nazar Kazakov f483b1bc4c everywhere: fix typos
Fix a lot of typos

Signed-off-by: Nazar Kazakov <nazar.kazakov.work@gmail.com>
2022-03-18 13:24:08 -04:00
Krzysztof Chruscinski fe423d52a7 testsuite: ztress: Delay start of the test
Delay start of threads and timer to ensure that setup
is completed. Especially, vital on multiple CPUs.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-15 13:19:28 -04:00
Krzysztof Chruscinski 1916a833f3 testsuite: ztress: Make cpu load calculation multi-cpu ready
Use idle threads on all cores for cpu load calculation.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-15 13:19:28 -04:00
Tristan Honscheid 082ca85b7c ztest: bug: Add friendly name helper function for all phases
The `handle_signal()` function in the new ztest API (`ztest_new.c`) uses
an array of strings to lookup a friendly name for each test phase, but
the array only has three elements despite there being six test phases.
This can lead to an out-of-bounds issue. Replace the array with a helper
function and switch statement.

Signed-off-by: Tristan Honscheid <honscheid@google.com>
2022-03-14 11:32:38 +01:00
Enjia Mai 2b1bccde07 tests: testsuite: add emulating send IPI in X2APIC mode
We emulate the interrupt by sending the IPI to core itself by
the local APIC for x86 platfrom.

But in X2APIC mode, this no longer works. So we emulate the
interrupt the by writing the IA32_X2APIC_SELF_IPI MSR to send
IPI to the core itself via LOAPIC also. According to SDM vol.3
chapter 10.12.11.

Fixes #42108

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-03-09 14:55:26 -05:00
Gerard Marull-Paretas 95fb0ded6b kconfig: remove Enable from boolean prompts
According to Kconfig guidelines, boolean prompts must not start with
"Enable...". The following command has been used to automate the changes
in this patch:

sed -i "s/bool \"[Ee]nables\? \(\w\)/bool \"\U\1/g" **/Kconfig*

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-03-09 15:35:54 +01:00
Andy Ross c5cf46a670 subsys/ztest: Revert "Make 1cpu tests run on CPU 0 specifically"
This change introduced some weird failures on x86 that will take some
time to untangle, and wasn't a particularly important feature to
merge.  Revert for now.

This reverts commit adc901aa6a.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2022-03-09 06:54:24 -05:00
Andy Ross adc901aa6a subsys/ztest: Make 1cpu tests run on CPU 0 specifically
Some hardware has "interesting" configuration like asymmetric default
interrupt masking (the intel_adsp devices in particular, but x86's
IO-APIC driver has tripped over this in the past too) that needs
special treatment if you want to run something on "core 1"
specifically, and 1cpu test cases pretty much by definition are going
to have been written without SMP details in mind.  Switch the logic
around a tiny bit such that these test cases always run on CPU ID zero
explicitly.

Actually in practice this was ALMOST guaranteed to be true already,
because test setup and happens serially, having been started on the
main thread, which starts on CPU 0 by definition.  Then the test
teardown aborts all the spawned threads that might have been running
on CPUs 1+, so those reach idle, and the next test case starts
syncronously on the same thread (and thus CPU) where it started.  But
nonetheless that wasn't actually enforced, and we've found at least
one simulation environment where timing conspires to break things.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2022-03-08 16:26:26 -05:00
Krzysztof Chruscinski 47ae656cc1 all: Deprecate UTIL_LISTIFY and replace with LISTIFY
UTIL_LISTIFY is deprecated. Replacing it with LISTIFY.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-03-08 11:03:30 +01:00
Daniel DeGrasse 5ba1787163 tests: ztest: add CONFIG_ZTEST_NO_YIELD to keep SOC awake after test
Some SOCs cannot be flashed reliably in low power modes. If
CONFIG_ZTEST_NO_YIELD is selected, do not yield to the idle thread after
testsuite completes, so that the SOC will not enter low power mode.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
2022-03-07 13:53:14 -06:00
Thomas Ebert Hansen 995ce7a226 ztest: Add skipping for non-kernel tests
Add ztest_test_skip() support to non-kernel tests by implementing
long jump buffer and TC_SKIP result collection.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2022-03-07 16:15:54 +01:00
Nicolas Pitre eee5b8e563 ring_buffer: make finish methods final
Make it possible to "finish" with fewer bytes than what was "claimed".

This was possible before on the get side, but the put side was
cummulative wrt finish. The revamp made it cummulative on both sides.
Turns out that existing users rely on the opposite behavior which is
more logical and useful. So make both sides that way.

Adjust documentation, test case and users accordingly.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2022-02-28 10:52:41 +01:00
Bradley Bolen c0dd594d4d arch: arm: aarch32: Change CPU_CORTEX_R kconfig option
Change the CPU_CORTEX_R kconfig option to CPU_AARCH32_CORTEX_R to
distinguish the armv7 version from the armv8 version of Cortex-R.

Signed-off-by: Bradley Bolen <bbolen@lexmark.com>
2022-02-23 08:14:15 -06:00
Torsten Rasmussen e4ccde3774 cmake: moved unittest.cmake to Zephyr CMake modules dir
Move the unittest.cmake to the new Zephyr CMake modules dir.

This allows us to have a single Zephyr CMake package and load unittest
module as: 'find_package(Zephyr COMPONENTS unittest)'

This unifies the way Zephyr package is sourced and removes the need for
a dedicated ZephyrUnittest package.

Deprecate the use of: 'find_package(ZephyrUnittest)'

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2022-02-22 10:02:39 -08:00
Carles Cufi e83a13aabf kconfig: Rename the TEST_EXTRA stack size option to align with the rest
All stack sizes should end with STACK_SIZE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-02-22 08:23:05 -05:00
Carles Cufi 4b8f1c04ab kconfig: Rename the ZTEST stack size option to align with the rest
All stack sizes should end with STACK_SIZE.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-02-22 08:23:05 -05:00
Anas Nashif 421dcc8dcd Revert "testsuite: ztress: Add test skipping if system clock is too high"
This reverts commit 913868b6c4.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-02-22 00:29:17 -05:00
Krzysztof Chruscinski 913868b6c4 testsuite: ztress: Add test skipping if system clock is too high
When system clock is set globally for the test which is executed
on various qemu platforms it may happen that clock is set too
high compared to CPU clock frequency. In that case test may stuck.
Added check and test skipping in that case.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-21 22:19:00 -05:00
Yuval Peress 35ec3c9579 ztest: Update verification to account for missing suite
Fix an issue where a test's suite name was misspelled and thus the
test never ran because it wasn't associated with a suite. Example:

ZTEST_SUITE(my_suite, NULL, NULL, NULL, NULL, NULL);
ZTEST(myy_suite, test)
{
}

The above will no longer pass since `myy_suite` with a double `y` will
fail the verification.

Signed-off-by: Yuval Peress <peress@google.com>
2022-02-17 09:08:21 -05:00
Yuval Peress 47113211c7 ztest: document test rules
Add documentation to test rules.

Signed-off-by: Yuval Peress <peress@google.com>
2022-02-14 09:31:28 -05:00
Krzysztof Chruscinski eb9814c626 testsuite: ztest: Fix concatenation in macro
Use UTIL_CAT which resolves input arguments instead of direct
preprocessor concatenation.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-02-01 08:16:10 -05:00
Krzysztof Chruscinski 3fd3793c76 testsuite: tc_util: Limit include range
tc_util.h is also included by unit tests and in that case it
cannot have dependencies to subsystems. Including log_ctrl.h
only for ARCH_POSIX where it is needed to flush logs before
exit.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-27 09:58:08 -05:00
Krzysztof Chruscinski 8850954c6d testsuite: ztest: Add logs flushing after suite
Flushing logs here is especially vital if LOG_PRINTK is enabled.
In that case printk goes to log and without flushing after all
tests are run you will not get the final report out.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-27 10:02:21 +01:00
Krzysztof Chruscinski b85689ba42 testsuite: tc_util: Flush logs before posix_exit
Flush all logs before terminating test in posix.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-27 10:02:21 +01:00
Yuval Peress 9c0b970bc2 ztest: run before function in test thread
A lot of tests need to be able to get their current tid and do some
action with it. It makes sense for the `before` function/rule to be
able to run in the same thread as the test. Note that the `after`
function does not run in the same thread because we need to guarantee
that it will run.

Signed-off-by: Yuval Peress <peress@google.com>
2022-01-20 14:20:03 -05:00
Antony Pavlov 8379533bed mips: add testsuite support
This commit provides the timestamp_serialize() macro for the MIPS
architecture.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
2022-01-19 13:48:21 -05:00
Antony Pavlov 0369998e61 arch: add MIPS architecture support
MIPS (Microprocessor without Interlocked Pipelined Stages) is a
instruction set architecture (ISA) developed by MIPS Computer
Systems, now MIPS Technologies.

This commit provides MIPS architecture support to Zephyr. It is
compatible with the MIPS32 Release 1 specification.

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
2022-01-19 13:48:21 -05:00
Gerard Marull-Paretas 103135c150 testsuite: busy_sim: drop get_dev_data/get_dev_config usage
Replace all get_dev_data()/get_dev_config() accessor utilities with
dev->data and dev->config.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-01-19 18:16:02 +01:00
Enjia Mai db3fa50916 testsuite: utils: use IPI instead of int instruction for testing on x86
For x86, make the testing purpose trigger_irq() function to send
interrupt processor interrupt to CPU by APIC, instead of executing
INT instruction. Doing this because:
1. It can be controlled by irq lock, more close to trigger irq.
2. We don't need to hardcode the interrupt vector.

Signed-off-by: Enjia Mai <enjiax.mai@intel.com>
2022-01-18 13:24:28 -05:00
Krzysztof Chruscinski 57a893dc0d testsuite: ztest: Use STRINGIFY in ZTEST_SUITE
Using macro which will resolve complex SUITE_NAME. Without
it wrong name was assigned when SUITE_NAME was consists of
concatenated defines.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-18 13:12:38 -05:00
Krzysztof Chruscinski 50c7c7b1e4 sys: time_units: Add Kconfig option for algorithm selection
Add maximum timeout used for conversion to Kconfig. Option is used
to determine which conversion algorithm to use: faster but overflowing
earlier or slower without early overflow.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-18 13:11:52 -05:00
Enjia Mai 7aba5fa633 tests: coverage: fix the blocking on mps2_an385 coverage report
The overall code coverage report of mps2_an385 was blocked by the
tests/net/lib/coap, the error message shows "No Mem available to
continue dump". So we enlarge the gcov heap size to prevent this
situation, try to make the report can be generated at least.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-01-12 16:30:39 -06:00
Anas Nashif 5e05393afa tests: ztress: fix dependency on SMP
Use CONFIG_MP_NUM_CPUS=1 with ztress and do not disable SMP completely.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2022-01-12 14:13:21 -05:00
Krzysztof Chruscinski 4d9507ae33 testsuite: ztress: Minor fixes
Fix initial thread priority and move starting of the
test timer after threads initialization to ensure that
it does not expire before threads are initiated.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-12 08:49:59 -05:00
Krzysztof Chruscinski 851d0f0a3b testsuite: ztress: Disable ztress for SMP
Currently, ztress is not supporting SMP, mainly because of
cpu load calculation algorithm. It may be re-enabled in the
future.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-12 08:49:59 -05:00
Yuval Peress ab1caef8c3 ztest: Update ztest with more powerful testing APIs
1. Test suites in prior ztest serve no purpose other than logical
ordering of tests into a named-group. Move the construct of setup and
teardown into the test suite and away from individual tests.
Additionally, add the constructs of before/after to the test suites.
This model more closely resembels other testing frameworks such as gTest
and Junit.
2. Test can be added to a suite by using ZTEST() or ZTEST_F() where _F
stands for fixture. In the case where _F is used, the argument `this`
will be provided with the type `struct suite_name##_fixture*`. Again,
this models other modern testing frameworks and allows the test to
directly access the already set up data related to the test suite.
3. Add the concept of test rules (from Junit). Rules are similar to the
before/after functions of the test suites but are global and run on all
suites. An example of a test rule can be to check that nothing was
logged to ERROR. The rule can cause the test to fail if anything was
logged to ERROR during an integration test. Another example would be a
rule that verifies that tests ran within some defined timeout.

Signed-off-by: Yuval Peress <peress@google.com>
2022-01-11 11:47:30 +01:00
Krzysztof Chruscinski 16bd0df2fd testsuite: ztest: Add framework for stress testing
Added framework for concurrency testing. Framework setup multiple
priority contexts and executes user handlers in that context. Test
terminates after certain number of repetitions or preemptions or
when timeout occurs. It can also be aborted by the user.

Framework can be used for testing resiliency to preemptions.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2022-01-01 07:37:22 -05:00
Torsten Rasmussen cbf815e745 cmake: remove CMake policy CMP0000 and CMP0002 in unittest.cmake
Two CMake policies has been removed:
CMP0000 was introduced in CMake 2.6 and set to OLD, but with all Zephyr
        CMake files using cmake_minimum_required() then there is no
	reason for having this policy to OLD.
CMP0002 was introduced in CMake 2.6 and was set to NEW.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-12-18 14:58:55 +01:00
Krzysztof Chruscinski 0a7667bf7f testsuite: busy_sim: Use xoshiro128++ when enabled
Taking random numbers from hardware may be time consuming thus
it was deferred to a work queue. On the other hand, taking them
from software algorithm is fast. Use xoshiro128++ when enabled,
instead of real random numbers from hardware RNG generator. They
are use for random intervals in the test so no security concerns
here.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-12-01 10:00:50 +01:00
Krzysztof Chruscinski f2e75a7140 testsuite: busy_sim: Add callback to the interrupt
Add optional callback which is called from the busy
interrupt context.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-12-01 10:00:50 +01:00
Krzysztof Chruscinski 4d6315a681 testsuite: ztest: Do logging flush only when default thread is used
Add guard to not pend until all logs are flushed when default
logging thread is disabled. In that case, logging has no control
where logs are processed and sleeping may not lead to flushing
log data. That may result in test hanging.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-11-29 10:34:22 -05:00
Daniel Leung bb595a85f1 kernel: mem_domain: add/remove partition funcs to return errors
This changes both k_mem_domain_add_partition() and
k_mem_domain_remove_partition() to return errors instead of
asserting when errors are encountered. This gives the application
chance to recover.

The arch_mem_domain_parition_add()/_remove() will be modified
later together with all the other arch_mem_domain_*() changes
since the architecture code for partition addition and removal
functions usually cannot be separately changed.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2021-11-22 12:45:22 -05:00
Krzysztof Chruscinski a50e13ceed testsuite: ztest: Add logs flushing after each test case
When deferred mode is used, logging is using lowest priority
thread to process the logs. When test cases are performed one
by one processor never reaches lowest priority thread until
whole suite is completed. Added flushing after each test case.

Feature is optional (by default enabled).
CONFIG_TEST_LOGGING_FLUSH_AFTER_TEST=n to disable.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-11-20 11:58:40 -05:00
Krzysztof Chruscinski c0808e3f59 logging: Minimal mode configuration cleanup
Remove LOG_MINIMAL kconfig option which was confusing
since LOG_MODE_MINIMAL existed. LOG_MINIMAL was used to
force minimal mode but because of invalid dependencies
it was leading to issues.

Refactored code to use LOG_MODE_MINIMAL everywhere and
renamed LOG_MINIMAL to LOG_DEFAULT_MINIMAL which has impact
on defualt logging mode (which still can be later changed
in conf file or in menuconfig).

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2021-11-20 11:58:40 -05:00
Christopher Friedt 918a574c88 clock: add k_cycle_get_64
This change adds `k_cycle_get_64()` on platforms that
support a 64-bit cycle counter.

The interface functions `arch_k_cycle_get_64()` and
`sys_clock_cycle_get_64()` are also introduced.

Fixes #39934

Signed-off-by: Christopher Friedt <chrisfriedt@gmail.com>
2021-11-08 13:41:53 -05:00
Yuval Peress 27f6a5e07d ztest: add a weak implementation of test_main()
Introduce a weak implementation of test_main() which calls:
* ztest_run_registered_test_suites(NULL);
* ztest_verify_all_registered_test_suites_ran();

This will attempt to run all registered test suites and verify that
they each ran.

Signed-off-by: Yuval Peress <peress@chromium.org>
2021-10-28 16:57:51 -04:00
Yuval Peress dee79d2b66 ztest: Add register functionality
Add new functionality to ztest to improve test modularity. The two
primary new entry points are:
* ztest_register_test_suite
* ztest_run_registered_test_suites

When registering a new test suite, users provide the name as well as
an optional predicate used to filter the tests for each run. Using NULL
as the predicate ensures that the test is run exactly once (after which
it is automatically filtered from future runs).

Calls to ztest_run_registered_test_suites take a state pointer as an
argument. This allows the the pragma functions to decide whether the
test should be run.

The biggest benefit of this system (other than the ability to filter
tests and maintain a larger test state) is the ability to better
modularize the test source code. Instead of all the various tests
having to coordinate and the main function having to know which tests
to run, each source file manages registering its own test
suite and handling the conditions for running the suite.

Signed-off-by: Yuval Peress <peress@chromium.org>
2021-10-28 16:57:51 -04:00
Immo Birnbaum eef767eabc testsuite: enable timestamp_serialize() for aarch32 Cortex-A CPUs
Enable the existing aarch32 Cortex-R implementation of
timestamp_serialize() for aarch32 Cortex-A CPUs as well.

Signed-off-by: Immo Birnbaum <Immo.Birnbaum@Weidmueller.com>
2021-10-28 15:26:50 +02:00
Yuval Peress f6f24a2a79 modules: Add fff mocking framework
Issue #38643

Introduce a more powerful and well established mocking framework
into Zephyr. It also allows running the actual FFF tests using the
zephyr SDK and ztest framework to ensure compatibility.

As per TSC meeting, the fff.h header was directly added to
subsys/testsuite/include/. As per the guidelines, the file is exactly
the same as it is in FFF's library, but re-styled with clang-format.

The west.yml entry was added using the "ci" group and filtered by
default. (note that the tests will break until the CI actually
specifies that the group is needed).

Signed-off-by: Yuval Peress <peress@google.com>
2021-10-22 09:43:13 -04:00
Maksim Masalski 164029b0c5 testsuite: suppress usage of setjmp in a testcode (rule 21_4-a)
According to the rule MISRAC-2012 21.4.a the standard header
file <setjmp.h> shall not be used. Suppress it, because it raises
violation in a testcode, not in a runtime code.
Tag suppresses reporting of violation for the current file,
starting from the line where the suppression is located.
It is a deliberate deviation.

Found as a coding guideline violation (MISRA R21.4.a) by static
coding scanning tool.

Signed-off-by: Maksim Masalski <maksim.masalski@intel.com>
2021-09-03 10:14:57 -04:00