summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ProfileData/SampleProfTest.cpp
diff options
context:
space:
mode:
authorWei Mi <wmi@google.com>2018-09-15 00:04:15 +0000
committerWei Mi <wmi@google.com>2018-09-15 00:04:15 +0000
commit67f57c6795bf4943cf2c2481112e30acf80d95a2 (patch)
treed61c9e0c06dff4e7cf7744027f3537bb5c059ee5 /llvm/unittests/ProfileData/SampleProfTest.cpp
parent01d250eed9278a24a4d94bd09153c772b3b67734 (diff)
downloadbcm5719-llvm-67f57c6795bf4943cf2c2481112e30acf80d95a2.tar.gz
bcm5719-llvm-67f57c6795bf4943cf2c2481112e30acf80d95a2.zip
Fix filesystem race issue in SampleProfTest introduced in rL342283.
Before this fix, multiple invocations of testRoundTrip will create multiple writers which share the same file as output destination. That could introduce filesystem race issue when multiple subtests are executed concurrently. This patch assign writers with different files as their output destinations. llvm-svn: 342301
Diffstat (limited to 'llvm/unittests/ProfileData/SampleProfTest.cpp')
-rw-r--r--llvm/unittests/ProfileData/SampleProfTest.cpp20
1 files changed, 9 insertions, 11 deletions
diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp
index 6c669445a2b..7e0f094f6a6 100644
--- a/llvm/unittests/ProfileData/SampleProfTest.cpp
+++ b/llvm/unittests/ProfileData/SampleProfTest.cpp
@@ -37,24 +37,21 @@ namespace {
struct SampleProfTest : ::testing::Test {
LLVMContext Context;
- std::string Profile;
- std::unique_ptr<raw_ostream> OS;
std::unique_ptr<SampleProfileWriter> Writer;
std::unique_ptr<SampleProfileReader> Reader;
- std::error_code EC;
- SampleProfTest()
- : Profile("profile"),
- OS(new raw_fd_ostream(Profile, EC, sys::fs::F_None)), Writer(),
- Reader() {}
+ SampleProfTest() : Writer(), Reader() {}
- void createWriter(SampleProfileFormat Format) {
+ void createWriter(SampleProfileFormat Format, const std::string &Profile) {
+ std::error_code EC;
+ std::unique_ptr<raw_ostream> OS(
+ new raw_fd_ostream(Profile, EC, sys::fs::F_None));
auto WriterOrErr = SampleProfileWriter::create(OS, Format);
ASSERT_TRUE(NoError(WriterOrErr.getError()));
Writer = std::move(WriterOrErr.get());
}
- void readProfile(const Module &M) {
+ void readProfile(const Module &M, const std::string &Profile) {
auto ReaderOrErr = SampleProfileReader::create(Profile, Context);
ASSERT_TRUE(NoError(ReaderOrErr.getError()));
Reader = std::move(ReaderOrErr.get());
@@ -62,7 +59,8 @@ struct SampleProfTest : ::testing::Test {
}
void testRoundTrip(SampleProfileFormat Format) {
- createWriter(Format);
+ std::string Profile = std::string("profile.") + std::to_string(Format);
+ createWriter(Format, Profile);
StringRef FooName("_Z3fooi");
FunctionSamples FooSamples;
@@ -103,7 +101,7 @@ struct SampleProfTest : ::testing::Test {
Writer->getOutputStream().flush();
- readProfile(M);
+ readProfile(M, Profile);
EC = Reader->read();
ASSERT_TRUE(NoError(EC));
OpenPOWER on IntegriCloud