~ubuntu-branches/ubuntu/warty/dejagnu/warty

« back to all changes in this revision

Viewing changes to config/vxworks.exp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Jacobowitz
  • Date: 2004-02-09 15:07:58 UTC
  • Revision ID: james.westby@ubuntu.com-20040209150758-oaj7r5zrop60v8sb
Tags: upstream-1.4.4
ImportĀ upstreamĀ versionĀ 1.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
 
2
# Foundation, Inc.
 
3
#
 
4
# This file is part of DejaGnu.
 
5
#
 
6
# DejaGnu is free software; you can redistribute it and/or modify it
 
7
# under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# DejaGnu is distributed in the hope that it will be useful, but
 
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
# General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU General Public License
 
17
# along with DejaGnu; if not, write to the Free Software Foundation,
 
18
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 
 
20
# This file was originally written by Rob Savoye. (rob@welcomehome.org)
 
21
# and modified by Bob Manson (manson@cygnus.com)
 
22
 
 
23
#
 
24
# Try to boot the machine into the requested OS.
 
25
#
 
26
proc ${board}_init { dest } {
 
27
    # This is not the right way to determine the required OS...
 
28
    global target_os
 
29
    set shell_prompt [board_info $dest shell_prompt]
 
30
    set do_reboot 0
 
31
 
 
32
    set desired_kernel [board_info $dest "kernel,$target_os"]
 
33
 
 
34
    if { $desired_kernel == "" } {
 
35
        vxworks_final_init $dest
 
36
        # Nothing to see here, nothing to do. Move along.
 
37
        return
 
38
    }
 
39
 
 
40
    remote_raw_open $dest raw
 
41
    remote_send $dest "\n"
 
42
    remote_expect $dest 5 {
 
43
        -re "$shell_prompt" {
 
44
            set do_reboot 1
 
45
        }
 
46
        -re "Press any key to stop auto-boot" {
 
47
            remote_send $dest "\n"
 
48
            exp_continue
 
49
        }
 
50
        -re "VxWorks Boot" {
 
51
            set boot_mon 0
 
52
            set boot_mon_prompt "VxWorks Boot"
 
53
        }
 
54
        -re "\[0-9\]\[\r\n\]+ *\[0-9\]\[\r\n\]" {
 
55
            remote_send $dest "\n"
 
56
            exp_continue
 
57
        }
 
58
        timeout {
 
59
            set do_reboot 1
 
60
        }
 
61
    }
 
62
 
 
63
    if { $do_reboot } {
 
64
        remote_close $dest
 
65
        remote_reboot $dest
 
66
        return
 
67
    }
 
68
    remote_binary $dest
 
69
    remote_send $dest "\n\n"
 
70
    remote_expect $dest 3 {
 
71
        timeout {}
 
72
        -re ".+" { exp_continue }
 
73
    }
 
74
    remote_send $dest "p\n"
 
75
    remote_expect $dest 20 {
 
76
        -re "file name\[ \t\]+: (\[^ \r\n\]+)\[ \r\n\]+" {
 
77
            set curr_file $expect_out(1,string)
 
78
            exp_continue
 
79
        }
 
80
        -re "$boot_mon_prompt" { }
 
81
    }
 
82
    if ![info exists curr_file] {
 
83
        remote_close $dest
 
84
        remote_reboot $dest
 
85
        return
 
86
    }
 
87
    if { $curr_file != $desired_kernel } {
 
88
        verbose "$curr_file != '$desired_kernel'"
 
89
        # Oh boy.
 
90
        remote_send $dest "c\n"
 
91
        remote_expect $dest 20 {
 
92
            -re "file name\[ \t\]+:.*$" {
 
93
                remote_send $dest "$desired_kernel\n"
 
94
                exp_continue
 
95
            }
 
96
            -re "\[a-z() \t\]+:.*$" {
 
97
                remote_send $dest "\n"
 
98
                exp_continue
 
99
            }
 
100
            -re "$boot_mon_prompt" {}
 
101
        }
 
102
    }
 
103
    remote_send $dest "@\n"
 
104
    remote_expect $dest 30 {
 
105
        -re "(^|\[\r\n\])$shell_prompt" {}
 
106
        -re ".+" {
 
107
            exp_continue
 
108
        }
 
109
    }
 
110
    vxworks_final_init $dest
 
111
    remote_close $dest
 
112
}
 
