diff options
author | Alexander Kornienko <alexfh@google.com> | 2018-09-17 12:11:01 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2018-09-17 12:11:01 +0000 |
commit | a195de86599bc46c7f603097bd5668d595fc09fb (patch) | |
tree | fbc92e95a609f5b49540ffc3499b13c93cbfc91d /llvm/unittests/ProfileData/SampleProfTest.cpp | |
parent | 9dd34c838536bdd49feb84ada617130d7e6aa019 (diff) | |
download | bcm5719-llvm-a195de86599bc46c7f603097bd5668d595fc09fb.tar.gz bcm5719-llvm-a195de86599bc46c7f603097bd5668d595fc09fb.zip |
Use createTemporaryFile in SampleProfTest
Create a temporary file in the system temporary directory instead of creating a
file in the current directory, which may be not writable. (Fix for an issue
introduced in r342283.)
llvm-svn: 342386
Diffstat (limited to 'llvm/unittests/ProfileData/SampleProfTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/SampleProfTest.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/unittests/ProfileData/SampleProfTest.cpp b/llvm/unittests/ProfileData/SampleProfTest.cpp index 7e0f094f6a6..73e8088b638 100644 --- a/llvm/unittests/ProfileData/SampleProfTest.cpp +++ b/llvm/unittests/ProfileData/SampleProfTest.cpp @@ -42,7 +42,7 @@ struct SampleProfTest : ::testing::Test { SampleProfTest() : Writer(), Reader() {} - void createWriter(SampleProfileFormat Format, const std::string &Profile) { + void createWriter(SampleProfileFormat Format, StringRef Profile) { std::error_code EC; std::unique_ptr<raw_ostream> OS( new raw_fd_ostream(Profile, EC, sys::fs::F_None)); @@ -51,7 +51,7 @@ struct SampleProfTest : ::testing::Test { Writer = std::move(WriterOrErr.get()); } - void readProfile(const Module &M, const std::string &Profile) { + void readProfile(const Module &M, StringRef Profile) { auto ReaderOrErr = SampleProfileReader::create(Profile, Context); ASSERT_TRUE(NoError(ReaderOrErr.getError())); Reader = std::move(ReaderOrErr.get()); @@ -59,7 +59,9 @@ struct SampleProfTest : ::testing::Test { } void testRoundTrip(SampleProfileFormat Format) { - std::string Profile = std::string("profile.") + std::to_string(Format); + SmallVector<char, 128> ProfilePath; + ASSERT_TRUE(NoError(llvm::sys::fs::createTemporaryFile("profile", "", ProfilePath))); + StringRef Profile(ProfilePath.data(), ProfilePath.size()); createWriter(Format, Profile); StringRef FooName("_Z3fooi"); |