Skip to content

Conversation

tpambor
Copy link
Contributor

@tpambor tpambor commented Oct 2, 2025

For details see individual commits.

Fixes errors that were found after adding validation of zassert string in #96335.

ZPOW2_CEIL returns unsigned long, so use it to store result and use same
format specifier for actual and expected values.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
@pdgendt pdgendt added the Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. label Oct 2, 2025
@tpambor tpambor marked this pull request as ready for review October 2, 2025 10:19
@zephyrbot zephyrbot added area: C Library C Standard Library area: Tests Issues related to a particular existing or missing test area: Networking area: Kernel labels Oct 2, 2025
pdgendt
pdgendt previously approved these changes Oct 2, 2025
jhedberg
jhedberg previously approved these changes Oct 2, 2025
Status is of type int, not long long unsigned int,
so use %d instead of %llu. Use %zu for size_t.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
param is of type uintptr_t, so use %lu for printing it.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Remove the second parameter of zassert_ok() calls, as it internally
checks for equality with 0. The second parameter should be the error
message.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Correctly escape percent sign in zassert strings.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
Copy link

sonarqubecloud bot commented Oct 2, 2025

@tpambor tpambor marked this pull request as draft October 2, 2025 11:13
@tpambor tpambor removed the Hotfix Fix for issues blocking development, i.e. CI issues, tests failing in CI, etc. label Oct 2, 2025
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


/* 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))

Copy link
Contributor

@keith-packard keith-packard left a comment

Choose a reason for hiding this comment

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

A couple of minor type nits, most of this looks good.

@tpambor
Copy link
Contributor Author

tpambor commented Oct 4, 2025

I will split this up into multiple PRs, so the changes can be easier reviewed be the respective maintainers. I created a tracking issue here #96968.

@tpambor
Copy link
Contributor Author

tpambor commented Oct 8, 2025

I will close this PR. I have now submitted individual PRs for all issues, for details see #96968.

@tpambor tpambor closed this Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: C Library C Standard Library area: Kernel area: Networking area: Tests Issues related to a particular existing or missing test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants