Collecting code coverage in a child process

This tutorial describes how to collect code coverage in a child process of an application.

This tutorial covers the following:

    1. Using the launch dialog to specify the child process to monitor and the instance number of that child process.
    2. How to use the Coverage Validator user interface to collect code coverage in the child process.

Related tutorials:

Code coverage for a .Net Core application.
Code coverage for a .Net Core application child process.
Code coverage for a service.
Code coverage for a service child process.
Code coverage for an IIS ISAPI DLL.
Code coverage for ASP.Net with IIS.
Code coverage for ASP.Net with Web Development Server.

Native applications and mixed-mode applications

This tutorial applies to all native applications, .Net applications and to mixed-mode applications.

.Net Core Applications

If your application is written entirely in .Net Core, or your application is mixed-mode with the startup code written in .Net core you need to read a different tutorial, see the list of related tutorials above this.

Example Application and Child Process Application

Coverage Validator ships with an example application and an example child process launched by the application. These can be found in the  following directories in the Coverage Validator installation directory:

  • examples\nativeExample
  • examples\serviceWithAChildProcess\childProcess 

You need to build both of these projects. The easiest thing to do is to build the examples.sln.

Collecting code coverage in the child process

Now that you have the example projects build, we can start collecting code coverage data from the child process.

  1. Choose the Launch > Applications > Launch Application… option.
    Coverage Validator launch menu
  2. The Launch dialog is displayed.
    Coverage Validator Native and .Net launch dialog
  3. Click Browse… next to Application to Launch and choose the executable that is going to launch the process you want to start collecting code coverage from. You can also choose a batch file or a powershell script. For this tutorial we’re going to start examples\nativeExample\Release10_0_x64\nativeExample_x64.exe.
    Coverage Validator native and .Net launch dialog with native example application
  4. Now we need to specify which child processes will be launched by the parent process. Click Edit… next to Application to Monitor.
    Coverage Validator native and .Net edit application to monitor
    The Applications to Monitor dialog will be displayed.
    Memory Validator native and .Net applications to monitor dialog
  5. We need to add an application definition. Click Add…. The Application to Monitor dialog will be displayed.
    Memory Validator native and .Net application to monitor dialog
  6. To add an application click Add…. The Application and DLL dialog is displayed.
    Memory Validator native and .Net Application and DLL dialog
  7. Type the path to the child process executable or use the Browse… button to open a Microsoft file dialog to select the child process executable. For this tutorial we’re going to choose the child process executable: examples\nativeExample\Release10_0_x64\childProcess_x64.exe.  
    Coverage Validator native and .Net application and DLL dialog with child process
  8. Click OK to complete adding the child process definition. Repeat steps 6 and 7 to add as many child process definitions as you need for your process.
  9. When you have added all the child process definitions click OK to close the Application To Monitor dialog.
    For this tutorial we’re only adding one child process definition, so click OK.
  10. Click OK to close the Applications To Monitor dialog.
  11. If you examine the Application to Monitor field on the launch dialog you can see it now has some entries in addition to the name of the file we’re going to launch.
    Coverage Validator native and .Net application to monitor combo
  12. Choose the child process in the Application to Monitor field.
    Coverage Validator native and .Net application to monitor child process
  13. We’re going to monitor the first childProcess_x64.exe that is launched. This is the default, indicated by the 1 in the small combo below the Application to Monitor field. If you wanted to monitor the third childProcess_x64.exe that is launched you’d set this to 3. 
  14. Now that we’ve specified the process to launch and the child process we can start the Application to Launch.
    Click Launch….
    Coverage Validator starts the Application to Launch (in this tutorial that’s nativeExample_x64.exe).
  15. When nativeExample_x64.exe is running choose the Child Process menu then choose Start ChildProcess….
    Coverage Validator native and .Net child process
    The child process is started. In this tutorial that’s childProcess_x64.exe.
    For childProcess_x64.exe you’ll see a cmd prompt open, there will be a pause while the application runs, then it will close.
  16. Coverage Validator will instrument your applications’s child process and start collecting code coverage data.
  17. Code coverage data will be collected until the child process finishes executing.  For best results, we recommend closing the child process normally (do not kill it with TaskManager or TerminateProcess). 
  18. You can close the parent process whenever you want – Coverage Validator is not tracking it.
  19. When the child process finishes executing Coverage Validator will display the code coverage results.
    Coverage Validator native and .Net child process coverage results

How Do I Repeat This?

There are three method of repeating this.

  1. To repeat launching the parent process and monitoring the child process just click the relaunch button on the toolbar.

     

  2. You can open the launch dialog then double click on an entry in the list at the bottom of the dialog.
    Coverage Validator native and .Net relaunch application
  3. You can open the launch dialog then select an entry in the list at the bottom of the dialog, edit any settings on the dialog, then click Launch.

I need to collect code coverage in a grand child process or other descendant. How do I do that?

The method described above only works for child processes of a parent process.
 
If you have a process that is a descendent process deeper than a child process read this article about Loading Validator into an application.

I’m not getting any code coverage data. What can I do?

There are a few things to check.

  1. Data Collection
    Have you got data collection turned off?
    There is a Collect data from application check box on the launch dialog.
    There are also data collection on/off buttons on the main toolbar, and Start collecting data and Stop collecting data options on the File menu.
  2. Diagnostics
    Check the diagnostics tab. If the injection and data transport is working correctly Coverage Validator will have some data. Information on instrumentation failures will be on the diagnostic tab.
  3. Debug Information
    Check the debug information dialog. You can access this from the Tools > DLL Debug Information… menu. This dialog will tell you which DLLs have debug information and which do not. Any DLLs that don’t have debug information you’ll need to ensure that debug information is built for these DLLs and is findable.

Conclusion

You have learned how to launch an application and monitor a child process launched by that application, how to use Coverage Validator to monitor the application’s child process, and what to look at to diagnose errors if things don’t work first time.

 

 

Fully functional, free for 30 days