Getting Code Coverage for a Statically Linked Library

This tutorial demonstrates using Coverage Validator to only collect code coverage for a statically linked library.

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

We are going to collect 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 Only 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, source files filter, include source files
  • 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 no 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(). When dllAdependentOnB_x64.dll loads it causes two other DLLs to load dllBDependentOnC_x64.dll and dllC_x64.dll. Notice that code coverage for these DLLs are not collected, but code coverage is collected for the files in the staticLibD directory (staticLibD.lib is linked to 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 no code coverage data is collected.
  • Close the application.
  • In the final coverage data if we examine the DLLs tab we can see code coverage results for only for dllAdependentOnB_x64.dll.
    Coverage Validator, include statically linked library code coverage 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 collect code coverage for.

  • If you know the name of the directory you 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 a statically linked library, ignoring all other code in the application.

Fully functional, free for 30 days