⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testing dd.htm

📁 What is this ``device driver stuff anyway? Here s a very short introduction to the concept.
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<a name="nx_id_528"></a>
<a href="#co_id_86_rtn_8">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_9"></a>
Writes 100 bytes of data to
<tt>/dev/none</tt>.
The kernel invokes
<tt>nonewrite</tt>
because the file descriptor
<tt><var>d</var></tt>
is associated with a special file.
The
<tt>nonewrite</tt>
interface counts these characters.
<a href="#co_id_86_rtn_9">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_10"></a>
Calls the
<tt>printf</tt>
interface to display on the console terminal a message that indicates that
<tt>nonewrite</tt>
wrote 100 bytes.
<a href="#co_id_86_rtn_10">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_11"></a>
Reads the count of characters written to the device now.
The count should be 100 higher than it was in the previous section of
code.
The
<tt>noneioctl</tt>
interface is used exactly the same as it was to get the initial count.
<a href="#co_id_86_rtn_11">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_12"></a>
Calls the
<tt>printf</tt>
interface to display on the console terminal the number of bytes.
<a href="#co_id_86_rtn_12">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_13"></a>
Clears the count of characters written to the
<tt>NONE</tt>
device.
The
<tt>DN_CLRCOUNT</tt>
macro accomplishes this task.
This time, no data is returned by the device driver, so the kernel
does not copy any data back to the test program.
All three arguments are passed to the
<tt>ioctl</tt>
system call for the sake of correctness.
When this
<tt>ioctl</tt>
call returns, the test program expects the current count
to be the value zero (0).
<a href="#co_id_86_rtn_13">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_14"></a>
Calls the
<tt>printf</tt>
interface to display the message ``set count'' on the console terminal.
<a href="#co_id_86_rtn_14">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_15"></a>
To determine if the previous code cleared the count to zero (0),
the test
program reads the characters from the
<tt>NONE</tt>
device again.
The
<tt>printf</tt>
interface is used to display the count.
<a href="#co_id_86_rtn_15">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_16"></a>
One design goal for the
<tt>/dev/none</tt>
device driver is that it should always return EOF on read operations.
The test program checks this action by trying to read 100 bytes from the
device.
If the design goal was met, the
<tt>read</tt>
system call should return zero (0) bytes.
<p>
<br>
The test program passes three arguments to the
<tt>read</tt>
system call:
</p><ul>
<p></p><li>
The first argument is the file descriptor.
<p></p></li><li>
The second argument points to where the data is stored.
<p></p></li><li>
The final argument tells how many bytes to read, in this example 100
bytes.
</li></ul><p>
</p><p>
As discussed previously, the kernel notices that the file descriptor
<tt><var>d</var></tt>
is associated with a device and finds the
<tt>dsent</tt>
entry for the device's
<tt>read</tt>
interface,
<tt>noneread</tt>.
The kernel calls
<tt>noneread</tt>
to service the read request.
The number of bytes successfully read is returned by the
<tt>read</tt>
system call.
<a href="#co_id_86_rtn_16">[Return to example]</a>
</p><p></p></li><li>
<a name="co_id_86_17"></a>
The
<tt>printf</tt>
interface prints the number of bytes that were read.
<a href="#co_id_86_rtn_17">[Return to example]</a>
<p></p></li><li>
<a name="co_id_86_18"></a>
The test program exits and the kernel automatically calls the
<tt>noneclose</tt>
interface. 
<a href="#co_id_86_rtn_18">[Return to example]</a>
</li></ol><p>
The following shows the output from a sample run of the test program,
which verifies that the driver is working correctly:
</p><p>
</p><pre>saw 0 bytes
wrote 100 bytes
saw 100 bytes
set count
saw 0 bytes
was able to read 0 bytes
</pre>
<p>
<a name="DecidRigorousTest"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="testing%20DD_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="testing%20DD_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#TestDevDrv"><img src="testing%20DD_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#WrtngTestProg"><img src="testing%20DD_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<a href="#HintsforTrackProblems"><img src="testing%20DD_files/NEXT.GIF" alt="[Next Section]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut16.html"><img src="testing%20DD_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="testing%20DD_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="testing%20DD_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h2>
11.2&nbsp;&nbsp;&nbsp;&nbsp;Expanding the Test Program
</h2>
<p>
You can expand the test program for the
<tt>/dev/none</tt>
device driver to do even more complete testing.
For example, the test program could check the character count between
each of several writes.
</p><p>
Because
<tt>/dev/none</tt>
is a simple driver, the test program is relatively
straightforward.
More complicated drivers require more complicated test programs, but the
strategy is the same: for each interface you provide in the driver, test it
independently from the other interfaces.
<a name="HintsforTrackProblems"></a>
</p><p></p><hr><p align="center">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/Digital_UNIX_Bookshelf.html"><img src="testing%20DD_files/BOOKSHELF.GIF" alt="[Return to Library]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/TOC.html"><img src="testing%20DD_files/TOC.GIF" alt="[Contents]" border="0"></a>
<a href="#TestDevDrv"><img src="testing%20DD_files/REW.GIF" alt="[Previous Chapter]" border="0"></a>
<a href="#DecidRigorousTest"><img src="testing%20DD_files/PREV.GIF" alt="[Previous Section]" border="0"></a>
<img src="testing%20DD_files/BLANK.GIF" border="0">
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut16.html"><img src="testing%20DD_files/FF.GIF" alt="[Next Chapter]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/INDEX.html"><img src="testing%20DD_files/INDEX.GIF" alt="[Index]" border="0"></a>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/HELP.html"><img src="testing%20DD_files/HELP.GIF" alt="[Help]" border="0"></a>
</p><p></p><hr><p>
</p><h2>
11.3&nbsp;&nbsp;&nbsp;&nbsp;Tracking Problems in Testing
</h2>
<p>
If the driver fails to behave as expected, you need to track down the
problem and correct it.
Use the following aids and hints:
</p><ul>
<p></p><li>
Refer to the
<cite>Kernel Debugging</cite>
book for guidelines in debugging the driver.
<p></p></li><li>
Use the
<tt>printf</tt>
kernel interface to display descriptive messages on the console terminal
when the driver calls different interfaces.
The messages that appear on the console should give you some insight
into the problem.
The
<tt>syslog</tt>
utility also logs these messages into a message file.
<p>
<br>
You cannot use the
<tt>printf</tt>
interface to debug all driver types.
For example,
<tt>printf</tt>
frequently is not useful in debugging terminal drivers because use of
the terminal driver may be required to display the contents of
<tt>printf</tt>
to the terminal.
</p><p></p></li><li>
Recompile and reinstall the kernel.
<p></p></li><li>
Rerun the test program with the reinstalled kernel.
<p></p></li><li>
Use synchronous traces of flow and variables where practical.
<p></p></li><li>
Do not use synchronous traces in the interrupt handler.
This means you should not use the
<tt>printf</tt>
interface in the interrupt handler.
<p></p></li><li>
Use asynchronous traces where synchronous traces cannot be used.
</li></ul><p>
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut15.html#test_wkshtfordevnone">Figure 11-1</a>
shows the device driver testing worksheet for the
<tt>/dev/none</tt>
device driver.
To identify the scope of your driver test program, use the device driver
testing
worksheet in
<a href="http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/HTML/AA-PUBVD-TE_html/drivertut29.html#dev_drv_wrkshts">Appendix C</a>.
</p><p>
<a name="test_wkshtfordevnone"></a>
</p><h3>Figure 11-1: Testing Worksheet for /dev/none</h3>
<p><img src="testing%20DD_files/zk-0510U.gif"></p><p>
<!--Metrics Tag -->
 <!-- Updated April 22, 2003 --> 
