[libc] [llvm] [libc] add bazel support for most of unistd (PR #80078)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 30 15:31:57 PST 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: None (michaelrj-google)

<details>
<summary>Changes</summary>

Much of unistd involves modifying files. The tests for these functions
need to use libc_make_test_file_path which didn't exist when they were
first implemented. This patch adds most of unistd to the bazel along
with the corresponding tests. Tests that modify directories had to be
disabled since bazel doesn't seem to handle them properly.


---

Patch is 36.71 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/80078.diff


27 Files Affected:

- (modified) libc/test/src/stdio/remove_test.cpp (+6-3) 
- (modified) libc/test/src/sys/stat/mkdirat_test.cpp (+2-1) 
- (modified) libc/test/src/unistd/CMakeLists.txt (+1) 
- (modified) libc/test/src/unistd/access_test.cpp (+3-1) 
- (modified) libc/test/src/unistd/chdir_test.cpp (+6-3) 
- (modified) libc/test/src/unistd/dup2_test.cpp (+2-1) 
- (modified) libc/test/src/unistd/dup3_test.cpp (+2-1) 
- (modified) libc/test/src/unistd/dup_test.cpp (+2-1) 
- (modified) libc/test/src/unistd/fchdir_test.cpp (+6-3) 
- (modified) libc/test/src/unistd/ftruncate_test.cpp (+3-2) 
- (modified) libc/test/src/unistd/isatty_test.cpp (+4-2) 
- (modified) libc/test/src/unistd/link_test.cpp (+6-5) 
- (modified) libc/test/src/unistd/linkat_test.cpp (+10-5) 
- (modified) libc/test/src/unistd/lseek_test.cpp (+4-2) 
- (modified) libc/test/src/unistd/pread_pwrite_test.cpp (+2-1) 
- (modified) libc/test/src/unistd/read_write_test.cpp (+5-2) 
- (modified) libc/test/src/unistd/readlink_test.cpp (+4-2) 
- (modified) libc/test/src/unistd/readlinkat_test.cpp (+4-2) 
- (modified) libc/test/src/unistd/rmdir_test.cpp (+3-3) 
- (modified) libc/test/src/unistd/symlink_test.cpp (+6-3) 
- (modified) libc/test/src/unistd/symlinkat_test.cpp (+10-5) 
- (modified) libc/test/src/unistd/truncate_test.cpp (+2-1) 
- (modified) libc/test/src/unistd/unlink_test.cpp (+3-3) 
- (modified) libc/test/src/unistd/unlinkat_test.cpp (+6-3) 
- (modified) utils/bazel/llvm-project-overlay/libc/BUILD.bazel (+253-1) 
- (modified) utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel (+12) 
- (added) utils/bazel/llvm-project-overlay/libc/test/src/unistd/BUILD.bazel (+340) 


``````````diff
diff --git a/libc/test/src/stdio/remove_test.cpp b/libc/test/src/stdio/remove_test.cpp
index 67bff906ef2a3..539c23d0fb906 100644
--- a/libc/test/src/stdio/remove_test.cpp
+++ b/libc/test/src/stdio/remove_test.cpp
@@ -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);
@@ -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));
 
@@ -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));
 }
diff --git a/libc/test/src/sys/stat/mkdirat_test.cpp b/libc/test/src/sys/stat/mkdirat_test.cpp
index ae11af4f6b9b1..cbacc16b402d7 100644
--- a/libc/test/src/sys/stat/mkdirat_test.cpp
+++ b/libc/test/src/sys/stat/mkdirat_test.cpp
@@ -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));
diff --git a/libc/test/src/unistd/CMakeLists.txt b/libc/test/src/unistd/CMakeLists.txt
index 8b9a8db374dd4..3a7fe6f45c091 100644
--- a/libc/test/src/unistd/CMakeLists.txt
+++ b/libc/test/src/unistd/CMakeLists.txt
@@ -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
 )
 
diff --git a/libc/test/src/unistd/access_test.cpp b/libc/test/src/unistd/access_test.cpp
index 6718005846026..1371afa1a00fa 100644
--- a/libc/test/src/unistd/access_test.cpp
+++ b/libc/test/src/unistd/access_test.cpp
@@ -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>
@@ -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);
diff --git a/libc/test/src/unistd/chdir_test.cpp b/libc/test/src/unistd/chdir_test.cpp
index 6676b71eed732..f187a771a1220 100644
--- a/libc/test/src/unistd/chdir_test.cpp
+++ b/libc/test/src/unistd/chdir_test.cpp
@@ -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);
diff --git a/libc/test/src/unistd/dup2_test.cpp b/libc/test/src/unistd/dup2_test.cpp
index 70ea1a72bc8e4..6fa09670e90a9 100644
--- a/libc/test/src/unistd/dup2_test.cpp
+++ b/libc/test/src/unistd/dup2_test.cpp
@@ -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);
diff --git a/libc/test/src/unistd/dup3_test.cpp b/libc/test/src/unistd/dup3_test.cpp
index 9c13de47f0be4..cb0761ad0d87d 100644
--- a/libc/test/src/unistd/dup3_test.cpp
+++ b/libc/test/src/unistd/dup3_test.cpp
@@ -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);
diff --git a/libc/test/src/unistd/dup_test.cpp b/libc/test/src/unistd/dup_test.cpp
index 23abf5969fc28..f303cda5caacf 100644
--- a/libc/test/src/unistd/dup_test.cpp
+++ b/libc/test/src/unistd/dup_test.cpp
@@ -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);
diff --git a/libc/test/src/unistd/fchdir_test.cpp b/libc/test/src/unistd/fchdir_test.cpp
index 0d870e35f51c5..0d1fc810a9e30 100644
--- a/libc/test/src/unistd/fchdir_test.cpp
+++ b/libc/test/src/unistd/fchdir_test.cpp
@@ -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);
diff --git a/libc/test/src/unistd/ftruncate_test.cpp b/libc/test/src/unistd/ftruncate_test.cpp
index 50a3508e0a872..d338ceb9ec42f 100644
--- a/libc/test/src/unistd/ftruncate_test.cpp
+++ b/libc/test/src/unistd/ftruncate_test.cpp
@@ -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];
@@ -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));
 }
diff --git a/libc/test/src/unistd/isatty_test.cpp b/libc/test/src/unistd/isatty_test.cpp
index c0e14c344b436..8f9c58f56b075 100644
--- a/libc/test/src/unistd/isatty_test.cpp
+++ b/libc/test/src/unistd/isatty_test.cpp
@@ -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) {
@@ -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();
diff --git a/libc/test/src/unistd/link_test.cpp b/libc/test/src/unistd/link_test.cpp
index bf6962b397b2c..fd377dd02114c 100644
--- a/libc/test/src/unistd/link_test.cpp
+++ b/libc/test/src/unistd/link_test.cpp
@@ -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
@@ -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));
 }
diff --git a/libc/test/src/unistd/linkat_test.cpp b/libc/test/src/unistd/linkat_test.cpp
index 62fbaacac08e4..50384b1ecafb0 100644
--- a/libc/test/src/unistd/linkat_test.cpp
+++ b/libc/test/src/unistd/linkat_test.cpp
@@ -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
diff --git a/libc/test/src/unistd/lseek_test.cpp b/libc/test/src/unistd/lseek_test.cpp
index fd73bccf0cb8f..40c0bf07df313 100644
--- a/libc/test/src/unistd/lseek_test.cpp
+++ b/libc/test/src/unistd/lseek_test.cpp
@@ -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);
@@ -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);
diff --git a/libc/test/src/unistd/pread_pwrite_test.cpp b/libc/test/src/unistd/pread_pwrite_test.cpp
index 1d17778e550f8..3c42fcc777a68 100644
--- a/libc/test/src/unistd/pread_pwrite_test.cpp
+++ b/libc/test/src/unistd/pread_pwrite_test.cpp
@@ -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);
diff --git a/libc/test/src/unistd/read_write_test.cpp b/libc/test/src/unistd/read_write_test.cpp
index 1330573582209..8b6ba427a343a 100644
--- a/libc/test/src/unistd/read_write_test.cpp
+++ b/libc/test/src/unistd/read_write_test.cpp
@@ -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"
@@ -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);
@@ -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) {
diff --git a/libc/test/src/unistd/readlink_test.cpp b/libc/test/src/unistd/readlink_test.cpp
index 19b339ec2b374..1919938082213 100644
--- a/libc/test/src/unistd/readlink_test.cpp
+++ b/libc/test/src/unistd/readlink_test.cpp
@@ -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:
diff --git a/libc/test/src/unistd/readlinkat_test.cpp b/libc/test/src/unistd/readlinkat_test.cpp
index 85cbca084778d..03b35c5718ab5 100644
--- a/libc/test/src/unistd/readlinkat_test.cpp
+++ b/libc/test/src/unistd/readlinkat_test.cpp
@@ -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:
diff --git a/libc/test/src/unistd/rmdir_test.cpp b/libc/test/src/unistd/rmdir_test.cpp
index 69228ce98c822..93cb0f3f53c1b 100644
--- a/libc/test/src/unistd/rmdir_test.cpp
+++ b/libc/test/src/unistd/rmdir_test.cpp
@@ -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));
 }
diff --git a/libc/test/src/unistd/symlink_test.cpp b/libc/test/src/unistd/symlink_test.cpp
index e0c5979a60876..2be0431e473eb 100644
--- a/libc/test/src/unistd/symlink_test.cpp
+++ b/libc/test/src/unistd/symlink_test.cpp
@@ -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
diff --git a/libc/test/src/unistd/symlinkat_test.cpp b/libc/test/src/unistd/symlinkat_test.cpp
index 1ab4dc8417d6c..4888574b6cd4c 100644
--- a/libc/test/src/unistd/symlinkat_test.cpp
+++ b/libc/test/src/unistd/symlinkat_test.cpp
@@ -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
diff --git a/libc/test/src/unistd/truncate_test.cpp b/libc/test/src/unistd/truncate_test.cpp
index 4d316ed1b16fe..a4cb9323bb865 100644
--- a/libc/test/src/unistd/truncate_test.cpp
+++ b/libc/test/src/unistd/truncate_test.cpp
@@ -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_...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/80078


More information about the llvm-commits mailing list