~ubuntu-branches/ubuntu/saucy/dejagnu/saucy

« back to all changes in this revision

Viewing changes to lib/mondfe.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) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
 
2
# 2001, 2002, 2003 Free Software 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 written by Rob Savoye. (rob@welcomehome.org)
 
21
 
 
22
#
 
23
# Connect to udi using mondfe
 
24
#
 
25
# HOSTNAME can be `iss' to talk to the simulator.
 
26
# The result is the value of `spawn_id' or -1 for failure.
 
27
#
 
28
proc mondfe_open { hostname } {
 
29
    global spawn_id
 
30
    global board_info
 
31
 
 
32
    set retries 0
 
33
    set result  -1
 
34
 
 
35
    set shell_prompt [board_info $hostname shell_prompt]
 
36
    if ![board_info $hostname exists mondfe,name] {
 
37
        perror "Must set board_info(${hostname},mondfe,name)"
 
38
        return -1
 
39
    }
 
40
    if [board_info $hostname exists mondfe] {
 
41
        set mondfe [board_info $hostname mondfe]
 
42
    } else {
 
43
        set mondfe "mondfe"
 
44
    }
 
45
 
 
46
    set remote_host [board_info $hostname mondfe,name]
 
47
 
 
48
    if [board_info $hostname exists mondfe_host] {
 
49
        set rh [board_info $hostname mondfe_host]
 
50
    } else {
 
51
        verbose "Attempting to connect to $hostname via mondfe."
 
52
        set rh "host"
 
53
    }
 
54
 
 
55
    set shell_id [remote_spawn $rh "$mondfe -D -TIP $remote_host"]
 
56
 
 
57
    remote_expect $rh 60 {
 
58
        "$shell_prompt" {
 
59
            verbose "Got prompt"
 
60
            set result 0
 
61
        }
 
62
        "*server bind*failed: Address already in use*" {
 
63
            warning "Socket file already exists."
 
64
            incr retries
 
65
            if { $retries <= 2 } {
 
66
                exp_continue
 
67
            }
 
68
        }
 
69
        -indices -re ".*(UDIERROR\[^\r\n\]*)\[\r\n\]" {
 
70
            warning "$expect_out(1,string)"
 
71
            exp_continue
 
72
        }
 
73
        -indices -re ".*(DFEERROR\[^\r\n\]*)\[\r\n\]" {
 
74
            warning "$expect_out(1,string)"
 
75
            exp_continue
 
76
        }
 
77
        timeout {
 
78
            warning "Timed out trying to connect."
 
79
            set result -1
 
80
            incr retries
 
81
            if { $retries <= 2 } {
 
82
                remote_send $rh "\n"
 
83
                exp_continue
 
84
            }
 
85
        }
 
86
    }
 
87
 
 
88
    if { $result < 0 } {
 
89
        perror "Couldn't connect after $retries retries."
 
90
        remote_close $rh
 
91
        return -1
 
92
    } else {
 
93
        set board_info($hostname,fileid) $shell_id
 
94
        return $shell_id
 
95
    }
 
96
}
 
97
 
 
98
#
 
99
# Downloads using the y (yank) command in mondfe
 
100
#
 
101
# FILE is a full path name to the file to download.
 
102
# Returns 1 if an error occured, 0 otherwise.
 
103
#
 
104
proc mondfe_ld { dest_machine file } {
 
105
    global decimal              # Regexp to match a decimal number.
 
106
 
 
107
    if ![file exists $file] {
 
108
        perror "$file doesn't exist."
 
109
        return ""
 
110
    }
 
111
 
 
112
    set shell_prompt [board_info $dest_machine shell_prompt]
 
113
 
 
114
    if [board_info $dest_machine exists mondfe_host] {
 
115
        set remote_host [board_info $dest_machine mondfe_host]
 
116
        set file [remote_download $remote_host $file montest]
 
117
    } else {
 
118
        set remote_host "host"
 
119
    }
 
120
 
 
121
    verbose "Downloading $file." 2
 
122
    verbose "Shell prompt is $shell_prompt." 3
 
123
    set result 1
 
124
    remote_send $remote_host "y $file\n"
 
125
    remote_expect $remote_host 60 {
 
126
        "y $file" {
 
127
            exp_continue
 
128
        }
 
129
        -re "loading $file\[\r\n\]+" {
 
130
            exp_continue
 
131
        }
 
132
        -re "Load(ing|ed) *TEXT section from\[^\r\n\]*\[\r\n\]+" {
 
133
            verbose -n "." 2
 
134
            exp_continue
 
135
        }
 
136
        -re "Load(ing|ed) *LIT section from\[^\r\n\]*\[\r\n\]+" {
 
137
            verbose -n "." 2
 
138
            exp_continue
 
139
        }
 
140
        -re "Load(ing|ed) *DATA section from\[^\r\n\]*\[\r\n\]+" {
 
141
            verbose -n "." 2
 
142
            exp_continue
 
143
        }
 
144
        -re "Clear(ing|ed) *BSS section from\[^\r\n\]*\[\r\n\]+" {
 
145
            verbose -n "." 2
 
146
            exp_continue
 
147
        }
 
148
        -re "(^|\[\r\n\]+)$shell_prompt$" {
 
149
            verbose "Downloaded $file successfully." 2
 
150
            set result 0
 
151
        }
 
152
        -re "Command failed.*$shell_prompt$" {
 
153
            set result 1
 
154
        }
 
155
        -re "DFEWARNING: $decimal : EMMAGIC:  Bad COFF file magic number.*Command failed.*$shell_prompt$" {
 
156
            warning "Bad COFF file magic number"
 
157
            set result 1
 
158
        }
 
159
        -re "Ignoring COMMENT section \($decimal bytes\)\[^\r\n\]*\[\r\n\]+" {
 
160
            verbose "Ignoring COMMENT section" 2
 
161
            exp_continue
 
162
        }
 
163
        timeout {
 
164
            perror "Timed out trying to download $file."
 
165
            set result 1
 
166
        }
 
167
    }
 
168
 
 
169
    if { $result && [info exists expect_out(buffer)] } {
 
170
        send_log $expect_out(buffer)
 
171
    }
 
172
 
 
173
    if [board_info $dest_machine exists mondfe_host] {
 
174
        remote_file $remote_machine delete $file
 
175
    }
 
176
 
 
177
    return $result
 
178
}
 
179
 
 
180
#
 
181
# Exit the remote shell
 
182
#
 
183
proc mondfe_close { hostname } {
 
184
    global board_info
 
185
 
 
186
    if [board_info $hostname exists mondfe_host] {
 
187
        set remote_host [board_info $hostname mondfe_host]
 
188
    } else {
 
189
        set remote_host "host"
 
190
    }
 
191
 
 
192
    if ![board_info $hostname exists fileid] {
 
193
        return 0
 
194
    }
 
195
 
 
196
    if [board_info $remote_host exists fileid] {
 
197
        remote_send $remote_host "q\n"
 
198
        remote_expect $remote_host 30 {
 
199
            "Goodbye." {
 
200
                verbose "Exited mondfe."
 
201
            }
 
202
            timeout {
 
203
                warning "mondfe didn't exit cleanly."
 
204
            }
 
205
        }
 
206
 
 
207
        remote_close $remote_host
 
208
    }
 
209
 
 
210
    unset board_info($hostname,fileid)
 
211
 
 
212
    return 0
 
213
}