Commit Graph

1066 Commits

Author SHA1 Message Date
Mohamed Moawad
e717d20b0b tests: lib: uuid: add heap arena for MINIMAL_LIBC compatibility
The UUID library utilities require dynamic memory allocation for certain
operations, but MINIMAL_LIBC provides no malloc heap by default. This
causes test failures when UUID functions attempt to allocate memory.

Add CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=256 to provide a minimal heap
arena sufficient for UUID operations which typically
require small heap allocations.

Signed-off-by: Mohamed Moawad <moawad@synopsys.com>
2025-07-28 08:40:20 -04:00
Sanjay Vallimanalan
07efbe6d97 tests: lib: json: add test for mixed array types
Add tests for encoding, parsing and calculating length mixed array
types.

Signed-off-by: Sanjay Vallimanalan <sanjay@linumiz.com>
2025-07-21 21:31:21 -04:00
Jukka Rissanen
fd0b14861d tests: net_buf: Add alignment tests
Make sure that net_buf pools created by NET_BUF_POOL_VAR_ALIGN_DEFINE
are aligned according to user needs.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2025-07-19 15:37:01 -04:00
Alberto Escolar Piedras
35ba7dbdf7 tests/lib/c_lib/thrd: Remove filter on NATIVE_APPLICATION
It is not possible to build anymore in that mode, so this filter
is not needed.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-19 09:38:15 +02:00
Christoph Winklhofer
d5354449be json: fix encoding of string null pointer
A segmentation fault occurs when a zero initialized struct with a string
field (JSON_TOK_STRING) is encoded. Encode a string null pointer as an
empty JSON string "".

Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-07-11 08:15:36 -10:00
Alberto Escolar Piedras
8f092623ae tests/lib/timespec_util: Skip two tests by now
These two (sub)tests assume the system tick period divides evenly all
time interval values being tested, but this is not the case in general,
and when it is not, these tests fail.

Let's skip these 2 tests by now so we can release without a broken
CI, and do not block other development while the tests themselves are
being fixed.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-07-08 07:14:08 -10:00
Benjamin Cabé
44aaa8443b tests: lib: net_buf: add tests for net_buf_linearize()
Add tests to ensure 100% line and branch coverage of previously untested
net_buf_linearize() function.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-26 11:01:49 -05:00
Sayooj K Karun
41adc8a61a include: zephyr: sys: Refactor MIN_HEAP_DEFINE macro
Remove calling of `min_heap_init()` from MIN_HEAP_DEFINE

Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
2025-06-26 11:58:05 -04:00
Duy Nguyen
0b52a83104 tests: libcxx: Update missing CONFIG_COMMON_LIBC_MALLOC
The prj.conf was missing CONFIG_COMMON_LIBC_MALLOC causing
warning of the depended config CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE

Signed-off-by: Duy Nguyen <duy.nguyen.xa@renesas.com>
2025-06-26 14:07:03 +02:00
Benjamin Cabé
f21f3b0d92 tests: do not use "sanity" word
Fix to align with guidelines regarding the use of inclusive language.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-25 16:00:10 -10:00
Chris Friedt
3e30e2eddd tests: lib: move time testsuite to c_lib
Presumably the time testsuite was separate from the c library set of
testsuites because it had a depedency on POSIX.

Since that dependency no longer exists, colocate the time testsuite
with the other c library testsuites.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
9ecb7965b6 tests: libc: thrd: use sys_clock_gettime() and timespec_add()
Use sys_clock_gettime() instead of clock_gettime() and use
timespec_add() instead of manually adding timespec structures.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
ec62630950 tests: libc: thrd: use timespec_from_timeout()
Use `timespec_from_timeout(K_MSEC(msec), &ts)` instead of leaning on
lazily-crafted timespecs with invalid tv_nsec fields.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
a17497162e tests: libc: thrd: do not pass NULL for thrd_sleep() duration
The specification does not say that the first struct timespec passed to
thrd_sleep() may be NULL.

Preserving the testpoint so that a possible future testsuite can be
run that expects faults to occur when undefined behaviour is used.

Faults are one possible solution to handling undefined behaviour, but
it would be good to come to a concensus about how that should be
handled in Zephyr for standard function calls belonging to ISO C or
POSIX.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Chris Friedt
a5a824db91 tests: libc: thrd: compare with thrd_success rather than ok or zero
The C standard does not guarantee that `thrd_success` is equal to
zero, so ensure that the test takes that into account.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-06-24 14:18:52 +02:00
Glenn Andrews
94084e5aba Lib: SMF: Add return code to signal event propagation
See Discussion https://github.com/zephyrproject-rtos/zephyr/discussions/83659
for information about the purpose of this change.

