<p>I have a very large code base that contains extensive unit tests (using CppUnit). <b>I need to work out what percentage of the code is exercised by these tests</b>, and (ideally) generate some sort of report that tells me on a per-library or per-file basis, how much of the code was exercised.</p>

<p>Here's the kicker: this has to run completely unnatended (eventually inside a continuous integration build), and has to be cross platform (well, WIN32 and *nix at least).</p>

<p>Can anyone suggest a tool, or set of tools that can help me do this? I can't change away from CppUnit (nor would I want to - it kicks ass), but otherwise I'm eager to hear any recommendations you might have.</p>

<p>Cheers,</p>

[{'answer_id': 33071, 'author': 'Justin Standard', 'author_id': 92, 'author_profile': 'https://Stackoverflow.com/users/92', 'pm_score': 5, 'selected': True, 'text': '<h3>Which tool should I use?</h3>\n<p>This <a href="http://web.archive.org/web/20090527141110/http://www.kimbly.com/blog/000331.html" rel="noreferrer">article describes</a> another developers frustrations searching for C++ code coverage tools.  The author\'s final solution was <a href="http://www.bullseye.com/" rel="noreferrer">Bullseye Coverage</a>.</p>\n<p><strong><a href="http://www.bullseye.com/" rel="noreferrer">Bullseye Coverage</a> features:</strong></p>\n<ul>\n<li><a href="http://www.bullseye.com/platform.html" rel="noreferrer">Cross Platform Support</a> (win32, unix, and embedded), (supports linux gcc compilers and MSVC6)</li>\n<li><a href="http://www.bullseye.com/usability.html" rel="noreferrer">Easy to use</a> (up and running in a few hours).</li>\n<li><a href="http://www.bullseye.com/measurementTechnique.html" rel="noreferrer">Provides &quot;best&quot; metrics</a>: Function Coverage and Condition/Decision Coverage.</li>\n<li>Uses source code instrumentation.</li>\n</ul>\n<p>As for hooking into your continuous integration, it depends on which CI solution you use, but you can likely hook the instrumentation / coverage measurement steps into the make file you use for automated testing.</p>\n<hr />\n<h3>Testing Linux vs Windows?</h3>\n<p>So long as all your tests run correctly in both environments, you should be fine measuring coverage on one or the other.  (Though Bullseye appears <a href="http://www.bullseye.com/platform.html" rel="noreferrer">to support both platforms</a>).  But why aren\'t you doing continuous integration builds in both environments??  If you deliver to clients in both environments then you <em>need</em> to be testing in both.</p>\n<p>For that reason, it sounds like you might need to have two continuous build servers set up, one for a linux build and one for a windows build.  Perhaps this can be easily accomplished with some virtualization software like <a href="http://www.vmware.com/" rel="noreferrer">vmware</a> or <a href="http://www.virtualbox.org/" rel="noreferrer">virtualbox</a>.  You may not need to run code coverage metrics on both OSs, but you should definitely be running your unit tests on both.</p>\n'}, {'answer_id': 33281, 'author': 'Imbue', 'author_id': 3175, 'author_profile': 'https://Stackoverflow.com/users/3175', 'pm_score': 3, 'selected': False, 'text': '<p>If you can use <a href="http://gcc.gnu.org/onlinedocs/gcc/index.html" rel="noreferrer">GNU GCC</a> as your complier, then the <a href="http://gcc.gnu.org/onlinedocs/gcc/Gcov.html" rel="noreferrer">gcov</a> tool works well. It\'s very easy to fully automate the whole process.</p>\n'}, {'answer_id': 34171, 'author': 'Thomi', 'author_id': 1304, 'author_profile': 'https://Stackoverflow.com/users/1304', 'pm_score': 0, 'selected': False, 'text': "<p>I guess I should have specified the compiler - we're using gcc for Linux, and MSVC 6 (yeah I know, it's old, but it works (mostly) for us) for WIn32.</p>\n\n<p>For that reasons, gcov won't work for our Win32 builds, and Bullseye won't work for our Linux builds.</p>\n\n<p>Then again maybe I only need coverage in one OS...</p>\n"}, {'answer_id': 1003818, 'author': 'Jeremy Mayhew', 'author_id': 123240, 'author_profile': 'https://Stackoverflow.com/users/123240', 'pm_score': 2, 'selected': False, 'text': '<p>If you are using the GCC toolchain, gcov is going to get you source, functional, and branch coverage statistics.  gcov works fine for MinGW and Cygwin.  This will allow you to get coverage statistics as well as emitting instrumented source code that allows you to visualize unexecuted code.</p>\n\n<p>However, if you really want to hit it out of the park with pretty reports, using gcov in conjunction with <a href="http://ltp.sourceforge.net/coverage/lcov.php" rel="nofollow noreferrer">lcov</a> is the way to go.  lcov will give you bar reports scoped to files and directories, functional coverage statistics, and color coded source file browsing to show coverage (green means executed, red means not...).</p>\n\n<p>lcov is easy on Linux, but may require some perl hacking on Cygwin.  I personally have had some problems executing the scripts (lcov is implemented in perl) on Windows.  I\'ve gotten a hacked up version to work, but be forewarned.</p>\n\n<p>Another approach is doing the gcov emit on windows, and doing the lcov post processing on Linux, where it will surely work out of the box.</p>\n'}, {'answer_id': 1355333, 'author': 'Ira Baxter', 'author_id': 120163, 'author_profile': 'https://Stackoverflow.com/users/120163', 'pm_score': 2, 'selected': False, 'text': '<p>Check out our <a href="http://www.semdesigns.com/Products/TestCoverage/CppTestCoverage.html" rel="nofollow noreferrer">SD C++ Test Coverage</a> tool. It can be obtained for GCC, and for MSVC6.</p>\n\n<p>It has low overhead probe data collection, a nice display of coverage data overlayed on your code, and complete report generation with rollups on coverage across the method/class/file/directory levels.</p>\n\n<p>EDIT: Aug 2015: Now supports GCC5 and various MS dialects through Visual Studio 2015.   To use these tools under Linux, you need Wine, but there the tools provide Linux-native sh scripting and a Linux/Java based UI, so the tool feels like a native Linux tool there.</p>\n'}]
['https://Stackoverflow.com/questions/33042', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1304/']