| |||
Verifying a toy driver with SATABS This page describes how to verify a small toy example with SATABS. The example contains some code snippets from a Linux 2.0 driver that gets reference counting wrong. The size of the program (approximately 200 lines of code) isn't very realistic, but the example is a good starting point for somebody who wants to learn using SATABS.
Prior to Linux 2.2, Linux driver needed to maintain a usecount
for the devices they manage. As soon as a device driver is
loaded, the corresponding device can be accessed through a
special file in the file system, typically located in the
Testing such a driver typically involves writing a
test harness that simulates the behaviour of the
program that calls the driver's
do
{
random = nondet_uchar ();
assume (0 <= random && random <= 3);
switch (random)
{
case 1:
rval = mydriver_open (&inode, &my_file);
if (rval == 0)
lock_held = TRUE;
break;
case 2:
assume (lock_held);
count = mydriver_read (&my_file, buffer, BUF_SIZE);
break;
case 3:
mydriver_release (&inode, &my_file);
lock_held = FALSE;
break;
default:
break;
}
}
while (random || lock_held);
When
int mydriver_open (struct inode *inode, struct file *filp)
{
assert (MAJOR (inode->i_rdev) == dummy_major);
MOD_INC_USE_COUNT;
if (locked)
return -1;
locked = TRUE;
return 0; /* success */
}
This bug might have gone unnoticed by traditional unit testing (unless the test engineer, following his intuition, had specified a test-case that tests exactly this very sequence of calls to the driver API).
A more detailed description of this example is
given in our
| |||
| |||
Example: Reference Counting in a Linux Driver
| |||
| |||
Requirements | |||
Instructions
|