Replace non-portable Awk code in dejagnu auxiliary launcher
[dejagnu.git] / config / vxworks.exp
blobb49a3f6c80b9468e8536a0d41555d72f48f6a610
1 # Copyright (C) 1992-2016 Free Software Foundation, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # DejaGnu is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
19 # This file was originally written by Rob Savoye <rob@welcomehome.org>
20 # and modified by Bob Manson <manson@cygnus.com>.
23 # Try to boot the machine into the requested OS.
25 proc ${board}_init { dest } {
26 # This is not the right way to determine the required OS...
27 global target_os
28 set shell_prompt [board_info $dest shell_prompt]
29 set do_reboot 0
31 set desired_kernel [board_info $dest "kernel,$target_os"]
33 if { $desired_kernel eq "" } {
34 vxworks_final_init $dest
35 # Nothing to see here, nothing to do. Move along.
36 return
39 remote_raw_open $dest raw
40 remote_send $dest "\n"
41 remote_expect $dest 5 {
42 -re $shell_prompt {
43 set do_reboot 1
45 -re "Press any key to stop auto-boot" {
46 remote_send $dest "\n"
47 exp_continue
49 -re "VxWorks Boot" {
50 set boot_mon 0
51 set boot_mon_prompt "VxWorks Boot"
53 -re {[0-9][\r\n]+ *[0-9][\r\n]} {
54 remote_send $dest "\n"
55 exp_continue
57 timeout {
58 set do_reboot 1
62 if { $do_reboot } {
63 remote_close $dest
64 remote_reboot $dest
65 return
67 remote_binary $dest
68 remote_send $dest "\n\n"
69 remote_expect $dest 3 {
70 timeout {}
71 -re ".+" { exp_continue }
73 remote_send $dest "p\n"
74 remote_expect $dest 20 {
75 -re {file name[ \t]+: ([^ \r\n]+)[ \r\n]+} {
76 set curr_file $expect_out(1,string)
77 exp_continue
79 -re $boot_mon_prompt { }
81 if {![info exists curr_file]} {
82 remote_close $dest
83 remote_reboot $dest
84 return
86 if { $curr_file ne $desired_kernel } {
87 verbose "$curr_file != '$desired_kernel'"
88 # Oh boy.
89 remote_send $dest "c\n"
90 remote_expect $dest 20 {
91 -re {file name[ \t]+:.*$} {
92 remote_send $dest "$desired_kernel\n"
93 exp_continue
95 -re {[a-z() \t]+:.*$} {
96 remote_send $dest "\n"
97 exp_continue
99 -re $boot_mon_prompt {}
102 remote_send $dest "@\n"
103 remote_expect $dest 30 {
104 -re "(^|\[\r\n\])$shell_prompt" {}
105 -re ".+" {
106 exp_continue
109 vxworks_final_init $dest
110 remote_close $dest
113 proc vxworks_final_init { dest } {
114 if {[board_info $dest exists preload_obj]} {
115 if { [target_compile [board_info $dest preload_obj] foo.out object [board_info $dest preload_obj_flags]] eq "" } {
116 vxworks_ld $dest foo.out
118 remote_file build delete foo.out
122 # Execute the command PROGRAM on VxWorks.
125 proc vxworks_exec { dest program pargs inp outp } {
126 global decimal hex
128 set shell_id [vxworks_open $dest]
129 if { $shell_id < 0 } {
130 return [list -1 "open failure"]
133 if { $inp ne "" } {
134 set inp [remote_download $dest $inp]
135 set suffix " < $inp"
136 } else {
137 set suffix ""
140 set shell_prompt [board_info $dest shell_prompt]
141 remote_send $dest "$program $pargs$suffix\n"
142 # FIXME: The value 300 below should probably be a parameter passed in.
143 remote_expect $dest 300 {
144 -re {\[VxWorks Boot\]:} {
145 remote_send $dest "@\n"
146 sleep 20
147 exp_continue
149 -re "(.*)value = (-*$decimal) = $hex\[^\r\n\]*\[\r\n\]+$shell_prompt" {
150 set result [list $expect_out(2,string) $expect_out(1,string)]
152 -re "undefined symbol: .*$shell_prompt" {
153 set result [list 1 "unknown command"]
155 -re "syntax error.*$shell_prompt" {
156 set result [list -1 "syntax error in command"]
158 default {
159 set result [list -1 "unable to execute command"]
162 if { $suffix ne "" } {
163 remote_file $dest delete $inp
165 return $result
168 proc vxworks_download { dest localfile remotefile } {
169 if {[board_info $dest exists vxworks_homedir]} {
170 set rfile "[board_info $dest vxworks_homedir]/$remotefile"
171 remote_download build $localfile $rfile
172 return $rfile
174 return [remote_raw_download $dest $localfile $remotefile]
177 proc vxworks_file { dest op args } {
178 set file [lindex $args 0]
179 if {[board_info $dest exists vxworks_homedir]} {
180 set dir "[board_info $dest vxworks_homedir]"
181 switch -- $op {
182 exists {
183 set file "$dir/[file tail $file]"
184 return [file exists $file]
186 delete {
187 foreach x $args {
188 set x "$dir/[file tail $x]"
189 if { [file exists $x] && [file isfile $x] } {
190 file delete -force -- $x
193 return {}
197 return [eval remote_raw_file \"$dest\" \"$op\" $args]
200 proc vxworks_send { dest string } {
201 # Convert LFs to CRs, 'cause that is what VxWorks wants to see.
202 regsub -all "\n" $string "\r" string
203 verbose "Sending '$string' to $dest" 2
204 return [remote_raw_send $dest $string]
207 proc vxworks_open { dest args } {
208 if {[board_info $dest exists fileid]} {
209 return [board_info $dest fileid]
212 set shell_prompt [board_info $dest shell_prompt]
214 set shell_id [remote_raw_open $dest]
216 if { $shell_id eq "" || $shell_id < 0 } {
217 return -1
220 if {[board_info $dest exists logname]} {
221 set logname [board_info $dest logname]
222 if {[board_info $dest exists password]} {
223 remote_send $dest "iam \"$logname\",\"[board_info $dest passwd]\"\r"
224 } else {
225 remote_send $dest "iam \"$logname\"\r"
228 remote_expect $dest 30 {
229 "iam*value = 0 = 0x0*$shell_prompt" {
230 verbose "Set default user." 2
232 timeout {
233 perror "Couldn't set default user."
234 return -1
239 set dir ""
240 if {[board_info $dest exists ftp_directory]} {
241 set dir [board_info $dest ftp_directory]
243 if {[board_info $dest exists vxworks_homedir]} {
244 set dir [board_info $dest vxworks_homedir]
246 if { $dir ne "" } {
247 set status [remote_exec $dest "cd" "\"$dir\""]
248 if {[lindex $status 0]} {
249 perror "Error in cd to $dir--[lindex $status 1]"
250 return 1
253 return $shell_id
256 # Load a file into vxworks
258 # The result is:
259 # 0 - success
260 # 1 - failed (eg: link failed so testcase should fail)
261 # -1 - unresolved (eg: timeout), may be fixed by rebooting
263 proc vxworks_ld { dest prog } {
264 global decimal hex
265 global board_info
267 if { $prog eq "" } {
268 return 1
271 set shell_id [remote_open $dest]
273 if { $shell_id < 0 } {
274 return -1
277 set prog [remote_download $dest $prog]
279 set shell_prompt [board_info $dest shell_prompt]
281 # We always want to exit the program via the code at the end.
282 # If the load fails we want `expect_out' stored in the log and this
283 # saves duplicating that code.
285 for { set x 0 } { $x < 3 } { incr x } {
286 remote_send $dest "\n"
287 remote_expect $dest 30 {
288 -re ".*$shell_prompt $" { set x 20 }
289 -re {\[VxWorks Boot\]:} {
290 remote_send $dest "@\n"
291 sleep 20
292 exp_continue
294 timeout { return -1 }
298 set tries 0
299 set maxtries 3
300 set result -7 ;# -7 is a local value meaning "not done"
302 while { $result == -7 && $tries < $maxtries } {
303 verbose "Loading $prog into vxworks."
304 remote_send $dest "ld < $prog\n"
305 incr tries
306 remote_expect $dest 300 {
307 -re "USER.*command not understood" {
308 perror "Need to set the user and password."
309 set result 1
311 -re "Stale NFS file handle.*$shell_prompt $" {
312 # Need to retry.
314 -re "undefined symbol:.*$shell_prompt $" {
315 # This is an error in the testcase, don't call perror.
316 warning "Undefined symbol, $prog not loaded."
317 set result 1
319 -re "memPartAlloc: block too.*$shell_prompt $" {
320 perror "Not enough memory to load $prog."
321 set result -1
323 -re "can't open input.*$shell_prompt $" {
324 perror "Can't access $prog."
325 set result 1
327 -re "value = (-*$decimal) = $hex.*$shell_prompt $" {
328 verbose "Loaded $prog into vxworks."
329 set board_info([board_info $dest name],vx_module) $expect_out(1,string)
330 set result 0
332 -re "(.*)$shell_prompt $" {
333 warning "Load failed: $expect_out(1,string)"
335 timeout {
336 warning "Timed out trying load $prog."
337 set result -1
342 if { $result && [info exists expect_out(buffer)] } {
343 send_log $expect_out(buffer)
346 remote_file $dest delete $prog
347 return $result
351 # Start a thread (process) executing
353 # The result is:
354 # 0 - success
355 # 1 - failed (eg: testcase aborted)
356 # -1 - unresolved, may be fixed by rebooting
358 proc vxworks_run { dest function pargs inp outp } {
359 global hex decimal
361 set shell_prompt [board_info $dest shell_prompt]
362 set output ""
364 # There isn't a command to wait for a thread to finish, so we have to keep
365 # polling. Instead, we expect the status wrapper to return an exit
366 # status.
368 set status [remote_exec $dest "sp" "$function $pargs" $inp $outp]
370 set tid [lindex $status 0]
372 # Bad task id, reboot and try again.
373 if { $tid == -1 || $tid == 0 } {
374 return -1
377 set result 1
378 # FIXME: The value 300 below should be a parameter.
379 remote_expect $dest 300 {
380 -re "task $hex - aborted.*$shell_prompt $" {
381 # FIXME: It's not clear we'll ever get here.
382 verbose "$function aborted"
383 set result 1
385 -re {[\r\n]syntax error[\r\n]} {
386 verbose "weirdness after task started"
387 set result -1
389 -re "(.*)\\*\\*\\* EXIT code ($decimal)\[\r\n\]" {
390 set output $expect_out(1,string)
391 set exit_code $expect_out(2,string)
392 if { ($exit_code + 0) != 0 } {
393 set result 1
394 } else {
395 set result 0
398 -re "Operation Fault.*fault type:" {
399 set result 1
401 -re "Bus Error" {
402 # This is here to try to cope with apparently flaky h/w.
403 # This is potentially an error in the testcase, but we don't
404 # really know, do we?
405 warning "Bus Error."
406 set result 1
407 set output "Bus Error"
408 remote_reboot $dest
410 timeout {
411 # Infinite loop? probably.
412 remote_exec $dest "td" $tid
413 set result 1
417 return [list $result $output]
421 # Unload the last executable that we loaded, so we can free up its memory.
423 proc vxworks_unld { dest } {
424 global board_info
426 if {[board_info $dest exists vx_module]} {
427 # Vxworks5.0 does not have the unld command.
428 if { [board_info $dest os] ne "vxworks5.0" } {
429 remote_exec $dest "unld" "[board_info $dest vx_module]"
431 unset board_info([board_info $dest name],vx_module)
436 # We loop around rebooting the box until either the load and run
437 # "work" or we give up.
439 proc vxworks_load {dest prog args} {
440 set result ""
441 set output ""
443 if { [llength $args] > 0 } {
444 set pargs "[lindex $args 0]"
445 } else {
446 set pargs ""
449 if { [llength $args] > 1 } {
450 set inp "[lindex $args 1]"
451 } else {
452 set inp ""
455 if { [llength $args] > 2 } {
456 set outp "[lindex $args 2]"
457 } else {
458 set outp ""
461 for { set x 0 } { $x < 3 } { incr x } {
462 set status [vxworks_ld $dest $prog]
463 if { $status >= 0 } {
464 if { $status > 0 } {
465 set result "fail"
466 } else {
467 set out [vxworks_run $dest __wrap_main $pargs $inp $outp]
468 set status [lindex $out 0]
469 set output [lindex $out 1]
470 # Get rid of the carriage returns, because they confuse
471 # callers that try to parse the result.
472 regsub -all "\r" $output "" output
473 if { $status != 0 } {
474 if { $status > 0 } {
475 set result "fail"
477 } else {
478 set result "pass"
482 if { $result ne "" } {
483 vxworks_unld $dest
484 return [list $result $output]
486 remote_reboot $dest
488 return [list "fail" ""]
491 set_board_info protocol "vxworks"
492 # -lm under vxworks isn't needed.
493 set_board_info mathlib ""
494 set_board_info shell_prompt "->"
495 set_board_info needs_status_wrapper 1
496 # FTP doesn't work in passive mode to this board.
497 set_board_info ftp_no_passive 1
498 # Wait 15 seconds after powercycling.
499 set_board_info reboot_delay 15
501 # We don't have sys/unistd.h.
502 set_board_info wrap_compile_flags "-DNO_UNISTD_H"
504 set_board_info gdb_prompt "\[(\]vxgdb\[)\]"
506 set_board_info is_vxworks 1
507 set_board_info gdb,nosignals 1