https://github.com/yingcong-wu updated
https://github.com/llvm/llvm-project/pull/77058
>From 202fb858344d102bd5199cd749bb15195dbce558 Mon Sep 17 00:00:00 2001
From: "Wu, Yingcong"
Date: Fri, 5 Jan 2024 00:48:34 -0800
Subject: [PATCH 1/7] try to directly create file in /tmp when filepath is too
long
---
libcxx/test/support/filesystem_test_helper.h | 15 ++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/libcxx/test/support/filesystem_test_helper.h
b/libcxx/test/support/filesystem_test_helper.h
index a049efe03d844e..271b2bb5cafe23 100644
--- a/libcxx/test/support/filesystem_test_helper.h
+++ b/libcxx/test/support/filesystem_test_helper.h
@@ -18,6 +18,7 @@
#include
#include
#include // for printf
+#include
#include
#include
#include
@@ -324,10 +325,22 @@ struct scoped_test_env
::sockaddr_un address;
address.sun_family = AF_UNIX;
+
+// If file.size() is too big, try to create a file directly inside
+// /tmp to make sure file path is short enough.
+if (file.size() <= sizeof(address.sun_path) && utils::exists("/tmp")) {
+fs::path const tmp = "/tmp";
+std::size_t i =
std::hash()(std::to_string(std::time(nullptr)));
+fs::path p = tmp / ("libcxx-socket-" + file + "-" +
std::to_string(i));
+while (utils::exists(p.string())) {
+ p = tmp / ("libcxx-socket-" + file + "-" + std::to_string(++i));
+}
+file = p.string();
+}
assert(file.size() <= sizeof(address.sun_path));
::strncpy(address.sun_path, file.c_str(), sizeof(address.sun_path));
int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
-::bind(fd, reinterpret_cast<::sockaddr*>(&address), sizeof(address));
+assert(::bind(fd, reinterpret_cast<::sockaddr*>(&address),
sizeof(address)) == 0);
return file;
}
#endif
>From 5d64d75bf7ad8422eb54594fa8cc8dfda7f14e4e Mon Sep 17 00:00:00 2001
From: "Wu, Yingcong"
Date: Fri, 5 Jan 2024 01:13:24 -0800
Subject: [PATCH 2/7] format
---
libcxx/test/support/filesystem_test_helper.h | 14 +++---
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/libcxx/test/support/filesystem_test_helper.h
b/libcxx/test/support/filesystem_test_helper.h
index 271b2bb5cafe23..d33fcf5497f084 100644
--- a/libcxx/test/support/filesystem_test_helper.h
+++ b/libcxx/test/support/filesystem_test_helper.h
@@ -329,13 +329,13 @@ struct scoped_test_env
// If file.size() is too big, try to create a file directly inside
// /tmp to make sure file path is short enough.
if (file.size() <= sizeof(address.sun_path) && utils::exists("/tmp")) {
-fs::path const tmp = "/tmp";
-std::size_t i =
std::hash()(std::to_string(std::time(nullptr)));
-fs::path p = tmp / ("libcxx-socket-" + file + "-" +
std::to_string(i));
-while (utils::exists(p.string())) {
- p = tmp / ("libcxx-socket-" + file + "-" + std::to_string(++i));
-}
-file = p.string();
+ fs::path const tmp = "/tmp";
+ std::size_t i =
std::hash()(std::to_string(std::time(nullptr)));
+ fs::path p = tmp / ("libcxx-socket-" + file + "-" +
std::to_string(i));
+ while (utils::exists(p.string())) {
+p = tmp / ("libcxx-socket-" + file + "-" + std::to_string(++i));
+ }
+ file = p.string();
}
assert(file.size() <= sizeof(address.sun_path));
::strncpy(address.sun_path, file.c_str(), sizeof(address.sun_path));
>From ec6ff976d4e338fb1cd219409ee47b75b3b6a324 Mon Sep 17 00:00:00 2001
From: "Wu, Yingcong"
Date: Fri, 5 Jan 2024 01:59:22 -0800
Subject: [PATCH 3/7] fix error
---
libcxx/test/support/filesystem_test_helper.h | 12 ++--
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libcxx/test/support/filesystem_test_helper.h
b/libcxx/test/support/filesystem_test_helper.h
index d33fcf5497f084..001625d97775f8 100644
--- a/libcxx/test/support/filesystem_test_helper.h
+++ b/libcxx/test/support/filesystem_test_helper.h
@@ -321,27 +321,27 @@ struct scoped_test_env
// allow tests to call this unguarded.
#if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(_WIN32)
std::string create_socket(std::string file) {
-file = sanitize_path(std::move(file));
+std::string socket_file = sanitize_path(file);
::sockaddr_un address;
address.sun_family = AF_UNIX;
// If file.size() is too big, try to create a file directly inside
// /tmp to make sure file path is short enough.
-if (file.size() <= sizeof(address.sun_path) && utils::exists("/tmp")) {
+if (socket_file.size() <= sizeof(address.sun_path) &&
utils::exists("/tmp")) {
fs::path const tmp = "/tmp";
std::size_t i =
std::hash()(std::to_string(std::time(nullptr)));