diff --git a/tool/run/log/serial b/tool/run/log/serial index e4ddf3eac4..02baa7ce11 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 {