aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ProfileData/CoverageMappingTest.cpp
diff options
context:
space:
mode:
authorPetr Hosek <phosek@google.com>2021-04-09 11:53:59 -0700
committerPetr Hosek <phosek@google.com>2021-05-11 15:26:45 -0700
commit8280ece0c972db24e51aae5074ca5433002f1071 (patch)
treed0349813ad8a97abc2413e11d1c06636d0ecdf1d /llvm/unittests/ProfileData/CoverageMappingTest.cpp
parenta0162a81b1377331c3e0ebb58ac349b2ffd7b598 (diff)
downloadllvm-8280ece0c972db24e51aae5074ca5433002f1071.zip
llvm-8280ece0c972db24e51aae5074ca5433002f1071.tar.gz
llvm-8280ece0c972db24e51aae5074ca5433002f1071.tar.bz2
[Coverage] Support overriding compilation directory
When making compilation relocatable, for example in distributed compilation scenarios, we want to set compilation dir to a relative value like `.` but this presents a problem when generating reports because if the file path is relative as well, for example `..`, you may end up writing files outside of the output directory. This change introduces a flag that allows overriding the compilation directory that's stored inside the profile with a different value that is absolute. Differential Revision: https://reviews.llvm.org/D100232
Diffstat (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp')
-rw-r--r--llvm/unittests/ProfileData/CoverageMappingTest.cpp35
1 files changed, 32 insertions, 3 deletions
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
index b10400b..6434474 100644
--- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -900,7 +900,7 @@ INSTANTIATE_TEST_CASE_P(ParameterizedCovMapTest, CoverageMappingTest,
std::pair<bool, bool>({true, true})),);
TEST(CoverageMappingTest, filename_roundtrip) {
- std::vector<std::string> Paths({"", "a", "b", "c", "d", "e"});
+ std::vector<std::string> Paths({"dir", "a", "b", "c", "d", "e"});
for (bool Compress : {false, true}) {
std::string EncodedFilenames;
@@ -915,8 +915,37 @@ TEST(CoverageMappingTest, filename_roundtrip) {
EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion), Succeeded());
ASSERT_EQ(ReadFilenames.size(), Paths.size());
- for (unsigned I = 1; I < Paths.size(); ++I)
- ASSERT_TRUE(ReadFilenames[I] == Paths[I]);
+ for (unsigned I = 1; I < Paths.size(); ++I) {
+ SmallString<256> P(Paths[0]);
+ llvm::sys::path::append(P, Paths[I]);
+ ASSERT_TRUE(ReadFilenames[I] == P);
+ }
+ }
+}
+
+TEST(CoverageMappingTest, filename_compilation_dir) {
+ std::vector<std::string> Paths({"dir", "a", "b", "c", "d", "e"});
+
+ for (bool Compress : {false, true}) {
+ std::string EncodedFilenames;
+ {
+ raw_string_ostream OS(EncodedFilenames);
+ CoverageFilenamesSectionWriter Writer(Paths);
+ Writer.write(OS, Compress);
+ }
+
+ StringRef CompilationDir = "out";
+ std::vector<std::string> ReadFilenames;
+ RawCoverageFilenamesReader Reader(EncodedFilenames, ReadFilenames,
+ CompilationDir);
+ EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion), Succeeded());
+
+ ASSERT_EQ(ReadFilenames.size(), Paths.size());
+ for (unsigned I = 1; I < Paths.size(); ++I) {
+ SmallString<256> P(CompilationDir);
+ llvm::sys::path::append(P, Paths[I]);
+ ASSERT_TRUE(ReadFilenames[I] == P);
+ }
}
}