1 |
27 |
unneback |
Serial Testing with ser_filter
|
2 |
|
|
|
3 |
|
|
Rationale
|
4 |
|
|
~~~~~~~~~
|
5 |
|
|
Since some targets only have one serial connection, a serial testing
|
6 |
|
|
harness needs to be able to share the connection with GDB (however,
|
7 |
|
|
the test and GDB can also run on separate lines).
|
8 |
|
|
|
9 |
|
|
The serial filter (ser_filter) sits between the serial port and GDB
|
10 |
|
|
and monitors the exchange of data between GDB and the
|
11 |
|
|
target. Normally, no changes are made to the data.
|
12 |
|
|
|
13 |
|
|
When a test request packet is sent from the test on the target, it is
|
14 |
|
|
intercepted by the filter. The filter and target then enter a loop,
|
15 |
|
|
exchanging protocol data between them which GDB never sees.
|
16 |
|
|
|
17 |
|
|
In the event of a timeout, or a crash on the target, the filter falls
|
18 |
|
|
back into its pass-through mode. If this happens due to a crash it
|
19 |
|
|
should be possible to start regular debugging with GDB. The filter
|
20 |
|
|
will then stay in the pass-though mode until GDB disconnects.
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
Adding A New Platform
|
24 |
|
|
~~~~~~~~~~~~~~~~~~~~~
|
25 |
|
|
The file ser_test_protocol.inl contains information about how to run
|
26 |
|
|
the serial tests on supported platforms. When adding a new serial
|
27 |
|
|
driver to eCos, ser_test_protocol.inl should be updated accordingly
|
28 |
|
|
so the driver can be tested.
|
29 |
|
|
|
30 |
|
|
The definitions TEST_SER_DEV and TEST_TTY_DEV are set according to
|
31 |
|
|
platform:
|
32 |
|
|
|
33 |
|
|
TEST_SER_DEV is the name of the serial device over which the serial
|
34 |
|
|
test protocol runs. The definition should be conditional on all
|
35 |
|
|
required configuration options.
|
36 |
|
|
|
37 |
|
|
TEST_TTY_DEV is the name of the TTY device over which the TTY test
|
38 |
|
|
protocol runs. The definition should be conditional on all required
|
39 |
|
|
configuration options. Note that this device is layered on top of a
|
40 |
|
|
serial device and must be conditional on that device's config
|
41 |
|
|
options as well as its own.
|
42 |
|
|
|
43 |
|
|
Here's an example for the PowerPC/Cogent where GDB is connected via
|
44 |
|
|
serial connector B:
|
45 |
|
|
|
46 |
|
|
#if defined(CYGPKG_HAL_POWERPC_COGENT) \
|
47 |
|
|
&& defined(CYGPKG_IO_SERIAL_POWERPC_COGENT) \
|
48 |
|
|
&& defined(CYGPKG_IO_SERIAL_POWERPC_COGENT_SERIAL_B)
|
49 |
|
|
# define TEST_SER_DEV CYGDAT_IO_SERIAL_POWERPC_COGENT_SERIAL_B_NAME
|
50 |
|
|
# if defined(CYGPKG_IO_SERIAL_TTY_TTY2)
|
51 |
|
|
# define TEST_TTY_DEV CYGDAT_IO_SERIAL_TTY_TTY2_DEV
|
52 |
|
|
# endif
|
53 |
|
|
#endif
|
54 |
|
|
|
55 |
|
|
|
56 |
|
|
On some targets it may also be necessary to intialize interrupt
|
57 |
|
|
vectors which are otherwise used by CygMon or an eCos GDB stub to
|
58 |
|
|
monitor characters from the host (looking for Control-C):
|
59 |
|
|
|
60 |
|
|
# define SER_OVERRIDE_INT_1 CYGNUM_HAL_INTERRUPT_9
|
61 |
|
|
# define SER_OVERRIDE_INT_2 CYGNUM_HAL_INTERRUPT_10
|
62 |
|
|
|
63 |
|
|
These definitions cause the serial test to restore the eCos handler
|
64 |
|
|
on the specified vectors before opening the serial device.
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
The file ser_test_protocol.inl also contains an array of serial
|
68 |
|
|
configurations (test_configs). It may be necessary to comment some of
|
69 |
|
|
these out for the platform if the driver or hardware cannot handle
|
70 |
|
|
all the given serial configurations.
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
The Protocol
|
74 |
|
|
~~~~~~~~~~~~
|
75 |
|
|
The protocol commands are prefixed with an @-character which the
|
76 |
|
|
serial filter is looking for. The protocol commands include:
|
77 |
|
|
|
78 |
|
|
PING
|
79 |
|
|
Allows the test on the target to probe for the filter. The filter
|
80 |
|
|
responds with OK, while GDB would just ignore the command. This
|
81 |
|
|
allows the tests to do nothing if they require the filter and it is
|
82 |
|
|
not present.
|
83 |
|
|
|
84 |
|
|
CONFIG
|
85 |
|
|
Requests a change of serial line configuration. Arguments of the
|
86 |
|
|
command specify baud rate, data bits, stop bits, and parity.
|
87 |
|
|
|
88 |
|
|
OPT
|
89 |
|
|
Requests changes in the filter's options. This allows various
|
90 |
|
|
amounts of tracing to be recorded when running tests without
|
91 |
|
|
requiring the filter to be restarted.
|
92 |
|
|
|
93 |
|
|
BINARY
|
94 |
|
|
Requests data to be sent from the filter to the target. The data is
|
95 |
|
|
checksummed, allowing errors in the transfer to be detected.
|
96 |
|
|
Sub-options of this command control how the data transfer is made:
|
97 |
|
|
|
98 |
|
|
NO_ECHO (serial driver receive test)
|
99 |
|
|
Just send data from the filter to the target. The test verifies
|
100 |
|
|
the checksum and PASS/FAIL depending on the result.
|
101 |
|
|
|
102 |
|
|
EOP_ECHO (serial driver half-duplex receive and send test)
|
103 |
|
|
As NO_ECHO but the test echoes back the data to the filter. The
|
104 |
|
|
filter does a checksum on the received data and sends the result
|
105 |
|
|
to the target. The test PASS/FAIL depending on the result of both
|
106 |
|
|
checksum verifications.
|
107 |
|
|
|
108 |
|
|
DUPLEX_ECHO (serial driver duplex receive and send test)
|
109 |
|
|
Smaller packets of data are sent back and forth in a pattern that
|
110 |
|
|
ensures that the serial driver will be both sending and receiving
|
111 |
|
|
at the same time. Again, checksums are computed and verified
|
112 |
|
|
resulting in PASS/FAIL.
|
113 |
|
|
|
114 |
|
|
TEXT
|
115 |
|
|
This is a test of the text translations in the TTY layer.
|
116 |
|
|
Requests a transfer of text data from the target to the filter and
|
117 |
|
|
possibly back again. The filter treats this as a binary transfer,
|
118 |
|
|
while the target may be doing translations on the data. The target
|
119 |
|
|
provides the filter with checksums for what it should expect to
|
120 |
|
|
see.
|
121 |
|
|
[This test is not implemented yet]
|
122 |
|
|
|
123 |
|
|
The above commands may be extended, and new commands added, as
|
124 |
|
|
required to test (new) parts of the serial drivers in eCos.
|
125 |
|
|
|
126 |
|
|
See ser_test_protocol.inl for further details on the protocols.
|
127 |
|
|
|
128 |
|
|
|
129 |
|
|
The Serial Tests
|
130 |
|
|
~~~~~~~~~~~~~~~~
|
131 |
|
|
The serial tests are built as any other eCos test. After running the
|
132 |
|
|
'make tests' command, the tests can be found in:
|
133 |
|
|
|
134 |
|
|
install/tests/io_serial/
|
135 |
|
|
|
136 |
|
|
serial1
|
137 |
|
|
A simple API test.
|
138 |
|
|
|
139 |
|
|
serial2
|
140 |
|
|
A simple serial send test. It writes out two strings, one raw and
|
141 |
|
|
one encoded as a GDB O-packet.
|
142 |
|
|
|
143 |
|
|
serial3 [requires the serial filter]
|
144 |
|
|
This tests the half-duplex send and receive capabilities of the
|
145 |
|
|
serial driver.
|
146 |
|
|
|
147 |
|
|
serial4 [requires the serial filter]
|
148 |
|
|
This test attempts to use a few different serial configurations,
|
149 |
|
|
testing the driver's configuration/setup functionality.
|
150 |
|
|
|
151 |
|
|
serial5 [requires the serial filter]
|
152 |
|
|
This tests the duplex send and receive capabilities of the serial
|
153 |
|
|
driver.
|
154 |
|
|
|
155 |
|
|
All tests should complete in less than 30 seconds.
|
156 |
|
|
|
157 |
|
|
|
158 |
|
|
Serial Filter Usage
|
159 |
|
|
~~~~~~~~~~~~~~~~~~~
|
160 |
|
|
Running the ser_filter program with no (or wrong) arguments results
|
161 |
|
|
in the below output:
|
162 |
|
|
|
163 |
|
|
Usage: ser_filter [-t -c -g -S] TcpIPport SerialPort BaudRate
|
164 |
|
|
or: ser_filter -n [-t -c -g -S] SerialPort BaudRate
|
165 |
|
|
-t: Enable tracing.
|
166 |
|
|
-f: Enable filter output tracing.
|
167 |
|
|
-g: Enable GDB tracing.
|
168 |
|
|
-S: Output data read from serial line.
|
169 |
|
|
-c: Output data on console instead of via GDB.
|
170 |
|
|
-n: No GDB.
|
171 |
|
|
|
172 |
|
|
The normal way to use it with GDB is to start the filter:
|
173 |
|
|
|
174 |
|
|
ser_filter -t 9000 com1 38400
|
175 |
|
|
|
176 |
|
|
In this case, the filter will be listening on port 9000 and connect
|
177 |
|
|
to the target via the serial port COM1 at 38400 baud. On a UNIX host,
|
178 |
|
|
replace "com1" with a device such as "/dev/ttyS0".
|
179 |
|
|
|
180 |
|
|
The '-t' option enables tracing which will cause the filter to
|
181 |
|
|
describe its actions on the console.
|
182 |
|
|
|
183 |
|
|
Now start GDB with one of the tests as an argument:
|
184 |
|
|
|
185 |
|
|
$ mips-tx39-elf-gdb -nw install/tests/io_serial/serial3
|
186 |
|
|
|
187 |
|
|
Then connect to the filter:
|
188 |
|
|
|
189 |
|
|
(gdb) target remote localhost:9000
|
190 |
|
|
|
191 |
|
|
This should result in a connection in exactly the same way as if you
|
192 |
|
|
had connected directly to the target on the serial line.
|
193 |
|
|
|
194 |
|
|
(gdb) load
|
195 |
|
|
...
|
196 |
|
|
(gdb) cont
|
197 |
|
|
|
198 |
|
|
Which should result in output similar to the below:
|
199 |
|
|
|
200 |
|
|
Continuing.
|
201 |
|
|
INFO:
|
202 |
|
|
PASS:
|
203 |
|
|
INFO:
|
204 |
|
|
PASS:
|
205 |
|
|
INFO:
|
206 |
|
|
PASS:
|
207 |
|
|
INFO:
|
208 |
|
|
PASS:
|
209 |
|
|
INFO:
|
210 |
|
|
PASS:
|
211 |
|
|
...
|
212 |
|
|
PASS:
|
213 |
|
|
INFO:
|
214 |
|
|
PASS:
|
215 |
|
|
PASS:
|
216 |
|
|
EXIT:
|
217 |
|
|
|
218 |
|
|
If any of the individual tests fail the testing will terminate with
|
219 |
|
|
a FAIL.
|
220 |
|
|
|
221 |
|
|
With tracing enabled, you would also see the filter's status output:
|
222 |
|
|
|
223 |
|
|
The PING command sent from the target to determine the presence of
|
224 |
|
|
the filter:
|
225 |
|
|
[400 11:35:16] Dispatching command PING
|
226 |
|
|
[400 11:35:16] Responding with status OK
|
227 |
|
|
|
228 |
|
|
Each of the binary commands result in output similar to:
|
229 |
|
|
[400 11:35:16] Dispatching command BINARY
|
230 |
|
|
[400 11:35:16] Binary data (Size:16, Flags:1).
|
231 |
|
|
[400 11:35:16] Sending CRC: '170231!', len: 7.
|
232 |
|
|
[400 11:35:16] Reading 16 bytes from target.
|
233 |
|
|
[400 11:35:16] Done. in_crc 170231, out_crc 170231.
|
234 |
|
|
[400 11:35:16] Responding with status OK
|
235 |
|
|
[400 11:35:16] Received DONE from target.
|
236 |
|
|
|
237 |
|
|
This tracing output is normally sent as O-packets to GDB which will
|
238 |
|
|
display the tracing text. By using the -c option, the tracing text
|
239 |
|
|
can be redirected to the console from which ser_filter was started.
|
240 |
|
|
|
241 |
|
|
|
242 |
|
|
The trace options -f, -g, and -S cause data sent from filter, GDB or
|
243 |
|
|
target to be output in hexadecimal form.
|
244 |
|
|
|
245 |
|
|
|
246 |
|
|
A Note on Failures
|
247 |
|
|
~~~~~~~~~~~~~~~~~~
|
248 |
|
|
A serial connection (especially when driven at a high baud rate) can
|
249 |
|
|
garble the transmitted data because of noise from the environment. It
|
250 |
|
|
is not the job of the serial driver to ensure data integrity - that
|
251 |
|
|
is the job of protocols layering on top of the serial driver.
|
252 |
|
|
|
253 |
|
|
In the current implementation the serial tests and the serial filter
|
254 |
|
|
are not resilient to such data errors. This means that the test may
|
255 |
|
|
crash or hang (possibly without reporting a FAIL). It also means that
|
256 |
|
|
you should be aware of random errors - a FAIL is not necessarily
|
257 |
|
|
caused by a bug in the serial driver.
|
258 |
|
|
|
259 |
|
|
Ideally, the serial testing infrastructure should be able to
|
260 |
|
|
distinguish random errors from consistent errors - the former are
|
261 |
|
|
most likely due to noise in the transfer medium, while the latter are
|
262 |
|
|
more likely to be caused by faulty drivers. The current
|
263 |
|
|
implementation of the infrastructure does not have this capability.
|
264 |
|
|
|
265 |
|
|
|
266 |
|
|
Debugging
|
267 |
|
|
~~~~~~~~~
|
268 |
|
|
If a test fails, the serial filter's output may provide some hints
|
269 |
|
|
about what the problem is. If the option '-S' is used when starting
|
270 |
|
|
the filter, data received from the target is printed out:
|
271 |
|
|
|
272 |
|
|
[400 11:35:16] 0000 50 41 53 53 3a 3c 42 69 'PASS:
|
273 |
|
|
[400 11:35:16] 0008 6e 61 72 79 20 74 65 73 'nary.tes'
|
274 |
|
|
[400 11:35:16] 0010 74 20 63 6f 6d 70 6c 65 't.comple'
|
275 |
|
|
[400 11:35:16] 0018 74 65 64 3e 0d 0a 49 4e 'ted>..IN'
|
276 |
|
|
[400 11:35:16] 0020 46 4f 3a 3c 42 49 4e 41 'FO:
|
277 |
|
|
[400 11:35:16] 0028 52 59 3a 31 32 38 3a 31 'RY:128:1'
|
278 |
|
|
[400 11:35:16] 0030 21 3e 0d 0a 40 42 49 4e '!>..@BIN'
|
279 |
|
|
[400 11:35:16] 0038 41 52 59 3a 31 32 38 3a 'ARY:128:'
|
280 |
|
|
[400 11:35:16] 0040 31 21 .. .. .. .. .. .. '1!'
|
281 |
|
|
|
282 |
|
|
In the case of an error during a testing command the data received by
|
283 |
|
|
the filter will be printed out, as will the data that was
|
284 |
|
|
expected. This allows the two data sets to be compared which may give
|
285 |
|
|
some idea of what the problem is.
|