diff options
author | iirina <elenairina@google.com> | 2018-08-09 06:49:18 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-08-09 06:50:36 -0700 |
commit | 6620107fb57598450d2cb7327f6b82c0a6e9afc3 (patch) | |
tree | f378693e115386c394769f8f35c7acc2945abc57 /tools | |
parent | 2fe53b7b2719dd5297da062f4cfcc7bb1e745058 (diff) |
Support 2 more valid gcov info lines in GcovParser.
Closes #5843.
PiperOrigin-RevId: 208041110
Diffstat (limited to 'tools')
-rw-r--r-- | tools/test/LcovMerger/java/com/google/devtools/lcovmerger/GcovParser.java | 18 | ||||
-rw-r--r-- | tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/GcovParserTest.java | 50 |
2 files changed, 62 insertions, 6 deletions
diff --git a/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/GcovParser.java b/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/GcovParser.java index 25592192b2..e62051e861 100644 --- a/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/GcovParser.java +++ b/tools/test/LcovMerger/java/com/google/devtools/lcovmerger/GcovParser.java @@ -119,19 +119,22 @@ public class GcovParser { return true; } - // function:start_line_number,end_line_number,execution_count,function_name + /** + * Valid lines: function:start_line_number,end_line_number,execution_count,function_name + * function:start_line_number,execution_count,function_name + */ private boolean parseFunction(String line) { String lineContent = line.substring(GCOV_FUNCTION_MARKER.length()); String[] items = lineContent.split(DELIMITER, -1); - if (items.length != 4) { + if (items.length != 4 && items.length != 3) { logger.log(Level.WARNING, "gcov info contains invalid line " + line); return false; } try { // Ignore end_line_number since it's redundant information. int startLine = Integer.parseInt(items[0]); - int execCount = Integer.parseInt(items[2]); - String functionName = items[3]; + int execCount = items.length == 4 ? Integer.parseInt(items[2]) : Integer.parseInt(items[1]); + String functionName = items.length == 4 ? items[3] : items[2]; currentSourceFileCoverage.addLineNumber(functionName, startLine); currentSourceFileCoverage.addFunctionExecution(functionName, execCount); } catch (NumberFormatException e) { @@ -141,11 +144,14 @@ public class GcovParser { return true; } - // lcount:line number,execution_count,has_unexecuted_block + /** + * Valid lines: lcount:line number,execution_count,has_unexecuted_block lcount:line + * number,execution_count + */ private boolean parseLCount(String line) { String lineContent = line.substring(GCOV_LINE_MARKER.length()); String[] items = lineContent.split(DELIMITER, -1); - if (items.length != 3) { + if (items.length != 3 && items.length != 2) { logger.log(Level.WARNING, "gcov info contains invalid line " + line); return false; } diff --git a/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/GcovParserTest.java b/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/GcovParserTest.java index 85b069ef0e..0bdd59911b 100644 --- a/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/GcovParserTest.java +++ b/tools/test/LcovMerger/javatests/com/google/devtools/lcovmerger/GcovParserTest.java @@ -73,6 +73,47 @@ public class GcovParserTest { "branch:35,nottaken", "lcount:36,1,0"); + private static final ImmutableList<String> GCOV_INFO_FILE2 = + ImmutableList.of( + "file:tmp.cpp", + "function:7,0,_ZN3FooIcEC2Ev", + "function:7,1,_ZN3FooIiEC2Ev", + "function:8,0,_ZN3FooIcE3incEv", + "function:8,2,_ZN3FooIiE3incEv", + "function:18,1,main", + "lcount:7,0", + "lcount:7,1", + "lcount:8,0", + "lcount:8,2", + "lcount:18,1", + "lcount:21,1", + "branch:21,taken", + "branch:21,nottaken", + "lcount:23,1", + "branch:23,taken", + "branch:23,nottaken", + "lcount:24,1", + "branch:24,taken", + "branch:24,nottaken", + "lcount:25,1", + "lcount:27,11", + "branch:27,taken", + "branch:27,taken", + "lcount:28,10", + "lcount:30,1", + "branch:30,nottaken", + "branch:30,taken", + "lcount:32,1", + "branch:32,nottaken", + "branch:32,taken", + "lcount:33,0", + "branch:33,notexec", + "branch:33,notexec", + "lcount:35,1", + "branch:35,taken", + "branch:35,nottaken", + "lcount:36,1"); + @Test(expected = IOException.class) public void testParseInvalidFile() throws IOException { GcovParser.parse(new ByteArrayInputStream("Invalid gcov file".getBytes(UTF_8))); @@ -88,6 +129,15 @@ public class GcovParserTest { assertGcovInfoFile(sourceFiles.get(0)); } + @Test + public void testParseTracefilWithDifferentFormat() throws IOException { + List<SourceFileCoverage> sourceFiles = + GcovParser.parse( + new ByteArrayInputStream(Joiner.on("\n").join(GCOV_INFO_FILE2).getBytes(UTF_8))); + assertThat(sourceFiles).hasSize(1); + assertGcovInfoFile(sourceFiles.get(0)); + } + private void assertGcovInfoFile(SourceFileCoverage sourceFileCoverage) { assertThat(sourceFileCoverage.sourceFileName()).isEqualTo("tmp.cpp"); |