The Windows 2000 Device Driver Book(c) A Guide for Programmers
Authors: Baker A. Lozano J.
Published year: 2000
Pages: 64-66/156
Buy this book on amazon.com >>
< BACK    NEXT >
[oR]

Testing Driver Dispatch Routines

Even though a driver may be far from complete when only the DriverEntry, Unload, and Dispatch routines are present, significant code paths can be tested at this point. In particular, all of the following can be verified with a simple Win32 console program:

  • Opens and closes a handle to the device.

  • Supports Win32 I/O function calls that return successfully, even if zero byte transfers are specified.

  • Manages requests from multiple callers .

While the successful completion of these tests is hardly earth-shattering, it does form a tried-and-true recipe for driver authoring: Build a driver framework that is proven before adding hardware interaction.

Testing Procedure

The following procedure checks all the code paths through a driver's Dispatch routines:

  1. Write IRP_MJ_CREATE and IRP_MJ_CLOSE Dispatch routines for the driver.

  2. Test the driver with a simple Win32 console program that gets a handle to the device under test and then closes the handle.

  3. Write other Dispatch routines but ensure that all call IoCompeteRequest rather than starting any device operations.

  4. Enhance the Win32 test program to make ReadFile , WriteFile , and DeviceIoControl calls that exercise each driver's Dispatch routine. Alternatively, the test program can request zero-byte transfers.

  5. If a device is sharable , run several copies of the test program at once to be sure the driver works with multiple open handles.

  6. If a driver supports multiple physical devices, repeat the test with each device unit.

Sample Test Program

This is an example of a Win32 console test program that can be used to verify code paths through a driver's Dispatch routines.

#include <windows.h>
#include <stdio.h>

void main() {
     HANDLE hDevice;
     BOOL status;
     hDevice = CreateFile( "\.\LBK1" ... );
     :
     status = ReadFile( hDevice, ... );
     :
     status = WriteFile( hDevice, ... );
     :
     status = DeviceIoControl( hDevice, ... );
     :
     status = CloseHandle( hDevice );
}
< BACK    NEXT >
< BACK    NEXT  >
[oR]

Summary

Dispatch routines form the basic interface between a requestor and a driver. This chapter presented the framework for these functions and discussed the details for accessing the user 's buffers and other parameters. Read, Write, and DeviceIoControl requests can now be presented to the driver.

The next chapter begins the interface with the real device. The path from starting the device to register data transfer to interrupt handling is discussed.

< BACK    NEXT >
< BACK    NEXT >
[oR]

Chapter 8. Interrupt-Driven I/O

CHAPTER OBJECTIVES

  • How Programmed I/O Works

  • Driver Initialization and Cleanup

  • Writing a Start I/O Routine

  • Writing an Interrupt Service Routine (ISR)

  • Writing a DpcForIsr Routine

  • The Parallel Port

  • Parallel Port Loopback Driver

  • Testing the Parallel Port Loopback Driver

  • Summary

Some devices transfer data through registers, requiring continual CPU interaction. Such devices usually move small amounts of data at relatively infrequent intervals. For example, the mouse and keyboard transfer just a few bytes sporadically. Such devices remain idle for minutes (or hours) at a time and so are given the ability to interrupt the processor whenever data is available. This chapter explains how to write the data transfer routines for drivers of this kind of hardware.

< BACK    NEXT >
The Windows 2000 Device Driver Book(c) A Guide for Programmers
Authors: Baker A. Lozano J.
Published year: 2000
Pages: 64-66/156
Buy this book on amazon.com >>

Similar books on Amazon