diff options
author | Bob Haarman <llvm@inglorion.net> | 2019-04-22 19:46:25 +0000 |
---|---|---|
committer | Bob Haarman <llvm@inglorion.net> | 2019-04-22 19:46:25 +0000 |
commit | 2eea99a4b982659c3de57c120bfea8dfa74b6028 (patch) | |
tree | 5f77fe5c16e1b0864293d1d0d8d46e5b3aa423ce /llvm/unittests/Support | |
parent | d8d9b7b20e7b8d7a79a069ddb78e3d9ea48b1a45 (diff) | |
download | bcm5719-llvm-2eea99a4b982659c3de57c120bfea8dfa74b6028.tar.gz bcm5719-llvm-2eea99a4b982659c3de57c120bfea8dfa74b6028.zip |
[Support] unflake TempFileCollisions test
Summary:
This test was added to verify that createUniqueEntity() does
not enter an infinite loop when all possible names are taken. However,
it also checked that all possible names are generated, which is flaky
(because the names are generated randomly). This change increases the
number of attempts we make to make flakes exceedingly
unlikely (3.88e-62).
Reviewers: fedor.sergeev, rsmith
Reviewed By: fedor.sergeev
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D56336
llvm-svn: 358914
Diffstat (limited to 'llvm/unittests/Support')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 3c0f7936030..750fd13db97 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -700,10 +700,18 @@ TEST_F(FileSystemTest, TempFileCollisions) { } }; - // We should be able to create exactly 16 temporary files. - for (int i = 0; i < 16; ++i) - EXPECT_TRUE(TryCreateTempFile()); - EXPECT_FALSE(TryCreateTempFile()); + // Our single-character template allows for 16 unique names. Check that + // calling TryCreateTempFile repeatedly results in 16 successes. + // Because the test depends on random numbers, it could theoretically fail. + // However, the probability of this happening is tiny: with 32 calls, each + // of which will retry up to 128 times, to not get a given digit we would + // have to fail at least 15 + 17 * 128 = 2191 attempts. The probability of + // 2191 attempts not producing a given hexadecimal digit is + // (1 - 1/16) ** 2191 or 3.88e-62. + int Successes = 0; + for (int i = 0; i < 32; ++i) + if (TryCreateTempFile()) ++Successes; + EXPECT_EQ(Successes, 16); for (fs::TempFile &T : TempFiles) cantFail(T.discard()); |