<!-- SiteCatalyst code version: G.0. w/dev site filtering
Copyright 1997-2003 Omniture, Inc. More info available at
http://www.omniture.com --><script language="JavaScript"><!--
/* Specify the Report Suite ID(s) to track here */
var s_account="HPHQGlobal,hphqWWesg,hphqbcs,hphqtru64"
/* Dynamic Report Suite ID Selection Config */
var s_dynamicAccountSelection = true
var s_dynamicAccountList = "hphqwwtrash=dec.com,cpqcorp.net,hpqcorp.net"
/* You may give each page an identifying user friendly name in place of urls. */
var s_pageName="Tru64-" + document.title;
if ( location.pathname.indexOf('/docs' ) != -1 )         { s_pageName = "Tru64-docs-" + document.title; }

/* Regionally assigned variables. */
var s_server=""
var s_channel=""
var s_pageType=""
var s_prop1="Tru64 UNIX"
if ( location.pathname.indexOf('/docs' ) != -1 )         { s_prop1 = "Tru64 documentation"; }
var s_prop2 = "";

   if ( location.search.indexOf('?jumpid=' ) != -1 )
        {
        s_prop2=location.search.substring((location.search.indexOf('?jumpid=' )+8),(location.search.length));
        }
			else
		{ 
		if (location.search.toUpperCase().indexOf('?' ) != -1 )        {
		s_prop2=location.search.toUpperCase().substring((location.search.toUpperCase().indexOf('?' )+1),(location.search.length));
		}
		}
var s_prop6=""
var s_prop7="w1"
var s_prop8="en-us"
var s_prop9="enterprise"
var s_prop10="w1|en-us|enterprise"
var s_prop13="HPHQGlobal,hphqWWesg,hphqbcs,hphqtru64"


/************************ ADDITIONAL FEATURES ************************
     Plugins
*/
/************************** CONFIG SECTION **************************/
/* You may add or alter any code config here.                       */
var s_charSet=""
// Netscape 4.X on Unix uses EUC-JP instead of SHIFT-JIS
if ((navigator.appName.indexOf('Netscape')>=0)&&
    (parseInt(navigator.appVersion)<=4)&&
    (navigator.userAgent.toLowerCase().indexOf('win')<0)&&
    (navigator.userAgent.toLowerCase().indexOf('mac')<0)) {
	s_charSet="EUC-JP"
}
/* E-commerce Config */
var s_eVarCFG=""

/* Link Tracking Config */
var s_trackDownloadLinks=true
var s_trackExternalLinks=true
var s_trackInlineStats=true
var s_linkDownloadFileTypes="exe,zip,wav,mp3,mov,mpg,avi,doc,pdf,xls,cgi,dot,pot,ppt,wmv,cgi,asx,tar,rpm,gz,crypt,sh"
var s_linkInternalFilters="hp,compaq,javascript:"
var s_linkLeaveQueryString=true


/********* INSERT THE DOMAIN AND PATH TO YOUR CODE BELOW ************/
//--></script><script language="JavaScript" src="testing%20DD_files/s_code.js"></script><img src="testing%20DD_files/s5932301575505.gif" name="s_i_hphqglobal" border="0" height="1" width="1">
<!-- End SiteCatalyst code version: G.0. -->

<!--End Tag -->
</p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -