[libcxx-commits] [PATCH] D98703: [libcxx] [test] Avoid race conditions between tests regarding temp directories

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Mar 19 07:13:06 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb982c6f5fa1b: [libcxx] [test] Avoid race conditions between tests regarding temp directories (authored by mstorsjo).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98703/new/

https://reviews.llvm.org/D98703

Files:
  libcxx/test/support/filesystem_test_helper.h


Index: libcxx/test/support/filesystem_test_helper.h
===================================================================
--- libcxx/test/support/filesystem_test_helper.h
+++ libcxx/test/support/filesystem_test_helper.h
@@ -296,14 +296,17 @@
     // sharing the same cwd). However, it is fairly unlikely to happen as
     // we generally don't use scoped_test_env from multiple threads, so
     // this is deemed acceptable.
+    // The cwd.filename() itself isn't unique across all tests in the suite,
+    // so start the numbering from a hash of the full cwd, to avoid
+    // different tests interfering with each other.
     static inline fs::path available_cwd_path() {
         fs::path const cwd = utils::getcwd();
         fs::path const tmp = fs::temp_directory_path();
-        fs::path const base = tmp / cwd.filename();
-        int i = 0;
-        fs::path p = base / ("static_env." + std::to_string(i));
+        std::string base = cwd.filename().string();
+        size_t i = std::hash<std::string>()(cwd.string());
+        fs::path p = tmp / (base + "-static_env." + std::to_string(i));
         while (utils::exists(p.string())) {
-            p = fs::path(base) / ("static_env." + std::to_string(++i));
+            p = tmp / (base + "-static_env." + std::to_string(++i));
         }
         return p;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98703.331867.patch
Type: text/x-patch
Size: 1328 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210319/08f30373/attachment.bin>


More information about the libcxx-commits mailing list