InstrProf: Make CoverageMapping testable and add a basic unit test

Make CoverageMapping easier to create, so that we can write targeted
unit tests for its internals, and add a some infrastructure to write
these tests. Finally, add a simple unit test for basic functionality.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229709 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Justin Bogner
2015-02-18 18:01:14 +00:00
parent 2032d755e7
commit 94da968134
4 changed files with 110 additions and 13 deletions

View File

@ -28,7 +28,7 @@ namespace llvm {
class IndexedInstrProfReader;
namespace coverage {
class ObjectFileCoverageMappingReader;
class CoverageMappingReader;
class CoverageMapping;
struct CounterExpressions;
@ -333,10 +333,22 @@ struct CoverageSegment {
CoverageSegment(unsigned Line, unsigned Col, bool IsRegionEntry)
: Line(Line), Col(Col), Count(0), HasCount(false),
IsRegionEntry(IsRegionEntry) {}
CoverageSegment(unsigned Line, unsigned Col, uint64_t Count,
bool IsRegionEntry)
: Line(Line), Col(Col), Count(Count), HasCount(true),
IsRegionEntry(IsRegionEntry) {}
friend bool operator==(const CoverageSegment &L, const CoverageSegment &R) {
return std::tie(L.Line, L.Col, L.Count, L.HasCount, L.IsRegionEntry) ==
std::tie(R.Line, R.Col, R.Count, R.HasCount, R.IsRegionEntry);
}
void setCount(uint64_t NewCount) {
Count = NewCount;
HasCount = true;
}
void addCount(uint64_t NewCount) { setCount(Count + NewCount); }
};
@ -384,7 +396,7 @@ class CoverageMapping {
public:
/// \brief Load the coverage mapping using the given readers.
static ErrorOr<std::unique_ptr<CoverageMapping>>
load(ObjectFileCoverageMappingReader &CoverageReader,
load(CoverageMappingReader &CoverageReader,
IndexedInstrProfReader &ProfileReader);
/// \brief Load the coverage mapping from the given files.