113
 
 
114
proc vxworks_final_init { dest } {
 
115
    if [board_info $dest exists preload_obj] {
 
116
        if { [target_compile [board_info $dest preload_obj] foo.out object [board_info $dest preload_obj_flags]] == "" } {
 
117
            vxworks_ld $dest foo.out
 
118
        }
 
119
        remote_file build delete foo.out
 
120
    }
 
121
}
 
122
#
 
123
# Execute the command PROGRAM on VxWorks.
 
124
#
 
125
 
 
126
proc vxworks_exec { dest program pargs inp outp } {
 
127
    global decimal hex
 
128
 
 
129
    set shell_id [vxworks_open $dest]
 
130
    if { $shell_id < 0 } {
 
131
        return [list -1 "open failure"]
 
132
    }
 
133
 
 
134
    if { $inp != "" } {
 
135
        set inp [remote_download $dest $inp]
 
136
        set suffix " < $inp"
 
137
    } else {
 
138
        set suffix ""
 
139
    }
 
140
 
 
141
    set shell_prompt [board_info $dest shell_prompt]
 
142
    remote_send $dest "${program} ${pargs}$suffix\n"
 
143
    # FIXME: The value 300 below should probably be a parameter passed in.
 
144
    remote_expect $dest 300 {
 
145
        -re "\\\[VxWorks Boot\\\]:" {
 
146
            remote_send $dest "@\n"
 
147
            sleep 20
 
148
            exp_continue
 
149
        }
 
150
        -re "(.*)value = (-*$decimal) = $hex\[^\r\n\]*\[\r\n\]+$shell_prompt" {
 
151
            set result [list $expect_out(2,string) $expect_out(1,string)]
 
152
        }
 
153
        -re "undefined symbol: .*$shell_prompt" {
 
154
            set result [list 1 "unknown command"]
 
155
        }
 
156
        -re "syntax error.*$shell_prompt" {
 
157
            set result [list -1 "syntax error in command"]
 
158
        }
 
159
        default {
 
160
            set result [list -1 "unable to execute command"]
 
161
        }
 
162
    }
 
163
    if { $suffix != "" } {
 
164
        remote_file $dest delete $inp
 
165
    }
 
166
    return $result
 
167
}
 
168
 
 
169
proc vxworks_download { dest localfile remotefile } {
 
170
    if [board_info $dest exists vxworks_homedir] {
 
171
        set rfile "[board_info $dest vxworks_homedir]/$remotefile"
 
172
        remote_download build $localfile $rfile
 
173
        return $rfile
 
174
    }
 
175
    return [remote_raw_download $dest $localfile $remotefile]
 
176
}
 
177
 
 
178
proc vxworks_file { dest op args } {
 
179
    set file [lindex $args 0]
 
180
    if [board_info $dest exists vxworks_homedir] {
 
181
        set dir "[board_info $dest vxworks_homedir]"
 
182
        switch $op {
 
183
            exists {
 
184
                set file "${dir}/[file tail $file]"
 
185
                return [file exists $file]
 
186
            }
 
187
            delete {
 
188
                foreach x $args {
 
189
                    set x "${dir}/[file tail $x]"
 
190
                    if { [file exists $x] && [file isfile $x] } {
 
191
                        exec rm -f $x
 
192
                    }
 
193
                }
 
194
                return
 
195
            }
 
196
        }
 
197
    }
 
198
    return [eval remote_raw_file \"$dest\" \"$op\" $args]
 
199
}
 
200
 
 
201
proc vxworks_send { dest string } {
 
202
    # Convert LFs to CRs, 'cause that is what VxWorks wants to see.
 
203
    regsub -all "\n" $string "\r" string
 
204
    verbose "Sending '$string' to $dest" 2
 
205
    return [remote_raw_send $dest "$string"]
 
206
}
 
207
 
 
208
proc vxworks_open { dest args } {
 
209
    if [board_info $dest exists fileid] {
 
210
        return [board_info $dest fileid]
 
211
    }
 
212
 
 
213
    set shell_prompt [board_info $dest shell_prompt]
 
214
 
 
215
    set shell_id [remote_raw_open $dest]
 
216
 
 
217
    if { $shell_id == "" || $shell_id < 0 } {
 
218
        return -1
 
219
    }
 
220
 
 
221
    if [board_info $dest exists logname] {
 
222
        set logname [board_info $dest logname]
 
223
        if [board_info $dest exists password] {
 
224
            remote_send $dest "iam \"$logname\",\"[board_info $dest passwd]\"\r"
 
225
        } else {
 
226
            remote_send $dest "iam \"$logname\"\r"
 
227
        }
 
228
 
 
229
        remote_expect $dest 30 {
 
230
            "iam*value = 0 = 0x0*$shell_prompt" {
 
231
                verbose "Set default user." 2
 
232
            }
 
233
            timeout {
 
234
                # ??? This is really an error.  It's not clear whether `perror'
 
235
                # or `warning' should be used here.  There are *lots* of other
 
236
                # cases like this.
 
237
                perror "Couldn't set default user."
 
238
                return -1
 
239
            }
 
240
        }
 
241
    }
 
242
 
 
243
    set dir ""
 
244
    if [board_info $dest exists ftp_directory] {
 
245
        set dir [board_info $dest ftp_directory]
 
246
    }
 
247
    if [board_info $dest exists vxworks_homedir] {
 
248
        set dir [board_info $dest vxworks_homedir]
 
249
    }
 
250
    if { $dir != "" } {
 
251
        set status [remote_exec $dest "cd" "\"$dir\""]
 
252
        if [lindex $status 0] {
 
253
            perror "Error in cd to $dir--[lindex $status 1]"
 
254
            return 1
 
255
        }
 
256
    }
 
257
    return $shell_id
 
258
}
 
259
#
 
260
# Load a file into vxworks
 
261
#
 
262
# The result is:
 
263
#  0 - success
 
264
#  1 - failed (eg: link failed so testcase should fail)
 
265
# -1 - unresolved (eg: timeout), may be fixed by rebooting
 
266
#
 
267
proc vxworks_ld { dest prog } {
 
268
    global decimal hex
 
269
    global board_info
 
270
 
 
271
    if { $prog == "" } {
 
272
        return 1
 
273
    }
 
274
 
 
275
    set shell_id [remote_open $dest]
 
276
 
 
277
    if { $shell_id < 0 } {
 
278
        return -1
 
279
    }
 
280
 
 
281
    set prog [remote_download $dest $prog]
 
282
 
 
283
    set shell_prompt [board_info $dest shell_prompt]
 
284
 
 
285
    # We always want to exit the program via the code at the end.
 
286
    # If the load fails we want `expect_out' stored in the log and this
 
287
    # saves duplicating that code.
 
288
 
 
289
    for { set x 0 } { $x < 3 } { incr x } {
 
290
        remote_send $dest "\n"
 
291
        remote_expect $dest 30 {
 
292
            -re ".*$shell_prompt $" { set x 20 }
 
293
            -re "\\\[VxWorks Boot\\\]:" {
 
294
                remote_send $dest "@\n"
 
295
                sleep 20
 
296
                exp_continue
 
297
            }
 
298
            timeout { return -1 }
 
299
        }
 
300
    }
 
301
 
 
302
    set tries 0
 
303
    set maxtries 3
 
304
    set result -7       ;# -7 is a local value meaning "not done"
 
305
 
 
306
    while { $result == -7 && $tries < $maxtries } {
 
307
        verbose "Loading $prog into vxworks."
 
308
        remote_send $dest "ld < $prog\n"
 
309
        incr tries
 
310
        remote_expect $dest 300 {
 
311
            -re "USER.*command not understood" {
 
312
                perror "Need to set the user and password."
 
313
                set result 1
 
314
            }
 
315
            -re "Stale NFS file handle.*$shell_prompt $" {
 
316
                # Need to retry.
 
317
            }
 
318
            -re "undefined symbol:.*$shell_prompt $" {
 
319
                # This is an error in the testcase, don't call perror.
 
320
                warning "Undefined symbol, $prog not loaded."
 
321
                set result 1
 
322
            }
 
323
            -re "memPartAlloc: block too.*$shell_prompt $" {
 
324
                perror "Not enough memory to load $prog."
 
325
                set result -1
 
326
            }
 
327
            -re "can't open input.*$shell_prompt $" {
 
328
                perror "Can't access $prog."
 
329
                set result 1
 
330
            }
 
331
            -re "value = (-*${decimal}) = ${hex}.*$shell_prompt $" {
 
332
                verbose "Loaded $prog into vxworks."
 
333
                set board_info([board_info $dest name],vx_module) $expect_out(1,string)
 
334
                set result 0
 
335
            }
 
336
            -re "(.*)$shell_prompt $" {
 
337
                warning "Load failed: $expect_out(1,string)"
 
338
            }
 
339
            timeout {
 
340
                warning "Timed out trying load $prog."
 
341
                set result -1
 
342
            }
 
343
        }
 
344
    }
 
345
 
 
346
    if { $result && [info exists expect_out(buffer)] } {
 
347
        send_log "$expect_out(buffer)"
 
348
    }
 
349
 
 
350
    remote_file $dest delete $prog
 
351
    return $result
 
352
}
 
353
 
 
354
#
 
355
# Start a thread (process) executing
 
356
#
 
357
# The result is:
 
358
#  0 - success
 
359
#  1 - failed (eg: testcase aborted)
 
360
# -1 - unresolved, may be fixed by rebooting
 
361
#
 
362
proc vxworks_run { dest function pargs inp outp } {
 
363
    global hex decimal
 
364
 
 
365
    set shell_prompt [board_info $dest shell_prompt]
 
366
    set output ""
 
367
 
 
368
    # There isn't a command to wait for a thread to finish, so we have to keep
 
369
    # polling. Instead, we expect the status wrapper to return an exit
 
370
    # status.
 
371
 
 
372
    set status [remote_exec $dest "sp" "$function $pargs" $inp $outp]
 
373
 
 
374
    set tid [lindex $status 0]
 
375
 
 
376
    # Bad task id, reboot and try again.
 
377
    if { $tid == -1 || $tid == 0 } {
 
378
        return -1
 
379
    }
 
380
 
 
381
    set result 1
 
382
    # FIXME: The value 300 below should be a parameter.
 
383
    remote_expect $dest 300 {
 
384
        -re "task ${hex} - aborted.*$shell_prompt $" {
 
385
            # FIXME: It's not clear we'll ever get here.
 
386
            verbose "$function aborted"
 
387
            set result 1
 
388
        }
 
389
        -re "\[\r\n\]syntax error\[\r\n\]" {
 
390
            verbose "weirdness after task started"
 
391
            set result -1
 
392
        }
 
393
        -re "(.*)\\*\\*\\* EXIT code ($decimal)\[\r\n\]" {
 
394
            set output "$expect_out(1,string)"
 
395
            set exit_code "$expect_out(2,string)"
 
396
            if { ($exit_code + 0) != 0 } {
 
397
                set result 1
 
398
            } else {
 
399
                set result 0
 
400
            }
 
401
        }
 
402
        -re "Operation Fault.*fault type:" {
 
403
            set result 1
 
404
        }
 
405
        -re "Bus Error" {
 
406
            # This is here to try to cope with apparently flaky h/w.
 
407
            # This is potentially an error in the testcase, but we don't
 
408
            # really know, do we?
 
409
            warning "Bus Error."
 
410
            set result 1
 
411
            set output "Bus Error"
 
412
            remote_reboot $dest
 
413
        }
 
414
        timeout {
 
415
            # Infinite loop? probably.
 
416
            remote_exec $dest "td" "$tid"
 
417
            set result 1
 
418
        }
 
419
    }
 
420
 
 
421
    return [list $result $output]
 
422
}
 
423
 
 
424
#
 
425
# Unload the last executable that we loaded, so we can free up its memory.
 
426
#
 
427
proc vxworks_unld { dest } {
 
428
    global board_info
 
429
 
 
430
    if [board_info $dest exists vx_module] {
 
431
        # Vxworks5.0 does not have the unld command.
 
432
        if { [board_info $dest os] != "vxworks5.0" } {
 
433
            remote_exec $dest "unld" "[board_info $dest vx_module]"
 
434
        }
 
435
        unset board_info([board_info $dest name],vx_module)
 
436
    }
 
437
}
 
438
 
 
439
#
 
440
# We loop around rebooting the box until either the load and run
 
441
# "work" or we give up.
 
442
#
 
443
proc vxworks_load {dest prog args} {
 
444
    set result ""
 
445
    set output ""
 
446
 
 
447
    if { [llength $args] > 0 } {
 
448
        set pargs "[lindex $args 0]"
 
449
    } else {
 
450
        set pargs ""
 
451
    }
 
452
 
 
453
    if { [llength $args] > 1 } {
 
454
        set inp "[lindex $args 1]"
 
455
    } else {
 
456
        set inp ""
 
457
    }
 
458
 
 
459
    if { [llength $args] > 2 } {
 
460
        set outp "[lindex $args 2]"
 
461
    } else {
 
462
        set outp ""
 
463
    }
 
464
 
 
465
    for { set x 0 } { $x < 3 } { incr x } {
 
466
        set status [vxworks_ld $dest $prog]
 
467
        if { $status >= 0 } {
 
468
            if { $status > 0 } {
 
469
                set result "fail"
 
470
            } else {
 
471
                set out [vxworks_run $dest __wrap_main $pargs $inp $outp]
 
472
                set status [lindex $out 0]
 
473
                set output [lindex $out 1]
 
474
                # Get rid of the carriage returns, because they confuse
 
475
                # callers that try to parse the result.
 
476
                regsub -all "\r" $output "" output
 
477
                if { $status != 0 } {
 
478
                    if { $status > 0 } {
 
479
                        set result "fail"
 
480
                    }
 
481
                } else {
 
482
                    set result "pass"
 
483
                }
 
484
            }
 
485
        }
 
486
        if { $result != "" } {
 
487
            vxworks_unld $dest
 
488
            return [list $result $output]
 
489
        }
 
490
        remote_reboot $dest
 
491
    }
 
492
    return [list "fail" ""]
 
493
}
 
494
 
 
495
set_board_info protocol "vxworks"
 
496
# -lm under vxworks isn't needed.
 
497
set_board_info mathlib ""
 
498
set_board_info shell_prompt "->"
 
499
set_board_info needs_status_wrapper 1
 
500
# FTP doesn't work in passive mode to this board.
 
501
set_board_info ftp_no_passive 1
 
502
# Wait 15 seconds after powercycling.
 
503
set_board_info reboot_delay 15
 
504
 
 
505
# We don't have sys/unistd.h.
 
506
set_board_info wrap_compile_flags "-DNO_UNISTD_H"
 
507
 
 
508
set_board_info gdb_prompt "\[(\]vxgdb\[)\]"
 
509
 
 
510
set_board_info is_vxworks 1
 
511
set_board_info gdb,nosignals 1