Commit graph

33 commits

Author SHA1 Message Date
Krzysztof Chruściński
adcd68936b tests: unit: util: Extend test_IS_EQ
Extend test to check for unsigned literals.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-12-13 20:04:33 +01:00
Emil Gydesen
1fc67d22d1 tests: unit: util: Add unit test of utf8_trunc and utf8_lcpy
The two functions did not have unit tests, and at least one
issue with input validation have been indentified and fixed
prior to these.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-27 08:48:31 -04:00
Rubin Gerritsen
8799ab1ec2 test: Apply semantic patch file ztest_strcmp.cocci
This patch file updates the use of assertion macros
comparing strings.

Command line used:
```
./scripts/coccicheck --mode=patch \
--cocci=scripts/coccinelle/ztest_strcmp.cocci tests/
```

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-14 19:25:42 +02:00
Adrien Ricciardi
bf8b1d67d6 sys: util: Add SIZEOF_FIELD() macro
This macro allows to know the size of a struct member at compile time.

Several parts of the Zephyr code are currently using directly the macro
code.

Also added a unit test.

Signed-off-by: Adrien Ricciardi <aricciardi@baylibre.com>
2024-06-07 21:43:07 +02:00
Fabio Baltieri
9e1eec9ced test: add a test for sign extend
Add tests for the sign extend functions.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
2024-02-26 11:41:20 +00:00
Krzysztof Chruściński
fdafbdb1c9 tests: unit: util: Extend FOR_EACH test
Extend test to check also no arguments.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-01-29 11:32:54 +01:00
Krzysztof Chruściński
04edca7a9f tests: unit: util: Add test for CONCAT macro
Add test for CONCAT.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-01-12 09:57:57 +01:00
Emil Gydesen
87c8b897b3 include: util: Add mem_xor functions
Add functions to do XOR on arrays of memory, with one that
takes arbitrary sizes and one for 32 bits and 128 bits as
those are common sizes for this functionality.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-01-05 09:06:36 +01:00
Christopher Friedt
1695b5a0b2 tests: unit: util: add array for-each tests
Add tests for the following two macros

* ARRAY_FOR_EACH(array, idx_var)
* ARRAY_FOR_EACH_PTR(array, ptr_var)

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
2024-01-04 08:27:29 +09:00
Krzysztof Chruściński
c0bb064d4e tests: unit: util: Fix compliance check warnings
As code is moved from test.inc to main.c a compliance check is
run for the first time on that code. Fixing warnings.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-01-02 16:01:11 +00:00
Krzysztof Chruściński
7b872d11ba tests: unit: util: Rework test structure for C++ testing
Rework test structure to handle C++ test in a better way. Similar
approach already applied in other tests which are executed for C
and C++. Getting rid of test.inc which due to non-standard extension
was not covered by complience check.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2024-01-02 16:01:11 +00:00
Pieter De Gendt
cc920696ed tests: unit: util: Add tests for IF_DISABLED
Add a testcase for the IF_DISABLED macro.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
2023-12-28 12:06:28 +00:00
Kornel Dulęba
8fc913374f include: util: Add DIV_ROUND_CLOSEST helper
It's similar to DIV_ROUND_UP, but rounds to the nearest integer.
Some basic unit tests were introduced to check that it works as
intended.

Signed-off-by: Kornel Dulęba <mindal@semihalf.com>
2023-07-21 10:49:41 +00:00
Gerard Marull-Paretas
3df3aab9d2 tests: unit: util: test DIV_ROUND_UP
Add a unit test for the DIV_ROUND_UP helper macro.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-04-11 12:00:37 +02:00
TOKITA Hiroshi
148d205c12 test: unit: util: add BIT_MASK macros tests
Adding tests for BIT_MASK, BIT_MASK64, IS_BIT_MASK, and IS_BIT_MASK_SHIFTED

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
2023-01-10 09:23:14 +01:00
Christopher Friedt
2e6e09acac tests: util: PART_OF_ARRAY, IS_ARRAY_ELEMENT, ARRAY_INDEX, ..
Add tests for `PART_OF_ARRAY()`, `IS_ARRAY_ELEMENT()`,
`ARRAY_INDEX()`, and `ARRAY_INDEX_FLOOR()`.

Signed-off-by: Christopher Friedt <cfriedt@fb.com>
2022-09-09 13:20:12 -05:00
Enjia Mai
dc15c03b96 tests: unit: move the util test to new ztest API
Migrate the testsuite tests/unit/util to the new ztest API.

Signed-off-by: Enjia Mai <enjia.mai@intel.com>
2022-09-09 08:33:00 -04:00
Fabio Baltieri
def230187b test: fix more legacy #include paths
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>
2022-08-02 16:41:41 +01:00
Gerard Marull-Paretas
ade7ccb918 tests: migrate includes to <zephyr/...>
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>
2022-05-06 20:02:14 +02:00
Peter Bigot
95d32549e7 tests/unit/util: refactor to test in both C and C++ language environments
Move all the tests into an include file that is included once from the
main C-compiled module, and again from a linked in C++-compiled
module.  The C compile invokes both test suites.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-08-12 16:39:37 -05:00
Krzysztof Chruscinski
4baf24203d tests: unit: util: Add tests for new macros
Added tests for GET_ARG_N and GET_ARGS_LESS_N

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-06-22 15:18:07 +02:00
Krzysztof Chruscinski
727f8e0889 tests: unit: util: Add test for nested FOR_EACH call
Added test for case were FOR_EACH call is nested.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-06-10 11:58:13 +02: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
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
Dominik Ermel
6ba69f19d4 sys/util.h: Add IS_EMPTY and LIST_DROP_EMPTY macros
IS_EMPTY macro allows to check if defined name is empty, i.e.
does not contain replacement list.
LIST_DROP_EMPTY macro may be used to process __VA_ARGS__ type lists,
e.g. a,b,,c , and remove empty elements.

Signed-off-by: Dominik Ermel <dominik.ermel@nordicsemi.no>
2020-05-08 17:50:25 +02:00
Krzysztof Chruscinski
8fcabf6032 tests: unit: util: Add test for FOR_EACH_FIXED_ARG macro
Added test for FOR_EACH_FIXED_ARG macro.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-05-06 14:30:18 +02:00
Krzysztof Chruscinski
8ab4a60471 tests: unit: util: Add tests for FOR_EACH and FOR_EACH_IDX macros
Extended suite to test macros.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2020-05-06 14:30:18 +02:00
Martí Bolívar
1edc84f526 sys/util.h: add UTIL_OR and UTIL_AND
These are short-circuiting utility helpers that can save typing
in situations where avoiding evaluation of the not-taken branch
skips invalid expressions.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-03-25 13:21:28 +01:00
Martí Bolívar
3c7a939743 tests: add util.h MACRO_MAP_CAT test
This wasn't tested when it was first added.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-03-25 13:21:28 +01:00
Kumar Gala
28a88fc638 sys/util.h: allow UTIL_LISTIFY to pass args to repeat macro
Change UTIL_LISTIFY to support passing arguments to the F macro.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-03-13 07:33:57 -06:00
Krzysztof Chruscinski
79519c4dbe tests: unit: util: Add test for IF_ENABLED()
Added test for new macro.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-12-18 08:14:52 -05:00
Anas Nashif
2051ad1846 tests: convert util test to a unit test
Merge tests/misc/util with existing util unit test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-09-30 07:09:42 -04:00
Anas Nashif
50d5e37b8a tests: move util 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
Renamed from tests/lib/sys/util/src/main.c (Browse further)