Skip to content

Revert "[libc] Migrate stdio tests to ErrnoCheckingTest." #143829

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 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions libc/test/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ add_libc_test(
libc.src.stdio.fread
libc.src.stdio.fseek
libc.src.stdio.fwrite
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand Down Expand Up @@ -69,7 +68,6 @@ add_libc_test(
libc.src.stdio.fread
libc.src.stdio.fwrite
libc.src.stdio.setvbuf
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand All @@ -90,7 +88,6 @@ add_libc_test(
libc.src.stdio.fread_unlocked
libc.src.stdio.funlockfile
libc.src.stdio.fwrite_unlocked
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand All @@ -112,7 +109,6 @@ add_libc_test(
libc.src.stdio.fread
libc.src.stdio.fseek
libc.src.stdio.fwrite
libc.test.UnitTest.ErrnoCheckingTest
LINK_LIBRARIES
LibcMemoryHelpers
)
Expand Down Expand Up @@ -430,7 +426,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
libc.src.sys.stat.mkdirat
libc.src.unistd.access
libc.src.unistd.close
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand All @@ -445,7 +440,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
libc.src.stdio.rename
libc.src.unistd.access
libc.src.unistd.close
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)

Expand All @@ -462,7 +456,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
libc.src.stdio.fgets
libc.src.stdio.fputs
libc.src.unistd.close
libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
endif()
Expand All @@ -483,7 +476,6 @@ add_libc_test(
libc.src.stdio.fopen
libc.src.stdio.fwrite
libc.src.stdio.getc
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand All @@ -506,7 +498,6 @@ add_libc_test(
libc.src.stdio.funlockfile
libc.src.stdio.fwrite
libc.src.stdio.getc_unlocked
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand All @@ -524,7 +515,6 @@ add_libc_test(
libc.src.stdio.fgets
libc.src.stdio.fopen
libc.src.stdio.fwrite
libc.test.UnitTest.ErrnoCheckingTest
)

add_libc_test(
Expand Down
14 changes: 8 additions & 6 deletions libc/test/src/stdio/fdopen_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
#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

using LlvmLibcStdioFdopenTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;

TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
TEST(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);
Expand Down Expand Up @@ -53,7 +52,8 @@ TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
ASSERT_ERRNO_SUCCESS();
}

TEST_F(LlvmLibcStdioFdopenTest, InvalidFd) {
TEST(LlvmLibcStdioFdopenTest, InvalidFd) {
libc_errno = 0;
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);
Expand All @@ -64,7 +64,8 @@ TEST_F(LlvmLibcStdioFdopenTest, InvalidFd) {
ASSERT_TRUE(nullptr == fp);
}

TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
TEST(LlvmLibcStdioFdopenTest, InvalidMode) {
libc_errno = 0;
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);
Expand All @@ -82,6 +83,7 @@ TEST_F(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();
}
5 changes: 3 additions & 2 deletions libc/test/src/stdio/fgetc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
#include "src/stdio/fopen.h"
#include "src/stdio/fwrite.h"
#include "src/stdio/getc.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"

#include "hdr/stdio_macros.h"
#include "src/__support/libc_errno.h"

class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test {
public:
using GetcFunc = int(FILE *);
void test_with_func(GetcFunc *func, const char *filename) {
Expand All @@ -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);
libc_errno = 0;

ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));

Expand Down
5 changes: 3 additions & 2 deletions libc/test/src/stdio/fgetc_unlocked_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include "src/stdio/funlockfile.h"
#include "src/stdio/fwrite.h"
#include "src/stdio/getc_unlocked.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"

#include "hdr/stdio_macros.h"
#include "src/__support/libc_errno.h"

class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test {
public:
using GetcFunc = int(FILE *);
void test_with_func(GetcFunc *func, const char *filename) {
Expand All @@ -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);
libc_errno = 0;

ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));

Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/stdio/fgets_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
#include "src/stdio/fgets.h"
#include "src/stdio/fopen.h"
#include "src/stdio/fwrite.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"

using LlvmLibcFgetsTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
#include "src/__support/libc_errno.h"

TEST_F(LlvmLibcFgetsTest, WriteAndReadCharacters) {
TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
constexpr char FILENAME[] = "testdata/fgets.test";
::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
ASSERT_FALSE(file == nullptr);
Expand All @@ -36,6 +35,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);
libc_errno = 0;

ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));

Expand Down
20 changes: 15 additions & 5 deletions libc/test/src/stdio/fileop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@
#include "src/stdio/fread.h"
#include "src/stdio/fseek.h"
#include "src/stdio/fwrite.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"

#include "hdr/stdio_macros.h"
#include "src/__support/libc_errno.h"

using LlvmLibcFILETest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::EQ;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::NE;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::returns;

TEST_F(LlvmLibcFILETest, SimpleFileOperations) {
TEST(LlvmLibcFILETest, SimpleFileOperations) {
constexpr char FILENAME[] = "testdata/simple_operations.test";
::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
ASSERT_FALSE(file == nullptr);
Expand All @@ -42,6 +41,7 @@ TEST_F(LlvmLibcFILETest, SimpleFileOperations) {
ASSERT_THAT(LIBC_NAMESPACE::fread(read_data, 1, sizeof(CONTENT), file),
returns(EQ(size_t(0))).with_errno(NE(0)));
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
libc_errno = 0;

LIBC_NAMESPACE::clearerr(file);
ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);
Expand Down Expand Up @@ -72,19 +72,23 @@ TEST_F(LlvmLibcFILETest, SimpleFileOperations) {
ASSERT_THAT(LIBC_NAMESPACE::fwrite(CONTENT, 1, sizeof(CONTENT), file),
returns(EQ(size_t(0))).with_errno(NE(0)));
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
libc_errno = 0;

LIBC_NAMESPACE::clearerr(file);

// Should be an error to puts.
ASSERT_THAT(LIBC_NAMESPACE::fputs(CONTENT, file),
returns(EQ(EOF)).with_errno(NE(0)));
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
libc_errno = 0;

LIBC_NAMESPACE::clearerr(file);
ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);

libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::fwrite("nothing", 1, 1, file),
returns(EQ(size_t(0))).with_errno(NE(0)));
libc_errno = 0;

ASSERT_EQ(LIBC_NAMESPACE::fclose(file), 0);

Expand All @@ -99,8 +103,10 @@ TEST_F(LlvmLibcFILETest, SimpleFileOperations) {
ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);

// This is not a readable file.
libc_errno = 0;
ASSERT_THAT(LIBC_NAMESPACE::fread(data, 1, 1, file),
returns(EQ(0)).with_errno(NE(0)));
libc_errno = 0;

ASSERT_EQ(0, LIBC_NAMESPACE::fclose(file));

Expand All @@ -115,18 +121,21 @@ TEST_F(LlvmLibcFILETest, SimpleFileOperations) {

// Check that the other functions correctly set libc_errno.

// libc_errno = 0;
// ASSERT_NE(LIBC_NAMESPACE::fseek(file, 0, SEEK_SET), 0);
// ASSERT_ERRNO_FAILURE();

// libc_errno = 0;
// ASSERT_NE(LIBC_NAMESPACE::fclose(file), 0);
// ASSERT_ERRNO_FAILURE();

// libc_errno = 0;
// ASSERT_EQ(LIBC_NAMESPACE::fopen("INVALID FILE NAME", "r"),
// static_cast<FILE *>(nullptr));
// ASSERT_ERRNO_FAILURE();
}

TEST_F(LlvmLibcFILETest, FFlush) {
TEST(LlvmLibcFILETest, FFlush) {
constexpr char FILENAME[] = "testdata/fflush.test";
::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w+");
ASSERT_FALSE(file == nullptr);
Expand All @@ -147,7 +156,7 @@ TEST_F(LlvmLibcFILETest, FFlush) {
ASSERT_EQ(LIBC_NAMESPACE::fclose(file), 0);
}

TEST_F(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
TEST(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
using MyStruct = struct {
char c;
unsigned long long i;
Expand All @@ -156,6 +165,7 @@ TEST_F(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
constexpr size_t WRITE_NMEMB = sizeof(WRITE_DATA) / sizeof(MyStruct);
constexpr char FILENAME[] = "testdata/fread_fwrite.test";

libc_errno = 0;
FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
ASSERT_FALSE(file == nullptr);
ASSERT_EQ(size_t(0), LIBC_NAMESPACE::fwrite(WRITE_DATA, 0, 1, file));
Expand Down
15 changes: 8 additions & 7 deletions libc/test/src/stdio/fopencookie_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
#include "src/stdio/fread.h"
#include "src/stdio/fseek.h"
#include "src/stdio/fwrite.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/MemoryMatcher.h"
#include "test/UnitTest/Test.h"

#include "hdr/stdio_macros.h"
#include "hdr/types/size_t.h"
#include "src/__support/libc_errno.h"

using LlvmLibcFOpenCookieTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
using MemoryView = LIBC_NAMESPACE::testing::MemoryView;

struct StringStream {
Expand Down Expand Up @@ -90,7 +88,7 @@ int close_ss(void *cookie) {
constexpr cookie_io_functions_t STRING_STREAM_FUNCS = {&read_ss, &write_ss,
&seek_ss, &close_ss};

TEST_F(LlvmLibcFOpenCookieTest, ReadOnlyCookieTest) {
TEST(LlvmLibcFOpenCookie, ReadOnlyCookieTest) {
constexpr char CONTENT[] = "Hello,readonly!";
auto *ss = reinterpret_cast<StringStream *>(malloc(sizeof(StringStream)));
ss->buf = reinterpret_cast<char *>(malloc(sizeof(CONTENT)));
Expand All @@ -117,6 +115,7 @@ TEST_F(LlvmLibcFOpenCookieTest, ReadOnlyCookieTest) {
ASSERT_EQ(size_t(0), LIBC_NAMESPACE::fwrite(CONTENT, 1, sizeof(CONTENT), f));
ASSERT_NE(LIBC_NAMESPACE::ferror(f), 0);
ASSERT_ERRNO_FAILURE();
libc_errno = 0;

LIBC_NAMESPACE::clearerr(f);
ASSERT_EQ(LIBC_NAMESPACE::ferror(f), 0);
Expand All @@ -125,7 +124,7 @@ TEST_F(LlvmLibcFOpenCookieTest, ReadOnlyCookieTest) {
free(ss);
}

TEST_F(LlvmLibcFOpenCookieTest, WriteOnlyCookieTest) {
TEST(LlvmLibcFOpenCookie, WriteOnlyCookieTest) {
size_t INIT_BUFSIZE = 32;
auto *ss = reinterpret_cast<StringStream *>(malloc(sizeof(StringStream)));
ss->buf = reinterpret_cast<char *>(malloc(INIT_BUFSIZE));
Expand All @@ -150,6 +149,7 @@ TEST_F(LlvmLibcFOpenCookieTest, WriteOnlyCookieTest) {
LIBC_NAMESPACE::fread(read_data, 1, sizeof(WRITE_DATA), f));
ASSERT_NE(LIBC_NAMESPACE::ferror(f), 0);
ASSERT_ERRNO_EQ(EBADF);
libc_errno = 0;

LIBC_NAMESPACE::clearerr(f);
ASSERT_EQ(LIBC_NAMESPACE::ferror(f), 0);
Expand All @@ -158,7 +158,7 @@ TEST_F(LlvmLibcFOpenCookieTest, WriteOnlyCookieTest) {
free(ss);
}

TEST_F(LlvmLibcFOpenCookieTest, AppendOnlyCookieTest) {
TEST(LlvmLibcFOpenCookie, AppendOnlyCookieTest) {
constexpr char INITIAL_CONTENT[] = "1234567890987654321";
constexpr char WRITE_DATA[] = "append";
auto *ss = reinterpret_cast<StringStream *>(malloc(sizeof(StringStream)));
Expand All @@ -178,6 +178,7 @@ TEST_F(LlvmLibcFOpenCookieTest, AppendOnlyCookieTest) {
ASSERT_EQ(LIBC_NAMESPACE::fread(read_data, 1, READ_SIZE, f), size_t(0));
ASSERT_NE(LIBC_NAMESPACE::ferror(f), 0);
ASSERT_ERRNO_FAILURE();
libc_errno = 0;

LIBC_NAMESPACE::clearerr(f);
ASSERT_EQ(LIBC_NAMESPACE::ferror(f), 0);
Expand All @@ -191,7 +192,7 @@ TEST_F(LlvmLibcFOpenCookieTest, AppendOnlyCookieTest) {
free(ss);
}

TEST_F(LlvmLibcFOpenCookieTest, ReadUpdateCookieTest) {
TEST(LlvmLibcFOpenCookie, ReadUpdateCookieTest) {
const char INITIAL_CONTENT[] = "1234567890987654321";
auto *ss = reinterpret_cast<StringStream *>(malloc(sizeof(StringStream)));
ss->buf = reinterpret_cast<char *>(malloc(sizeof(INITIAL_CONTENT)));
Expand Down Expand Up @@ -222,7 +223,7 @@ TEST_F(LlvmLibcFOpenCookieTest, ReadUpdateCookieTest) {
free(ss);
}

TEST_F(LlvmLibcFOpenCookieTest, WriteUpdateCookieTest) {
TEST(LlvmLibcFOpenCookie, WriteUpdateCookieTest) {
constexpr char WRITE_DATA[] = "hello, file";
auto *ss = reinterpret_cast<StringStream *>(malloc(sizeof(StringStream)));
ss->buf = reinterpret_cast<char *>(malloc(sizeof(WRITE_DATA)));
Expand Down
Loading
Loading