Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate .gcov file from llvm-cov?

I've create a project on Xcode 7 that generates code coverage data.

Inside its DerivedData folder, I can run llvm-cov show:

/usr/local/opt/llvm/bin/llvm-cov show -instr-profile Build/Intermediates/CodeCoverage/testetestes/Coverage.profdata Build/Intermediates/CodeCoverage/testetestes/Products/Debug-iphonesimulator/testetestes.framework/testetestes

This will produce an output like this:

/Users/marcelofabri/Desktop/testetestes/testetestes/Example.swift:
   |    1|//
   |    2|//  Example.swift
   |    3|//  testetestes
   |    4|//
   |    5|//  Created by Marcelo Fabri on 09/06/15.
   |    6|//  Copyright © 2015 Marcelo Fabri. All rights reserved.
   |    7|//
   |    8|
   |    9|import UIKit
   |   10|
   |   11|class Example: NSObject {
  1|   12|    func testando() {
  1|   13|        if let url = NSURL(string: "dasdas") {
  1|   14|            print("ae \(url)")
  0|   15|        } else {
  0|   16|            print("oi")
  0|   17|        }
  1|   18|    }
   |   19|}

/Users/marcelofabri/Desktop/testetestes/testetestes/OutraClasse.swift:
   |    1|//
   |    2|//  OutraClasse.swift
   |    3|//  testetestes
   |    4|//
   |    5|//  Created by Marcelo Fabri on 18/06/15.
   |    6|//  Copyright © 2015 Marcelo Fabri. All rights reserved.
   |    7|//
   |    8|
   |    9|import UIKit
   |   10|
   |   11|class OutraClasse: NSObject {
   |   12|
  1|   13|    func outroTestando() {
  1|   14|        if let numero = Int("123") {
  1|   15|            print("ae \(numero)")
  0|   16|        } else {
  0|   17|            print("oi")
  0|   18|        }
  1|   19|    }
   |   20|
   |   21|}

However, I'd like to get .gcov files, since it's what most tools use. Is there a way to do this without parsing the output and creating .gcov file manually?

like image 915
Marcelo Fabri Avatar asked Jun 25 '15 03:06

Marcelo Fabri


People also ask

What is Llvm COV?

The llvm-cov tool shows code coverage information for programs that are instrumented to emit profile data. It can be used to work with gcov -style coverage or with clang 's instrumentation based profiling. If the program is invoked with a base name of gcov , it will behave as if the llvm-cov gcov command were called.


1 Answers

According to Apple gcov is not a part of Xcode 7 coverage support. Gcov was gcc legacy that stayed around till appearance of replacement. Apparently they dropped legacy gcov file format support in favor of new intermediate format — profdata. I did research on my own and didn't find any tools that converts profdata back to gcov, however there is Slather from Venom. Slather is able to generate coverage reports in Gutter JSON, Cobertura XML, HTML and plain test. It also able to provide integration with popular service like Coveralls. Currently it works also only with gcov, but they have issue opened and PR request pending for support of profdata. They usually move fast, so it likely soon will be merged into master.

Also if you will decide to write your own tool there are multiple approaches that you may consider for reviewing:

  • Converting of plain text output from llvm-cov show
  • Converting of binary format of profdata by following format documentation
  • Help Slather guys an introduce cross-coverting from their model back into gcov, as soon as they will merge in profdata support
like image 67
Nikita Leonov Avatar answered Sep 30 '22 15:09

Nikita Leonov