如何在命令行中使用MS代码覆盖工具? [英] How to use MS code coverage tool in command line?
问题描述
我有以下C ++代码。
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);
}
我编译它以获得执行
cl /Zi hello.cpp -link /Profile
$ b b
然后,我执行并生成.coverage二进制文件。
Then, I instrument the execution and generated the .coverage binary.
vsinstr -coverage hello.exe
start vsperfmon -coverage -output:mytestrun.coverage
vsperfcmd -shutdown
在VS2010中的覆盖文件,我的结果没有任何东西。
When I open the coverage file in VS2010, I got nothing in its results.
可能有什么问题?
我按照此帖。
What might be wrong? I followed the instructions in this post.
推荐答案
您需要在监视器启动后运行程序:
You need to run your program after the monitor starts:
-
> vsinstr / coverage hello.exe
-
> start vsperfmon / coverage /output:mytestrun.coverage
-
> hello.exe
-
> vsperfcmd / shutdown
> vsinstr /coverage hello.exe
> start vsperfmon /coverage /output:mytestrun.coverage
> hello.exe
> vsperfcmd /shutdown
运行步骤3时,您应该在vsperfmon.exe中看到一些通知.exe已启动。
When you run step 3, you should see some notification in vsperfmon.exe that hello.exe has started.
如果您打算进行多个测试运行,则只需运行步骤2-4。换句话说,你只需要在生成二进制文件(步骤1)后对其进行一次测试。
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.
这篇关于如何在命令行中使用MS代码覆盖工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!