1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

llvm-cov: Support specifying multiple source files

Make llvm-cov compatible with gcov for cases where multiple files are
specified on the command line. That is, loop over each one and report
coverage, and report errors on stderr only rather than via return
code.

llvm-svn: 211959
This commit is contained in:
Justin Bogner 2014-06-27 20:41:25 +00:00
parent 9f5cb23096
commit e30ccae2b9
2 changed files with 34 additions and 29 deletions

View File

@ -102,12 +102,12 @@ RUN: diff -aub test_no_gcda.cpp.gcov test.cpp.gcov
RUN: diff -aub test_no_gcda.h.gcov test.h.gcov RUN: diff -aub test_no_gcda.h.gcov test.h.gcov
# Invalid gcno file. # Invalid gcno file.
RUN: not llvm-cov test.c -gcno=test_read_fail.gcno RUN: llvm-cov test.c -gcno=test_read_fail.gcno
# Bad file checksum on gcda. # Bad file checksum on gcda.
RUN: not llvm-cov test.c -gcda=test_file_checksum_fail.gcda RUN: llvm-cov test.c -gcda=test_file_checksum_fail.gcda
# Bad function checksum on gcda # Bad function checksum on gcda
RUN: not llvm-cov test.c -gcda=test_func_checksum_fail.gcda RUN: llvm-cov test.c -gcda=test_func_checksum_fail.gcda
XFAIL: powerpc64-, s390x, mips-, mips64-, sparc XFAIL: powerpc64-, s390x, mips-, mips64-, sparc

View File

@ -24,7 +24,7 @@
#include <system_error> #include <system_error>
using namespace llvm; using namespace llvm;
static cl::opt<std::string> SourceFile(cl::Positional, cl::Required, static cl::list<std::string> SourceFiles(cl::Positional, cl::OneOrMore,
cl::desc("SOURCEFILE")); cl::desc("SOURCEFILE"));
static cl::opt<bool> AllBlocks("a", cl::Grouping, cl::init(false), static cl::opt<bool> AllBlocks("a", cl::Grouping, cl::init(false),
@ -76,15 +76,7 @@ static cl::opt<std::string> InputGCNO("gcno", cl::cat(DebugCat), cl::init(""),
static cl::opt<std::string> InputGCDA("gcda", cl::cat(DebugCat), cl::init(""), static cl::opt<std::string> InputGCDA("gcda", cl::cat(DebugCat), cl::init(""),
cl::desc("Override inferred gcda file")); cl::desc("Override inferred gcda file"));
//===----------------------------------------------------------------------===// void reportCoverage(StringRef SourceFile) {
int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
SmallString<128> CoverageFileStem(ObjectDir); SmallString<128> CoverageFileStem(ObjectDir);
if (CoverageFileStem.empty()) { if (CoverageFileStem.empty()) {
// If no directory was specified with -o, look next to the source file. // If no directory was specified with -o, look next to the source file.
@ -97,37 +89,38 @@ int main(int argc, char **argv) {
// A file was given. Ignore the source file and look next to this file. // A file was given. Ignore the source file and look next to this file.
sys::path::replace_extension(CoverageFileStem, ""); sys::path::replace_extension(CoverageFileStem, "");
if (InputGCNO.empty()) std::string GCNO = InputGCNO.empty()
InputGCNO = (CoverageFileStem.str() + ".gcno").str(); ? std::string(CoverageFileStem.str()) + ".gcno"
if (InputGCDA.empty()) : InputGCNO;
InputGCDA = (CoverageFileStem.str() + ".gcda").str(); std::string GCDA = InputGCDA.empty()
? std::string(CoverageFileStem.str()) + ".gcda"
: InputGCDA;
GCOVFile GF; GCOVFile GF;
std::unique_ptr<MemoryBuffer> GCNO_Buff; std::unique_ptr<MemoryBuffer> GCNO_Buff;
if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) { if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(GCNO, GCNO_Buff)) {
errs() << InputGCNO << ": " << ec.message() << "\n"; errs() << GCNO << ": " << ec.message() << "\n";
return 1; return;
} }
GCOVBuffer GCNO_GB(GCNO_Buff.get()); GCOVBuffer GCNO_GB(GCNO_Buff.get());
if (!GF.readGCNO(GCNO_GB)) { if (!GF.readGCNO(GCNO_GB)) {
errs() << "Invalid .gcno File!\n"; errs() << "Invalid .gcno File!\n";
return 1; return;
} }
std::unique_ptr<MemoryBuffer> GCDA_Buff; std::unique_ptr<MemoryBuffer> GCDA_Buff;
if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) { if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(GCDA, GCDA_Buff)) {
if (ec != errc::no_such_file_or_directory) { if (ec != errc::no_such_file_or_directory) {
errs() << InputGCDA << ": " << ec.message() << "\n"; errs() << GCDA << ": " << ec.message() << "\n";
return 1; return;
} }
// Clear the filename to make it clear we didn't read anything. // Clear the filename to make it clear we didn't read anything.
InputGCDA = "-"; GCDA = "-";
} else { } else {
GCOVBuffer GCDA_GB(GCDA_Buff.get()); GCOVBuffer GCDA_GB(GCDA_Buff.get());
if (!GF.readGCDA(GCDA_GB)) { if (!GF.readGCDA(GCDA_GB)) {
errs() << "Invalid .gcda File!\n"; errs() << "Invalid .gcda File!\n";
return 1; return;
} }
} }
@ -138,6 +131,18 @@ int main(int argc, char **argv) {
PreservePaths, UncondBranch, LongNames, NoOutput); PreservePaths, UncondBranch, LongNames, NoOutput);
FileInfo FI(Options); FileInfo FI(Options);
GF.collectLineCounts(FI); GF.collectLineCounts(FI);
FI.print(SourceFile, InputGCNO, InputGCDA); FI.print(SourceFile, GCNO, GCDA);
}
int main(int argc, char **argv) {
// Print a stack trace if we signal out.
sys::PrintStackTraceOnErrorSignal();
PrettyStackTraceProgram X(argc, argv);
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
for (const auto &SourceFile : SourceFiles)
reportCoverage(SourceFile);
return 0; return 0;
} }