Modifies run actions of hierarchical state machines
to return a value indicating if the event was handled
by the run action or should be propagated up to the
parent run action. Flat state machines are not affected,
and their run action returns void.

smf_set_handled() has been removed and replaced by
this return value. smf_set_state() will not propagate
events regardless of the return value as the transition
is considered to have occurred.

Documentation, tests, samples, has been updated.
USB-C and hawkBit use SMF and have been updated to use
the new return codes.

Signed-off-by: Glenn Andrews <glenn.andrews.42@gmail.com>
2025-06-17 16:04:04 +02:00
Anas Nashif
e5edf45596 tests: c_lib: thrd: run test on 1 cpu
This test fails sporadically on SMP, so make it run only on one CPU.

Related to zephyrproject-rtos/zephyr#91620

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-06-14 12:36:48 -04:00
Fin Maaß
c2fff4a3e4 devicetree: Enhance DT_ENUM_HAS_VALUE macro for arrays
On arrays DT_ENUM_HAS_VALUE() and DT_INST_ENUM_HAS_VALUE()
were only checking the first index, this changes it to check all indexes.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-06-12 11:44:46 +02:00
Benjamin Cabé
3c93678b2c tests: lib: min_heap: add test coverage for edge cases
Add missing tests for edge cases (ex. peek on empty heap, push to full
heap, ...) to get to 100% coverage (lines & branches)

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-11 16:24:59 -07:00
Benjamin Cabé
37919afd78 tests: lib: min_heap: use more descriptive assert_ macros
make test cases more readable using more direct assert_ macros, for
example zassert_not_null(foo, ...) instead of
zassert_true(foo != NULL, ...).

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-06-11 16:24:59 -07:00
Jamie McCrae
99650914c5 tests: lib: devicetree: Add sub-partition tests
Adds tests for sub-partition macros

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-06-11 10:13:56 -07:00
Fabian Blatz
c7a61d6418 tests: lib: gui: lvgl: Remove LV_FONT_SIMSUN_16_CJK symbol
In 9.3 due to font licensing issues LV_FONT_SIMSUN_16_CJK was deprecated.
Instead select now LV_FONT_SOURCE_HAN_SANS_SC_16_CJK symbol.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
2025-06-11 08:20:09 +02:00
Sayooj K Karun
ada616b83f tests: lib: min_heap Add unit tests for min-heap API
Introduce test suite using Ztest for validating the min-heap API.
Covers insertion, removal, ordering, and custom comparators.

The tests verify correct behavior under both static and dynamic
initialization modes.

Signed-off-by: Sayooj K Karun <sayooj@aerlync.com>
2025-06-07 13:29:24 +01:00
Fin Maaß
1c319304d1 tests: add for DT_ALL_INST_HAS_PROP_STATUS_OKAY() macro
add test for DT_ALL_INST_HAS_PROP_STATUS_OKAY() macro.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-06-06 08:42:41 +02:00
Fin Maaß
416a76002e tests: add for DT_ALL_INST_HAS_BOOL_STATUS_OKAY() macro
add test for DT_ALL_INST_HAS_BOOL_STATUS_OKAY() macro.

Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
2025-06-06 08:42:41 +02:00
Alberto Escolar Piedras
13fa0c5ebc tests/c_lib/common/src/test_sqrt: Fix code compliance issues
Fix several code compliance issues.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-05-29 15:17:32 +01:00
Alberto Escolar Piedras
37089cfc03 tests/c_lib/common/src/test_sqrt: Fix when double is not 64 bits
The combination of
3231269244
74c9e7afab
broke this test, when __SIZEOF_DOUBLE__ != 8.
In that case the test will fail to build,
as the variables the code uses are left ifdef'ed out.

Let's fix it.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-05-29 15:17:32 +01:00
Keith Packard
3231269244 tests/c_lib: Skip double sqrt test when double is not 64 bits
This test only works for 64-bit values. On targets which use 32 bits for
double, skip this version. The float test will check the 32-bit math for
that.

This is the 'nicer' version of this fix which uses sizeof rather than
relying on __SIZEOF_DOUBLE__.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-05-26 19:40:06 -04:00
Keith Packard
74c9e7afab tests/c_lib: Skip double sqrt test when double is not 64 bits
This test only works for 64-bit values. On targets which use 32 bits for
double, skip this version. The float test will check the 32-bit math for
that.

Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-23 17:41:40 -04:00
Chris Friedt
13fe95b51d tests: lib: timeutil: add timespec util testsuite
Add a timespec util testsuite. This should have reasonably high enough
coverage to be useful.

I would have preferred to add this as an architecture-independent
unit test (for the unit_testing platform) under tests/unit/timeutil but
there is an inconsistency about the size of time_t on the unit_testing
and native_sim/native platforms. On every other platform supported by
Zephyr, time_t is 64-bits. However, on those platforms, time_t is only
32-bits.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-22 23:57:17 +02:00
Krzysztof Chruściński
96e2f8bcd0 tests: lib: Fix zassert string
Fix wrong parameter used in zassert macros.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-05-22 16:17:23 +02:00
Daniel Mangum
3675ff2c14 tests: lib: p4wq: turn of time slicing
Turns off time slicing as these tests do not expect time slicing and
previously operated without time slicing, but now fallback to the new
default of a time slice size of 20 added in e337b7b. This explicitly sets
the time slice size to 0.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2025-05-17 14:10:13 +02:00
Anas Nashif
d881fb334b boards: qemu_nios2: drop board definition
Remove qemu_nios2, more removals will follow.

Part of #89280

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-05-15 20:01:05 -04:00
Chris Friedt
cfae041834 posix: implement the XSI_SINGLE_PROCESS Option Group
gettimeofday() was already implemented, but incorrectly lumped into
POSIX_TIMERS.

putenv() is really just a wrapper around setenv().

The only one left to implement was gethostid() which was relatively
trivial.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-05-13 22:23:21 -04:00
Benjamin Cabé
878de4727a tests: lib: json: zero-initialize structs before using memcmp in tests
Zero-initialize the `test_int_limits` and `test_enums` structs before
assignment and decoding in their respective tests.

This ensures that all padding bytes are set to zero, making
`memcmp`-based comparisons reliable and portable across different
architectures and compilers.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-05-06 18:23:49 +02:00
Hao Luo
660390835b dts: ambiq: change to enable ambiq drivers in overlays
Keep minimal system in board dts, only enable driver in overlays

Signed-off-by: Hao Luo <hluo@ambiq.com>
2025-05-05 21:56:47 +02:00
Jamie McCrae
c6eb665acf tests: lib: devicetree: devices: Add sub-partition check
Adds a sub-partition check to this test

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-04-30 18:44:06 +02:00
Benjamin Cabé
01a0c24e17 dts: vendor-prefixes: change description for zephyr entry
Use a better "vendor" name for "zephyr"

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-04-29 02:41:53 +02:00
Chris Friedt
a10f96e153 posix + tests: use CLOCK_REALTIME where specified by POSIX
Use CLOCK_REALTIME for the default clock source throughout
the POSIX implementation and tests so that we are
consistent with the specification.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
2025-04-24 22:58:43 +02:00
Anas Nashif
c2c3f7570f tests: lib: fix doxygen groups
Group test using doxygen and general fixes to structure.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-04-22 14:03:29 +02:00
Anas Nashif
7d36a18b7b tests: kernel: fix kheap doxygen groups
Fix grouping and general doxygen fixups.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-04-22 14:03:29 +02:00
Simone Orru
36ec017a38 uuid: Add sample for UUID utilities
Add a sample that showcases the usqge of the
UUID utilities.

Signed-off-by: Simone Orru <simone.orru@secomind.com>
2025-04-14 09:47:26 +02:00
Simone Orru
25c94a3019 uuid: Add tests for UUID utilities
Add some tests for the UUID utilities.

Signed-off-by: Simone Orru <simone.orru@secomind.com>
2025-04-14 09:47:26 +02:00
Christoph Winklhofer
a5e295c452 json: improve parsing and serializing of integers
Add support for parsing and serializing of following integer types:
'int8_t', 'uint8_t', 'int16_t', 'uint16_t' and 'uint32_t'.

The generic integer token JSON_TOK_INT and JSON_TOK_UINT, in combination
with the field size (set by JSON_OBJ_DESCR_PRIM) allows to parse different
integer types, for example:

struct foo {
  int64_t i64;
  uint32_t u32;
  int16_t i16;
  uint8_t u8;
};

