]> granicus.if.org Git - llvm/commitdiff
[gcov] Sort file info before printing it
authorVedant Kumar <vsk@apple.com>
Wed, 26 Apr 2017 00:16:10 +0000 (00:16 +0000)
committerVedant Kumar <vsk@apple.com>
Wed, 26 Apr 2017 00:16:10 +0000 (00:16 +0000)
The order in which GCOV file info is printed depends on the string hash
function. This makes some GCOV tests brittle, because the tests must be
updated whenever the hash function changes.

Sort the filenames before printing out the file info to solve the
problem. This should be relatively cheap.

Differential Revision: https://reviews.llvm.org/D32512

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301371 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/GCOV.cpp
test/tools/llvm-cov/Inputs/test_-b.output
test/tools/llvm-cov/Inputs/test_-f.output
test/tools/llvm-cov/Inputs/test_long_file_names.output
test/tools/llvm-cov/Inputs/test_long_paths.output
test/tools/llvm-cov/Inputs/test_missing.output
test/tools/llvm-cov/Inputs/test_no_gcda.output
test/tools/llvm-cov/Inputs/test_no_options.output
test/tools/llvm-cov/Inputs/test_no_output.output
test/tools/llvm-cov/Inputs/test_no_preserve_paths.output
test/tools/llvm-cov/Inputs/test_preserve_paths.output

