llvm.org GIT mirror llvm / 5455b4c
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342301 91177308-0d34-0410-b5e6-96231b3b80d8 Wei Mi 1 year, 1 month ago
1 changed file(s) with 11 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
3636
3737 struct SampleProfTest : ::testing::Test {
3838 LLVMContext Context;
39 std::string Profile;
40 std::unique_ptr OS;
4139 std::unique_ptr Writer;
4240 std::unique_ptr Reader;
43 std::error_code EC;
44
45 SampleProfTest()
46 : Profile("profile"),
47 OS(new raw_fd_ostream(Profile, EC, sys::fs::F_None)), Writer(),
48 Reader() {}
49
50 void createWriter(SampleProfileFormat Format) {
41
42 SampleProfTest() : Writer(), Reader() {}
43
44 void createWriter(SampleProfileFormat Format, const std::string &Profile) {
45 std::error_code EC;
46 std::unique_ptr OS(
47 new raw_fd_ostream(Profile, EC, sys::fs::F_None));
5148 auto WriterOrErr = SampleProfileWriter::create(OS, Format);
5249 ASSERT_TRUE(NoError(WriterOrErr.getError()));
5350 Writer = std::move(WriterOrErr.get());
5451 }
5552
56 void readProfile(const Module &M) {
53 void readProfile(const Module &M, const std::string &Profile) {
5754 auto ReaderOrErr = SampleProfileReader::create(Profile, Context);
5855 ASSERT_TRUE(NoError(ReaderOrErr.getError()));
5956 Reader = std::move(ReaderOrErr.get());
6158 }
6259
6360 void testRoundTrip(SampleProfileFormat Format) {
64 createWriter(Format);
61 std::string Profile = std::string("profile.") + std::to_string(Format);
62 createWriter(Format, Profile);
6563
6664 StringRef FooName("_Z3fooi");
6765 FunctionSamples FooSamples;
102100
103101 Writer->getOutputStream().flush();
104102
105 readProfile(M);
103 readProfile(M, Profile);
106104
107105 EC = Reader->read();
108106 ASSERT_TRUE(NoError(EC));