From 0f47ac958bf6231f5a8f474ee0b096daaf06051c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Thu, 12 Feb 2015 12:35:37 +0100 Subject: [PATCH] log/serial: handle spurious EOF While booting up, some devices send garbage over the serial connection. This can result in an unexpected EOF event within expect(1). A filter program may be specified with '--log-serial-filter' to circumvent this problem. Then, the output of the serial program is piped through the filter, which may sanitize the character stream. Fixes #1395. --- tool/run/log/serial | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/tool/run/log/serial b/tool/run/log/serial index e4ddf3eac..02baa7ce1 100644 --- a/tool/run/log/serial +++ b/tool/run/log/serial @@ -1,7 +1,8 @@ ## # Get the output of the target machine via serial connection # -# \param --log-serial-cmd Cmd that is executed to capture the output +# \param --log-serial-cmd Cmd that is executed to capture the output +# \param --log-serial-filter Sanitize output by piping it through a filter # source [genode_dir]/tool/run/log.inc @@ -16,6 +17,11 @@ proc log_serial_cmd { } { } +proc log_serial_filter { } { + return [get_cmd_arg --log-serial-filter ""] +} + + ## # Log output of the test machine via serial device # @@ -24,14 +30,36 @@ proc run_log { wait_for_re timeout_value } { set kernel_msg [run_boot_string] - eval spawn [log_serial_cmd] + # + # Certain devices send garbage through the serial connection that may + # result in an unexpected EOF in expect. This is caused by TCL using the + # terminal encoding for the channel to the spawned program and interpreting + # the input for conversion to UTF-8. In the case of the serial connection, + # this may not be valid with garbage bytes in the character stream. If any + # garbage coming from the serial connection is interpreted as the beginning + # of a UTF-8 multi-byte sequence but does not resemble the complete + # sequence (i.e., is truncated), parsing may result in EOF. To prevent this + # from happening one may use a filter that sanitizes the serial output, + # i.e., lets only ASCII characters through. + # + set serial_cmd_chain [log_serial_cmd] + if {[get_cmd_switch --log-serial-filter]} { + set serial_cmd_chain "$serial_cmd_chain | [log_serial_filter]" + } + + # + # XXX the initial timeout was estimated by testing and is merely enough + # to load large scenarios via TFTP. + # + set timeout 210 + + spawn /bin/sh -c "$serial_cmd_chain" set output_spawn_id $spawn_id - set timeout 210 expect { - $kernel_msg { } + -i $output_spawn_id $kernel_msg { } eof { - puts stderr "Serial command process died unexpectedly" + puts stderr "Aborting, received EOF" return false } timeout {