Clang detects a value of the wrong size passed to printf with %h or %hh
modifiers. Insert explicit casts to the expected type.
Signed-off-by: Keith Packard <keithp@keithp.com>
lib -> libraries to be consistent with everything else.
And fix identifier for a few stray tests that were wrongly
labeled/tagged.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Prior to #41602, due to the ordering of operations (first mul,
then div), an intermediate value would overflow, resulting in
a time non-linearity.
This test ensures that time rolls-over properly.
Signed-off-by: Chris Friedt <cfriedt@meta.com>
Add CONFIG_CRC for building CRC related routines.
CRC routines are now being built for each application, whether used or
not and are add in the build system unconditionally.
Keep CONFIG_CRC enabled by default for now and until all users have
converted to use the new option.
Partial fix for #50654
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
When building with clang, the unittests were giving us an error:
```
error: undefined symbol: llvm_gcda_start_file
```
This seems to be from linking in `gcov` regardless of the toolchain.
It appears that clang doesn't need any special library for coverage.
With this change the following now produce identical coverage reports:
```
$ ZEPHYR_TOOLCHAIN_VARIANT=zephyr ./scripts/twister -p unit_testing \
--coverage -i -T tests/unit/intmath/
$ ZEPHYR_TOOLCHAIN_VARIANT=host ./scripts/twister -p unit_testing \
--coverage -i -T tests/unit/intmath/
$ ZEPHYR_TOOLCHAIN_VARIANT=llvm ./scripts/twister -p unit_testing \
--coverage -i --coverage-tool lcov \
--gcov-tool $(pwd)/scripts/utils/llvm-gcov.sh \
-T tests/unit/intmath/
```
Signed-off-by: Yuval Peress <peress@google.com>
These tests all assume that the same underlying cbprintf function will be
used for all operations, which is not true when using picolibc. Force the
use of the minimal C library as that will check the right code paths.
Signed-off-by: Keith Packard <keithp@keithp.com>
This commit removes CONFIG defines from main.c and instead uses the
proper Kconfig handling of specifying extra Kconfig options in
testcase.yaml.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Add a bunch of missing "zephyr/" prefixes to #include statements in
various test and test framework files.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Fix the deprecated calls to loading ZephyrUnittest by replacing them
with `Zephyr COMPONENTS unittest`.
Signed-off-by: Yuval Peress <peress@google.com>
This adds some bits to support tagged arguments to be used for
packaging. If enabled, the packaging function no longer looks at
the format strings to determine the types of arguments, but
instead, each argument is tagged with a type by preceding it
with another argument as type (integer). This allows the format
strings to be removed from the final binary to conserve space.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
In order to bring consistency in-tree, migrate all tests to the new
prefix <zephyr/...>. Note that the conversion has been scripted, refer
to #45388 for more details.
Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
If the sys_slist_t instance is not empty, its head and tail points to
some sys_snode_t instances. If sys_slist_append_list is executed with
tail being NULL the list object is corrupted. Tail of the sys_slist_t
instance is set to NULL. If one executes sys_slist_append on that node,
then nodes pointed by head are lost.
The commit fixes the issue and adds unit tests to verify correct
behavior.
Added change verifies if head and tail of appended list are not NULL.
In other case the list object is invalid and should not be appended
to a valid list instance.
Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
The ARRAY_SIZE macro uses sizeof and thus the return
type should be an unsigned value. size_t is typically
the type used for sizeof and fits well for the
ARRAY_SIZE macro as well.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Aligned tests to handle the fact that static packaging return
error when detects read-write string and storing read-write
positions is not enabled.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Add the IN_RANGE macro which returns true if a value is
within a supplied range of values (inclusive).
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
As described in #42403, there was an issue with the existing crc16_ansi()
implementation, since it was not calculating the CRC-16-ANSI (aka
CRC-16-MODBUS). This is because the existing crc16() function only
supported non-reflected input and output (and the CRC-16-ANSI requires
reflection on both) and also it did not seem to support correctly inial
seeds different from 0x0000 (and, again, the CRC-16-ANSI requires 0xffff
as an initial seed).
This commit replaces the existing crc16() with a functional pair,
crc16() and crc16_reflect(), that also work with any poly, any initial seed
and allow to select whether reflection is performed.
It also adapts crc16_ansi() so that it actually returns the correct CRC.
Fixes#42403.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
Since the crc16_ccitt and crc16_itu_t functions can compute several
flavors of checksum depending on the initial seed and XOR out value, add
tests for some common variants that are documented as supported.
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
It's not uncommon to have Zephyr running in environments where it
shares a memory bus with a foreign/non-Zephyr system (both the older
Intel Quark and cAVS audio DSP systems share this property). In those
circumstances, it would be nice to have a utility that allows an
arbitrary-sized chunk of that memory to be used as a unidirectional
buffered byte stream without requiring complicated driver support.
sys_winstream is one such abstraction.
This code is lockless, it makes no synchronization demands of the OS
or hardware beyond memory ordering[1]. It implements a simple
file/socket-style read/write API. It produces small code and is high
performance (e.g. a read or write on Xtensa is about 60 cycles plus
one per byte copied). It's bidirectional, with no internal Zephyr
dependencies (allowing it to be easily ported to the foreign system).
And it's quite a bit simpler (especially for the reader) than the
older cAVS trace protocol it's designed to replace.
[1] Which means that right now it won't work reliably on arm64 until
we add a memory barrier framework to Zephyr! See notes in the code;
the locations for the barriers are present, but there's no utility to
call.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
Adding cmake_minimum_required() as this is required by CMake.
CMP0000 is a deprecated policy which allows to omit this function call,
however doing so will result in CMake printing a warning.
Adding cmake_minimum_required() to tests missing this call will remove
the warning and also allow us to remove the policy setting.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Add flags to macro which checks if string must be packaged
using runtime approach.
Added flag CBPRINTF_MUST_RUNTIME_PACKAGE_CONST_CHAR. When flag
is set then const char pointers are considered as pointers to
fixed strings and do not require runtime packaging.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
The current implementation relies on preprocessor concatenation to
work. This makes it incompatible with any content which expansion
is not a valid preprocessor token such as strings, pointers, etc.
and therefore limits its usefulness. Replace it with an implementation
that can cope with all cases.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
There might be a sign extension when a long is promoted to
int_value_type and the former type is smaller than the later.
This produces the wrong output if the specified format is unsigned.
Let's avoid this problem by handling signed and unsigned cases
explicitly. When the type already matches int_value_type then the
compiler is smart enough to recognize the redundancy and removes
unneeded duplications automatically, meaning that the code will stay
small when code size matters.
A similar issue also existed in the restricted %llu case.
The fix is the same as above.
Those fixes exposed wrong results in the printk.c test with %llx
so fix that as well.
Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
Add tests to ensure that conversions remain linear for large time deltas
when no skew is present.
Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
Added test cases for cbprintf_fsc_package() and use of
CBPRINTF_PACKAGE_ADD_STRING_IDXS flag.
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
Added support for conversion from a standard package which contains
pointers to read only strings to fully self-contained (fsc) package.
Fsc package contains all strings associated with the package thus
access to read only strings is not needed to format a string.
In order to allow conversion to fsc package, standard package must
contain locations of all string pointers within the package. Appending
that information is optional and is controlled by flags parameter
which was added to packaging API. If option flag is set then
package contains header, arguments, locations of read only strings and
transient strings (each prefixed with string argument location).
Package header has been extended with field which contains number of
read only string locations.
A function for conversion to fsc package has been added
(cbprintf_fsc_package()).
Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>