[libc-commits] [libc] [libc][fcntl] Simplify the handling of the return value from syscall … (PR #96325)
Xu Zhang via libc-commits
libc-commits at lists.llvm.org
Tue Jun 25 09:14:37 PDT 2024
================
@@ -162,4 +163,23 @@ TEST(LlvmLibcFcntlTest, UseAfterClose) {
ASSERT_THAT(LIBC_NAMESPACE::close(fd), Succeeds(0));
ASSERT_EQ(-1, LIBC_NAMESPACE::fcntl(fd, F_GETFL));
ASSERT_ERRNO_EQ(EBADF);
+ LIBC_NAMESPACE::libc_errno = 0;
+}
+
+TEST(LlvmLibcFcntlTest, SetGetOwnerTest) {
+ using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
+ pid_t pid = LIBC_NAMESPACE::getpid();
+ ASSERT_GT(pid, -1);
+ constexpr const char *TEST_FILE_NAME = "testdata/fcntl_set_get_owner.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);
+ ASSERT_ERRNO_SUCCESS();
----------------
simonzgx wrote:
@nickdesaulniers If `errno` is not cleared, the UT will fail at this line (`errno` is expected to be 0, but it actually NOT), because at the end of the previous test case (UseAfterClose), `errno` was set to `EBADF`.
https://github.com/llvm/llvm-project/pull/96325
More information about the libc-commits
mailing list