Specifications

Driver Testing and Debugging
15-3
a file or to a remote terminal. You can also write cmn_err statements to the console, but
massive amounts of statements to the console severely slows system speed.
Calculations and cmn_err statements that are for debugging and other testing should be
coded within conditional compiler statements in the driver. This saves you the task of
removing extraneous code when you release the driver for production, and makes that
debugging code readily available should you need to troubleshoot the driver after it is in
the field. You can provide separate code for different types of testing to which the driver is
subjected. For instance, you might use TEST for functionality testing, PERFON for mini-
mal performance testing, and FULLPERF for full performance monitoring. Each of the
testing options is then defined in the code as either 0 (turned off) or 1 (turned on), as illus-
trated below.
Note that minimal performance monitoring is turned off, which is appropriate because full
performance monitoring is turned on.
Debug code is then enclosed within #if TEST and #endif. When the code is compiled
with the -DTEST option, the test code executes.
The testing procedure can be refined further by using flags within the conditionally-com-
piled code. Then, when TEST is turned on, you can specify the exact sort of testing
without recompiling and reinstalling the driver. The flags should use the driver prefix. For
instance, the following code sets three flags for testing the intr(D2) interrupt routine,
the strategy(D2) routine, and driver performance:
#if TEST
int xx_intpr = 1;
int xx_stratpr = 1;
int xx_perfpr = 1;
#else
int xx_intpr = 0;
int xx_stratpr = 0;
int xx_perfpr = 0;
#endif
You can change the flags by recompiling and reinstalling the driver, or you can change
them in the running system either with a kernel debugger or by writing a small program to
use getksym(2) and /dev/kmem.
/* TEST = 1 for functionality testing
*/
#define TEST 1
/*
* PERFON = 1 for minimal performance monitoring
*/
#define PERFON 0
/*
* FULLPERF = 1 for full performance monitoring
*/
#define FULLPERF 1