如何在命令行中使用 MS 代码覆盖工具?

2023-03-09C/C++开发问题
1

本文介绍了如何在命令行中使用 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:

  1. <代码>>vsinstr/coverage hello.exe
  2. <代码>>启动 vsperfmon/coverage/output:mytestrun.coverage
  3. <代码>>你好.exe
  4. <代码>>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 代码覆盖工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&amp;()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6