Skip to content

Commit 4a8bb08

Browse files
authored
[libc] Move ASSERT_ERRNO_* macro to ErrnoCheckingTest.h (#158727)
Move these macro away from Test.h, since the generic Test.h (and associated test framework library) doesn't #include or depend on any errno-handling logic. Conversely, all tests that directly ASSERT various errno values are now migrated to ErrnoCheckingTest framework, which clears it our / validates it after every use case.
1 parent f33fb0d commit 4a8bb08

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

libc/test/UnitTest/ErrnoCheckingTest.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,21 @@
1313
#include "src/__support/macros/config.h"
1414
#include "test/UnitTest/Test.h"
1515

16+
// Define macro to validate the value stored in the errno and restore it
17+
// to zero.
18+
19+
#define ASSERT_ERRNO_EQ(VAL) \
20+
do { \
21+
ASSERT_EQ(VAL, static_cast<int>(libc_errno)); \
22+
libc_errno = 0; \
23+
} while (0)
24+
#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(libc_errno))
25+
#define ASSERT_ERRNO_FAILURE() \
26+
do { \
27+
ASSERT_NE(0, static_cast<int>(libc_errno)); \
28+
libc_errno = 0; \
29+
} while (0)
30+
1631
namespace LIBC_NAMESPACE_DECL {
1732
namespace testing {
1833

libc/test/UnitTest/Test.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,6 @@
3737
#include "LibcTest.h"
3838
#endif
3939

40-
// These are defined the same way for each framework, in terms of the macros
41-
// they all provide.
42-
43-
#define ASSERT_ERRNO_EQ(VAL) \
44-
do { \
45-
ASSERT_EQ(VAL, static_cast<int>(libc_errno)); \
46-
libc_errno = 0; \
47-
} while (0)
48-
#define ASSERT_ERRNO_SUCCESS() ASSERT_EQ(0, static_cast<int>(libc_errno))
49-
#define ASSERT_ERRNO_FAILURE() \
50-
do { \
51-
ASSERT_NE(0, static_cast<int>(libc_errno)); \
52-
libc_errno = 0; \
53-
} while (0)
54-
5540
// Some macro utility to append file names with LIBC_TEST macro's value to be
5641
// used in stdio tests.
5742
#undef STR

libc/test/src/errno/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ add_libc_unittest(
1212
errno_test.cpp
1313
DEPENDS
1414
libc.src.errno.errno
15+
libc.test.UnitTest.ErrnoCheckingTest
1516
)

libc/test/src/errno/errno_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "src/__support/libc_errno.h"
10+
#include "test/UnitTest/ErrnoCheckingTest.h"
1011
#include "test/UnitTest/Test.h"
1112

1213
TEST(LlvmLibcErrnoTest, Basic) {

0 commit comments

Comments
 (0)