Added timeout catch for expect_wrap
Change-Id: Ic9902ab2abea624ffd44ff374c43b7a0736839b5
Signed-off-by: Joy Onyerikwu <onyekachukwu.joy.onyerikwu@ibm.com>
diff --git a/lib/tools.exp b/lib/tools.exp
index 7d0f8f2..e58b208 100755
--- a/lib/tools.exp
+++ b/lib/tools.exp
@@ -65,7 +65,7 @@
}
-proc expect_wrap {pattern_list message {timeout 15}} {
+proc expect_wrap {pattern_list message {timeout 15} {fail_on_timeout 1}} {
# Run the expect command for the caller and return the list index of the
# matching pattern.
@@ -90,6 +90,13 @@
# expected (e.g. "an SOL login prompt").
# This will be included in output messages.
# timeout The expect timeout value.
+ # fail_on_timeout A flag governing the behavior when the
+ # expect command results in a timeout.
+ # If set to 1, this procedure will print an
+ # error message to standard error and exit
+ # the program with a non-zero return code.
+ # If set to 0, it will return
+ # [expect_wrap_timeout].
# Example usage:
# set result [expect_wrap\
@@ -135,7 +142,12 @@
append cmd_buf " ${flag} {$pattern} {set expect_result $ix}\n"
incr ix
}
- append cmd_buf " timeout {handle_timeout \$message}\n"
+
+ if { $fail_on_timeout } {
+ append cmd_buf " timeout {handle_timeout \$message}\n"
+ } else {
+ append cmd_buf " timeout {set expect_result \[expect_wrap_timeout\]}\n"
+ }
append cmd_buf " eof {handle_eof \$message}\n"
append cmd_buf "}\n"
@@ -149,6 +161,14 @@
}
+proc expect_wrap_timeout {} {
+
+ # Return constant value of 1000.
+
+ return 1000
+
+}
+
proc send_wrap {buffer {add_lf 1}} {