Commit c47341cd c47341cd2a51499373b884892c235e2436e1b127 by Sergey Poznyakoff

(mailbox_prog_start)

(mailbox_prog_command,mailbox_prog_stop,mailbox_prog_test): New
functions.
1 parent ccbb3271
......@@ -130,4 +130,113 @@ proc mailbox_test { args } {
return $result
}
proc mailbox_prog_start {cmd} {
global verbose
global MU_TOOL
global MU_TOOL_FLAGS
global mailbox_prog_prompt
global expect_out
global mailbox_spawn_id
verbose "Spawning $cmd"
set mailbox_spawn_id [remote_spawn host $cmd]
if { $mailbox_spawn_id < 0 || $mailbox_spawn_id == "" } {
perror "Spawning $cmd failed."
return 1;
}
mu_expect 360 {
-re "\[\r\n\]?${mailbox_prog_prompt}$" {
verbose "program initialized."
}
default {
perror "program not initialized"
return 1
}
}
return 0
}
proc mailbox_prog_send { string } {
return [mu_send "$string"]
}
proc mailbox_prog_command { cmd } {
return [mu_command $cmd]
}
proc mailbox_prog_stop {} {
verbose "Stopping program"
remote_close host
}
# mailbox_prog_test [-message MESSAGE][-default (FAIL|XFAIL)][-noprompt]
# COMMAND PATTERN [PATTERN...]
# COMMAND - Command to send.
# PATTERN - Sequence to expect in return.
# MESSAGE - [optional] message to output
proc mailbox_prog_test { args } {
global verbose
global mailbox_prog_prompt
global suppress_flag;
upvar timeout timeout
set default ""
set message ""
set wait_for_prompt 1
for {set i 0} {$i < [llength $args]} {incr i} {
set a [lindex $args $i]
if {"$a" == "-default"} {
set default [lindex $args [expr $i + 1]]
incr i
} elseif {"$a" == "-message"} {
set message [lindex $args [expr $i + 1]]
incr i
} elseif {"$a" == "-noprompt"} {
set wait_for_prompt 0
} else {
set args [lrange $args $i end]
break
}
}
if {"$message" == ""} {
set message [lindex $args 0]
}
if $verbose>2 then {
send_user "Message is \"$message\"\n"
}
set command [lindex $args 0]
set pattern [lrange $args 1 end]
set result [mu_test $command $pattern]
if {$wait_for_prompt} {
mu_expect 30 {
-re "\[\r\n\]?${mailbox_prog_prompt}$" {}
default {
perror "prog not initialized"
return 1
}
}
}
if {$result == 0} {
pass "$message"
} elseif {$result == 1} {
if { "$default" == "" || "$default" != "FAIL" } {
fail "$message"
} else {
xfail "$message"
set result 0
}
} elseif {$result == -2} {
fail "$message (timeout)"
} elseif {$result == -3} {
fail "$message (eof)"
} else {
fail "$message"
}
return $result
}
......