This tutorial describes how to collect code coverage in an IIS ISAPI DLL.
This tutorial covers the following:
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.
This tutorial applies to all native ISAPI DLLs and to mixed-mode ISAPI DLLs that uses the native Win32 services API.
Coverage Validator ships with an example ISAPI DLL in the examples\isapiExample folder in the Coverage Validator installation directory.
The ISAPI DLL has already been modified to use the NT Service API. In this tutorial we’ll describe the modification you would make to the ISAPI DLL to make it work correctly with Coverage Validator.
The NT Service API is a simple API that allows you to load the Coverage Validator profiling DLL and start the process of collecting code coverage.
The API also includes some debugging functions to help provide debugging information via log files (the only way to get data out of an ISAPI DLL without a connection to the Coverage Validator user interface).
The purpose of attachToCoverageValidator() is to use the NT Service API to instrument the ISAPI DLL with Coverage Validator.
// code to load Coverage Validator into the IIS process for this ISAPI
// this assumes the ISAPI is in C:\testISAPIWebsite\
#include "..\..\svlCVStubService\svlCVStubService.h"
#include "..\..\..\svlCommon\svlServiceError.h"
static void attachToCoverageValidator()
{
svlCVStub_setLogFileName(L"C:\\testISAPIWebsite\\svl_CV_log.txt");
svlCVStub_deleteLogFile();
SVL_SERVICE_ERROR errCode;
#ifdef IS6432
// x86 with x64 GUI
errCode = svlCVStub_LoadCoverageValidator6432();
#else //#ifdef IS6432
// x86 with x86 GUI
// x64 with x64 GUI
errCode = svlCVStub_LoadCoverageValidator();
#endif //#ifdef IS6432
if (errCode != SVL_OK)
{
DWORD lastError;
lastError = GetLastError();
svlCVStub_writeToLogFileW(L"Coverage Validator load failed. \r\n");
svlCVStub_writeToLogFileLastError(lastError);
svlCVStub_writeToLogFile(errCode);
svlCVStub_dumpPathToLogFile();
}
else
{
svlCVStub_writeToLogFileW(L"Coverage Validator load success. \r\n");
errCode = svlCVStub_StartCoverageValidatorForIIS();
if (errCode != SVL_OK)
{
DWORD lastError;
lastError = GetLastError();
svlCVStub_writeToLogFileW(L"Starting Coverage Validator failed. \r\n");
svlCVStub_writeToLogFileLastError(lastError);
svlCVStub_writeToLogFile(errCode);
}
svlCVStub_writeToLogFileW(L"Finished starting Coverage Validator\r\n");
}
}
Now that the NT Service API has been implemented in your service, we can start collecting memory allocation data from the service.
If errors are found you will be presented with a dialog box specific to the error so that you can correct the error before starting the web browser.
To finish collecting code coverage, you need to stop IIS.
If you had selected Stop IIS when web browser is closed on the Monitor IIS and ISAPI dialog then you have nothing to do.
Otherwise, choose Launch > Services > Stop IIS
Coverage Validator will collect code coverage through the service shutdown procedure and then present you with the complete code coverage data.
There are a few things to check.
svlCVStub_setLogFileName(SZLOGFILENAME);
You have learned how to add the NT Service API to an ISAPI DLL, how to use Coverage Validator to monitor ISS and ISAPI, and what to look at to diagnose errors if things don’t work first time.