您的位置:首页 > 编程语言 > C语言/C++

使用VS2008 Team System对C++本地代码进行Code Coverage Report

2014-09-03 09:56 621 查看
http://blogs.msdn.com/b/cellfish/archive/2008/11/16/native-c-code-coverage-reports-using-visual-studio-2008-team-system.aspx

The code coverage tool in Visual Studio 2008 Team System is quite easy to use from within the IDE unless you want code coverage for your native C++ code. In order to generate a code coverage report for native C++ you have to use the command line tools. This
is how you do it:

First of all your project must be compiled using the /PROFILE link option. If you bring up your project properties it can be found here:

Configuration Properties -> Linker -> Advanced -> Profile
The profiler tools can then be found in the following directory:

C:/Program Files/Microsoft Visual Studio 9.0/Team Tools/Performance Tools
You need to add some instrumentation code to your EXE or DLL file and that is done with this command:

vsinstr.exe <YOUR_EXE_OR_DLL> /COVERAGE

This will copy the original file to an ".orig"-file and create a new file with the original name that contains instrumentation code needed to gather coverage data.
Now start the listener with this command:

VSPerfMon.exe /COVERAGE /OUTPUT:<REPORT_FILE_NAME>
Now run your EXE or some test suite that uses the file you want to calculate coverage for.
The listener started in step four (4) will not stop by it self once your test suite is finished so you have to stop in manually using this command (from a second command prompt):

VSPerfCmd.exe /SHUTDOWN
When the listener has stopped you just drag-n-drop the created ".coverage"-file into Visual Studio and you can view the results.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