index ba92a91cc917bfefc69584b26340e728ca492f6d..d4b4552282252f37b00120fbe647435432c25a4e 100644 (file)
@@ -589,8 +589,12 @@ FileInfo::openCoveragePath(StringRef CoveragePath) {
 /// print -  Print source files with collected line count information.
 void FileInfo::print(raw_ostream &InfoOS, StringRef MainFilename,
                      StringRef GCNOFile, StringRef GCDAFile) {
-  for (const auto &LI : LineInfo) {
-    StringRef Filename = LI.first();
+  SmallVector<StringRef, 4> Filenames;
+  for (const auto &LI : LineInfo)
+    Filenames.push_back(LI.first());
+  std::sort(Filenames.begin(), Filenames.end());
+
+  for (StringRef Filename : Filenames) {
     auto AllLines = LineConsumer(Filename);
 
     std::string CoveragePath = getCoveragePath(Filename, MainFilename);
@@ -603,7 +607,7 @@ void FileInfo::print(raw_ostream &InfoOS, StringRef MainFilename,
     CovOS << "        -:    0:Runs:" << RunCount << "\n";
     CovOS << "        -:    0:Programs:" << ProgramCount << "\n";
 
-    const LineData &Line = LI.second;
+    const LineData &Line = LineInfo[Filename];
     GCOVCoverage FileCoverage(Filename);
     for (uint32_t LineIndex = 0; LineIndex < Line.LastLine || !AllLines.empty();
          ++LineIndex) {
index 515987d45ea64ba93f90a2fd0a4de9dff99de1bb..a6495fdaaa52341be7381dfdc94eecbace7986db 100644 (file)
@@ -1,3 +1,9 @@
+File './test.h'
+Lines executed:100.00% of 1
+No branches
+No calls
+./test.h:creating 'test.h.gcov'
+
 File 'test.cpp'
 Lines executed:84.21% of 38
 Branches executed:100.00% of 15
@@ -5,9 +11,3 @@ Taken at least once:86.67% of 15
 No calls
 test.cpp:creating 'test.cpp.gcov'
 
-File './test.h'
-Lines executed:100.00% of 1
-No branches
-No calls
-./test.h:creating 'test.h.gcov'
-
index d97aa18174a0fc197dc10c3e2b28b37aac0befdc..b0a73ea67061a67bc99867e67090c14faf792ce0 100644 (file)
@@ -1,3 +1,9 @@
+Function '_ZN1AC1Ev'
+Lines executed:100.00% of 1
+
+Function '_ZN1AC2Ev'
+Lines executed:100.00% of 1
+
 Function '_ZN1A1BEv'
 Lines executed:100.00% of 1
 
@@ -22,17 +28,11 @@ Lines executed:100.00% of 4
 Function 'main'
 Lines executed:91.67% of 24
 
-Function '_ZN1AC1Ev'
-Lines executed:100.00% of 1
-
-Function '_ZN1AC2Ev'
+File './test.h'
 Lines executed:100.00% of 1
+./test.h:creating 'test.h.gcov'
 
 File 'test.cpp'
 Lines executed:84.21% of 38
 test.cpp:creating 'test.cpp.gcov'
 
-File './test.h'
-Lines executed:100.00% of 1
-./test.h:creating 'test.h.gcov'
-
index e09f4cb9857fd270bcf8d8a84bb6fe8ae0d9cd37..e74b63652811a5084fabf84b0c041f6521c5a793 100644 (file)
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'test_paths.cpp##test.h.gcov'
-
 File 'srcdir/./nested_dir/../test.cpp'
 Lines executed:84.21% of 38
 srcdir/./nested_dir/../test.cpp:creating 'test_paths.cpp##test.cpp.gcov'
 
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'test_paths.cpp##test.h.gcov'
+
index 376ee5b78dfbb45e9d503fd06e88496f81e3c61f..faf3d8ae634ec627242b6ab9ba99036c73eafe32 100644 (file)
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'srcdir#^#test_paths.cpp##srcdir#nested_dir#^#test.h.gcov'
-
 File 'srcdir/./nested_dir/../test.cpp'
 Lines executed:84.21% of 38
 srcdir/./nested_dir/../test.cpp:creating 'srcdir#^#test_paths.cpp##srcdir#nested_dir#^#test.cpp.gcov'
 
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'srcdir#^#test_paths.cpp##srcdir#nested_dir#^#test.h.gcov'
+
index ada0c36030975dab8ba0d474ad7440de2491ce92..a3e32dd7daaeafc8bd97d6ca2a0416635613bf57 100644 (file)
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'test.h.gcov'
-
 File 'srcdir/./nested_dir/../test.cpp'
 Lines executed:84.21% of 38
 srcdir/./nested_dir/../test.cpp:creating 'test.cpp.gcov'
 
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'test.h.gcov'
+
index e994be7291094c908dc538458ff84c2b6c09ed41..46efaca3e465fa1dff34a80ff0a24842caad9ba9 100644 (file)
@@ -1,8 +1,8 @@
-File 'test.cpp'
-Lines executed:0.00% of 38
-test.cpp:creating 'test.cpp.gcov'
-
 File './test.h'
 Lines executed:0.00% of 1
 ./test.h:creating 'test.h.gcov'
 
+File 'test.cpp'
+Lines executed:0.00% of 38
+test.cpp:creating 'test.cpp.gcov'
+
index 8be8c1c210af821b4dc84f4a6bb67d3eb42c6d44..dd76811593e6f7eeb166c163dcf4bc981bd9f348 100644 (file)
@@ -1,8 +1,8 @@
-File 'test.cpp'
-Lines executed:84.21% of 38
-test.cpp:creating 'test.cpp.gcov'
-
 File './test.h'
 Lines executed:100.00% of 1
 ./test.h:creating 'test.h.gcov'
 
+File 'test.cpp'
+Lines executed:84.21% of 38
+test.cpp:creating 'test.cpp.gcov'
+
index 74286b9a2fcae2760a52c0544199e73f37ab79ee..b41e20e32550a94090624daac6d1850b5f0914f4 100644 (file)
@@ -1,6 +1,6 @@
-File 'test.cpp'
-Lines executed:84.21% of 38
-
 File './test.h'
 Lines executed:100.00% of 1
 
+File 'test.cpp'
+Lines executed:84.21% of 38
+
index ada0c36030975dab8ba0d474ad7440de2491ce92..a3e32dd7daaeafc8bd97d6ca2a0416635613bf57 100644 (file)
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'test.h.gcov'
-
 File 'srcdir/./nested_dir/../test.cpp'
 Lines executed:84.21% of 38
 srcdir/./nested_dir/../test.cpp:creating 'test.cpp.gcov'
 
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'test.h.gcov'
+
index 5331972556310950dd2ad780be683d744fbd6d65..0164f2de9c80b479c42539720fe0a877ac01ecdf 100644 (file)
@@ -1,8 +1,8 @@
-File 'srcdir/./nested_dir/../test.h'
-Lines executed:100.00% of 1
-srcdir/./nested_dir/../test.h:creating 'srcdir#nested_dir#^#test.h.gcov'
-
 File 'srcdir/./nested_dir/../test.cpp'
 Lines executed:84.21% of 38
 srcdir/./nested_dir/../test.cpp:creating 'srcdir#nested_dir#^#test.cpp.gcov'
 
+File 'srcdir/./nested_dir/../test.h'
+Lines executed:100.00% of 1
+srcdir/./nested_dir/../test.h:creating 'srcdir#nested_dir#^#test.h.gcov'
+