Skip to content

[libc] adjust printf macro test to use all 64 bits #98195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

michaelrj-google
Copy link
Contributor

The previous printf macro test for 64 bit octal used the number 0123,
which is not large enough to ensure that the macro is actually reading a
64 bit number. This patch enlarges the number, and also makes sure the
return value of sprintf is correct for the macro tests.

The previous printf macro test for 64 bit octal used the number 0123,
which is not large enough to ensure that the macro is actually reading a
64 bit number. This patch enlarges the number, and also makes sure the
return value of sprintf is correct for the macro tests.
@llvmbot llvmbot added the libc label Jul 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2024

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

The previous printf macro test for 64 bit octal used the number 0123,
which is not large enough to ensure that the macro is actually reading a
64 bit number. This patch enlarges the number, and also makes sure the
return value of sprintf is correct for the macro tests.


Full diff: https://github.com/llvm/llvm-project/pull/98195.diff

1 Files Affected:

  • (modified) libc/test/src/stdio/sprintf_test.cpp (+4-3)
diff --git a/libc/test/src/stdio/sprintf_test.cpp b/libc/test/src/stdio/sprintf_test.cpp
index 8e9870f71a959..7ccc0a2652e2b 100644
--- a/libc/test/src/stdio/sprintf_test.cpp
+++ b/libc/test/src/stdio/sprintf_test.cpp
@@ -39,18 +39,19 @@ using LIBC_NAMESPACE::fputil::testing::RoundingMode;
     for (char &c : buff) {                                                     \
       c = 0;                                                                   \
     }                                                                          \
-    LIBC_NAMESPACE::sprintf(buff, "%" FMT, X);                                 \
-    ASSERT_STREQ(buff, expected);                                              \
+    written = LIBC_NAMESPACE::sprintf(buff, "%" FMT, X);                       \
+    ASSERT_STREQ_LEN(written, buff, expected);                                 \
   } while (0)
 
 TEST(LlvmLibcSPrintfTest, Macros) {
   char buff[128];
+  int written;
   macro_test(PRIu8, 1, "1");
   macro_test(PRIX16, 0xAA, "AA");
   macro_test(PRId32, -123, "-123");
   macro_test(PRIX32, 0xFFFFFF85, "FFFFFF85");
   macro_test(PRIo8, 0xFF, "377");
-  macro_test(PRIo64, 0123, "123");
+  macro_test(PRIo64, 0123456712345671234567ll, "123456712345671234567");
 }
 
 TEST(LlvmLibcSPrintfTest, SimpleNoConv) {

@michaelrj-google michaelrj-google merged commit 8492ad5 into llvm:main Jul 9, 2024
6 of 7 checks passed
@michaelrj-google michaelrj-google deleted the libcPrintfMacroTestFix branch July 9, 2024 17:55
mikhailramalho added a commit to mikhailramalho/llvm-project that referenced this pull request Jul 9, 2024
Similar to llvm#98195.

This patch enlarges the number to ensure that a 64-bit number is being
read.
mikhailramalho added a commit to mikhailramalho/llvm-project that referenced this pull request Jul 9, 2024
Similar to llvm#98195.

This patch enlarges the number to ensure that a 64-bit number is being
read.
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this pull request Jul 14, 2024
The previous printf macro test for 64 bit octal used the number 0123,
which is not large enough to ensure that the macro is actually reading a
64 bit number. This patch enlarges the number, and also makes sure the
return value of sprintf is correct for the macro tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants