[libcxx-commits] [PATCH] D98703: [libcxx] [test] Readd randomness to temporary directory names

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 16 07:26:04 PDT 2021

mstorsjo added inline comments.

Comment at: libcxx/test/support/filesystem_test_helper.h:324-331
+        base += "-" + random_utils::random_string(4);
         int i = 0;
         fs::path p = tmp / (base + "-static_env." + std::to_string(i));
         while (utils::exists(p.string())) {
             p = tmp / (base + "-static_env." + std::to_string(++i));
Quuxplusone wrote:
> How about (suggested edit)? My logic is that if this piece of code ever produces a collision EVER, then we need a programmer to revisit this piece of code; there's no sense in trying to make the code "work around" a collision, because the whole point is that collisions shouldn't happen.
> However, I still don't understand why there's a collision here in the first place. You say "As some multiple test subdirectories contain tests with the same file names..." but shouldn't we just be using the entire (unique) path, then? Why (and where) are we throwing away the parts of the path that aren't the filename?
> Also, is it possible that we could still have collisions when the same llvm-lit process spawns two copies of the same test (does it ever do that? idk) or when two different llvm-lit processes spawn the same test at the same time (do we support running two llvm-lit runs simultaneously? idk)
No, we can't just add an incrementing integer and forcibly require it to be unique - it's a race condition.

Originally this used random names and all was well - but to simplify building in environments without randomness available, it was chosen to use `cwd.filename()` as uniquefier, under the assumption that `cwd.filename()` is unique within the set of tests that use these helpers.

At this point, cwd would be something like `<build-dir>/test/std/input.output/filesystems/class.directory_iterator/directory_iterator.members/Output/copy_assign.pass.cpp.dir`. The assumption made in the commit that removed randomness was that `cwd.filename()`, i.e. `copy_assign.pass.cpp.dir` would be unique (i.e. the only possible race condition is if there's multiple instances in parallel within the same test), but in this case, there's 3 `copy_ssign.pass.cpp` under test/std/input.output/filesystems.

Including the full path from `cwd` on top of `tmp` is a huge mess (also see D98702 about an issue with leftover intermediate directories - we don't want to create a deep tree of possibly leftover intermediate directoreis).

Adding a small bit of randomness should guard against the few testcases with similar names hitting the same dir at the same time.

The alternative woule perhaps be to create the temp dir tree directly under cwd instead of under the system temp root - maybe that would be ok? That would at least avoid littering that dir excessively. But maybe there's other reasons why the filesystem tests wants to keep these temp files outside of the normal test file tree?

(One run of llvm-lit normally doesn't launch the same test twice afaik, but two runs of llvm-lit in parallel on the same tree would trigger the same issues. I don't think we explicitly forbid being able to run two instances of llvm-lit with overlapping sets of tests at the same time - being able to do that sounds handy to me.)

  rG LLVM Github Monorepo



More information about the libcxx-commits mailing list