Skip to content
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

[libc] add bazel support for most of unistd #80078

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions libc/test/src/stdio/remove_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ TEST(LlvmLibcRemoveTest, CreateAndRemoveFile) {
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/remove.test.file";

constexpr const char *FILENAME = "remove.test.file";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(fd, 0);
Expand All @@ -40,7 +42,8 @@ TEST(LlvmLibcRemoveTest, CreateAndRemoveDir) {
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata/remove.test.dir";
constexpr const char *FILENAME = "remove.test.dir";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
ASSERT_THAT(LIBC_NAMESPACE::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU),
Succeeds(0));

Expand All @@ -51,5 +54,5 @@ TEST(LlvmLibcRemoveTest, CreateAndRemoveDir) {

TEST(LlvmLibcRemoveTest, RemoveNonExistent) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(LIBC_NAMESPACE::remove("testdata/non-existent"), Fails(ENOENT));
ASSERT_THAT(LIBC_NAMESPACE::remove("non-existent"), Fails(ENOENT));
}
3 changes: 2 additions & 1 deletion libc/test/src/sys/stat/mkdirat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

TEST(LlvmLibcMkdiratTest, CreateAndRemove) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata/mkdirat.testdir";
constexpr const char *FILENAME = "testdata/mkdirat.testdir";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
ASSERT_THAT(LIBC_NAMESPACE::mkdirat(AT_FDCWD, TEST_DIR, S_IRWXU),
Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::rmdir(TEST_DIR), Succeeds(0));
Expand Down
1 change: 1 addition & 0 deletions libc/test/src/unistd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ add_libc_unittest(
libc.src.unistd.fsync
libc.src.unistd.read
libc.src.unistd.write
libc.src.stdio.remove
libc.test.UnitTest.ErrnoSetterMatcher
)

Expand Down
4 changes: 3 additions & 1 deletion libc/test/src/unistd/access_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "src/unistd/close.h"
#include "src/unistd/unlink.h"
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/LibcTest.h"
#include "test/UnitTest/Test.h"

#include <sys/stat.h>
Expand All @@ -22,7 +23,8 @@ TEST(LlvmLibcAccessTest, CreateAndTest) {
// test that it is accessable in those modes but not in others.
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/access.test";
constexpr const char *FILENAME = "access.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(fd, 0);
Expand Down
9 changes: 6 additions & 3 deletions libc/test/src/unistd/chdir_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ TEST(LlvmLibcChdirTest, ChangeAndOpen) {
// directory and open the same file to make sure that the "chdir" operation
// succeeded.
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "testdata/chdir.test";
constexpr const char *TEST_FILE_BASE = "chdir.test";
constexpr const char *FILENAME = "testdata";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "testdata/chdir.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME2);
constexpr const char *FILENAME3 = "chdir.test";
auto TEST_FILE_BASE = libc_make_test_file_path(FILENAME3);
libc_errno = 0;

int fd = LIBC_NAMESPACE::open(TEST_FILE, O_PATH);
Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/unistd/dup2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
constexpr int DUPFD = 0xD0;
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup2.test";
constexpr const char *FILENAME = "dup2.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(fd, 0);
Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/unistd/dup3_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup3.test";
constexpr const char *FILENAME = "dup3.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(fd, 0);
Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/unistd/dup_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
TEST(LlvmLibcdupTest, ReadAndWriteViaDup) {
libc_errno = 0;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/dup.test";
constexpr const char *FILENAME = "dup.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(fd, 0);
Expand Down
9 changes: 6 additions & 3 deletions libc/test/src/unistd/fchdir_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ TEST(LlvmLibcChdirTest, ChangeAndOpen) {
// directory and open the same file to make sure that the "fchdir" operation
// succeeded.
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "testdata/fchdir.test";
constexpr const char *TEST_FILE_BASE = "fchdir.test";
constexpr const char *FILENAME = "testdata";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "testdata/fchdir.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME2);
constexpr const char *FILENAME3 = "fchdir.test";
auto TEST_FILE_BASE = libc_make_test_file_path(FILENAME3);
libc_errno = 0;

int dir_fd = LIBC_NAMESPACE::open(TEST_DIR, O_DIRECTORY);
Expand Down
5 changes: 3 additions & 2 deletions libc/test/src/unistd/ftruncate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace cpp = LIBC_NAMESPACE::cpp;

TEST(LlvmLibcFtruncateTest, CreateAndTruncate) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char TEST_FILE[] = "testdata/ftruncate.test";
constexpr const char *FILENAME = "ftruncate.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
constexpr const char WRITE_DATA[] = "hello, ftruncate";
constexpr size_t WRITE_SIZE = sizeof(WRITE_DATA);
char buf[WRITE_SIZE];
Expand Down Expand Up @@ -68,5 +69,5 @@ TEST(LlvmLibcFtruncateTest, CreateAndTruncate) {

TEST(LlvmLibcFtruncateTest, TruncateBadFD) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(LIBC_NAMESPACE::ftruncate(1, off_t(1)), Fails(EINVAL));
ASSERT_THAT(LIBC_NAMESPACE::ftruncate(0, off_t(1)), Fails(EINVAL));
}
6 changes: 4 additions & 2 deletions libc/test/src/unistd/isatty_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ TEST(LlvmLibcIsATTYTest, BadFdTest) {
}

TEST(LlvmLibcIsATTYTest, DevTTYTest) {
constexpr const char *TTY_FILE = "/dev/tty";
constexpr const char *FILENAME = "/dev/tty";
auto TTY_FILE = libc_make_test_file_path(FILENAME);
libc_errno = 0;
int fd = LIBC_NAMESPACE::open(TTY_FILE, O_RDONLY);
if (fd > 0) {
Expand All @@ -50,7 +51,8 @@ TEST(LlvmLibcIsATTYTest, DevTTYTest) {
}

TEST(LlvmLibcIsATTYTest, FileTest) {
constexpr const char *TEST_FILE = "testdata/isatty.test";
constexpr const char *FILENAME = "isatty.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
libc_errno = 0;
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
Expand Down
11 changes: 6 additions & 5 deletions libc/test/src/unistd/link_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

TEST(LlvmLibcLinkTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/link.test";
constexpr const char *TEST_FILE_LINK = "testdata/link.test.link";
constexpr const char *FILENAME = "link.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "link.test.link";
auto TEST_FILE_LINK = libc_make_test_file_path(FILENAME2);

// The test strategy is as follows:
// 1. Create a normal file
Expand All @@ -44,7 +46,6 @@ TEST(LlvmLibcLinkTest, CreateAndUnlink) {

TEST(LlvmLibcLinkTest, LinkToNonExistentFile) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(
LIBC_NAMESPACE::link("testdata/non-existent-file", "testdata/bad-link"),
Fails(ENOENT));
ASSERT_THAT(LIBC_NAMESPACE::link("non-existent-file", "bad-link"),
Fails(ENOENT));
}
15 changes: 10 additions & 5 deletions libc/test/src/unistd/linkat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@

TEST(LlvmLibcLinkatTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "linkat.test";
constexpr const char *TEST_FILE_PATH = "testdata/linkat.test";
constexpr const char *TEST_FILE_LINK = "linkat.test.link";
constexpr const char *TEST_FILE_LINK_PATH = "testdata/linkat.test.link";
constexpr const char *FILENAME = "testdata";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "linkat.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME2);
constexpr const char *FILENAME3 = "testdata/linkat.test";
auto TEST_FILE_PATH = libc_make_test_file_path(FILENAME3);
constexpr const char *FILENAME4 = "linkat.test.link";
auto TEST_FILE_LINK = libc_make_test_file_path(FILENAME4);
constexpr const char *FILENAME5 = "testdata/linkat.test.link";
auto TEST_FILE_LINK_PATH = libc_make_test_file_path(FILENAME5);

// The test strategy is as follows:
// 1. Create a normal file
Expand Down
6 changes: 4 additions & 2 deletions libc/test/src/unistd/lseek_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

TEST(LlvmLibcUniStd, LseekTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/lseek.test";
constexpr const char *FILENAME = "testdata/lseek.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(fd, 0);
Expand Down Expand Up @@ -52,7 +53,8 @@ TEST(LlvmLibcUniStd, LseekTest) {
TEST(LlvmLibcUniStd, LseekFailsTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/lseek.test";
constexpr const char *FILENAME = "testdata/lseek.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_RDONLY);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(fd, 0);
Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/unistd/pread_pwrite_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ TEST(LlvmLibcUniStd, PWriteAndPReadBackTest) {

using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;

constexpr const char *TEST_FILE = "testdata/pread_pwrite.test";
constexpr const char *FILENAME = "pread_pwrite.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(fd, 0);
Expand Down
7 changes: 5 additions & 2 deletions libc/test/src/unistd/read_write_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "src/errno/libc_errno.h"
#include "src/fcntl/open.h"
#include "src/stdio/remove.h"
#include "src/unistd/close.h"
#include "src/unistd/fsync.h"
#include "src/unistd/read.h"
Expand All @@ -19,7 +20,9 @@

TEST(LlvmLibcUniStd, WriteAndReadBackTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "__unistd_read_write.test";
constexpr const char *FILENAME = "__unistd_read_write.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);

int write_fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(write_fd, 0);
Expand All @@ -39,7 +42,7 @@ TEST(LlvmLibcUniStd, WriteAndReadBackTest) {
EXPECT_STREQ(read_buf, HELLO);
ASSERT_THAT(LIBC_NAMESPACE::close(read_fd), Succeeds(0));

// TODO: 'remove' the test file after the test.
ASSERT_THAT(LIBC_NAMESPACE::remove(TEST_FILE), Succeeds(0));
}

TEST(LlvmLibcUniStd, WriteFails) {
Expand Down
6 changes: 4 additions & 2 deletions libc/test/src/unistd/readlink_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ namespace cpp = LIBC_NAMESPACE::cpp;

TEST(LlvmLibcReadlinkTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char LINK_VAL[] = "readlink_test_value";
constexpr const char LINK[] = "testdata/readlink.test.link";
constexpr const char *FILENAME = "readlink_test_value";
auto LINK_VAL = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "readlink.test.link";
auto LINK = libc_make_test_file_path(FILENAME2);
libc_errno = 0;

// The test strategy is as follows:
Expand Down
6 changes: 4 additions & 2 deletions libc/test/src/unistd/readlinkat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ namespace cpp = LIBC_NAMESPACE::cpp;

TEST(LlvmLibcReadlinkatTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char LINK_VAL[] = "readlinkat_test_value";
constexpr const char LINK[] = "testdata/readlinkat.test.link";
constexpr const char *FILENAME = "readlinkat_test_value";
auto LINK_VAL = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "readlinkat.test.link";
auto LINK = libc_make_test_file_path(FILENAME2);
libc_errno = 0;

// The test strategy is as follows:
Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/unistd/rmdir_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

TEST(LlvmLibcRmdirTest, CreateAndRemove) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata/rmdir.testdir";
constexpr const char *FILENAME = "rmdir.testdir";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
ASSERT_THAT(LIBC_NAMESPACE::mkdir(TEST_DIR, S_IRWXU), Succeeds(0));
ASSERT_THAT(LIBC_NAMESPACE::rmdir(TEST_DIR), Succeeds(0));
}

TEST(LlvmLibcRmdirTest, RemoveNonExistentDir) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(LIBC_NAMESPACE::rmdir("testdata/non-existent-dir"),
Fails(ENOENT));
ASSERT_THAT(LIBC_NAMESPACE::rmdir("non-existent-dir"), Fails(ENOENT));
}
9 changes: 6 additions & 3 deletions libc/test/src/unistd/symlink_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

TEST(LlvmLibcSymlinkTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE_BASE = "symlink.test";
constexpr const char *TEST_FILE = "testdata/symlink.test";
constexpr const char *TEST_FILE_LINK = "testdata/symlink.test.symlink";
constexpr const char *FILENAME = "symlink.test";
auto TEST_FILE_BASE = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "symlink.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME2);
constexpr const char *FILENAME3 = "symlink.test.symlink";
auto TEST_FILE_LINK = libc_make_test_file_path(FILENAME3);

// The test strategy is as follows:
// 1. Create a normal file
Expand Down
15 changes: 10 additions & 5 deletions libc/test/src/unistd/symlinkat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@

TEST(LlvmLibcSymlinkatTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "symlinkat.test";
constexpr const char *TEST_FILE_PATH = "testdata/symlinkat.test";
constexpr const char *TEST_FILE_LINK = "symlinkat.test.link";
constexpr const char *TEST_FILE_LINK_PATH = "testdata/symlinkat.test.link";
constexpr const char *FILENAME = "testdata";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "symlinkat.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME2);
constexpr const char *FILENAME3 = "testdata/symlinkat.test";
auto TEST_FILE_PATH = libc_make_test_file_path(FILENAME3);
constexpr const char *FILENAME4 = "symlinkat.test.link";
auto TEST_FILE_LINK = libc_make_test_file_path(FILENAME4);
constexpr const char *FILENAME5 = "testdata/symlinkat.test.link";
auto TEST_FILE_LINK_PATH = libc_make_test_file_path(FILENAME5);

// The test strategy is as follows:
// 1. Create a normal file
Expand Down
3 changes: 2 additions & 1 deletion libc/test/src/unistd/truncate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ namespace cpp = LIBC_NAMESPACE::cpp;

TEST(LlvmLibcTruncateTest, CreateAndTruncate) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char TEST_FILE[] = "testdata/truncate.test";
constexpr const char *FILENAME = "truncate.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
constexpr const char WRITE_DATA[] = "hello, truncate";
constexpr size_t WRITE_SIZE = sizeof(WRITE_DATA);
char buf[WRITE_SIZE];
Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/unistd/unlink_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@

TEST(LlvmLibcUnlinkTest, CreateAndUnlink) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_FILE = "testdata/unlink.test";
constexpr const char *FILENAME = "unlink.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME);
int write_fd = LIBC_NAMESPACE::open(TEST_FILE, O_WRONLY | O_CREAT, S_IRWXU);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(write_fd, 0);
Expand All @@ -27,6 +28,5 @@ TEST(LlvmLibcUnlinkTest, CreateAndUnlink) {

TEST(LlvmLibcUnlinkTest, UnlinkNonExistentFile) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Fails;
ASSERT_THAT(LIBC_NAMESPACE::unlink("testdata/non-existent-file"),
Fails(ENOENT));
ASSERT_THAT(LIBC_NAMESPACE::unlink("non-existent-file"), Fails(ENOENT));
}
9 changes: 6 additions & 3 deletions libc/test/src/unistd/unlinkat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

TEST(LlvmLibcUnlinkatTest, CreateAndDeleteTest) {
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::Succeeds;
constexpr const char *TEST_DIR = "testdata";
constexpr const char *TEST_FILE = "openat.test";
constexpr const char *FILENAME = "testdata";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
constexpr const char *FILENAME2 = "openat.test";
auto TEST_FILE = libc_make_test_file_path(FILENAME2);
int dir_fd = LIBC_NAMESPACE::open(TEST_DIR, O_DIRECTORY);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(dir_fd, 0);
Expand All @@ -33,7 +35,8 @@ TEST(LlvmLibcUnlinkatTest, CreateAndDeleteTest) {
}

TEST(LlvmLibcUnlinkatTest, UnlinkatNonExistentFile) {
constexpr const char *TEST_DIR = "testdata";
constexpr const char *FILENAME = "testdata";
auto TEST_DIR = libc_make_test_file_path(FILENAME);
int dir_fd = LIBC_NAMESPACE::open(TEST_DIR, O_DIRECTORY);
ASSERT_ERRNO_SUCCESS();
ASSERT_GT(dir_fd, 0);
Expand Down
Loading
Loading