~ubuntu-branches/ubuntu/oneiric/dejagnu/oneiric

« back to all changes in this revision

Viewing changes to config/i960.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
#
 
21
# Initialize the board on initial connection or after rebooting.
 
22
# Since the board autobauds, we have to be a bit aggressive about
 
23
# getting a valid prompt.
 
24
#
 
25
proc ${board}_init { dest } {
 
26
    global i960_try_count
 
27
 
 
28
    set prompt [board_info $dest shell_prompt]
 
29
    set done 0
 
30
 
 
31
    if ![info exists i960_try_count] {
 
32
        set i960_try_count 1
 
33
    }
 
34
 
 
35
    remote_close $dest
 
36
    if { [remote_open $dest] != "" } {
 
37
        for { set tries 0 } { $tries < 7 && ! $done } { incr tries } {
 
38
            remote_send $dest "\n"
 
39
            remote_expect $dest 1 {
 
40
                -re "${prompt}" {
 
41
                    set done 1
 
42
                }
 
43
                -re ".+" { exp_continue }
 
44
                timeout { }
 
45
            }
 
46
        }
 
47
    }
 
48
 
 
49
    remote_close $dest
 
50
    if { ! $done } {
 
51
        if { $i960_try_count == 3 } {
 
52
            perror "Couldn't connect to board."
 
53
        } else {
 
54
            incr i960_try_count
 
55
            remote_close $dest
 
56
            remote_reboot $dest
 
57
        }
 
58
    }
 
59
    if [info exists i960_try_count] {
 
60
        unset i960_try_count
 
61
    }
 
62
}
 
63
 
 
64
proc i960_ld { dest prog } {
 
65
    if ![file exists $prog] {
 
66
        perror "$prog does not exist."
 
67
        return "untested"
 
68
    }
 
69
    set shell_prompt [board_info $dest shell_prompt]
 
70
    set strip [board_info $dest strip]
 
71
    set rprog [remote_download host $prog a.out]
 
72
    if { $strip != "" } {
 
73
        remote_exec host $strip $rprog
 
74
    }
 
75
    remote_upload host $rprog a.out
 
76
 
 
77
    set id [remote_open $dest]
 
78
    if { $id < 0 } {
 
79
        return -1
 
80
    }
 
81
    remote_binary $dest
 
82
    remote_send $dest "\n"
 
83
    remote_expect $dest 5 {
 
84
        -re $shell_prompt { }
 
85
    }
 
86
    remote_send $dest "do\n"
 
87
    remote_expect $dest 5 {
 
88
        -re "Downloading" { }
 
89
    }
 
90
    # Nasty.
 
91
    if { [board_info $dest connect] == "telnet" } {
 
92
        global board_info
 
93
 
 
94
        remote_close $dest
 
95
        set hp [split [board_info $dest netport] ":"]
 
96
        set host [lindex $hp 0]
 
97
        set port [lindex $hp 1]
 
98
        set status -1
 
99
        while { $status != 0 } {
 
100
            set status [catch "socket $host $port" id2]
 
101
            if { $status != 0 } {
 
102
                sleep 5
 
103
            }
 
104
        }
 
105
    } else {
 
106
        set id2 [exp_open -leaveopen -i $id]
 
107
    }
 
108
    if [catch "exec sx -bX a.out <@$id2 >@$id2 2>/dev/null" error] {
 
109
        perror "exec sx failed: $error"
 
110
    }
 
111
    if { [board_info $dest connect] == "telnet" } {
 
112
        close $id2
 
113
        sleep 2
 
114
        remote_open $dest
 
115
        remote_binary $dest
 
116
    }
 
117
    set result 1
 
118
    remote_send $dest "\n"
 
119
    remote_expect $dest 1 {
 
120
        -re "$shell_prompt" {
 
121
            set result 0
 
122
            exp_continue
 
123
        }
 
124
        timeout { }
 
125
    }
 
126
    return $result
 
127
}
 
128
 
 
129
proc i960_spawn { dest prog args } {
 
130
    set shell_prompt [board_info $dest shell_prompt]
 
131
 
 
132
    for { set tries 0 } { $tries < 3 } { incr tries } {
 
133
        set result [remote_ld $dest $prog]
 
134
        if { $result == 0 } {
 
135
            set comm "go [board_info $dest start_addr]"
 
136
            remote_send $dest "$comm\n"
 
137
            remote_expect $dest 10 {
 
138
                -re "$comm\[\r\n\]\[\r\n\]?" { }
 
139
                default { }
 
140
            }
 
141
            return [board_info $dest fileid]
 
142
        } else {
 
143
            remote_reboot $dest
 
144
        }
 
145
    }
 
146
    return -1
 
147
}
 
148
 
 
149
proc i960_wait { dest timeout } {
 
150
    set output ""
 
151
    set shell_prompt [board_info $dest shell_prompt]
 
152
 
 
153
    remote_expect $dest $timeout {
 
154
        -re " fault at \[0-9a-h\]+, subtype \[0-9a-h\]+" {
 
155
            set status -1
 
156
            exp_continue
 
157
        }
 
158
        -re "(.*)(\[\r\n\]|^)Program Exit: (\[0-9\]+)\[\r\n\]" {
 
159
            append output $expect_out(1,string)
 
160
            set status $expect_out(3,string)
 
161
            exp_continue
 
162
        }
 
163
        -re "(.*)$shell_prompt" {
 
164
            append output $expect_out(1,string)
 
165
            set bstatus [check_for_board_status output]
 
166
            if { $bstatus >= 0 } {
 
167
                set status $bstatus
 
168
            }
 
169
        }
 
170
        -re "\[\r\n\]+" {
 
171
            # Sometimes the board goes wacky in the head, and we have
 
172
            # to shoot it.
 
173
            append output $expect_out(buffer)
 
174
            if { [string length $output] < 512000 } {
 
175
                exp_continue
 
176
            } else {
 
177
                set status -1
 
178
            }
 
179
        }
 
180
        default {
 
181
            set status -1
 
182
        }
 
183
    }
 
184
    return [list $status $output]
 
185
}
 
186
 
 
187
proc i960_load { dest prog args } {
 
188
    for { set x 0 } { $x < 3 } { incr x } {
 
189
        set id [eval remote_spawn \{$dest\} \{$prog\} $args]
 
190
        if { $id < 0 } {
 
191
            return [list "fail" ""]
 
192
        }
 
193
        set result [remote_wait $dest 120]
 
194
        set status [lindex $result 0]
 
195
        set output [lindex $result 1]
 
196
 
 
197
        if { $status == 0 } {
 
198
            return [list "pass" $output]
 
199
        } else {
 
200
            global i960_retry
 
201
 
 
202
            if { [board_info $dest exists unreliable] && ![info exists i960_retry] } {
 
203
                set i960_retry 1
 
204
                remote_reboot $dest
 
205
                set result [eval i960_load \{$dest\} \{$prog\} $args]
 
206
                unset i960_retry
 
207
                return $result
 
208
            } else {
 
209
                if { $status < 0 } {
 
210
                    remote_reboot $dest
 
211
                }
 
212
                return [list "fail" $output]
 
213
            }
 
214
        }
 
215
    }
 
216
}
 
217
 
 
218
set_board_info shell_prompt "=>"
 
219
set_board_info send_initial_cr 1
 
220
# We take care of getting a prompt in ${board}_init.
 
221
set_board_info dont_wait_for_prompt 1