Excluding Code Coverage for a Statically Linked Library

This tutorial demonstrates using Coverage Validator to only collect code coverage for a specific DLL.

We’re going to use the nativeExample.exe example application that ships with Coverage Validator.

We are going to prevent collecting code coverage for the staticLibD library. Because it is not possible to specify a static library by a compilation until like an .EXE or .DLL we specify the static library components by source code. In this example we are going to identify the source by the directory that holds the source code.

  • This tutorial requires that you have built the examples\examples.sln solution. This will create the nativeExample application and various supporting DLLs.
    If you don’t have Visual Studio you can download prebuilt examples by running the Settings menu > First Run Settings Wizard… then navigating to the Build example projects page and clicking Download….
  • Open the settings dialog by clicking the tools icon on the toolbar.
    Coverage Validator settings toolbar
  • We need to reset all the settings (just in case you have conflicting settings from a previous tutorial). Click Reset All.
  • Select the Source Files Filter tab.
  • Select the Don’t hook the files in the list for code coverage radiobox.
  • Click Add Dir… then in the directory chooser select <Coverage Validator install dir>\examples\staticLibD then click Ok.
    Coverage Validator, exclude source files filter
  • Click OK to close the settings dialog.
  • Launch the sample application. Click on the launch icon on the toolbar.
    Coverage Validator launch toolbar
  • The Launch Application or Service dialog is displayed.
    Coverage Validator launch application or service dialog
  • The launch dialog is displayed.
  • Click Browse… and select <Coverage Validator install dir>\examples\nativeExample\ReleaseNonLinkXX_X_x64\nativeExample_x64.exe where XX_X represents the version of Visual Studio you have. If you’re using the prebuilt versions choose 10_0 for XX_X.
    Coverage Validator launch native application dialog
  • Click Launch.
  • The nativeExample_x64.exe is launched. 
  • Choose some menu options on the Colour and Help menus. Notice that code coverage data is collected.
  • On the Test menu, choose Load Library….
  • Choose dllAdependentOnB_x64.dll in the file chooser.
  • The DLL is loaded and a function inside the DLL is called via GetProcAddress(). Code coverage is collected for the other DLLs that load when dllADependentOnB.dll loads. These DLLs are dllBdependentOnC.dll and dllC.dll. Notice that no code coverage is collected for the staticLibD.lib library that is linked dllC_x64.dll.
  • On the Test menu, choose Free Library….
  • The DLL is unloaded.
  • Choose some menu options on the Colour and Help menus. Notice that code coverage data is collected.
  • Close the application.
  • In the final coverage data if we examine the DLLs tab we can see results for nativeExample_x64.exe, dllBDependentOnC_x64.dll and dllC_x64.dll.
    Coverage Validator, exclude statically linked library results

Alternate options

In the above example we configured just one directory using Add Dir….

There are multiple methods for configuring which source files to exclude collecting code coverage.

  • If you know the name of the directory you don’t want to get code coverage for, click Add Dir… then select the directory from the directory chooser.
  • If you want to add one source file at a time, click Add File… and choose the source file. Repeat as needed.
  • If you want to type the source file name or directory name directly into the list, click Add… then type the name. Click outside the text field to complete the edit, or escape to cancel.

Conclusion

You have learned how to configure Coverage Validator to collect code coverage for an application while ignoring all code for a statically linked library.

Fully functional, free for 30 days