[PATCH] Added basic testing support for llvm-cov.
Justin Bogner
mail at justinbogner.com
Mon Nov 11 15:52:18 PST 2013
Yuchen Wu <yuchenericwu at hotmail.com> writes:
> Strange... This one should be right.
...
> From 2279ecca7375199bc2f97bc0f2b777db02092ff5 Mon Sep 17 00:00:00 2001
> From: Yuchen Wu <yuchen_wu at apple.com>
> Date: Fri, 1 Nov 2013 20:52:48 -0700
> Subject: [PATCH 12/18] llvm-cov: Added command-line option to specify dir.
>
> This will allow for much easier testing when the input files are in a
> different folder from the test script.
> ---
> include/llvm/Support/GCOV.h | 3 ++-
> lib/IR/GCOV.cpp | 25 ++++++++++++++-----------
> tools/llvm-cov/llvm-cov.cpp | 17 +++++++++++------
> 3 files changed, 27 insertions(+), 18 deletions(-)
>
> diff --git a/include/llvm/Support/GCOV.h b/include/llvm/Support/GCOV.h
> index ccc7c6e..6c20b10 100644
> --- a/include/llvm/Support/GCOV.h
> +++ b/include/llvm/Support/GCOV.h
> @@ -251,7 +251,8 @@ public:
> }
> void setRunCount(uint32_t Runs) { RunCount = Runs; }
> void setProgramCount(uint32_t Programs) { ProgramCount = Programs; }
> - void print(raw_fd_ostream &OS, StringRef gcnoFile, StringRef gcdaFile);
> + void print(raw_fd_ostream &OS, StringRef WorkingDir, StringRef gcnoFile,
> + StringRef gcdaFile);
> private:
> StringMap<LineCounts> LineInfo;
> uint32_t RunCount;
> diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp
> index 3aeddfb..e4041af 100644
> --- a/lib/IR/GCOV.cpp
> +++ b/lib/IR/GCOV.cpp
> @@ -261,23 +261,26 @@ void GCOVLines::dump() {
> // FileInfo implementation.
>
> /// print - Print source files with collected line count information.
> -void FileInfo::print(raw_fd_ostream &OS, StringRef gcnoFile,
> - StringRef gcdaFile) {
> +void FileInfo::print(raw_fd_ostream &OS, StringRef WorkingDir,
> + StringRef gcnoFile, StringRef gcdaFile) {
> for (StringMap<LineCounts>::iterator I = LineInfo.begin(), E = LineInfo.end();
> I != E; ++I) {
> - StringRef Filename = I->first();
> - OS << " -: 0:Source:" << Filename << "\n";
> - OS << " -: 0:Graph:" << gcnoFile << "\n";
> - OS << " -: 0:Data:" << gcdaFile << "\n";
> - OS << " -: 0:Runs:" << RunCount << "\n";
> - OS << " -: 0:Programs:" << ProgramCount << "\n";
> - LineCounts &L = LineInfo[Filename];
> + StringRef RelFilename = I->first();
> + Twine AbsFilename = WorkingDir + I->first();
> OwningPtr<MemoryBuffer> Buff;
> - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
> - errs() << Filename << ": " << ec.message() << "\n";
> + if (error_code ec = MemoryBuffer::getFileOrSTDIN(AbsFilename.str(), Buff)) {
> + errs() << AbsFilename << ": " << ec.message() << "\n";
> return;
> }
> StringRef AllLines = Buff.take()->getBuffer();
> +
> + OS << " -: 0:Source:" << RelFilename << "\n";
> + OS << " -: 0:Graph:" << gcnoFile << "\n";
> + OS << " -: 0:Data:" << gcdaFile << "\n";
> + OS << " -: 0:Runs:" << RunCount << "\n";
> + OS << " -: 0:Programs:" << ProgramCount << "\n";
> +
> + LineCounts &L = LineInfo[RelFilename];
> uint32_t i = 0;
> while (!AllLines.empty()) {
> if (L.find(i) != L.end()) {
> diff --git a/tools/llvm-cov/llvm-cov.cpp b/tools/llvm-cov/llvm-cov.cpp
> index c4a0d65..ffbf6e5 100644
> --- a/tools/llvm-cov/llvm-cov.cpp
> +++ b/tools/llvm-cov/llvm-cov.cpp
> @@ -20,6 +20,7 @@
> #include "llvm/Support/raw_ostream.h"
> #include "llvm/Support/Signals.h"
> #include "llvm/Support/system_error.h"
> +#include <unistd.h>
Pretty sure this is left over from the previous patch - you don't use
it.
> using namespace llvm;
>
> static cl::opt<bool>
> @@ -34,6 +35,9 @@ InputGCDA("gcda", cl::desc("<input gcda file>"), cl::init(""));
> static cl::opt<std::string>
> OutputFile("o", cl::desc("<output llvm-cov file>"), cl::init("-"));
>
> +static cl::opt<std::string>
> +WorkingDir("C", cl::desc("change path of working directory"),
> + cl::init(""));
>
> //===----------------------------------------------------------------------===//
> int main(int argc, char **argv) {
> @@ -54,8 +58,9 @@ int main(int argc, char **argv) {
> errs() << " " << argv[0] << ": No gcov input file!\n";
>
> OwningPtr<MemoryBuffer> GCNO_Buff;
> - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
> - errs() << InputGCNO << ": " << ec.message() << "\n";
> + if (error_code ec =
> + MemoryBuffer::getFileOrSTDIN(WorkingDir + InputGCNO, GCNO_Buff)) {
> + errs() << WorkingDir + InputGCNO << ": " << ec.message() << "\n";
I think this only works correctly if the working dir is specified on the
command line with a trailing slash. What if this is called with a
spelling like "-C /some/dir"?
> return 1;
> }
> GCOVBuffer GCNO_GB(GCNO_Buff.take());
> @@ -66,8 +71,9 @@ int main(int argc, char **argv) {
>
> if (!InputGCDA.empty()) {
> OwningPtr<MemoryBuffer> GCDA_Buff;
> - if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
> - errs() << InputGCDA << ": " << ec.message() << "\n";
> + if (error_code ec =
> + MemoryBuffer::getFileOrSTDIN(WorkingDir + InputGCDA, GCDA_Buff)) {
> + errs() << WorkingDir + InputGCDA << ": " << ec.message() << "\n";
> return 1;
> }
> GCOVBuffer GCDA_GB(GCDA_Buff.take());
> @@ -77,12 +83,11 @@ int main(int argc, char **argv) {
> }
> }
>
> -
> if (DumpGCOV)
> GF.dump();
>
> FileInfo FI;
> GF.collectLineCounts(FI);
> - FI.print(OS, InputGCNO, InputGCDA);
> + FI.print(OS, WorkingDir, InputGCNO, InputGCDA);
Does this behave strangely if InputGCDA or InputGCNO are absolute paths?
> return 0;
> }
More information about the llvm-commits
mailing list