Skip to content

[libc] Fix stdio tests after #143802 #143810

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
merged 1 commit into from
Jun 11, 2025

Conversation

michaelrj-google
Copy link
Contributor

In #143802 the stdio test cleanup missed a few places where errno was
being set to a failing value, and one where the framework needed to
included.

In llvm#143802 the stdio test cleanup missed a few places where errno was
being set to a failing value, and one where the framework needed to
included.
@llvmbot
Copy link
Member

llvmbot commented Jun 11, 2025

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

In #143802 the stdio test cleanup missed a few places where errno was
being set to a failing value, and one where the framework needed to
included.


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

5 Files Affected:

  • (modified) libc/docs/configure.rst (+1-1)
  • (modified) libc/test/src/stdio/fgetc_test.cpp (+1)
  • (modified) libc/test/src/stdio/fgetc_unlocked_test.cpp (+1)
  • (modified) libc/test/src/stdio/fgets_test.cpp (+1)
  • (modified) libc/test/src/stdio/setvbuf_test.cpp (+1)
diff --git a/libc/docs/configure.rst b/libc/docs/configure.rst
index 8d53390ae19bf..109412225634f 100644
--- a/libc/docs/configure.rst
+++ b/libc/docs/configure.rst
@@ -29,7 +29,7 @@ to learn about the defaults for your platform and target.
     - ``LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR``: Enable -fstack-protector-strong to defend against stack smashing attack.
     - ``LIBC_CONF_KEEP_FRAME_POINTER``: Keep frame pointer in functions for better debugging experience.
 * **"errno" options**
-    - ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, and LIBC_ERRNO_MODE_SYSTEM.
+    - ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, LIBC_ERRNO_MODE_SYSTEM, and LIBC_ERRNO_MODE_SYSTEM_INLINE.
 * **"general" options**
     - ``LIBC_ADD_NULL_CHECKS``: Add nullptr checks in the library's implementations to some functions for which passing nullptr is undefined behavior.
 * **"math" options**
diff --git a/libc/test/src/stdio/fgetc_test.cpp b/libc/test/src/stdio/fgetc_test.cpp
index 7c652f666a8f3..1faa49112fb63 100644
--- a/libc/test/src/stdio/fgetc_test.cpp
+++ b/libc/test/src/stdio/fgetc_test.cpp
@@ -33,6 +33,7 @@ class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
     // This is an error and not a real EOF.
     ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
     ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
+    ASSERT_ERRNO_FAILURE();
 
     ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
 
diff --git a/libc/test/src/stdio/fgetc_unlocked_test.cpp b/libc/test/src/stdio/fgetc_unlocked_test.cpp
index f4471dd82df15..7b2efe642fb5e 100644
--- a/libc/test/src/stdio/fgetc_unlocked_test.cpp
+++ b/libc/test/src/stdio/fgetc_unlocked_test.cpp
@@ -36,6 +36,7 @@ class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
     // This is an error and not a real EOF.
     ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
     ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
+    ASSERT_ERRNO_FAILURE();
 
     ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
 
diff --git a/libc/test/src/stdio/fgets_test.cpp b/libc/test/src/stdio/fgets_test.cpp
index c00a9256af52d..2d7c68d490811 100644
--- a/libc/test/src/stdio/fgets_test.cpp
+++ b/libc/test/src/stdio/fgets_test.cpp
@@ -36,6 +36,7 @@ TEST_F(LlvmLibcFgetsTest, WriteAndReadCharacters) {
   // This is an error and not a real EOF.
   ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
   ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
+  ASSERT_ERRNO_FAILURE();
 
   ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));
 
diff --git a/libc/test/src/stdio/setvbuf_test.cpp b/libc/test/src/stdio/setvbuf_test.cpp
index 4144bc1bef447..a0936ba79ef73 100644
--- a/libc/test/src/stdio/setvbuf_test.cpp
+++ b/libc/test/src/stdio/setvbuf_test.cpp
@@ -11,6 +11,7 @@
 #include "src/stdio/fread.h"
 #include "src/stdio/fwrite.h"
 #include "src/stdio/setvbuf.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
 #include "test/UnitTest/Test.h"
 
 #include "hdr/stdio_macros.h"

@vonosmas
Copy link
Contributor

Thank you for the fixup! Retiring my change, since your fix is cleaner.

@michaelrj-google michaelrj-google merged commit 3c7af17 into llvm:main Jun 11, 2025
14 of 16 checks passed
@michaelrj-google michaelrj-google deleted the libcStdioTestFix branch June 11, 2025 23:52
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 12, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime-2 running on rocm-worker-hw-02 while building libc at step 10 "Add check check-libc-amdgcn-amd-amdhsa".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/7159