struct json_obj_descr foo_descr[] = {
  JSON_OBJ_DESCR_PRIM(struct foo, i64, JSON_TOK_INT),
  JSON_OBJ_DESCR_PRIM(struct foo, u32, JSON_TOK_UINT),
  JSON_OBJ_DESCR_PRIM(struct foo, i16, JSON_TOK_INT),
  JSON_OBJ_DESCR_PRIM(struct foo, u8, JSON_TOK_UINT),
};

These tokens also support parsing and serializing enums:

enum unsigned_enum { UA=0, UB=1, UC=2 };
enum signed_enum { SA=-1, SB=0, SC=1 };

struct foo {
  enum unsigned_enum u;
  enum signed_enum s;
};

struct json_obj_descr foo_descr[] = {
  JSON_OBJ_DESCR_PRIM(struct foo, u, JSON_TOK_UINT),
  JSON_OBJ_DESCR_PRIM(struct foo, s, JSON_TOK_INT),
};

Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-04-11 06:32:50 +02:00
Christoph Winklhofer
63d33e631c json: support parsing and serializing of strings with char arrays
Support parsing and serializing of struct fields that are defined as a
char array.

Use the token JSON_TOK_STRING_BUF to parse and serialize a string for a
char array, for example:

struct foo {
  const char *str;
  char str_buf[30];
};

struct json_obj_descr foo_descr[] = {
  JSON_OBJ_DESCR_PRIM(struct foo, str, JSON_TOK_STRING),
  JSON_OBJ_DESCR_PRIM(struct foo, str_buf, JSON_TOK_STRING_BUF),
};

The struct 'json_obj_descr' now has an additional union member 'field'
to store the size of the struct field, which is used with the token
'JSON_TOK_STRING_BUF' to determine the element size.

Fixes: #65200
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-04-11 06:32:50 +02:00
Benjamin Cabé
975b8e137f tests: json: fix tests involving double numbers
Update the JSON test cases to explicitly cast NAN and INFINITY to double
type to avoid implicit promotion.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-04-10 14:43:19 +02:00
Christoph Winklhofer
fc37c02eb1 json: improve parsing and serializing of 'float' and 'double'
Up to now, the handling of type float was offloaded to the users of the
JSON utility, with the token JSON_TOK_FLOAT.

Improve handling of floating point types and support the types 'float'
and 'double' in a built-in way so that they can be directly parsed to
and serialized from variables (of type float or double).

The types are serialized in the shortest representation, either as a
decimal number or in scientific notation:
  * float (with JSON_TOK_FLOAT_FP): encoded with maximal 9 digits
  * double (with JSON_TOK_DOUBLE_FP): encoded with maximal 16 digits
  * NaN, Infinity, -Infinity: encoded and decoded as:
    {"nan_val":NaN,"inf_pos":Infinity,"inf_neg":-Infinity}

Enable the floating point functionality with the Kconfig option:
  JSON_LIBRARY_FP_SUPPORT=y

It requires a libc implementation with support for floating point
functions: strtof(), strtod(), isnan() and isinf().

Fixes: #59412
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-04-09 22:05:14 +02:00
Christoph Winklhofer
061e345972 json: Fix calculation of object size
The calculation of the object size may be incorrect when the size of
a field is smaller than the struct alignment. When such a struct is
used in an array field, the decoded object contains wrong values.

The alignment influences the object size. For example the following
struct has a calculated object size of 8 bytes, however due to
alignment the real size of the struct is 12 bytes:

struct test_bool {
  bool b1; /* offset 0, size 1 */
           /* 3-byte padding */
  int i1;  /* offset 4, size 4 */
  bool b2; /* offset 8, size 1 */
           /* 3-byte padding */
};

This commit changes the object size calculation and computes the size
with the offset and size of the last field in the struct (rounded up
by the struct alignment).

Fixes: #85121
Signed-off-by: Christoph Winklhofer <cj.winklhofer@gmail.com>
2025-04-08 11:44:51 +02:00
Anas Nashif
5c8cf1c18c tests: fix various test ids and use existing scheme
Fix IDs and match them to what we have in the MAINTAINERS file.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-04-07 11:22:36 +02:00
Anas Nashif
1a9a43a7fa tests: unskip some tests
Few tests are being skipped for no goot reason (anymore). Add some
coverage using few platforms that work with intention to expand if all
works well and if needed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-03-28 21:52:13 +01:00