2014-08-23 00:56:03 +02:00
|
|
|
//===- CoverageSummaryInfo.h - Coverage summary for function/file ---------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These structures are used to represent code coverage metrics
|
|
|
|
// for functions/files.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_COV_COVERAGESUMMARYINFO_H
|
|
|
|
#define LLVM_COV_COVERAGESUMMARYINFO_H
|
|
|
|
|
2016-04-29 20:53:05 +02:00
|
|
|
#include "llvm/ProfileData/Coverage/CoverageMapping.h"
|
2014-08-23 00:56:03 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// \brief Provides information about region coverage for a function/file.
|
|
|
|
struct RegionCoverageInfo {
|
|
|
|
/// \brief The number of regions that were executed at least once.
|
|
|
|
size_t Covered;
|
|
|
|
|
|
|
|
/// \brief The number of regions that weren't executed.
|
|
|
|
size_t NotCovered;
|
|
|
|
|
|
|
|
/// \brief The total number of regions in a function/file.
|
|
|
|
size_t NumRegions;
|
|
|
|
|
2015-02-14 03:01:24 +01:00
|
|
|
RegionCoverageInfo() : Covered(0), NotCovered(0), NumRegions(0) {}
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
RegionCoverageInfo(size_t Covered, size_t NumRegions)
|
|
|
|
: Covered(Covered), NotCovered(NumRegions - Covered),
|
|
|
|
NumRegions(NumRegions) {}
|
|
|
|
|
2015-02-14 03:01:24 +01:00
|
|
|
RegionCoverageInfo &operator+=(const RegionCoverageInfo &RHS) {
|
|
|
|
Covered += RHS.Covered;
|
|
|
|
NotCovered += RHS.NotCovered;
|
|
|
|
NumRegions += RHS.NumRegions;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
bool isFullyCovered() const { return Covered == NumRegions; }
|
|
|
|
|
|
|
|
double getPercentCovered() const {
|
2016-04-29 03:31:49 +02:00
|
|
|
if (NumRegions == 0)
|
|
|
|
return 0.0;
|
2014-08-23 00:56:03 +02:00
|
|
|
return double(Covered) / double(NumRegions) * 100.0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Provides information about line coverage for a function/file.
|
|
|
|
struct LineCoverageInfo {
|
|
|
|
/// \brief The number of lines that were executed at least once.
|
|
|
|
size_t Covered;
|
|
|
|
|
|
|
|
/// \brief The number of lines that weren't executed.
|
|
|
|
size_t NotCovered;
|
|
|
|
|
|
|
|
/// \brief The number of lines that aren't code.
|
|
|
|
size_t NonCodeLines;
|
|
|
|
|
|
|
|
/// \brief The total number of lines in a function/file.
|
|
|
|
size_t NumLines;
|
|
|
|
|
2015-02-14 03:01:24 +01:00
|
|
|
LineCoverageInfo()
|
|
|
|
: Covered(0), NotCovered(0), NonCodeLines(0), NumLines(0) {}
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
LineCoverageInfo(size_t Covered, size_t NumNonCodeLines, size_t NumLines)
|
|
|
|
: Covered(Covered), NotCovered(NumLines - NumNonCodeLines - Covered),
|
|
|
|
NonCodeLines(NumNonCodeLines), NumLines(NumLines) {}
|
|
|
|
|
2015-02-14 03:01:24 +01:00
|
|
|
LineCoverageInfo &operator+=(const LineCoverageInfo &RHS) {
|
|
|
|
Covered += RHS.Covered;
|
|
|
|
NotCovered += RHS.NotCovered;
|
|
|
|
NonCodeLines += RHS.NonCodeLines;
|
|
|
|
NumLines += RHS.NumLines;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-08-23 00:56:03 +02:00
|
|
|
bool isFullyCovered() const { return Covered == (NumLines - NonCodeLines); }
|
|
|
|
|
|
|
|
double getPercentCovered() const {
|
2016-04-29 03:31:49 +02:00
|
|
|
if (NumLines - NonCodeLines == 0)
|
|
|
|
return 0.0;
|
2014-08-23 00:56:03 +02:00
|
|
|
return double(Covered) / double(NumLines - NonCodeLines) * 100.0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Provides information about function coverage for a file.
|
|
|
|
struct FunctionCoverageInfo {
|
2014-09-30 14:45:13 +02:00
|
|
|
/// \brief The number of functions that were executed.
|
|
|
|
size_t Executed;
|
2014-08-23 00:56:03 +02:00
|
|
|
|
|
|
|
/// \brief The total number of functions in this file.
|
|
|
|
size_t NumFunctions;
|
|
|
|
|
2015-02-14 03:01:24 +01:00
|
|
|
FunctionCoverageInfo() : Executed(0), NumFunctions(0) {}
|
|
|
|
|
2014-09-30 14:45:13 +02:00
|
|
|
FunctionCoverageInfo(size_t Executed, size_t NumFunctions)
|
|
|
|
: Executed(Executed), NumFunctions(NumFunctions) {}
|
2014-08-23 00:56:03 +02:00
|
|
|
|
2015-02-14 03:01:24 +01:00
|
|
|
void addFunction(bool Covered) {
|
|
|
|
if (Covered)
|
|
|
|
++Executed;
|
|
|
|
++NumFunctions;
|
|
|
|
}
|
|
|
|
|
2014-09-30 14:45:13 +02:00
|
|
|
bool isFullyCovered() const { return Executed == NumFunctions; }
|
2014-08-23 00:56:03 +02:00
|
|
|
|
|
|
|
double getPercentCovered() const {
|
2016-04-29 03:31:49 +02:00
|
|
|
if (NumFunctions == 0)
|
|
|
|
return 0.0;
|
2014-09-30 14:45:13 +02:00
|
|
|
return double(Executed) / double(NumFunctions) * 100.0;
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief A summary of function's code coverage.
|
|
|
|
struct FunctionCoverageSummary {
|
|
|
|
StringRef Name;
|
2014-09-30 14:45:13 +02:00
|
|
|
uint64_t ExecutionCount;
|
2014-08-23 00:56:03 +02:00
|
|
|
RegionCoverageInfo RegionCoverage;
|
|
|
|
LineCoverageInfo LineCoverage;
|
|
|
|
|
2015-02-14 03:01:24 +01:00
|
|
|
FunctionCoverageSummary(StringRef Name) : Name(Name), ExecutionCount(0) {}
|
|
|
|
|
2014-09-30 14:45:13 +02:00
|
|
|
FunctionCoverageSummary(StringRef Name, uint64_t ExecutionCount,
|
2014-08-23 00:56:03 +02:00
|
|
|
const RegionCoverageInfo &RegionCoverage,
|
|
|
|
const LineCoverageInfo &LineCoverage)
|
2014-09-30 14:45:13 +02:00
|
|
|
: Name(Name), ExecutionCount(ExecutionCount),
|
|
|
|
RegionCoverage(RegionCoverage), LineCoverage(LineCoverage) {
|
2014-08-23 00:56:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Compute the code coverage summary for the given function coverage
|
|
|
|
/// mapping record.
|
2014-09-12 08:52:44 +02:00
|
|
|
static FunctionCoverageSummary
|
2014-09-20 17:31:56 +02:00
|
|
|
get(const coverage::FunctionRecord &Function);
|
2014-08-23 00:56:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief A summary of file's code coverage.
|
|
|
|
struct FileCoverageSummary {
|
|
|
|
StringRef Name;
|
|
|
|
RegionCoverageInfo RegionCoverage;
|
|
|
|
LineCoverageInfo LineCoverage;
|
|
|
|
FunctionCoverageInfo FunctionCoverage;
|
2015-02-14 03:01:24 +01:00
|
|
|
|
|
|
|
FileCoverageSummary(StringRef Name) : Name(Name) {}
|
|
|
|
|
|
|
|
void addFunction(const FunctionCoverageSummary &Function) {
|
|
|
|
RegionCoverage += Function.RegionCoverage;
|
|
|
|
LineCoverage += Function.LineCoverage;
|
|
|
|
FunctionCoverage.addFunction(/*Covered=*/Function.ExecutionCount > 0);
|
|
|
|
}
|
2014-08-23 00:56:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_COV_COVERAGESUMMARYINFO_H
|