aboutsummaryrefslogtreecommitdiff
path: root/tests/gdbmtool/config/default.exp
blob: 737689672297b2a139b87a2bfcd079361a2944d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
verbose "STARTED" 1

# Make sure we use POSIX locale
set env(LC_ALL) "C"
set env(TERM) ""

set gdbmtool_prompt "gdbmtool> "

proc gdbmtool_start {args} {
    global gdbmtool_spawn_id
    global top_builddir
    global gdbmtool_prompt

    set cmd "$top_builddir/tools/gdbmtool -q $args"
    verbose "running $cmd" 1

    set gdbmtool_spawn_id [remote_spawn host $cmd]
    if { $gdbmtool_spawn_id < 0 || $gdbmtool_spawn_id == "" } {
	perror "Spawning $cmd failed."
	return 1;
    }

    remote_expect host 60 {
	-re "\[\r\n\]?${gdbmtool_prompt}$" {
	    verbose "gdbmtool initialized."
	}
	default {
	    perror "gdbmtool not initialized"
            return 1
	}
    }
    return 0
}

proc gdbmtool_stop {} {
    verbose "Stopping gdbmtool"
    gdbmtool_command "quit"
    remote_close host
}

proc gdbmtool_send {string} {
    return [remote_send host "$string"]
}

proc gdbmtool_command {cmd} {
    set res [gdbmtool_send "$cmd\n"]
    remote_expect host 60 {
	-ex "\r\n" { }
	default {
	    perror "gdbmtool_command for target failed";
	    return -1
	}
    }
    verbose "RESULT: $res" 2
    return $res
}

proc gdbmtool_test { command expcode } {
    gdbmtool_command $command
    uplevel remote_expect host 60 $expcode
#    set code [catch \
#	{uplevel remote_expect host 60 $expcode} string];
}

# mu_test COMMAND PATTERN
# COMMAND   - Command to send to the program
# PATTERN   - A list of strings to expect in return
# Return value:
#        -3 - eof
#        -2 - timeout
#        -1 - generic failure
#         1 - test fails
#         0 - test succeeds
proc seq_test { args } {
    set command [lindex $args 0]
    set pattern [lindex $args 1]

    set result -1
    if { "${command}" != "" } {
	set res [gdbmtool_command "${command}"]
	if { $res != "" } {
	    return $result;
        }
    }

    global timeout;
    if [info exists timeout] {
	set tmt $timeout;
    } else {
	set tmt 60;
    }

    set result 0
    for {set i 0} {$result == 0 && $i < [llength $pattern]} {incr i} {
	set regexp 0
	switch -regexp -- "[lindex ${pattern} $i]" {
	    ^-re.*$	{ set regexp 1; incr i }
	    ^--         { incr i }
	}

	regsub "\[ \t\]*$" [lindex ${pattern} $i] "" pat
	verbose "i=$i, pat=$pat" 2

	if {$regexp} {
	    verbose "REGEX for $pat / [llength $pat] " 3
	    remote_expect host $tmt {
	       -re "$pat\[ \r\t\]*\r\n" { }
	       default {
		   set result 1
		   break
	       }
	       timeout {
		   set result -2
		   break
	       }
	       eof {
		   set result -3
		   break
	       }
	   }
       } else {
	   remote_expect host $tmt {
	       -ex "$pat" {
		   # go on
	       }
 	       default {
		   set result 1
		   break
	       }
	       timeout {
		   set result -2
		   break
	       }
	       eof {
		   set result -3
		   break
	       }
	   }

	   if {$result == 0} {
	       remote_expect host $tmt {
		   -re "\[ \t]*\r\n" { }
		   default { set result 1 }
		   timeout { set result -2 }
		   eof { set result -3 }
	       }
	   }
       }
    }
    return $result
}

# mail_test [-message MESSAGE][-default (FAIL|XFAIL)][-noprompt]
#            COMMAND PATTERN [PATTERN...]
# COMMAND   - Command to send to mail.
# PATTERN   - Sequence to expect in return. 
# MESSAGE   - [optional] message to output
proc gdbmtool_test { args } {
    global gdbmtool_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]
    }

    verbose "Message is \"$message\"" 2
    
    set command [lindex $args 0]
    set pattern [lrange $args 1 end]

    set result [seq_test $command $pattern]
    if {$wait_for_prompt} {
	remote_expect host 30 {
		-re "\[\r\n\]?${gdbmtool_prompt}$" {}
		default {
			perror "gdbmtool 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
}



Return to:

Send suggestions and report system problems to the System administrator.