6

I have the following C++ code.

#include <iostream>
using namespace std;

int testfunction(int input)
{
    if (input > 0) {
        return 1;
    }
    else {
        return 0;
    }
}

int main()
{
    testfunction(-1);
    testfunction(1);
}

I compiled it to get the execution

cl /Zi hello.cpp -link /Profile

Then, I instrument the execution and generated the .coverage binary.

vsinstr -coverage hello.exe
start vsperfmon -coverage -output:mytestrun.coverage
vsperfcmd -shutdown

When I open the coverage file in VS2010, I got nothing in its results.

enter image description here

What might be wrong? I followed the instructions in this post.

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
prosseek
  • 182,215
  • 215
  • 566
  • 871

1 Answers1

15

You need to run your program after the monitor starts:

  1. > vsinstr /coverage hello.exe
  2. > start vsperfmon /coverage /output:mytestrun.coverage
  3. > hello.exe
  4. > vsperfcmd /shutdown

When you run step 3, you should see some notification in vsperfmon.exe that hello.exe has started.

If you plan on doing multiple test runs, you only need to run steps 2-4. In other words, you only need to instrument your binary (step 1) once after it's built.

Chris Schmich
  • 29,128
  • 5
  • 77
  • 94
  • Zam. Why couldn't MS document it this easily? https://msdn.microsoft.com/en-us/library/dd299398(v=vs.90).aspx – granadaCoder Apr 28 '16 at 19:44
  • 2
    For future readers........here is a alternate solution to creating multiple .coverage files : http://stackoverflow.com/questions/415562/mstest-code-coverage/37005493#37005493 – granadaCoder May 03 '16 at 20:23
  • 1
    Great, now how do we use the coverage file? – Dan Apr 13 '18 at 03:09