Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch running of VS code coverage tools

I came up a batch file to generate code coverage file as is written in this post.

cl /Zi hello.cpp -link /Profile
vsinstr -coverage hello.exe
start vsperfmon /coverage /output:run.coverage
hello
vsperfcmd /shutdown

However, I got this error message when I run the batch file.

enter image description here

I had to run vsperfcmd /shutdown manually to finish it. What might be wrong?

like image 330
prosseek Avatar asked Feb 10 '11 15:02

prosseek


People also ask

How do you run code coverage in VS code?

On the Test menu, select Analyze Code Coverage for All Tests. You can also run code coverage from the Test Explorer tool window. Show Code Coverage Coloring in the Code Coverage Results window. By default, code that is covered by tests is highlighted in light blue.

Which tool is used for code coverage?

Code coverage tools are available for many programming languages and as part of many popular QA tools. They are integrated with build tools like Ant, Maven, and Gradle, with CI tools like Jenkins, project management tools like Jira, and a host of other tools that make up the software development toolset.

How do I track code coverage?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

Does Visual Studio code have code coverage?

In Visual Studio, to use the code coverage tool, you right click on a test in the Test Explorer and then choose Analyze Code Coverage for Selected Test. This would look at the code paths for this one unit test. Typically, you run code coverage on the entire project to verify that all your code paths are being run.


1 Answers

This is just a timing issue.

The start vsperfmon /coverage /output:run.coverage command starts up vsperfmon.exe in a separate process.

Concurrently, your script goes on to run hello. If hello is a really simple program, it is possible that it executes and completes before vsperfmon.exe is running and fully initialized. If your script hits vsperfcmd /shutdown before the monitor is up and running, you will get the error you're showing.

vsperfcmd is just a controller/launcher for vsperfmon, so you can use that exclusively in your batch file:

cl /Zi hello.cpp -link /Profile
vsinstr -coverage hello.exe
vsperfcmd /start:coverage /output:run.coverage
hello
vsperfcmd /shutdown

In this case, the first call to vsperfcmd will block until the monitor is up and fully running.

like image 54
Chris Schmich Avatar answered Oct 14 '22 14:10

Chris Schmich