Coverage

I have lately turned my interest towards C and Objective-C, looking into iPhone application development.

So I my continued quest to get my tools box for this defined I am monitoring some interesting mailing lists to pick up stuff as it appears.

The other day somebody write to the official Apple Xcode list inquiring about using gcov and generating HTML data. My brain started spinning, I felt like I had read something about this on CPAN.

After a quick search on search.cpan.org I located: gcov2perl a part of the Devel::Cover distribution.

I have been a long time fan of Devel::Cover, having worked as a Perl programmer for many years, so I was happy to see that this particular tool might scratch this itch.

So I threw together your normal example helloworld.c

  1. #include<stdio.h>
  2. main()
  3. {
  4. printf("Hello World\n");
  5. }

I skimmed a tutorial on gcov to see how it would normally work.

Compile with options of using gcov:

% gcc -fprofile-arcs -ftest-coverage helloworld.c

Run the executable produced:

% ./a.out

Turned to gcov2perl and followed the manual here (changed it to reflect my own example):

Creates a single gcov file in our case:

% gcov helloworld.c

Transform data to Devel::Cover’s format:

% gcov2perl helloworld.c.gcov

Create the report:

% cover

Open the report in your browser:

% open cover_db/coverage.html

first1.png

And by clicking the filename you get this report:

second1.png

The helloworld.c example is very simple, but it proves a point – that it actually works.

I am only scratching the surface of what can be done and I have not fallen into any pitfalls – everything worked fine and looks good, but I am sure it can become more difficult.

Have fun covering your C code and presenting in using a very nice Perl tool.

Leave a comment

1 Comments.

  1. Another response to the mail on the Xcode mailing list contained this link to an interesting article. Still the Devel::Cover solution is quite interesting, the article however might lift the solution described above into Xcode’s build process for automation.

    See: http://www.mactech.com/articles/mactech/Vol.24/24.03/Unittestingandanalysiscoverage/index.html

Leave a Reply


[ Ctrl + Enter ]