Being Cellfish

Stuff I wished I've found in some blog (and sometimes did)

Native C++ Code Coverage reports using Visual Studio 2008 Team System

Change of Address
This blog has moved to

Native C++ Code Coverage reports using Visual Studio 2008 Team System

Rate This
  • Comments 18

The code coverage tool in Visual Studio 2008 Team System is quite easy to use from within the IDE unless you want code coverage for your native C++ code. In order to generate a code coverage report for native C++ you have to use the command line tools. This is how you do it:

  1. First of all your project must be compiled using the /PROFILE link option. If you bring up your project properties it can be found here:
    Configuration Properties -> Linker -> Advanced -> Profile
  2. The profiler tools can then be found in the following directory:
    C:\Program Files\Microsoft Visual Studio 9.0\Team Tools\Performance Tools
  3. You need to add some instrumentation code to your EXE or DLL file and that is done with this command:
    vsinstr.exe <YOUR_EXE_OR_DLL> /COVERAGE
    This will copy the original file to an ".orig"-file and create a new file with the original name that contains instrumentation code needed to gather coverage data.
  4. Now start the listener with this command:
  5. Now run your EXE or some test suite that uses the file you want to calculate coverage for.
  6. The listener started in step four (4) will not stop by it self once your test suite is finished so you have to stop in manually using this command (from a second command prompt):
    VSPerfCmd.exe /SHUTDOWN
  7. When the listener has stopped you just drag-n-drop the created ".coverage"-file into Visual Studio and you can view the results.
  • I am using VS 2010. Code covergage report shows blocks covered and their percentage. Is there anyway I can see lines of code covered and their percentage in the report.I opened the report in VS 2010.

  • @Anand; Not sure if lines are available for C++ coverage. Doesn't really matter since you can have lines with a lot of statements or spreat a statement over several lines. Blocks is really the only kind of useful number anyway for you.

    I'm sorry StackOverflow did not show anything because I really don't have an idea what could be wrong of all DLLs are instrumented but still not showing coverage. Maybe you can try instrumenting one DLL/EXE at a time and get coverage for each of them in separate runs. If that doe snot give you DLL coverage numbers I suspect the EXE is using DLLs from a different location than you think.

  • thx,

    but my .coverage generate an empty result, which doesn,t use any binary file.

Page 2 of 2 (18 items) 12