aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ProfileData/CoverageMappingTest.cpp
diff options
context:
space:
mode:
authorPetr Hosek <phosek@google.com>2021-02-10 00:25:34 -0800
committerPetr Hosek <phosek@google.com>2021-02-18 12:27:42 -0800
commit97ec8fa5bb07e3f5bf25ddcb216b545cd3d03b65 (patch)
tree8e98f16e91b6e85c8006c9b5f2b38a5d7445d8a0 /llvm/unittests/ProfileData/CoverageMappingTest.cpp
parent063236646849564094f5fcfc947ad36dba0efedb (diff)
downloadllvm-97ec8fa5bb07e3f5bf25ddcb216b545cd3d03b65.zip
llvm-97ec8fa5bb07e3f5bf25ddcb216b545cd3d03b65.tar.gz
llvm-97ec8fa5bb07e3f5bf25ddcb216b545cd3d03b65.tar.bz2
[Coverage] Store compilation dir separately in coverage mapping
We currently always store absolute filenames in coverage mapping. This is problematic for several reasons. It poses a problem for distributed compilation as source location might vary across machines. We are also duplicating the path prefix potentially wasting space. This change modifies how we store filenames in coverage mapping. Rather than absolute paths, it stores the compilation directory and file paths as given to the compiler, either relative or absolute. Later when reading the coverage mapping information, we recombine relative paths with the working directory. This approach is similar to handling ofDW_AT_comp_dir in DWARF. Finally, we also provide a new option, -fprofile-compilation-dir akin to -fdebug-compilation-dir which can be used to manually override the compilation directory which is useful in distributed compilation cases. Differential Revision: https://reviews.llvm.org/D95753
Diffstat (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp')
-rw-r--r--llvm/unittests/ProfileData/CoverageMappingTest.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
index cbe9c1e..44b7a13 100644
--- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp
+++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp
@@ -129,6 +129,7 @@ struct InputFunctionCoverageData {
struct CoverageMappingTest : ::testing::TestWithParam<std::pair<bool, bool>> {
bool UseMultipleReaders;
StringMap<unsigned> Files;
+ std::vector<std::string> Filenames;
std::vector<InputFunctionCoverageData> InputFunctions;
std::vector<OutputFunctionCoverageData> OutputFunctions;
@@ -146,7 +147,7 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::pair<bool, bool>> {
auto R = Files.find(Name);
if (R != Files.end())
return R->second;
- unsigned Index = Files.size();
+ unsigned Index = Files.size() + 1;
Files.try_emplace(Name, Index);
return Index;
}
@@ -200,11 +201,12 @@ struct CoverageMappingTest : ::testing::TestWithParam<std::pair<bool, bool>> {
void readCoverageRegions(const std::string &Coverage,
OutputFunctionCoverageData &Data) {
- SmallVector<StringRef, 8> Filenames(Files.size());
+ Filenames.resize(Files.size() + 1);
for (const auto &E : Files)
- Filenames[E.getValue()] = E.getKey();
+ Filenames[E.getValue()] = E.getKey().str();
std::vector<CounterExpression> Expressions;
- RawCoverageMappingReader Reader(Coverage, Filenames, Data.Filenames,
+ ArrayRef<std::string> FilenameRefs = llvm::makeArrayRef(Filenames);
+ RawCoverageMappingReader Reader(Coverage, FilenameRefs, Data.Filenames,
Expressions, Data.Regions);
EXPECT_THAT_ERROR(Reader.read(), Succeeded());
}
@@ -895,7 +897,7 @@ INSTANTIATE_TEST_CASE_P(ParameterizedCovMapTest, CoverageMappingTest,
std::pair<bool, bool>({true, true})),);
TEST(CoverageMappingTest, filename_roundtrip) {
- std::vector<StringRef> Paths({"a", "b", "c", "d", "e"});
+ std::vector<std::string> Paths({"", "a", "b", "c", "d", "e"});
for (bool Compress : {false, true}) {
std::string EncodedFilenames;
@@ -905,16 +907,12 @@ TEST(CoverageMappingTest, filename_roundtrip) {
Writer.write(OS, Compress);
}
- std::vector<StringRef> ReadFilenames;
+ std::vector<std::string> ReadFilenames;
RawCoverageFilenamesReader Reader(EncodedFilenames, ReadFilenames);
- BinaryCoverageReader::DecompressedData Decompressed;
- EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion, Decompressed),
- Succeeded());
- if (!Compress)
- ASSERT_EQ(Decompressed.size(), 0U);
+ EXPECT_THAT_ERROR(Reader.read(CovMapVersion::CurrentVersion), Succeeded());
ASSERT_EQ(ReadFilenames.size(), Paths.size());
- for (unsigned I = 0; I < Paths.size(); ++I)
+ for (unsigned I = 1; I < Paths.size(); ++I)
ASSERT_TRUE(ReadFilenames[I] == Paths[I]);
}
}