Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/kernel/common/src/pow2.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ BUILD_ASSERT(sizeof(static_array9) == 16);
static void test_pow2_ceil_x(unsigned long test_value,
unsigned long expected_result)
{
volatile unsigned int x = test_value;
unsigned int result = Z_POW2_CEIL(x);
volatile unsigned long x = test_value;
unsigned long result = Z_POW2_CEIL(x);

zassert_equal(result, expected_result,
"ZPOW2_CEIL(%lu) returned %ld, expected %lu",
"ZPOW2_CEIL(%lu) returned %lu, expected %lu",
test_value, result, expected_result);
}

Expand Down
18 changes: 9 additions & 9 deletions tests/kernel/obj_core/obj_core_stats/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ ZTEST(obj_core_stats_thread, test_obj_core_stats_thread_test)
/* Disable the stats (re-using query2 and query3) */

status = k_obj_core_stats_disable(K_OBJ_CORE(test_thread));
zassert_equal(status, 0, "Expected 0, got %llu\n", status);
zassert_equal(status, 0, "Expected 0, got %d\n", status);

k_sem_give(&wake_test_thread);
k_sem_take(&wake_main_thread, K_FOREVER);
Expand All @@ -351,7 +351,7 @@ ZTEST(obj_core_stats_thread, test_obj_core_stats_thread_test)
/* Enable the stats */

status = k_obj_core_stats_enable(K_OBJ_CORE(test_thread));
zassert_equal(status, 0, "Expected 0, got %llu\n", status);
zassert_equal(status, 0, "Expected 0, got %d\n", status);

k_sem_give(&wake_test_thread);
k_sem_take(&wake_main_thread, K_FOREVER);
Expand Down Expand Up @@ -440,14 +440,14 @@ static void test_mem_block_query(const char *str,
"%s: Failed to get query stats (%d)\n", str, status);

zassert_equal(query.free_bytes, expected->free_bytes,
"%s: Expected %u free bytes, got %u\n",
"%s: Expected %zu free bytes, got %zu\n",
str, expected->free_bytes, query.free_bytes);
#ifdef CONFIG_SYS_MEM_BLOCKS_RUNTIME_STATS
zassert_equal(query.allocated_bytes, expected->allocated_bytes,
"%s: Expected %u allocated bytes, got %u\n",
"%s: Expected %zu allocated bytes, got %zu\n",
str, expected->allocated_bytes, query.allocated_bytes);
zassert_equal(query.max_allocated_bytes, expected->max_allocated_bytes,
"%s: Expected %u max_allocated bytes, got %d\n",
"%s: Expected %zu max_allocated bytes, got %zu\n",
str, expected->max_allocated_bytes,
query.max_allocated_bytes);
#endif
Expand Down Expand Up @@ -575,7 +575,7 @@ static void test_mem_slab_raw(const char *str, struct k_mem_slab_info *expected)
"%s: Expected %u blocks, got %u\n",
str, expected->num_blocks, raw.num_blocks);
zassert_equal(raw.block_size, expected->block_size,
"%s: Expected block size=%u blocks, got %u\n",
"%s: Expected block size=%zu blocks, got %zu\n",
str, expected->block_size, raw.block_size);
zassert_equal(raw.num_used, expected->num_used,
"%s: Expected %u used, got %d\n",
Expand All @@ -599,13 +599,13 @@ static void test_mem_slab_query(const char *str,
"%s: Failed to get query stats (%d)\n", str, status);

zassert_equal(query.free_bytes, expected->free_bytes,
"%s: Expected %u free bytes, got %u\n",
"%s: Expected %zu free bytes, got %zu\n",
str, expected->free_bytes, query.free_bytes);
zassert_equal(query.allocated_bytes, expected->allocated_bytes,
"%s: Expected %u allocated bytes, got %u\n",
"%s: Expected %zu allocated bytes, got %zu\n",
str, expected->allocated_bytes, query.allocated_bytes);
zassert_equal(query.max_allocated_bytes, expected->max_allocated_bytes,
"%s: Expected %u max_allocated bytes, got %d\n",
"%s: Expected %zu max_allocated bytes, got %zu\n",
str, expected->max_allocated_bytes,
query.max_allocated_bytes);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/kernel/timer/timer_behavior/src/jitter_drift.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ static void do_test_using(void (*sample_collection_fn)(void), const char *mechan
+ expected_period_drift;

zassert_true(min_us >= min_us_bound,
"Shortest timer period too short (off by more than expected %d%)",
"Shortest timer period too short (off by more than expected %d%%)",
CONFIG_TIMER_TEST_PERIOD_MAX_DRIFT_PERCENT);
zassert_true(max_us <= max_us_bound,
"Longest timer period too long (off by more than expected %d%)",
"Longest timer period too long (off by more than expected %d%%)",
CONFIG_TIMER_TEST_PERIOD_MAX_DRIFT_PERCENT);


Expand Down
2 changes: 1 addition & 1 deletion tests/lib/c_lib/thrd/src/thrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ ZTEST(libc_thrd, test_thrd_create_join)

zassert_equal(thrd_success, thrd_create(&thr, fun, &param));
zassert_equal(thrd_success, thrd_join(thr, &res));
zassert_equal(BIOS_FOOD, param, "expected: %d actual: %d", BIOS_FOOD, param);
zassert_equal(BIOS_FOOD, param, "expected: %lu actual: %lu", BIOS_FOOD, param);
Copy link
Contributor

@keith-packard keith-packard Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param is uintptr_t, which is not a type that printf knows about internally. Include <inttypes.h> and use "%" PRIuPTR for both, adding a cast to (uintptr_t) for BIOS_FOOD so they match.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use PRIuPTR or others from inttypes.h, as they are not widely used in Zephyr. A quick search showed only three occurrences of PRIuPTR. As far as I know, in Zephyr's type system, PRIuPTR is always lu.

#37718 (comment)

So int32_t is always an int, intptr_t is always a long, and PRIuPTR is
always "lu", for all supported architectures.

If there is consensus to start using defines from inttypes.h, I'm happy to use them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several people have commented that the inttypes.h stuff is not their favorite, to the point that Zephyr attempts to enforce some level of type uniformity. It usually overrides the toolchain types by pre-loading zephyr_stdint.h. you can use %lu with uintptr_t and %d with int32_t when CONFIG_ENFORCE_ZEPHYR_STDINT is set.

Copy link
Member

@aescolar aescolar Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess a safe option would be to cast both parameters to (unsigned long) and use "%ul" (this is a error print at the end)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, a reasonable plan (although, I think you meant %lu)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, a cast + lu would work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I used now the cast + lu, see #97202

zassert_equal(FORTY_TWO, res);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/lib/c_lib/thrd/src/thrd.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <zephyr/sys/timeutil.h>

/* arbitrary magic numbers used for testing */
#define BIOS_FOOD 0xb105f00d
#define BIOS_FOOD 0xb105f00dUL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the best way to represent a uintptr_t constant is -- C has things like UINT64_C(x), which can be used to create a 64-bit constant, but it doesn't have UINTPTR_C(x) for uintptr_t. An odd asymmetry in the C spec. Probably the most spec-compliant way to define this would be ((uintptr_t) UINTMAX_C(0xb105f00d))

#define FORTY_TWO 42
#define SEVENTY_THREE 73
#define DONT_CARE 0x370ca2e5
Expand Down
4 changes: 2 additions & 2 deletions tests/net/dhcpv6/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,13 @@ static void verify_dhcpv6_oro_sol_max_rt(struct net_if *iface,
net_pkt_cursor_backup(pkt, &backup);

ret = dhcpv6_find_option(pkt, DHCPV6_OPTION_CODE_ORO, &length);
zassert_ok(ret, 0, "ORO option not found");
zassert_ok(ret, "ORO option not found");
zassert_true(length >= sizeof(uint16_t) && length % sizeof(uint16_t) == 0,
"Invalid ORO length");

while (length >= sizeof(uint16_t)) {
ret = net_pkt_read_be16(pkt, &oro);
zassert_ok(ret, 0, "ORO read error");
zassert_ok(ret, "ORO read error");
length -= sizeof(uint16_t);

if (oro == DHCPV6_OPTION_CODE_SOL_MAX_RT) {
Expand Down
Loading