Repository navigation
Conversation
xiaoxiang781216
previously approved these changes
Nov 9, 2026
The test expects the output of the Default profile. Make each case follow the options of printf(), so that it also passes with the Minimal and Full profiles of libc, and with each option turned on or off on its own. LIBC_PRINTF_SHORT and LIBC_PRINTF_LONG_LONG change no case: %hhn and %lln store at their size with both settings. Add cases for -0.0, %a and %A, %b and %B, and the wN length. Part of apache/nuttx#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
printf() now keeps the trailing zeros of %#g, and it takes a negative precision from * as no precision, as C says. Add cases for both. Part of apache/nuttx#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
Add the program printfengine. It checks the digits of %e, %f and %g: ties of values that are exact in binary, %.0f rounds, the form of %g, the sign, infinity, NaN, the limits of binary64 and 17 correct digits. With LIBC_PRINTF_EXACT it also checks all digits of a double, and with LIBC_PRINTF_EXACT_LDOUBLE the range and the digits of a long double. Each format goes through a function with no format attribute. An error prints the format and stops with an assertion. Part of apache/nuttx#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
printf() now prints nothing for %n also when LIBC_PRINTF_PERCENT_N is off, where it printed "?" before. The test expects the same text with the option on or off, and checks the store only when the option is on. Add a check that snprintf(NULL, 0, ...) returns the length without the %n. Part of apache/nuttx#21467 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
xiaoxiang781216
approved these changes
Nov 9, 2026
cederom
approved these changes
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
depends-on: apache/nuttx/pull/21595
Part of apache/nuttx#21467.
Summary
Tests of
printf()for the merged apache/nuttx#21505 and apache/nuttx#21507, and for apache/nuttx#21595. Four commits:printftestfollows the printf options. It expected the output of the Default profile, so it failed with the other profiles of libc and when one printf option was turned off. Each case now followsLIBC_FLOATINGPOINT,LIBC_NUMBERED_ARGS,LIBC_PRINTF_ALT_FORM,LIBC_PRINTF_INT_PRECISION,LIBC_PRINTF_OCTAL(%oprints "?"),LIBC_PRINTF_LEFT_JUSTIFY(the-flag pads on the left),LIBC_PRINTF_HEXFLOAT,LIBC_PRINTF_C23andLIBC_PRINTF_PERCENT_N.LIBC_PRINTF_SHORTandLIBC_PRINTF_LONG_LONGchange no case:%hhnand%llnstore at their size with both settings. New cases: the sign of -0.0,%aand%A,%band%B, and thewNlength. A precision ofINT_MINfrom*is no precision, so%.*d|%.*s|expects1|ab|in all profiles.printftest: cases for%#g, which keeps the trailing zeros (%#gof 1.0 is1.00000,%#.0gof 1.0 is1.), and for a negative precision from*, which is no precision (%.*swith -2 prints the whole string,%0*.*dkeeps the0flag).printfengine, checks the digits of%e,%fand%g: ties of values that are exact in binary,%.0frounds, the form of%g, the sign, infinity and NaN, the limits of binary64 and 17 correct digits. WithLIBC_PRINTF_EXACTit checks all digits of adouble, and withLIBC_PRINTF_EXACT_LDOUBLEthe range and the digits of along double. It followsprintftest: the same layout, and Make and CMake files.printftest:%nprints nothing also whenLIBC_PRINTF_PERCENT_Nis off (libs/libc/stream: Print nothing for %n when LIBC_PRINTF_PERCENT_N is off. nuttx#21595), where it printed?before. The test expects the same text with the option on or off, and checks the store only when the option is on. New case:snprintf(NULL, 0, "ab%n|%s", &n, "str")returns 6.Impact
testing/libc/printftest/printftest_main.c, and the new program intesting/libc/printfenginewith the optionCONFIG_TESTING_PRINTFENGINE, off by default. It depends onLIBC_FLOATINGPOINT. No change to any other code.Commit 4 needs apache/nuttx#21595: on master
printftestfails at%nwithLIBC_PRINTF_PERCENT_Noff. So this PR must merge after it.Testing
qemu-armv8aunder QEMU with HVF, nuttx apache/nuttx#21595 (9ae1b2e6d85, on master d1191e0ad01),printftest,printfengine, then ostest; each run passes and ostest exits with status 0:qemu-armv8a:knsh(kernel)qemu-armv8a:knshqemu-armv8a:knshqemu-armv8a:knshLIBC_PRINTF_OCTAL=n,LIBC_PRINTF_LEFT_JUSTIFY=nqemu-armv8a:knshLIBC_PRINTF_PERCENT_N=yqemu-armv8a:knshLIBC_PRINTF_PERCENT_N=y,LIBC_PRINTF_OCTAL=n,LIBC_PRINTF_LEFT_JUSTIFY=nqemu-armv8a:nsh(flat)qemu-armv8a:nshLIBC_PRINTF_PERCENT_N=yprintfengineneeds floating point, so it does not run with Minimal.On nuttx master d1191e0ad01 (
qemu-armv8a:knsh, Default)printftestfails at commit 4, as it must:"ab%n|%s" returned 7: "ab?|str", expected "ab|str".printfenginepasses there. WithLIBC_PRINTF_PERCENT_N=yboth pass on master.Builds with
-Werrorand both programs on:qemu-armv8a:nshandrv-virt:nsh64, each with Default and with Full andLIBC_PRINTF_PERCENT_N=y.tools/checkpatch.sh -c -u -m -gpasses.Not run: a CMake build, a protected build, hardware.