Here is the relevant piece of the build log for the reference
Step 10 (Add check check-libc-amdgcn-amd-amdhsa) failure: test (failure)
...
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcUngetcTest.UngetAndReadBack
[       OK ] LlvmLibcUngetcTest.UngetAndReadBack (322 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[2679/2807] Running hermetic test libc.test.src.stdio.fprintf_test.__hermetic__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFPrintfTest.WriteToFile
[       OK ] LlvmLibcFPrintfTest.WriteToFile (472 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[2680/2807] Running hermetic test libc.test.src.stdio.fgetc_test.__hermetic__
FAILED: libc/test/src/stdio/libc.test.src.stdio.fgetc_test.__hermetic__.__cmd__ /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-amdgcn-amd-amdhsa-bins/libc/test/src/stdio/libc.test.src.stdio.fgetc_test.__hermetic__.__cmd__ 
cd /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-amdgcn-amd-amdhsa-bins/libc/test/src/stdio && /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/bin/amdhsa-loader /home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.build/runtimes/runtimes-amdgcn-amd-amdhsa-bins/libc/test/src/stdio/libc.test.src.stdio.fgetc_test.__hermetic__.__build__
[==========] Running 2 tests from 1 test suite.
[ RUN      ] LlvmLibcGetcTest.WriteAndReadCharactersWithFgetc
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/test/src/stdio/fgetc_test.cpp:36: FAILURE
          Expected: 0
          Which is: 0
To be not equal to: static_cast<int>(libc_errno)
          Which is: 0
[  FAILED  ] LlvmLibcGetcTest.WriteAndReadCharactersWithFgetc
[ RUN      ] LlvmLibcGetcTest.WriteAndReadCharactersWithGetc
/home/botworker/builds/openmp-offload-amdgpu-runtime-2/llvm.src/libc/test/src/stdio/fgetc_test.cpp:36: FAILURE
          Expected: 0
          Which is: 0
To be not equal to: static_cast<int>(libc_errno)
          Which is: 0
[  FAILED  ] LlvmLibcGetcTest.WriteAndReadCharactersWithGetc
Ran 2 tests.  PASS: 0  FAIL: 2
[2681/2807] Running hermetic test libc.test.src.stdio.asprintf_test.__hermetic__
[==========] Running 5 tests from 1 test suite.
[ RUN      ] LlvmLibcASPrintfTest.SimpleNoConv
[       OK ] LlvmLibcASPrintfTest.SimpleNoConv (50 us)
[ RUN      ] LlvmLibcASPrintfTest.PercentConv
[       OK ] LlvmLibcASPrintfTest.PercentConv (89 us)
[ RUN      ] LlvmLibcASPrintfTest.CharConv
[       OK ] LlvmLibcASPrintfTest.CharConv (82 us)
[ RUN      ] LlvmLibcASPrintfTest.LargeStringNoConv
[       OK ] LlvmLibcASPrintfTest.LargeStringNoConv (693 us)
[ RUN      ] LlvmLibcASPrintfTest.ManyReAlloc
[       OK ] LlvmLibcASPrintfTest.ManyReAlloc (463 us)
Ran 5 tests.  PASS: 5  FAIL: 0
[2682/2807] Running hermetic test libc.test.src.stdio.printf_test.__hermetic__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcPrintfTest.PrintOut
[       OK ] LlvmLibcPrintfTest.PrintOut (136 us)
Ran 1 tests.  PASS: 1  FAIL: 0
A simple string with no conversions.
1234567890
1234 and more

@Kewen12
Copy link
Contributor

Kewen12 commented Jun 12, 2025

Hello, it seems like this PR failed some related tests which breaks our buildbot. Could you please take a look. Thanks!

bot: https://lab.llvm.org/buildbot/#/builders/10/builds/7159

Kewen12 added a commit to Kewen12/llvm-project that referenced this pull request Jun 12, 2025
ronlieb pushed a commit that referenced this pull request Jun 12, 2025
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jun 12, 2025
@Kewen12
Copy link
Contributor

Kewen12 commented Jun 12, 2025

Hi @michaelrj-google, I had to revert it to unblock our downstream. Please reland it later. Thanks!

@michaelrj-google
Copy link
Contributor Author

all good, we'll see about getting a combined patch up that doesn't break any of the tests later

tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
In llvm#143802 the stdio test cleanup missed a few places where errno was
being set to a failing value, and one where the framework needed to
included.
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
In llvm#143802 the stdio test cleanup missed a few places where errno was
being set to a failing value, and one where the framework needed to
included.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
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.

6 participants