Skip to main content

If you don't have an IBM ID and password, register here.

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

Simulate devices using DSF

Getting started with the Linux kernel Device Simulator Framework

Martin Ridgeway (mridge@us.ibm.com), Software Engineer, IBM
Martin Ridgeway is a team lead on the Linux Test Project at the IBM Linux Technology Center. Some of the projects he has worked on over the past year include the Linux Test Project and kernel code coverage analysis. He can be reached at mridge@us.ibm.com.

Summary:  The Device Simulator Framework (DSF) provides an easy-to-use ioctl interface to all your devices, real or imagined. Intended for experienced kernel and device driver software developers, DSF makes it easier to debug and test device code that would otherwise be difficult to simulate or recreate.

Date:  23 Mar 2004
Level:  Advanced

Comments:  

Creating test cases for the Linux kernel is pretty straightforward; usually either very specific or very broad coverage is desired. When testing in userspace, however, it can be very difficult to test for special conditions. Things like branch code that is seldom executed, non-existent devices, and error path code are hard to test.

The Device Simulator Framework (DSF) addresses this problem area, with a kernelspace-to-userspace ioctl interface that allows the test case developer to execute specific targeted areas of the kernel. DSF is especially helpful in executing device driver kernel code where the device may not be present. While DSF is not a replacement for actual device testing, it can greatly assist you in debugging and testing driver code.

DSF can also speed test case development, since you aren't forced to learn the ioctl interface for user/kernel space communication.

Currently, only the later release Linux 2.5.xx through the current 2.6.xx kernels are supported.

Getting started

To begin, I recommend that you download the entire Linux Test Project (LTP) test suite, which includes the DSF code. The Linux Test Project is a joint project with IBM's Linux Technology Center (LTC) and several other organizations (see Resources for a link).

After you extract the archive, you will find the user/kernel template test code in the testcases/kernel/device-drivers/dev_sim_framework directory. Build the LTP test suite and install it, and then change into the DSF directory. Once in the DSF directory, you will see both kernel_space and user_space directories. The respective kernel module and user space files reside in these directories. Change into these directories and run make to build the templates.

An ioctl request

The ioctl function manipulates the underlying device parameters of special files. In particular, many operating attributes of character special files (for example, terminals) can be controlled with ioctl requests.


Using the templates

Once you build the templates, you can load the kernel module with insmod or modprobe prior to executing the userspace code. Change into the user_space directory and execute the userspace code. The user code will run and return very quickly since the template simply communicates with the registered kernel module and returns.

Modifying the template to execute the desired kernel code is relatively straightforward. However, some knowledge of kernel programming is required. The functions defined within the EXPORT_SYMBOL tags are open to all kernel code and can be called directly from your kernel modules without kernel code modification. You can also manually modify the kernel source to export additional functions for test after rebuilding and rebooting the new kernel.


DSF in use

The following code is an example of how to implement a device type test:


Listing 1. Dummy device code

   switch(cmd) {
     case LTP_OPTION1: rc = test_option(); break;
     case PCI_ENABLE:  rc = pci_enable(); break;
     default:
      printk("Mismatching ioctl command\n");
                           break;
           }

   .
   .
   .

   /*
   * pci_enable
   *  enable a pci device so that it may be used in
   *  later testing in the user test program
   */

   static int pci_enable() {
   int rc = 0;
   struct pci_dev *dev = ltp_pci.dev;

   /* check if can enable the device pointer */
   if(!dev) {
     printk("tpci: dev is NULL\n");
     return 1;
   }

   if( pci_enable_device(dev) ) {
     printk("tpci: failed to enable pci device\n");
     rc = 1;
   }

   else {
     printk("tpci: enabled pci device\n");
     rc = 0;
   }

   return rc;
   }

This example enables a "dummy" PCI device that calls the pci kernel APIs. The dummy device can also be used for other tests.


Summary

If you are a Linux kernel and device driver developer with a moderate level of experience, the benefit of using the DSF template is twofold: You can develop test cases faster and more consistently since the DSF template can be used for many different tests. Also, you can target specific areas of the kernel for execution, which eliminates the typical userspace test case hit-or-miss approach to executing kernel code.

The goal of the Linux Test Project is to help device driver developers standardize device unit tests and increase device driver stability in the Linux kernel. With that in mind, please do feel free to contact me at mridge@us.ibm.com with your experiences using DSF, or to participate in the LTP mailing list (see Resources for a link).


Resources

About the author

Martin Ridgeway is a team lead on the Linux Test Project at the IBM Linux Technology Center. Some of the projects he has worked on over the past year include the Linux Test Project and kernel code coverage analysis. He can be reached at mridge@us.ibm.com.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in

If you don't have an IBM ID and password, register here.


Forgot your IBM ID?


Forgot your password?
Change your password


By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)


By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux
ArticleID=11384
ArticleTitle=Simulate devices using DSF
publish-date=03232004
author1-email=mridge@us.ibm.com
author1-email-cc=youngt01@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).