|
8 | 8 | #include <cstdlib> |
9 | 9 | #include <set> |
10 | 10 | #include <unistd.h> |
| 11 | +#include <thread> |
11 | 12 |
|
12 | 13 | using namespace std; |
13 | 14 | using namespace wobble::sys; |
@@ -43,13 +44,52 @@ add_method("isdir", []() { |
43 | 44 | wassert(actual(isdir("testdir")).istrue()); |
44 | 45 | }); |
45 | 46 |
|
| 47 | +#pragma GCC diagnostic pop |
| 48 | + |
46 | 49 | add_method("abspath", []() { |
47 | | - std::string cwd = std::filesystem::current_path().string(); |
48 | | - wassert(actual(abspath(".")) == cwd + "/"); |
49 | | - wassert(actual(abspath("foo")) == cwd + "/foo"); |
50 | | - wassert(actual(abspath("foo/")) == cwd + "/foo/"); |
| 50 | + auto cwd = std::filesystem::current_path(); |
| 51 | + wassert(actual(abspath(".")) == cwd); |
| 52 | + wassert(actual(abspath("foo")) == cwd / "foo"); |
| 53 | + wassert(actual(abspath("foo/")) == cwd / "foo/"); |
| 54 | +}); |
| 55 | + |
| 56 | +add_method("abspath_concurrency", []() { |
| 57 | + // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118733 |
| 58 | + std::filesystem::path workdir("testdir"); |
| 59 | + rmtree_ifexists(workdir); |
| 60 | + std::filesystem::create_directory(workdir); |
| 61 | + |
| 62 | + auto expected = std::filesystem::absolute(workdir) / "dir"; |
| 63 | + |
| 64 | + auto testpath = workdir / "dir"; |
| 65 | + bool done = false; |
| 66 | + |
| 67 | + auto glitch = [&done, &testpath] { |
| 68 | + while (! done) |
| 69 | + { |
| 70 | + std::filesystem::remove(testpath); |
| 71 | + std::filesystem::create_directory(testpath); |
| 72 | + } |
| 73 | + }; |
| 74 | + |
| 75 | + std::thread glitcher(glitch); |
| 76 | + |
| 77 | + int failed_iteration = -1; |
| 78 | + std::string failed_message; |
| 79 | + for (unsigned iteration = 0; iteration < 1000; ++iteration) |
| 80 | + try { |
| 81 | + wassert(actual(abspath(testpath)) == expected); |
| 82 | + } catch (std::exception& e) { |
| 83 | + failed_iteration = iteration; |
| 84 | + failed_message = e.what(); |
| 85 | + break; |
| 86 | + } |
| 87 | + done = true; |
| 88 | + glitcher.join(); |
| 89 | + |
| 90 | + if (failed_iteration != -1) |
| 91 | + wfail_test("abspath failed at iteration " + std::to_string(failed_iteration) + ": " + failed_message); |
51 | 92 | }); |
52 | | -#pragma GCC diagnostic pop |
53 | 93 |
|
54 | 94 | add_method("timestamp", []() { |
55 | 95 | using namespace wobble; |
|
0 commit comments