How to use MS code coverage tool in command line?(如何在命令行中使用 MS 代码覆盖工具?)
问题描述
我有以下 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
然后,我检测执行并生成 .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
- <代码>>启动 vsperfmon/coverage/output:mytestrun.coverage
- <代码>>你好.exe
- <代码>>vsperfcmd/shutdown
当您运行第 3 步时,您应该会在 vsperfmon.exe 中看到一些通知,提示 hello.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 代码覆盖工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在命令行中使用 MS 代码覆盖工具?
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- CString 到 char* 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
