Setting up Windows kernel driver coverage

This section describes how to setup Coco to measure code coverage in a WindowsKernel driver. This setup was tested with the Kernel-Mode Driver Framework (KMDF) and the target machine was a Hyper-V virtual machine.

Create an option file

For this example it is convenient to use the --cs-option-file option, so various Coco parameters don't need to be given as command line parameters in the options of Visual Studio. Read more about this option in Miscellaneous. Create a text file and add the following lines:

--cs-on
--cs-memory-pool=64000
--cs-architecture=Kernel
--cs-condition
--cs-line
--cs-function
--cs-hit
--cs-coverage-save-function=coverage\_init
--cs-trigger-function=DriverEntry

Add the following line with the path to the downloaded coverage.h file:

--cs-custom-library-source=Path_to_Coco\samples\windows-kernel-coverage\coverage.h

Note: If the DRIVER_INITIALIZE object of your driver is still named DriverEntry, you do not have to change anything in the parameters listed above. Otherwise you would have to rename the switch --cs-trigger-function=<DriverEntry> to the name of your driver's DRIVER_INITIALIZE object.

Setup your Visual Studio

Add the following line --cs-option-file=<path to option file> to the Visual Studio Settings under Project Settings > C/C++ > Commandline > Additional options and Project Settings > Linker > Commandline > Additional options.

Change the <path to option file> to point to the Coco options file that you created earlier.

Using the console application cocodump

Build the console application cocodump.exe (found in %SQUISHCOCO%\samples\windows-kernel-coverage) with Visual Studio in the Release configuration and transfer it to the target machine.

cocodump.exe executable needs to be executed with administrator rights. The usage of the cocodump.exe tool is as following:

cocodump.exe <drivername> <outputfile>

You can run this application on the target machine once you installed the driver.

Note: To confirm that coverage instrumentation is working, use the winobj tool to verify that there is an element with the name coco-<drivername> in the Device and the /??/ folder.

Use the cocodump.exe application with the name of your driver.

For example, to dump the execution data from your driver with the name mydriver into the file C:\mydriver.csexe you would need to call:

cocodump.exe mydriver "C:\mydriver.csexe"

Confirm that the file has been created and import it into the main .csmes file in your project with the CoverageBrowser.

Check the command line output of the cocodump.exe tool for any error messages.

If you have further question or problems, contact froglogic support.

Coco v7.1.0 ©2024 The Qt Company Ltd.
Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.