Skip to content

Commit 5a668bd

Browse files
authored
[libc] Migrate sys/epoll tests to use ErrnoCheckingTest. (#132823)
This is similar to PR #132107 but for tests for sys/epoll.h functions. ErrnoCheckingTest ensures that errno is properly reset at the beginning of the test case, and is validated at the end of it, so that the manual code such as the one proposed in PR #131650 would not be necessary.
1 parent 7fa104e commit 5a668bd

File tree

8 files changed

+35
-16
lines changed

8 files changed

+35
-16
lines changed

libc/test/src/sys/epoll/linux/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ add_libc_unittest(
1111
libc.src.errno.errno
1212
libc.src.sys.epoll.epoll_create
1313
libc.src.unistd.close
14+
libc.test.UnitTest.ErrnoCheckingTest
1415
libc.test.UnitTest.ErrnoSetterMatcher
1516
)
1617

@@ -25,6 +26,7 @@ add_libc_unittest(
2526
libc.src.errno.errno
2627
libc.src.sys.epoll.epoll_create1
2728
libc.src.unistd.close
29+
libc.test.UnitTest.ErrnoCheckingTest
2830
libc.test.UnitTest.ErrnoSetterMatcher
2931
)
3032

@@ -42,6 +44,7 @@ add_libc_unittest(
4244
libc.src.sys.epoll.epoll_ctl
4345
libc.src.unistd.pipe
4446
libc.src.unistd.close
47+
libc.test.UnitTest.ErrnoCheckingTest
4548
libc.test.UnitTest.ErrnoSetterMatcher
4649
)
4750

@@ -60,6 +63,7 @@ add_libc_unittest(
6063
libc.src.sys.epoll.epoll_wait
6164
libc.src.unistd.pipe
6265
libc.src.unistd.close
66+
libc.test.UnitTest.ErrnoCheckingTest
6367
libc.test.UnitTest.ErrnoSetterMatcher
6468
)
6569

@@ -78,6 +82,7 @@ add_libc_unittest(
7882
libc.src.sys.epoll.epoll_pwait
7983
libc.src.unistd.pipe
8084
libc.src.unistd.close
85+
libc.test.UnitTest.ErrnoCheckingTest
8186
libc.test.UnitTest.ErrnoSetterMatcher
8287
)
8388

@@ -97,5 +102,6 @@ add_libc_unittest(
97102
libc.src.sys.epoll.epoll_pwait2
98103
libc.src.unistd.pipe
99104
libc.src.unistd.close
105+
libc.test.UnitTest.ErrnoCheckingTest
100106
libc.test.UnitTest.ErrnoSetterMatcher
101107
)

libc/test/src/sys/epoll/linux/epoll_create1_test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,24 @@
66
//
77
//===----------------------------------------------------------------------===//
88
#include "hdr/sys_epoll_macros.h"
9-
#include "src/errno/libc_errno.h"
109
#include "src/sys/epoll/epoll_create1.h"
1110
#include "src/unistd/close.h"
11+
#include "test/UnitTest/ErrnoCheckingTest.h"
1212
#include "test/UnitTest/ErrnoSetterMatcher.h"
1313
#include "test/UnitTest/Test.h"
1414

1515
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
16+
using LlvmLibcEpollCreate1Test = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
1617

17-
TEST(LlvmLibcEpollCreate1Test, Basic) {
18+
TEST_F(LlvmLibcEpollCreate1Test, Basic) {
1819
int fd = LIBC_NAMESPACE::epoll_create1(0);
1920
ASSERT_GT(fd, 0);
2021
ASSERT_ERRNO_SUCCESS();
2122

2223
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds());
2324
}
2425

25-
TEST(LlvmLibcEpollCreate1Test, CloseOnExecute) {
26+
TEST_F(LlvmLibcEpollCreate1Test, CloseOnExecute) {
2627
int fd = LIBC_NAMESPACE::epoll_create1(EPOLL_CLOEXEC);
2728
ASSERT_GT(fd, 0);
2829
ASSERT_ERRNO_SUCCESS();

libc/test/src/sys/epoll/linux/epoll_create_test.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8-
#include "src/errno/libc_errno.h"
98
#include "src/sys/epoll/epoll_create.h"
109
#include "src/unistd/close.h"
10+
#include "test/UnitTest/ErrnoCheckingTest.h"
1111
#include "test/UnitTest/ErrnoSetterMatcher.h"
1212
#include "test/UnitTest/Test.h"
1313
#include <sys/syscall.h> // For syscall numbers.
1414

1515
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
16+
using LlvmLibcEpollCreateTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
1617

17-
TEST(LlvmLibcEpollCreateTest, Basic) {
18+
TEST_F(LlvmLibcEpollCreateTest, Basic) {
1819
int fd = LIBC_NAMESPACE::epoll_create(1);
1920
ASSERT_GT(fd, 0);
2021
ASSERT_ERRNO_SUCCESS();
@@ -23,7 +24,7 @@ TEST(LlvmLibcEpollCreateTest, Basic) {
2324
}
2425

2526
#ifdef SYS_epoll_create
26-
TEST(LlvmLibcEpollCreateTest, Fails) {
27+
TEST_F(LlvmLibcEpollCreateTest, Fails) {
2728
ASSERT_THAT(LIBC_NAMESPACE::epoll_create(0), Fails(EINVAL));
2829
}
2930
#endif

libc/test/src/sys/epoll/linux/epoll_ctl_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88

99
#include "hdr/sys_epoll_macros.h"
1010
#include "hdr/types/struct_epoll_event.h"
11-
#include "src/errno/libc_errno.h"
1211
#include "src/sys/epoll/epoll_create1.h"
1312
#include "src/sys/epoll/epoll_ctl.h"
1413
#include "src/unistd/close.h"
1514
#include "src/unistd/pipe.h"
15+
#include "test/UnitTest/ErrnoCheckingTest.h"
1616
#include "test/UnitTest/ErrnoSetterMatcher.h"
1717
#include "test/UnitTest/Test.h"
1818

1919
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
20+
using LlvmLibcEpollCtlTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
2021

21-
TEST(LlvmLibcEpollCtlTest, Basic) {
22+
TEST_F(LlvmLibcEpollCtlTest, Basic) {
2223
int epfd = LIBC_NAMESPACE::epoll_create1(0);
2324
ASSERT_GT(epfd, 0);
2425
ASSERT_ERRNO_SUCCESS();

libc/test/src/sys/epoll/linux/epoll_pwait2_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@
88
#include "hdr/sys_epoll_macros.h"
99
#include "hdr/types/struct_epoll_event.h"
1010
#include "hdr/types/struct_timespec.h"
11-
#include "src/errno/libc_errno.h"
1211
#include "src/sys/epoll/epoll_create1.h"
1312
#include "src/sys/epoll/epoll_ctl.h"
1413
#include "src/sys/epoll/epoll_pwait2.h"
1514
#include "src/unistd/close.h"
1615
#include "src/unistd/pipe.h"
16+
#include "test/UnitTest/ErrnoCheckingTest.h"
1717
#include "test/UnitTest/ErrnoSetterMatcher.h"
1818
#include "test/UnitTest/Test.h"
1919

2020
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
21+
using LlvmLibcEpollPwaitTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
2122

22-
TEST(LlvmLibcEpollPwaitTest, Basic) {
23+
TEST_F(LlvmLibcEpollPwaitTest, Basic) {
2324
int epfd = LIBC_NAMESPACE::epoll_create1(0);
2425
ASSERT_GT(epfd, 0);
2526
ASSERT_ERRNO_SUCCESS();

libc/test/src/sys/epoll/linux/epoll_pwait_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
//===----------------------------------------------------------------------===//
88
#include "hdr/sys_epoll_macros.h"
99
#include "hdr/types/struct_epoll_event.h"
10-
#include "src/errno/libc_errno.h"
1110
#include "src/sys/epoll/epoll_create1.h"
1211
#include "src/sys/epoll/epoll_ctl.h"
1312
#include "src/sys/epoll/epoll_pwait.h"
1413
#include "src/unistd/close.h"
1514
#include "src/unistd/pipe.h"
16-
15+
#include "test/UnitTest/ErrnoCheckingTest.h"
1716
#include "test/UnitTest/ErrnoSetterMatcher.h"
1817
#include "test/UnitTest/Test.h"
1918

2019
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
20+
using LlvmLibcEpollPwaitTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
2121

22-
TEST(LlvmLibcEpollPwaitTest, Basic) {
22+
TEST_F(LlvmLibcEpollPwaitTest, Basic) {
2323
int epfd = LIBC_NAMESPACE::epoll_create1(0);
2424
ASSERT_GT(epfd, 0);
2525
ASSERT_ERRNO_SUCCESS();

libc/test/src/sys/epoll/linux/epoll_wait_test.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@
77
//===----------------------------------------------------------------------===//
88
#include "hdr/sys_epoll_macros.h"
99
#include "hdr/types/struct_epoll_event.h"
10-
#include "src/errno/libc_errno.h"
1110
#include "src/sys/epoll/epoll_create1.h"
1211
#include "src/sys/epoll/epoll_ctl.h"
1312
#include "src/sys/epoll/epoll_wait.h"
1413
#include "src/unistd/close.h"
1514
#include "src/unistd/pipe.h"
15+
#include "test/UnitTest/ErrnoCheckingTest.h"
1616
#include "test/UnitTest/ErrnoSetterMatcher.h"
1717
#include "test/UnitTest/Test.h"
1818

1919
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
20+
using LlvmLibcEpollWaitTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
2021

21-
TEST(LlvmLibcEpollWaitTest, Basic) {
22+
TEST_F(LlvmLibcEpollWaitTest, Basic) {
2223
int epfd = LIBC_NAMESPACE::epoll_create1(0);
2324
ASSERT_GT(epfd, 0);
2425
ASSERT_ERRNO_SUCCESS();

utils/bazel/llvm-project-overlay/libc/test/src/sys/epoll/BUILD.bazel

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# See https://llvm.org/LICENSE.txt for license information.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

5-
# Tests for LLVM libc string.h functions.
5+
# Tests for LLVM libc sys/epoll.h functions.
66

77
load("//libc/test:libc_test_rules.bzl", "libc_test")
88

@@ -17,6 +17,9 @@ libc_test(
1717
"//libc:epoll_create",
1818
"//libc:close",
1919
],
20+
deps = [
21+
"//libc/test/UnitTest:errno_test_helpers",
22+
],
2023
)
2124

2225
libc_test(
@@ -28,6 +31,7 @@ libc_test(
2831
],
2932
deps = [
3033
"//libc:hdr_sys_epoll_macros",
34+
"//libc/test/UnitTest:errno_test_helpers",
3135
],
3236
)
3337

@@ -43,6 +47,7 @@ libc_test(
4347
deps = [
4448
"//libc:hdr_sys_epoll_macros",
4549
"//libc:types_struct_epoll_event",
50+
"//libc/test/UnitTest:errno_test_helpers",
4651
],
4752
)
4853

@@ -59,6 +64,7 @@ libc_test(
5964
deps = [
6065
"//libc:hdr_sys_epoll_macros",
6166
"//libc:types_struct_epoll_event",
67+
"//libc/test/UnitTest:errno_test_helpers",
6268
],
6369
)
6470

@@ -75,6 +81,7 @@ libc_test(
7581
deps = [
7682
"//libc:hdr_sys_epoll_macros",
7783
"//libc:types_struct_epoll_event",
84+
"//libc/test/UnitTest:errno_test_helpers",
7885
],
7986
)
8087

@@ -92,5 +99,6 @@ libc_test(
9299
"//libc:hdr_sys_epoll_macros",
93100
"//libc:types_struct_epoll_event",
94101
"//libc:types_struct_timespec",
102+
"//libc/test/UnitTest:errno_test_helpers",
95103
],
96104
)

0 commit comments

Comments
 (0)