📄 io-serial-testing-with-serfilter.html
字号:
<!-- Copyright (C) 2003 Red Hat, Inc. --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/). --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission is obtained from the copyright holder. --><HTML><HEAD><TITLE>Serial testing with ser_filter</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="How to Write a Driver"HREF="io-how-to-write-a-driver.html"><LINKREL="PREVIOUS"TITLE="How to Write a Driver"HREF="io-how-to-write-a-driver.html"><LINKREL="NEXT"TITLE="Device Driver Interface to the Kernel"HREF="devapi-device-driver-interface-to-the-kernel.html"></HEAD><BODYCLASS="SECTION"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="io-how-to-write-a-driver.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 17. How to Write a Driver</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="devapi-device-driver-interface-to-the-kernel.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="SECTION"><H1CLASS="SECTION"><ANAME="IO-SERIAL-TESTING-WITH-SERFILTER">Serial testing with ser_filter</H1><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="IO-SERFILTER-RATIONALE">Rationale</H2><P>Since some targets only have one serial connection, a serial testing harnessneeds to be able to share the connection with <SPANCLASS="APPLICATION">GDB</SPAN>(however, the test and <SPANCLASS="APPLICATION">GDB</SPAN> can also run on separatelines).</P><P>The <ICLASS="FIRSTTERM">serial filter</I> (<SPANCLASS="APPLICATION">ser_filter</SPAN>)sits between the serial port and <SPANCLASS="APPLICATION">GDB</SPAN> and monitorsthe exchange of data between <SPANCLASS="APPLICATION">GDB</SPAN> and the target.Normally, no changes are made to the data.</P><P>When a test request packet is sent from the test on the target, it is intercepted by the filter.</P><P>The filter and target then enter a loop, exchanging protocol data betweenthem which <SPANCLASS="APPLICATION">GDB</SPAN> never sees.</P><P>In the event of a timeout, or a crash on the target, the filter fallsback into its pass-through mode. If this happens due to a crash it should bepossible to start regular debugging with <SPANCLASS="APPLICATION">GDB</SPAN>. Thefilter will stay in the pass-though mode until <SPANCLASS="APPLICATION">GDB</SPAN>disconnects.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="IO-SERFILTER-PROTOCOL">The Protocol</H2><P>The protocol commands are prefixed with an <TTCLASS="LITERAL">"@"</TT>character which the serial filter is looking for. The protocolcommands include:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="LITERAL">PING</TT></DT><DD><P>Allows the test on the target to probe for the filter. The filter responds with <TTCLASS="LITERAL">OK</TT>, while <SPANCLASS="APPLICATION">GDB</SPAN> would just ignore the command. This allows the tests to do nothing if they require the filter and it is not present.</P></DD><DT><TTCLASS="LITERAL">CONFIG</TT></DT><DD><P>Requests a change of serial line configuration. Arguments to the command specify baud rate, data bits, stop bits, and parity. [This command is not fully implemented yet - there is no attempt made to recover if the new configuration turns out to cause loss of data.]</P></DD><DT><TTCLASS="LITERAL">BINARY</TT></DT><DD><P>Requests data to be sent from the filter to the target. The data is checksummed, allowing errors in the transfer to be detected. Sub-options of this command control how the data transfer is made:</P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="LITERAL">NO_ECHO</TT></DT><DD><P>(serial driver receive test) Just send data from the filter to the target. The test verifies the checksum and PASS/FAIL depending on the result. </P></DD><DT><TTCLASS="LITERAL">EOP_ECHO</TT></DT><DD><P>(serial driver half-duplex receive and send test) As <TTCLASS="LITERAL">NO_ECHO</TT> but the test echoes back the data to the filter. The filter does a checksum on the received data and sends the result to the target. The test PASS/FAIL depending on the result of both checksum verifications.</P></DD><DT><TTCLASS="LITERAL">DUPLEX_ECHO</TT></DT><DD><P>(serial driver duplex receive and send test) Smaller packets of data are sent back and forth in a pattern that ensures that the serial driver will be both sending and receiving at the same time. Again, checksums are computed and verified resulting in PASS/FAIL. </P></DD></DL></DIV></DD><DT><TTCLASS="LITERAL">TEXT</TT></DT><DD><P> This is a test of the text translations in the TTY layer. Requests a transfer of text data from the target to the filter and possibly back again. The filter treats this as a binary transfer, while the target ma be doing translations on the data. The target provides the filter with checksums for what it should expect to see. This test is not implemented yet. </P></DD></DL></DIV><P>The above commands may be extended, and new commands added, asrequired to test (new) parts of the serial drivers in<SPANCLASS="PRODUCTNAME">eCos</SPAN>.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="IO-SERFILTER-SERIAL-TESTS">The Serial Tests</H2><P>The serial tests are built as any other eCos test. After running the<BCLASS="COMMAND">make tests</B> command, the tests can be found in<TTCLASS="FILENAME">install/tests/io_serial/</TT></P><P></P><DIVCLASS="VARIABLELIST"><DL><DT><TTCLASS="FILENAME">serial1</TT></DT><DD><P>A simple API test.</P></DD><DT><TTCLASS="FILENAME">serial2</TT></DT><DD><P>A simple serial send test. It writes out two strings, one raw and one encoded as a <SPANCLASS="APPLICATION">GDB</SPAN> O-packet</P></DD><DT><TTCLASS="FILENAME">serial3</TT> [ requires the serial filter ]</DT><DD><P>This tests the half-duplex send and receive capabilities of the serial driver. </P></DD><DT><TTCLASS="FILENAME">serial4</TT> [ requires the serial filter ]</DT><DD><P>This test attempts to use a few different serial configurations, testing the driver's configuration/setup functionality. </P></DD><DT><TTCLASS="FILENAME">serial5</TT> [ requires the serial filter ]</DT><DD><P>This tests the duplex send and receive capabilities of the serial driver. </P></DD></DL></DIV><P>All tests should complete in less than 30 seconds.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="IO-SERFILTER-USAGE">Serial Filter Usage</H2><P>Running the ser_filter program with no (or wrong) arguments results inthe following output:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">Usage: ser_filter [-t -S] TcpIPport SerialPort BaudRate or: ser_filter -n [-t -S] SerialPort BaudRate -t: Enable tracing. -S: Output data read from serial line. -c: Output data on console instead of via GDB. -n: No GDB. </PRE></TD></TR></TABLE><P>The normal way to use it with GDB is to start the filter:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">$ <TTCLASS="USERINPUT"><B>ser_filter -t 9000 com1 38400</B></TT></PRE></TD></TR></TABLE><P>In this case, the filter will be listening on port 9000 and connect to thetarget via the serial port <TTCLASS="LITERAL">COM1</TT> at 38400 baud. On a UNIXhost, replace "<TTCLASS="LITERAL">COM1</TT>" with a device such as "<TTCLASS="FILENAME">/dev/ttyS0</TT>".</P><P>The <TTCLASS="OPTION">-t</TT> option enables tracing which will cause thefilter to describe its actions on the console.</P><P>Now start <SPANCLASS="APPLICATION">GDB</SPAN> with one of the tests as anargument:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">$ <TTCLASS="USERINPUT"><B>mips-tx39-elf-gdb -nw install/tests/io_serial/serial3</B></TT></PRE></TD></TR></TABLE><P>Then connect to the filter:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">(gdb) <TTCLASS="USERINPUT"><B>target remote localhost:9000</B></TT></PRE></TD></TR></TABLE><P>This should result in a connection in exactly the same way as if youhad connected directly to the target on the serial line.</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">(gdb) <TTCLASS="USERINPUT"><B>c</B></TT></PRE></TD></TR></TABLE><P>Which should result in output similar to the below:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">Continuing. INFO: <BINARY:16:1!> PASS: <Binary test completed>INFO: <BINARY:128:1!> PASS: <Binary test completed>INFO: <BINARY:256:1!> PASS: <Binary test completed>INFO: <BINARY:1024:1!> PASS: <Binary test completed>INFO: <BINARY:512:0!>PASS: <Binary test completed>... PASS: <Binary test completed>INFO: <BINARY:16384:0!>PASS: <Binary test completed>PASS: <serial13 test OK>EXIT: <done></PRE></TD></TR></TABLE><P>If any of the individual tests fail the testing will terminate with a <TTCLASS="COMPUTEROUTPUT">FAIL</TT>.</P><P>With tracing enabled, you would also see the filter's status output:</P><P>The <TTCLASS="LITERAL">PING</TT> command sent from the target to determine thepresence of the filter:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">[400 11:35:16] Dispatching command PING [400 11:35:16] Responding with status OK</PRE></TD></TR></TABLE><P>Each of the binary commands result in output similar to:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">[400 11:35:16] Dispatching command BINARY [400 11:35:16] Binary data (Size:16, Flags:1). [400 11:35:16] Sending CRC: '170231!', len: 7. [400 11:35:16] Reading 16 bytes from target. [400 11:35:16] Done. in_crc 170231, out_crc 170231. [400 11:35:16] Responding with status OK [400 11:35:16] Received DONE from target.</PRE></TD></TR></TABLE><P>This tracing output is normally sent as O-packets to <SPANCLASS="APPLICATION">GDB</SPAN> which will display the tracing text. By using the<TTCLASS="OPTION">-c </TT> option, the tracing text can be redirected to theconsole from which ser_filter was started.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="IO-SERFILTER-FAILURES">A Note on Failures</H2><P>A serial connection (especially when driven at a high baud rate) can garble thetransmitted data because of noise from the environment. It is not the job ofthe serial driver to ensure data integrity - that is the job of protocolslayering on top of the serial driver. </P><P>In the current implementation the serial tests and the serial filter arenot resilient to such data errors. This means that the test may crash or hang(possibly without reporting a <TTCLASS="COMPUTEROUTPUT">FAIL</TT>). It alsomeans that you should be aware of random errors - a <TTCLASS="COMPUTEROUTPUT">FAIL</TT> is not necessarily caused by a bug in the serial driver.</P><P>Ideally, the serial testing infrastructure should be able to distinguishrandom errors from consistent errors - the former are most likely due to noisein the transfer medium, while the latter are more likely to be caused by faultydrivers. The current implementation of the infrastructure does not have thiscapability.</P></DIV><DIVCLASS="SECTION"><H2CLASS="SECTION"><ANAME="IO-SERFILTER-DEBUGGING">Debugging</H2><P>If a test fails, the serial filter's output may provide some hints aboutwhat the problem is. If the option <TTCLASS="OPTION">-S</TT> is used when startingthe filter, data received from the target is printed out: </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">[400 11:35:16] 0000 50 41 53 53 3a 3c 42 69 'PASS:<Bi'[400 11:35:16] 0008 6e 61 72 79 20 74 65 73 'nary.tes' [400 11:35:16] 0010 74 20 63 6f 6d 70 6c 65 't.comple' [400 11:35:16] 0018 74 65 64 3e 0d 0a 49 4e 'ted>..IN' [400 11:35:16] 0020 46 4f 3a 3c 42 49 4e 41 'FO:<BINA'[400 11:35:16] 0028 52 59 3a 31 32 38 3a 31 'RY:128:1' [400 11:35:16] 0030 21 3e 0d 0a 40 42 49 4e '!..@BIN' [400 11:35:16] 0038 41 52 59 3a 31 32 38 3a 'ARY:128:' [400 11:35:16] 0040 31 21 .. .. .. .. .. .. '1!' </PRE></TD></TR></TABLE><P>In the case of an error during a testing command the data received by thefilter will be printed out, as will the data that was expected. This allowsthe two data sets to be compared which may give some idea of what the problemis.</P></DIV></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="io-how-to-write-a-driver.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="devapi-device-driver-interface-to-the-kernel.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">How to Write a Driver</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-how-to-write-a-driver.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Device Driver Interface to the Kernel</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -