Skip to content

Commit a93e55e

Browse files
authored
Revert "[libc] Migrate stdio tests to ErrnoCheckingTest." (#143829)
Reverts #143802. Follow-up fix 3c7af17 wasn't robust enough and itself got reverted.
1 parent c3be452 commit a93e55e

13 files changed

+59
-52
lines changed

libc/test/src/stdio/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ add_libc_test(
2020
libc.src.stdio.fread
2121
libc.src.stdio.fseek
2222
libc.src.stdio.fwrite
23-
libc.test.UnitTest.ErrnoCheckingTest
2423
)
2524

2625
add_libc_test(
@@ -69,7 +68,6 @@ add_libc_test(
6968
libc.src.stdio.fread
7069
libc.src.stdio.fwrite
7170
libc.src.stdio.setvbuf
72-
libc.test.UnitTest.ErrnoCheckingTest
7371
)
7472

7573
add_libc_test(
@@ -90,7 +88,6 @@ add_libc_test(
9088
libc.src.stdio.fread_unlocked
9189
libc.src.stdio.funlockfile
9290
libc.src.stdio.fwrite_unlocked
93-
libc.test.UnitTest.ErrnoCheckingTest
9491
)
9592

9693
add_libc_test(
@@ -112,7 +109,6 @@ add_libc_test(
112109
libc.src.stdio.fread
113110
libc.src.stdio.fseek
114111
libc.src.stdio.fwrite
115-
libc.test.UnitTest.ErrnoCheckingTest
116112
LINK_LIBRARIES
117113
LibcMemoryHelpers
118114
)
@@ -430,7 +426,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
430426
libc.src.sys.stat.mkdirat
431427
libc.src.unistd.access
432428
libc.src.unistd.close
433-
libc.test.UnitTest.ErrnoCheckingTest
434429
)
435430

436431
add_libc_test(
@@ -445,7 +440,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
445440
libc.src.stdio.rename
446441
libc.src.unistd.access
447442
libc.src.unistd.close
448-
libc.test.UnitTest.ErrnoCheckingTest
449443
libc.test.UnitTest.ErrnoSetterMatcher
450444
)
451445

@@ -462,7 +456,6 @@ if(${LIBC_TARGET_OS} STREQUAL "linux")
462456
libc.src.stdio.fgets
463457
libc.src.stdio.fputs
464458
libc.src.unistd.close
465-
libc.test.UnitTest.ErrnoCheckingTest
466459
libc.test.UnitTest.ErrnoSetterMatcher
467460
)
468461
endif()
@@ -483,7 +476,6 @@ add_libc_test(
483476
libc.src.stdio.fopen
484477
libc.src.stdio.fwrite
485478
libc.src.stdio.getc
486-
libc.test.UnitTest.ErrnoCheckingTest
487479
)
488480

489481
add_libc_test(
@@ -506,7 +498,6 @@ add_libc_test(
506498
libc.src.stdio.funlockfile
507499
libc.src.stdio.fwrite
508500
libc.src.stdio.getc_unlocked
509-
libc.test.UnitTest.ErrnoCheckingTest
510501
)
511502

512503
add_libc_test(
@@ -524,7 +515,6 @@ add_libc_test(
524515
libc.src.stdio.fgets
525516
libc.src.stdio.fopen
526517
libc.src.stdio.fwrite
527-
libc.test.UnitTest.ErrnoCheckingTest
528518
)
529519

530520
add_libc_test(

libc/test/src/stdio/fdopen_test.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@
99
#include "src/stdio/fdopen.h"
1010

1111
#include "hdr/fcntl_macros.h"
12+
#include "src/__support/libc_errno.h"
1213
#include "src/fcntl/open.h"
1314
#include "src/stdio/fclose.h"
1415
#include "src/stdio/fgets.h"
1516
#include "src/stdio/fputs.h"
1617
#include "src/unistd/close.h"
17-
#include "test/UnitTest/ErrnoCheckingTest.h"
1818
#include "test/UnitTest/ErrnoSetterMatcher.h"
1919
#include "test/UnitTest/Test.h"
2020

2121
#include <sys/stat.h> // For S_IRWXU
2222

23-
using LlvmLibcStdioFdopenTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
24-
25-
TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
23+
TEST(LlvmLibcStdioFdopenTest, WriteAppendRead) {
2624
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
25+
libc_errno = 0;
2726
constexpr const char *TEST_FILE_NAME = "testdata/write_read_append.test";
2827
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
2928
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC | O_RDWR, S_IRWXU);
@@ -53,7 +52,8 @@ TEST_F(LlvmLibcStdioFdopenTest, WriteAppendRead) {
5352
ASSERT_ERRNO_SUCCESS();
5453
}
5554

56-
TEST_F(LlvmLibcStdioFdopenTest, InvalidFd) {
55+
TEST(LlvmLibcStdioFdopenTest, InvalidFd) {
56+
libc_errno = 0;
5757
constexpr const char *TEST_FILE_NAME = "testdata/invalid_fd.test";
5858
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
5959
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_TRUNC);
@@ -64,7 +64,8 @@ TEST_F(LlvmLibcStdioFdopenTest, InvalidFd) {
6464
ASSERT_TRUE(nullptr == fp);
6565
}
6666

67-
TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
67+
TEST(LlvmLibcStdioFdopenTest, InvalidMode) {
68+
libc_errno = 0;
6869
constexpr const char *TEST_FILE_NAME = "testdata/invalid_mode.test";
6970
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
7071
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_CREAT | O_RDONLY, S_IRWXU);
@@ -82,6 +83,7 @@ TEST_F(LlvmLibcStdioFdopenTest, InvalidMode) {
8283
auto *fp2 = LIBC_NAMESPACE::fdopen(fd, "w");
8384
ASSERT_ERRNO_EQ(EINVAL);
8485
ASSERT_TRUE(nullptr == fp2);
86+
libc_errno = 0;
8587
LIBC_NAMESPACE::close(fd);
8688
ASSERT_ERRNO_SUCCESS();
8789
}

libc/test/src/stdio/fgetc_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#include "src/stdio/fopen.h"
1515
#include "src/stdio/fwrite.h"
1616
#include "src/stdio/getc.h"
17-
#include "test/UnitTest/ErrnoCheckingTest.h"
1817
#include "test/UnitTest/Test.h"
1918

2019
#include "hdr/stdio_macros.h"
20+
#include "src/__support/libc_errno.h"
2121

22-
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
22+
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test {
2323
public:
2424
using GetcFunc = int(FILE *);
2525
void test_with_func(GetcFunc *func, const char *filename) {
@@ -33,6 +33,7 @@ class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
3333
// This is an error and not a real EOF.
3434
ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
3535
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
36+
libc_errno = 0;
3637

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

libc/test/src/stdio/fgetc_unlocked_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
#include "src/stdio/funlockfile.h"
1818
#include "src/stdio/fwrite.h"
1919
#include "src/stdio/getc_unlocked.h"
20-
#include "test/UnitTest/ErrnoCheckingTest.h"
2120
#include "test/UnitTest/Test.h"
2221

2322
#include "hdr/stdio_macros.h"
23+
#include "src/__support/libc_errno.h"
2424

25-
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
25+
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test {
2626
public:
2727
using GetcFunc = int(FILE *);
2828
void test_with_func(GetcFunc *func, const char *filename) {
@@ -36,6 +36,7 @@ class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
3636
// This is an error and not a real EOF.
3737
ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
3838
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
39+
libc_errno = 0;
3940

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

libc/test/src/stdio/fgets_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
#include "src/stdio/fgets.h"
1313
#include "src/stdio/fopen.h"
1414
#include "src/stdio/fwrite.h"
15-
#include "test/UnitTest/ErrnoCheckingTest.h"
1615
#include "test/UnitTest/Test.h"
1716

18-
using LlvmLibcFgetsTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
17+
#include "src/__support/libc_errno.h"
1918

20-
TEST_F(LlvmLibcFgetsTest, WriteAndReadCharacters) {
19+
TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
2120
constexpr char FILENAME[] = "testdata/fgets.test";
2221
::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
2322
ASSERT_FALSE(file == nullptr);
@@ -36,6 +35,7 @@ TEST_F(LlvmLibcFgetsTest, WriteAndReadCharacters) {
3635
// This is an error and not a real EOF.
3736
ASSERT_EQ(LIBC_NAMESPACE::feof(file), 0);
3837
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
38+
libc_errno = 0;
3939

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

libc/test/src/stdio/fileop_test.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@
1717
#include "src/stdio/fread.h"
1818
#include "src/stdio/fseek.h"
1919
#include "src/stdio/fwrite.h"
20-
#include "test/UnitTest/ErrnoCheckingTest.h"
2120
#include "test/UnitTest/ErrnoSetterMatcher.h"
2221
#include "test/UnitTest/Test.h"
2322

2423
#include "hdr/stdio_macros.h"
24+
#include "src/__support/libc_errno.h"
2525

26-
using LlvmLibcFILETest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
2726
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::EQ;
2827
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::NE;
2928
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::returns;
3029

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

4646
LIBC_NAMESPACE::clearerr(file);
4747
ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);
@@ -72,19 +72,23 @@ TEST_F(LlvmLibcFILETest, SimpleFileOperations) {
7272
ASSERT_THAT(LIBC_NAMESPACE::fwrite(CONTENT, 1, sizeof(CONTENT), file),
7373
returns(EQ(size_t(0))).with_errno(NE(0)));
7474
ASSERT_NE(LIBC_NAMESPACE::ferror(file), 0);
75+
libc_errno = 0;
7576

7677
LIBC_NAMESPACE::clearerr(file);
7778

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

8385
LIBC_NAMESPACE::clearerr(file);
8486
ASSERT_EQ(LIBC_NAMESPACE::ferror(file), 0);
8587

88+
libc_errno = 0;
8689
ASSERT_THAT(LIBC_NAMESPACE::fwrite("nothing", 1, 1, file),
8790
returns(EQ(size_t(0))).with_errno(NE(0)));
91+
libc_errno = 0;
8892

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

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

101105
// This is not a readable file.
106+
libc_errno = 0;
102107
ASSERT_THAT(LIBC_NAMESPACE::fread(data, 1, 1, file),
103108
returns(EQ(0)).with_errno(NE(0)));
109+
libc_errno = 0;
104110

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

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

116122
// Check that the other functions correctly set libc_errno.
117123

124+
// libc_errno = 0;
118125
// ASSERT_NE(LIBC_NAMESPACE::fseek(file, 0, SEEK_SET), 0);
119126
// ASSERT_ERRNO_FAILURE();
120127

128+
// libc_errno = 0;
121129
// ASSERT_NE(LIBC_NAMESPACE::fclose(file), 0);
122130
// ASSERT_ERRNO_FAILURE();
123131

132+
// libc_errno = 0;
124133
// ASSERT_EQ(LIBC_NAMESPACE::fopen("INVALID FILE NAME", "r"),
125134
// static_cast<FILE *>(nullptr));
126135
// ASSERT_ERRNO_FAILURE();
127136
}
128137

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

150-
TEST_F(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
159+
TEST(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
151160
using MyStruct = struct {
152161
char c;
153162
unsigned long long i;
@@ -156,6 +165,7 @@ TEST_F(LlvmLibcFILETest, FOpenFWriteSizeGreaterThanOne) {
156165
constexpr size_t WRITE_NMEMB = sizeof(WRITE_DATA) / sizeof(MyStruct);
157166
constexpr char FILENAME[] = "testdata/fread_fwrite.test";
158167

168+
libc_errno = 0;
159169
FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
160170
ASSERT_FALSE(file == nullptr);
161171
ASSERT_EQ(size_t(0), LIBC_NAMESPACE::fwrite(WRITE_DATA, 0, 1, file));

libc/test/src/stdio/fopencookie_test.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
#include "src/stdio/fread.h"
1616
#include "src/stdio/fseek.h"
1717
#include "src/stdio/fwrite.h"
18-
#include "test/UnitTest/ErrnoCheckingTest.h"
1918
#include "test/UnitTest/MemoryMatcher.h"
2019
#include "test/UnitTest/Test.h"
2120

2221
#include "hdr/stdio_macros.h"
2322
#include "hdr/types/size_t.h"
2423
#include "src/__support/libc_errno.h"
2524

26-
using LlvmLibcFOpenCookieTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
2725
using MemoryView = LIBC_NAMESPACE::testing::MemoryView;
2826

2927
struct StringStream {
@@ -90,7 +88,7 @@ int close_ss(void *cookie) {
9088
constexpr cookie_io_functions_t STRING_STREAM_FUNCS = {&read_ss, &write_ss,
9189
&seek_ss, &close_ss};
9290

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

121120
LIBC_NAMESPACE::clearerr(f);
122121
ASSERT_EQ(LIBC_NAMESPACE::ferror(f), 0);
@@ -125,7 +124,7 @@ TEST_F(LlvmLibcFOpenCookieTest, ReadOnlyCookieTest) {
125124
free(ss);
126125
}
127126

128-
TEST_F(LlvmLibcFOpenCookieTest, WriteOnlyCookieTest) {
127+
TEST(LlvmLibcFOpenCookie, WriteOnlyCookieTest) {
129128
size_t INIT_BUFSIZE = 32;
130129
auto *ss = reinterpret_cast<StringStream *>(malloc(sizeof(StringStream)));
131130
ss->buf = reinterpret_cast<char *>(malloc(INIT_BUFSIZE));
@@ -150,6 +149,7 @@ TEST_F(LlvmLibcFOpenCookieTest, WriteOnlyCookieTest) {
150149
LIBC_NAMESPACE::fread(read_data, 1, sizeof(WRITE_DATA), f));
151150
ASSERT_NE(LIBC_NAMESPACE::ferror(f), 0);
152151
ASSERT_ERRNO_EQ(EBADF);
152+
libc_errno = 0;
153153

154154
LIBC_NAMESPACE::clearerr(f);
155155
ASSERT_EQ(LIBC_NAMESPACE::ferror(f), 0);
@@ -158,7 +158,7 @@ TEST_F(LlvmLibcFOpenCookieTest, WriteOnlyCookieTest) {
158158
free(ss);
159159
}
160160

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

182183
LIBC_NAMESPACE::clearerr(f);
183184
ASSERT_EQ(LIBC_NAMESPACE::ferror(f), 0);
@@ -191,7 +192,7 @@ TEST_F(LlvmLibcFOpenCookieTest, AppendOnlyCookieTest) {
191192
free(ss);
192193
}
193194

194-
TEST_F(LlvmLibcFOpenCookieTest, ReadUpdateCookieTest) {
195+
TEST(LlvmLibcFOpenCookie, ReadUpdateCookieTest) {
195196
const char INITIAL_CONTENT[] = "1234567890987654321";
196197
auto *ss = reinterpret_cast<StringStream *>(malloc(sizeof(StringStream)));
197198
ss->buf = reinterpret_cast<char *>(malloc(sizeof(INITIAL_CONTENT)));
@@ -222,7 +223,7 @@ TEST_F(LlvmLibcFOpenCookieTest, ReadUpdateCookieTest) {
222223
free(ss);
223224
}
224225

225-
TEST_F(LlvmLibcFOpenCookieTest, WriteUpdateCookieTest) {
226+
TEST(LlvmLibcFOpenCookie, WriteUpdateCookieTest) {
226227
constexpr char WRITE_DATA[] = "hello, file";
227228
auto *ss = reinterpret_cast<StringStream *>(malloc(sizeof(StringStream)));
228229
ss->buf = reinterpret_cast<char *>(malloc(sizeof(WRITE_DATA)));

0 commit comments

Comments
 (0)