summaryrefslogtreecommitdiff
path: root/libc/test/src/stdio/fdopen_test.cpp
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2025-06-13 10:25:26 -0700
committerGitHub <noreply@github.com>2025-06-13 10:25:26 -0700
commitc609112a5383c10272e3afceedd4d03f26437cf0 (patch)
tree2174cc81e0a1168757159aea0e872b3ebf3420d9 /libc/test/src/stdio/fdopen_test.cpp
parentb81d5e06c7cba8c9f1f5380daed4b9ee139214ba (diff)
Fix/reapply "[libc] Migrate stdio tests to ErrnoCheckingTest." (#143972)
This reverts commit a93e55e57ed00a55f822c64e3520c7c732b58480 and fixes build and test failures: * Proper include added to setvbuf_test.cpp * fgetc/fgetc_unlocked/fgets tests are ported to ErrnoSetterMatcher and are made more precise. This fixes inconsistencies between expectations in regular and GPU builds - ErrnoSetterMatcher is configured to omit errno matching on GPUs, as fgetc implementation on GPU doesn't set errno, in contrast to Linux.
Diffstat (limited to 'libc/test/src/stdio/fdopen_test.cpp')
-rw-r--r--libc/test/src/stdio/fdopen_test.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/libc/test/src/stdio/fdopen_test.cpp b/libc/test/src/stdio/fdopen_test.cpp
index 104fc478b100..b53184c30be3 100644
--- a/libc/test/src/stdio/fdopen_test.cpp
+++ b/libc/test/src/stdio/fdopen_test.cpp
@@ -9,20 +9,21 @@
#include "src/stdio/fdopen.h"
#include "hdr/fcntl_macros.h"
-#include "src/__support/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/stdio/fclose.h"
#include "src/stdio/fgets.h"
#include "src/stdio/fputs.h"
#include "src/unistd/close.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include <sys/stat.h> // For S_IRWXU
-TEST(LlvmLibcStdioFdopenTest, WriteAppendRead) {
+using LlvmLibcStdioFdopenTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
- libc_errno = 0;
constexpr const char *TEST_FILE_NAME = "testdata/write_read_append.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
@@ -52,8 +53,7 @@ TEST(LlvmLibcStdioFdopenTest, WriteAppendRead) {
ASSERT_ERRNO_SUCCESS();
}
-TEST(LlvmLibcStdioFdopenTest, InvalidFd) {
- libc_errno = 0;
+TEST_F(LlvmLibcStdioFdopenTest, InvalidFd) {
constexpr const char *TEST_FILE_NAME = "testdata/invalid_fd.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC);
@@ -64,8 +64,7 @@ TEST(LlvmLibcStdioFdopenTest, InvalidFd) {
ASSERT_TRUE(nullptr == fp);
}
-TEST(LlvmLibcStdioFdopenTest, InvalidMode) {
- libc_errno = 0;
+TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
constexpr const char *TEST_FILE_NAME = "testdata/invalid_mode.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_RDONLY, S_IRWXU);
@@ -83,7 +82,6 @@ TEST(LlvmLibcStdioFdopenTest, InvalidMode) {
auto *fp2 = LIBC_NAMESPACE::fdopen(fd, "w");
ASSERT_ERRNO_EQ(EINVAL);
ASSERT_TRUE(nullptr == fp2);
- libc_errno = 0;
LIBC_NAMESPACE::close(fd);
ASSERT_ERRNO_SUCCESS();
}