Added to repository
Showing
2 changed files
with
365 additions
and
0 deletions
testsuite/lib/DISTFILES
0 → 100644
1 | mailutils.exp |
testsuite/lib/mailutils.exp
0 → 100644
1 | # -*- tcl -*- | ||
2 | # This file is part of Mailutils testsuite. | ||
3 | # Copyright (C) 2002, Free Software Foundation | ||
4 | # | ||
5 | # This program is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published by | ||
7 | # the Free Software Foundation; either version 2 of the License, or | ||
8 | # (at your option) any later version. | ||
9 | # | ||
10 | # This program is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | # GNU General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with this program; if not, write to the Free Software Foundation, | ||
17 | # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
18 | |||
19 | verbose "STARTED" 1 | ||
20 | |||
21 | proc mu_init {} { | ||
22 | global TOOL_EXECUTABLE | ||
23 | global MU_TOOL | ||
24 | global MU_SPOOL_SOURCE | ||
25 | global MU_FOLDER_SOURCE | ||
26 | global MU_SPOOL_DIR | ||
27 | global MU_FOLDER_DIR | ||
28 | global MU_RC_DIR | ||
29 | global MU_MAKESPOOL | ||
30 | global TOOL_NAME | ||
31 | global MU_TOOL_ARGS | ||
32 | global base_dir | ||
33 | global top_srcdir | ||
34 | global objdir | ||
35 | global host_board | ||
36 | |||
37 | if [info exists TOOL_EXECUTABLE] { | ||
38 | set MU_TOOL $TOOL_EXECUTABLE | ||
39 | } | ||
40 | |||
41 | if ![info exists MU_TOOL] { | ||
42 | if ![is_remote host] { | ||
43 | set MU_TOOL [findfile $base_dir/../$TOOL_NAME "$base_dir/../$TOOL_NAME" [transform $TOOL_NAME]] | ||
44 | set MU_SPOOL_SOURCE "$top_srcdir/testsuite/spool" | ||
45 | set MU_FOLDER_SOURCE "$top_srcdir/testsuite/folder" | ||
46 | set MU_SPOOL_DIR "$objdir/data/spool" | ||
47 | set MU_FOLDER_DIR "$objdir/data/folder" | ||
48 | set MU_RC_DIR "$top_srcdir/testsuite/etc" | ||
49 | set MU_MAKESPOOL "$top_srcdir/testsuite/makespool" | ||
50 | } else { | ||
51 | if [info exists host_board] { | ||
52 | if [board_info $host_board exists top_builddir] { | ||
53 | append MU_TOOL "[board_info $host_board top_builddir]/$TOOL_NAME/$TOOL_NAME" | ||
54 | } elseif [board_info $host_board exists top_srcdir] { | ||
55 | append MU_TOOL "[board_info $host_board top_srcdir]/$TOOL_NAME/$TOOL_NAME" | ||
56 | } | ||
57 | } | ||
58 | |||
59 | if ![info exists MU_TOOL] { | ||
60 | perror "The test suite is not set up for the remote testing" | ||
61 | perror "Please, read file README in $TOOL_NAME/testsuite subdirectory" | ||
62 | perror "for instructions on how to set up it." | ||
63 | exit 1 | ||
64 | } | ||
65 | set MU_RC_DIR "[board_info $host_board top_srcdir]/etc" | ||
66 | set MU_SPOOL_SOURCE "[board_info $host_board top_srcdir]/spool" | ||
67 | set MU_FOLDER_SOURCE "[board_info $host_board top_srcdir]/folder" | ||
68 | set MU_SPOOL_DIR "[board_info $host_board objdir]/data/spool" | ||
69 | set MU_FOLDER_DIR "[board_info $host_board objdir]/data/folder" | ||
70 | set MU_MAKESPOOL "[board_info $host_board top_srcdir]/makespool" | ||
71 | } | ||
72 | } | ||
73 | } | ||
74 | |||
75 | ### Only procedures should come after this point. | ||
76 | |||
77 | proc mu_prepare_spools {} { | ||
78 | global MU_SPOOL_SOURCE | ||
79 | global MU_SPOOL_DIR | ||
80 | global MU_FOLDER_SOURCE | ||
81 | global MU_FOLDER_DIR | ||
82 | global MU_MAKESPOOL | ||
83 | |||
84 | set output [remote_exec host "$MU_MAKESPOOL \ | ||
85 | $MU_SPOOL_SOURCE $MU_SPOOL_DIR\ | ||
86 | $MU_FOLDER_SOURCE $MU_FOLDER_DIR"] | ||
87 | } | ||
88 | |||
89 | proc mu_cleanup_spools {} { | ||
90 | global MU_SPOOL_SOURCE | ||
91 | global MU_SPOOL_DIR | ||
92 | global MU_FOLDER_SOURCE | ||
93 | global MU_FOLDER_DIR | ||
94 | global MU_MAKESPOOL | ||
95 | |||
96 | if { $MU_SPOOL_SOURCE != $MU_SPOOL_DIR } { | ||
97 | set output [remote_exec host "$MU_MAKESPOOL -r \ | ||
98 | $MU_SPOOL_DIR $MU_FOLDER_DIR"] | ||
99 | } | ||
100 | } | ||
101 | |||
102 | proc mu_version {} { | ||
103 | global MU_TOOL | ||
104 | global MU_TOOL_FLAGS | ||
105 | global MU_TOOL_VERSION | ||
106 | |||
107 | if [info exists MU_TOOL_VERSION] { | ||
108 | return | ||
109 | } | ||
110 | |||
111 | set output [remote_exec host "$MU_TOOL --version"] | ||
112 | regexp " \[0-9\]\[^ \t\n\r\]+" "$output" MU_TOOL_VERSION | ||
113 | } | ||
114 | |||
115 | ## | ||
116 | |||
117 | proc mu_send { string } { | ||
118 | global suppress_flag; | ||
119 | if {[info exists suppress_flag] && $suppress_flag} { | ||
120 | return "suppressed"; | ||
121 | } | ||
122 | return [remote_send host "$string"] | ||
123 | } | ||
124 | |||
125 | proc mu_command { cmd } { | ||
126 | set res [mu_send "$cmd\n"] | ||
127 | mu_expect 30 { | ||
128 | -ex "\r\n" { } | ||
129 | default { | ||
130 | perror "mu_command for target failed"; | ||
131 | return -1 | ||
132 | } | ||
133 | } | ||
134 | return $res | ||
135 | } | ||
136 | |||
137 | proc mu_expect { args } { | ||
138 | global env | ||
139 | if { [lindex $args 0] == "-notransfer" } { | ||
140 | set notransfer -notransfer; | ||
141 | set args [lrange $args 1 end]; | ||
142 | } else { | ||
143 | set notransfer ""; | ||
144 | } | ||
145 | |||
146 | if { [llength $args] == 2 && [lindex $args 0] != "-re" } { | ||
147 | set gtimeout [lindex $args 0]; | ||
148 | set expcode [list [lindex $args 1]]; | ||
149 | } else { | ||
150 | upvar timeout timeout; | ||
151 | |||
152 | set expcode $args; | ||
153 | if [target_info exists mailutils,timeout] { | ||
154 | if [info exists timeout] { | ||
155 | if { $timeout < [target_info mailutils,timeout] } { | ||
156 | set gtimeout [target_info mailutils,timeout]; | ||
157 | } else { | ||
158 | set gtimeout $timeout; | ||
159 | } | ||
160 | } else { | ||
161 | set gtimeout [target_info mailutils,timeout]; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | if ![info exists gtimeout] { | ||
166 | global timeout; | ||
167 | if [info exists timeout] { | ||
168 | set gtimeout $timeout; | ||
169 | } else { | ||
170 | # Eeeeew. | ||
171 | set gtimeout 60; | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | |||
176 | global suppress_flag; | ||
177 | global remote_suppress_flag; | ||
178 | global verbose | ||
179 | if [info exists remote_suppress_flag] { | ||
180 | set old_val $remote_suppress_flag; | ||
181 | } | ||
182 | if [info exists suppress_flag] { | ||
183 | if { $suppress_flag } { | ||
184 | set remote_suppress_flag 1; | ||
185 | } | ||
186 | } | ||
187 | |||
188 | verbose "RUNNING remote_expect host $gtimeout $notransfer $expcode" 2 | ||
189 | |||
190 | set code [catch \ | ||
191 | {uplevel remote_expect host $gtimeout $notransfer $expcode} string]; | ||
192 | if [info exists old_val] { | ||
193 | set remote_suppress_flag $old_val; | ||
194 | } else { | ||
195 | if [info exists remote_suppress_flag] { | ||
196 | unset remote_suppress_flag; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | if {$code == 1} { | ||
201 | global errorInfo errorCode; | ||
202 | |||
203 | return -code error -errorinfo $errorInfo -errorcode $errorCode $string | ||
204 | } elseif {$code == 2} { | ||
205 | return -code return $string | ||
206 | } elseif {$code == 3} { | ||
207 | return | ||
208 | } elseif {$code > 4} { | ||
209 | return -code $code $string | ||
210 | } | ||
211 | } | ||
212 | |||
213 | # mu_test COMMAND PATTERN | ||
214 | # COMMAND - Command to send to mail | ||
215 | # PATTERN - A list of strings to expect in return | ||
216 | # Return value: | ||
217 | # -3 - eof | ||
218 | # -2 - timeout | ||
219 | # -1 - generic failure | ||
220 | # 1 - test fails | ||
221 | # 0 - test succeeds | ||
222 | proc mu_test { args } { | ||
223 | global verbose | ||
224 | global suppress_flag | ||
225 | upvar timeout timeout | ||
226 | |||
227 | set command [lindex $args 0] | ||
228 | set pattern [lindex $args 1] | ||
229 | |||
230 | if { [info exists suppress_flag] && $suppress_flag } { | ||
231 | set do_suppress 1 | ||
232 | } else { | ||
233 | set do_suppress 0 | ||
234 | } | ||
235 | |||
236 | if $verbose>2 then { | ||
237 | send_user "Command: \"$command\"\n" | ||
238 | send_user "Pattern: \"$pattern\"\n" | ||
239 | } | ||
240 | |||
241 | set result -1 | ||
242 | if { "${command}" != "" } { | ||
243 | if { [mu_command "${command}"] != "" } { | ||
244 | if { ! $do_suppress } { | ||
245 | perror "Couldn't send \"$command\"."; | ||
246 | } | ||
247 | return $result; | ||
248 | } | ||
249 | } | ||
250 | |||
251 | if [info exists timeout] { | ||
252 | set tmt $timeout; | ||
253 | } else { | ||
254 | global timeout; | ||
255 | if [info exists timeout] { | ||
256 | set tmt $timeout; | ||
257 | } else { | ||
258 | set tmt 60; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | set result 0 | ||
263 | for {set i 0} {$i < [llength $pattern]} {incr i} { | ||
264 | regsub "\[ \t\]*$" [lindex ${pattern} $i] "" pat | ||
265 | verbose "i=$i, pat=$pat" 2 | ||
266 | mu_expect $tmt { | ||
267 | -ex "$pat" { | ||
268 | if { $expect_out(buffer) != $expect_out(0,string) } { | ||
269 | verbose "Got \"$expect_out(buffer)\"" 2 | ||
270 | verbose "instead of expected \"$pat\\r\\n\"" 2 | ||
271 | set result 1 | ||
272 | break | ||
273 | } | ||
274 | mu_expect $tmt { | ||
275 | -re "\[ \t]*\r\n" { } | ||
276 | default { | ||
277 | set result 1 | ||
278 | break | ||
279 | } | ||
280 | timeout { | ||
281 | set result -2 | ||
282 | break | ||
283 | } | ||
284 | eof { | ||
285 | set result -3 | ||
286 | break | ||
287 | } | ||
288 | } | ||
289 | } | ||
290 | default { | ||
291 | set result 1 | ||
292 | break | ||
293 | } | ||
294 | timeout { | ||
295 | set result -2 | ||
296 | break | ||
297 | } | ||
298 | eof { | ||
299 | set result -3 | ||
300 | break | ||
301 | } | ||
302 | } | ||
303 | } | ||
304 | |||
305 | return $result | ||
306 | } | ||
307 | |||
308 | proc mu_test_file {args} { | ||
309 | global verbose | ||
310 | |||
311 | set default "" | ||
312 | set message "" | ||
313 | |||
314 | for {set i 0} {$i < [llength $args]} {incr i} { | ||
315 | set a [lindex $args $i] | ||
316 | if {"$a" == "-default"} { | ||
317 | set default [lindex $args [expr $i + 1]] | ||
318 | incr i | ||
319 | } elseif {"$a" == "-message"} { | ||
320 | set message [lindex $args [expr $i + 1]] | ||
321 | incr i | ||
322 | } else { | ||
323 | set args [lrange $args $i end] | ||
324 | break | ||
325 | } | ||
326 | } | ||
327 | |||
328 | if {"$message" == ""} { | ||
329 | set message "Contents of [lindex $args 0]" | ||
330 | } | ||
331 | |||
332 | if $verbose>2 then { | ||
333 | send_user "Message is \"$message\"\n" | ||
334 | } | ||
335 | |||
336 | set filename [lindex $args 0] | ||
337 | set pattern [lrange $args 1 end] | ||
338 | |||
339 | set res [remote_spawn host "/bin/cat $filename"] | ||
340 | if { $res < 0 || $res == "" } { | ||
341 | perror "Reading $filename failed." | ||
342 | return 1; | ||
343 | } | ||
344 | set result [mu_test "" $pattern] | ||
345 | if {$result == 0} { | ||
346 | pass "$message" | ||
347 | } elseif {$result == 1} { | ||
348 | if { "$default" == "" || "$default" != "FAIL" } { | ||
349 | fail "$message" | ||
350 | } else { | ||
351 | xfail "$message" | ||
352 | set result 0 | ||
353 | } | ||
354 | } elseif {$result == -2} { | ||
355 | fail "$message (timeout)" | ||
356 | } elseif {$result == -3} { | ||
357 | fail "$message (eof)" | ||
358 | } else { | ||
359 | fail "$message" | ||
360 | } | ||
361 | return $result | ||
362 | } | ||
363 | |||
364 |
-
Please register or sign in to post a comment