-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc] Migrate dirent/fcntl/sched/signal tests to ErrnoCheckingTest. #158700
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
Conversation
Remove direct libc_errno.h inclusion and manipulation of libc_errno in various unit tests, instead relying on ErrnoCheckingTest machinery. This is the final mechanical change of migrating libc unit tests to ErrnoCheckingTest - after it, all the unit tests relying on ASSERT_ERRNO_* macro will be using ErrnoCheckingTest.h
@llvm/pr-subscribers-libc Author: Alexey Samsonov (vonosmas) ChangesRemove direct libc_errno.h inclusion and manipulation of libc_errno in various unit tests, instead relying on ErrnoCheckingTest machinery. This is the final mechanical change of migrating libc unit tests to ErrnoCheckingTest - after it, all the unit tests relying on ASSERT_ERRNO_* macro will be using ErrnoCheckingTest.h Patch is 25.70 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/158700.diff 18 Files Affected:
diff --git a/libc/test/src/dirent/CMakeLists.txt b/libc/test/src/dirent/CMakeLists.txt
index b8ae813141c0d..8db512129f893 100644
--- a/libc/test/src/dirent/CMakeLists.txt
+++ b/libc/test/src/dirent/CMakeLists.txt
@@ -14,5 +14,6 @@ add_libc_unittest(
libc.src.dirent.opendir
libc.src.dirent.readdir
libc.src.errno.errno
+ libc.test.UnitTest.ErrnoCheckingTest
)
diff --git a/libc/test/src/dirent/dirent_test.cpp b/libc/test/src/dirent/dirent_test.cpp
index 3f0095ca5ebe8..2862b140ba8ed 100644
--- a/libc/test/src/dirent/dirent_test.cpp
+++ b/libc/test/src/dirent/dirent_test.cpp
@@ -7,19 +7,20 @@
//===----------------------------------------------------------------------===//
#include "src/__support/CPP/string_view.h"
-#include "src/__support/libc_errno.h"
#include "src/dirent/closedir.h"
#include "src/dirent/dirfd.h"
#include "src/dirent/opendir.h"
#include "src/dirent/readdir.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include <dirent.h>
+using LlvmLibcDirentTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
using string_view = LIBC_NAMESPACE::cpp::string_view;
-TEST(LlvmLibcDirentTest, SimpleOpenAndRead) {
+TEST_F(LlvmLibcDirentTest, SimpleOpenAndRead) {
::DIR *dir = LIBC_NAMESPACE::opendir("testdata");
ASSERT_TRUE(dir != nullptr);
// The file descriptors 0, 1 and 2 are reserved for standard streams.
@@ -54,18 +55,14 @@ TEST(LlvmLibcDirentTest, SimpleOpenAndRead) {
ASSERT_EQ(LIBC_NAMESPACE::closedir(dir), 0);
}
-TEST(LlvmLibcDirentTest, OpenNonExistentDir) {
- libc_errno = 0;
+TEST_F(LlvmLibcDirentTest, OpenNonExistentDir) {
::DIR *dir = LIBC_NAMESPACE::opendir("___xyz123__.non_existent__");
ASSERT_TRUE(dir == nullptr);
ASSERT_ERRNO_EQ(ENOENT);
- libc_errno = 0;
}
-TEST(LlvmLibcDirentTest, OpenFile) {
- libc_errno = 0;
+TEST_F(LlvmLibcDirentTest, OpenFile) {
::DIR *dir = LIBC_NAMESPACE::opendir("testdata/file1.txt");
ASSERT_TRUE(dir == nullptr);
ASSERT_ERRNO_EQ(ENOTDIR);
- libc_errno = 0;
}
diff --git a/libc/test/src/fcntl/CMakeLists.txt b/libc/test/src/fcntl/CMakeLists.txt
index b522fef7439df..ff62210c13f43 100644
--- a/libc/test/src/fcntl/CMakeLists.txt
+++ b/libc/test/src/fcntl/CMakeLists.txt
@@ -14,6 +14,7 @@ add_libc_unittest(
libc.src.fcntl.creat
libc.src.fcntl.open
libc.src.unistd.close
+ libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
@@ -32,6 +33,7 @@ add_libc_unittest(
libc.src.unistd.getpid
libc.hdr.types.struct_flock
libc.hdr.fcntl_macros
+ libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
@@ -48,5 +50,6 @@ add_libc_unittest(
libc.src.fcntl.openat
libc.src.unistd.close
libc.src.unistd.read
+ libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
diff --git a/libc/test/src/fcntl/creat_test.cpp b/libc/test/src/fcntl/creat_test.cpp
index d60c984934703..c578cf289689b 100644
--- a/libc/test/src/fcntl/creat_test.cpp
+++ b/libc/test/src/fcntl/creat_test.cpp
@@ -6,16 +6,18 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/fcntl/creat.h"
#include "src/fcntl/open.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>
-TEST(LlvmLibcCreatTest, CreatAndOpen) {
+using LlvmLibcCreatTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcCreatTest, CreatAndOpen) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/creat.test";
int fd = LIBC_NAMESPACE::creat(TEST_FILE, S_IRWXU);
diff --git a/libc/test/src/fcntl/fcntl_test.cpp b/libc/test/src/fcntl/fcntl_test.cpp
index 082c42481777b..84feb34e537a0 100644
--- a/libc/test/src/fcntl/fcntl_test.cpp
+++ b/libc/test/src/fcntl/fcntl_test.cpp
@@ -9,17 +9,19 @@
#include "hdr/fcntl_macros.h"
#include "hdr/stdio_macros.h"
#include "hdr/types/struct_flock.h"
-#include "src/__support/libc_errno.h"
#include "src/fcntl/fcntl.h"
#include "src/fcntl/open.h"
#include "src/unistd/close.h"
#include "src/unistd/getpid.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include <sys/stat.h> // For S_IRWXU
-TEST(LlvmLibcFcntlTest, FcntlDupfd) {
+using LlvmLibcFcntlTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcFcntlTest, FcntlDupfd) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_dup.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
@@ -41,7 +43,7 @@ TEST(LlvmLibcFcntlTest, FcntlDupfd) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd3), Succeeds(0));
}
-TEST(LlvmLibcFcntlTest, FcntlGetFl) {
+TEST_F(LlvmLibcFcntlTest, FcntlGetFl) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getfl.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
@@ -57,7 +59,7 @@ TEST(LlvmLibcFcntlTest, FcntlGetFl) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
-TEST(LlvmLibcFcntlTest, FcntlSetFl) {
+TEST_F(LlvmLibcFcntlTest, FcntlSetFl) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_setfl.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
@@ -92,7 +94,7 @@ TEST(LlvmLibcFcntlTest, FcntlSetFl) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
-TEST(LlvmLibcFcntlTest, FcntlGetLkRead) {
+TEST_F(LlvmLibcFcntlTest, FcntlGetLkRead) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkread.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
@@ -124,7 +126,7 @@ TEST(LlvmLibcFcntlTest, FcntlGetLkRead) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
-TEST(LlvmLibcFcntlTest, FcntlGetLkWrite) {
+TEST_F(LlvmLibcFcntlTest, FcntlGetLkWrite) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_getlkwrite.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
@@ -155,7 +157,7 @@ TEST(LlvmLibcFcntlTest, FcntlGetLkWrite) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
}
-TEST(LlvmLibcFcntlTest, UseAfterClose) {
+TEST_F(LlvmLibcFcntlTest, UseAfterClose) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_NAME = "testdata/fcntl_use_after_close.test";
auto TEST_FILE = libc_make_test_file_path(TEST_FILE_NAME);
@@ -165,8 +167,7 @@ TEST(LlvmLibcFcntlTest, UseAfterClose) {
ASSERT_ERRNO_EQ(EBADF);
}
-TEST(LlvmLibcFcntlTest, SetGetOwnerTest) {
- libc_errno = 0;
+TEST_F(LlvmLibcFcntlTest, SetGetOwnerTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
pid_t pid = LIBC_NAMESPACE::getpid();
ASSERT_GT(pid, -1);
diff --git a/libc/test/src/fcntl/openat_test.cpp b/libc/test/src/fcntl/openat_test.cpp
index 1997476f16a60..e40260ad1f205 100644
--- a/libc/test/src/fcntl/openat_test.cpp
+++ b/libc/test/src/fcntl/openat_test.cpp
@@ -6,17 +6,19 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/fcntl/openat.h"
#include "src/unistd/close.h"
#include "src/unistd/read.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
#include "hdr/fcntl_macros.h"
-TEST(LlvmLibcUniStd, OpenAndReadTest) {
+using LlvmLibcOpenAtTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcOpenAtTest, OpenAndReadTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "openat.test";
@@ -36,7 +38,7 @@ TEST(LlvmLibcUniStd, OpenAndReadTest) {
ASSERT_THAT(LIBC_NAMESPACE::close(dir_fd), Succeeds(0));
}
-TEST(LlvmLibcUniStd, FailTest) {
+TEST_F(LlvmLibcOpenAtTest, FailTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
EXPECT_THAT(LIBC_NAMESPACE::openat(AT_FDCWD, "openat.test", O_RDONLY),
Fails(ENOENT));
diff --git a/libc/test/src/sched/CMakeLists.txt b/libc/test/src/sched/CMakeLists.txt
index 362c526312d42..93752ed26108d 100644
--- a/libc/test/src/sched/CMakeLists.txt
+++ b/libc/test/src/sched/CMakeLists.txt
@@ -14,6 +14,7 @@ add_libc_unittest(
libc.src.errno.errno
libc.src.sched.sched_getaffinity
libc.src.sched.sched_setaffinity
+ libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
@@ -26,6 +27,7 @@ add_libc_unittest(
DEPENDS
libc.src.errno.errno
libc.src.sched.sched_yield
+ libc.test.UnitTest.ErrnoCheckingTest
)
add_libc_unittest(
@@ -39,6 +41,7 @@ add_libc_unittest(
libc.src.errno.errno
libc.src.sched.sched_get_priority_min
libc.src.sched.sched_get_priority_max
+ libc.test.UnitTest.ErrnoCheckingTest
)
add_libc_unittest(
@@ -70,6 +73,7 @@ add_libc_unittest(
libc.src.sched.sched_get_priority_min
libc.src.sched.sched_get_priority_max
libc.src.unistd.getuid
+ libc.test.UnitTest.ErrnoCheckingTest
)
add_libc_unittest(
@@ -87,6 +91,7 @@ add_libc_unittest(
libc.src.sched.sched_get_priority_min
libc.src.sched.sched_rr_get_interval
libc.src.unistd.getuid
+ libc.test.UnitTest.ErrnoCheckingTest
)
add_libc_unittest(
@@ -104,5 +109,6 @@ add_libc_unittest(
libc.src.errno.errno
libc.src.sched.sched_getaffinity
libc.src.sched.__sched_getcpucount
+ libc.test.UnitTest.ErrnoCheckingTest
libc.test.UnitTest.ErrnoSetterMatcher
)
diff --git a/libc/test/src/sched/affinity_test.cpp b/libc/test/src/sched/affinity_test.cpp
index 1c8599bb67d4c..51159bae7907c 100644
--- a/libc/test/src/sched/affinity_test.cpp
+++ b/libc/test/src/sched/affinity_test.cpp
@@ -7,18 +7,19 @@
//===----------------------------------------------------------------------===//
#include "src/__support/OSUtil/syscall.h"
-#include "src/__support/libc_errno.h"
#include "src/sched/sched_getaffinity.h"
#include "src/sched/sched_setaffinity.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "hdr/types/cpu_set_t.h"
#include "hdr/types/pid_t.h"
#include <sys/syscall.h>
-TEST(LlvmLibcSchedAffinityTest, SmokeTest) {
+using LlvmLibcSchedAffinityTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcSchedAffinityTest, SmokeTest) {
cpu_set_t mask;
- libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
ASSERT_GT(tid, pid_t(0));
@@ -29,19 +30,15 @@ TEST(LlvmLibcSchedAffinityTest, SmokeTest) {
Succeeds(0));
}
-TEST(LlvmLibcSchedAffinityTest, BadMask) {
+TEST_F(LlvmLibcSchedAffinityTest, BadMask) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
- libc_errno = 0;
ASSERT_THAT(
LIBC_NAMESPACE::sched_getaffinity(tid, sizeof(cpu_set_t), nullptr),
Fails(EFAULT));
- libc_errno = 0;
ASSERT_THAT(
LIBC_NAMESPACE::sched_setaffinity(tid, sizeof(cpu_set_t), nullptr),
Fails(EFAULT));
-
- libc_errno = 0;
}
diff --git a/libc/test/src/sched/cpu_count_test.cpp b/libc/test/src/sched/cpu_count_test.cpp
index 06e4fff98bd21..217324e3e4766 100644
--- a/libc/test/src/sched/cpu_count_test.cpp
+++ b/libc/test/src/sched/cpu_count_test.cpp
@@ -7,18 +7,19 @@
//===----------------------------------------------------------------------===//
#include "src/__support/OSUtil/syscall.h"
-#include "src/__support/libc_errno.h"
#include "src/sched/sched_getaffinity.h"
#include "src/sched/sched_getcpucount.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "hdr/sched_macros.h"
#include "hdr/types/cpu_set_t.h"
#include "hdr/types/pid_t.h"
-TEST(LlvmLibcSchedCpuCountTest, SmokeTest) {
+using LlvmLibcSchedCpuCountTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcSchedCpuCountTest, SmokeTest) {
cpu_set_t mask;
- libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
pid_t tid = LIBC_NAMESPACE::syscall_impl<pid_t>(SYS_gettid);
ASSERT_GT(tid, pid_t(0));
diff --git a/libc/test/src/sched/get_priority_test.cpp b/libc/test/src/sched/get_priority_test.cpp
index bf4fca8ece092..fb168c2e96430 100644
--- a/libc/test/src/sched/get_priority_test.cpp
+++ b/libc/test/src/sched/get_priority_test.cpp
@@ -6,14 +6,16 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/sched/sched_get_priority_max.h"
#include "src/sched/sched_get_priority_min.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include "hdr/sched_macros.h"
-TEST(LlvmLibcSchedGetPriorityTest, HandleBadPolicyTest) {
+using LlvmLibcSchedGetPriorityTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcSchedGetPriorityTest, HandleBadPolicyTest) {
// Test arbitrary values for which there is no policy.
{
@@ -57,9 +59,7 @@ TEST(LlvmLibcSchedGetPriorityTest, HandleBadPolicyTest) {
}
}
-TEST(LlvmLibcSchedGetPriorityTest, SmokeTest) {
- libc_errno = 0;
-
+TEST_F(LlvmLibcSchedGetPriorityTest, SmokeTest) {
// We Test:
// SCHED_OTHER, SCHED_FIFO, SCHED_RR
// Linux specific test could also include:
diff --git a/libc/test/src/sched/getcpu_test.cpp b/libc/test/src/sched/getcpu_test.cpp
index fc4ada8a722f5..cf19d25f816df 100644
--- a/libc/test/src/sched/getcpu_test.cpp
+++ b/libc/test/src/sched/getcpu_test.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "src/__support/OSUtil/syscall.h"
-#include "src/__support/libc_errno.h"
#include "src/sched/getcpu.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
diff --git a/libc/test/src/sched/param_and_scheduler_test.cpp b/libc/test/src/sched/param_and_scheduler_test.cpp
index b8ee1233dfb86..57eb59865b1aa 100644
--- a/libc/test/src/sched/param_and_scheduler_test.cpp
+++ b/libc/test/src/sched/param_and_scheduler_test.cpp
@@ -14,6 +14,7 @@
#include "src/sched/sched_setparam.h"
#include "src/sched/sched_setscheduler.h"
#include "src/unistd/getuid.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include "hdr/sched_macros.h"
@@ -35,11 +36,9 @@
// Linux specific test could also include:
// SCHED_ISO, SCHED_DEADLINE
-class SchedTest : public LIBC_NAMESPACE::testing::Test {
+class SchedTest : public LIBC_NAMESPACE::testing::ErrnoCheckingTest {
public:
void testSched(int policy, bool is_mandatory) {
- libc_errno = 0;
-
int init_policy = LIBC_NAMESPACE::sched_getscheduler(0);
ASSERT_GE(init_policy, 0);
ASSERT_ERRNO_SUCCESS();
@@ -56,22 +55,18 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
// Negative pid
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(-1, policy, ¶m), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getscheduler(-1), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
// Invalid Policy
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy | 128, ¶m), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
// Out of bounds priority
param.sched_priority = min_priority - 1;
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy, ¶m), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
param.sched_priority = max_priority + 1;
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy, ¶m), -1);
@@ -99,12 +94,10 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
param.sched_priority = -1;
ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(0, ¶m), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
param.sched_priority = max_priority + 1;
ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(0, ¶m), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
for (int priority = min_priority; priority <= max_priority; ++priority) {
ASSERT_EQ(LIBC_NAMESPACE::sched_getparam(0, ¶m), 0);
@@ -116,11 +109,9 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
// Negative pid
ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(-1, ¶m), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getparam(-1, ¶m), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
// Success/unsupported policy/missing permissions
int setparam_result = LIBC_NAMESPACE::sched_setparam(0, ¶m);
@@ -141,7 +132,6 @@ class SchedTest : public LIBC_NAMESPACE::testing::Test {
// Null test
ASSERT_EQ(LIBC_NAMESPACE::sched_setscheduler(0, policy, nullptr), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
}
};
@@ -159,13 +149,9 @@ LIST_SCHED_TESTS(SCHED_BATCH, true)
LIST_SCHED_TESTS(SCHED_IDLE, true)
TEST(LlvmLibcSchedParamAndSchedulerTest, NullParamTest) {
- libc_errno = 0;
-
ASSERT_EQ(LIBC_NAMESPACE::sched_setparam(0, nullptr), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
ASSERT_EQ(LIBC_NAMESPACE::sched_getparam(0, nullptr), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
}
diff --git a/libc/test/src/sched/sched_rr_get_interval_test.cpp b/libc/test/src/sched/sched_rr_get_interval_test.cpp
index e5dc4e31d1c9d..a8c85346c3047 100644
--- a/libc/test/src/sched/sched_rr_get_interval_test.cpp
+++ b/libc/test/src/sched/sched_rr_get_interval_test.cpp
@@ -6,19 +6,20 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/sched/sched_get_priority_min.h"
#include "src/sched/sched_getscheduler.h"
#include "src/sched/sched_rr_get_interval.h"
#include "src/sched/sched_setscheduler.h"
#include "src/unistd/getuid.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
#include "hdr/sched_macros.h"
#include "hdr/types/struct_timespec.h"
-TEST(LlvmLibcSchedRRGetIntervalTest, SmokeTest) {
- libc_errno = 0;
+using LlvmLibcSchedRRGetIntervalTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcSchedRRGetIntervalTest, SmokeTest) {
auto SetSched = [&](int policy) {
int min_priority = LIBC_NAMESPACE::sched_get_priority_min(policy);
ASSERT_GE(min_priority, 0);
@@ -59,19 +60,16 @@ TEST(LlvmLibcSchedRRGetIntervalTest, SmokeTest) {
// Null timespec
ASSERT_EQ(LIBC_NAMESPACE::sched_rr_get_interval(0, nullptr), -1);
ASSERT_ERRNO_EQ(EFAULT);
- libc_errno = 0;
// Negative pid
ASSERT_EQ(LIBC_NAMESPACE::sched_rr_get_interval(-1, &ts), -1);
ASSERT_ERRNO_EQ(EINVAL);
- libc_errno = 0;
}
// Negative tests don't have SCHED_RR set
SetSched(SCHED_OTHER);
ASSERT_EQ(LIBC_NAMESPACE::sched_rr_get_interval(0, &ts), 0);
ASSERT_ERRNO_SUCCESS();
- libc_errno = 0;
// TODO: Missing unkown pid -> ESRCH. This is read only so safe to try a few
// unlikely values.
diff --git a/libc/test/src/sched/yield_test.cpp b/libc/test/src/sched/yield_test.cpp
index 4d13d50e25eb2..1cd30abb88513 100644
--- a/libc/test/src/sched/yield_test.cpp
+++ b/libc/test/src/sched/yield_test.cpp
@@ -6,12 +6,13 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/libc_errno.h"
#include "src/sched/sched_yield.h"
+#include "test/UnitTest/ErrnoCheckingTest.h"
#include "test/UnitTest/Test.h"
-TEST(LlvmLibcSchedYieldTest, SmokeTest) {
- libc_errno = 0;
+using LlvmLibcSchedYieldTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
+
+TEST_F(LlvmLibcSchedYieldTest, SmokeTest) {
// sched_yield() always succeeds, just do a basic test that errno/ret are
// properly 0.
ASSERT_EQ(LIBC_NAMESPACE::sched_yield(), 0);
diff --git a/libc/test/src/signal/CMakeLists.txt b/libc/test/src/signal/CMakeLists.txt
index 6b50...
[truncated]
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Remove direct libc_errno.h inclusion and manipulation of libc_errno in various unit tests, instead relying on ErrnoCheckingTest machinery.
This is the final mechanical change of migrating libc unit tests to ErrnoCheckingTest - after it, all the unit tests relying on ASSERT_ERRNO_* macro will be using ErrnoCheckingTest.h