OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [dejagnu/] [lib/] [tip.exp] - Blame information for rev 1767

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Copyright (C) 97, 98, 1999 Free Software Foundation, Inc.
2
 
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# DejaGnu@cygnus.com
19
 
20
#
21
# Connect via tip as part of remote_open.
22
# returns -1 if it failed, the spawn_id if it worked; also sets
23
# [board_info ${hostname} fileid] with the spawn_id on success.
24
#
25
proc tip_open { hostname } {
26
    global verbose
27
    global spawn_id
28
 
29
    set tries 0
30
    set result -1
31
 
32
    if [board_info $hostname exists name] {
33
        set hostname [board_info ${hostname} name];
34
    }
35
    set port [board_info ${hostname} tipname]
36
    if [board_info ${hostname} exists shell_prompt] {
37
        set shell_prompt [board_info ${hostname} shell_prompt]
38
    } else {
39
        set shell_prompt ".*> " # Pick something reasonably generic.
40
    }
41
 
42
    if [board_info ${hostname} exists fileid] {
43
        unset board_info(${hostname},fileid);
44
    }
45
    spawn tip -v $port
46
    if { $spawn_id < 0 } {
47
        perror "invalid spawn id from tip"
48
        return -1
49
    }
50
    expect {
51
        -re ".*connected.*$" {
52
            send "\r\n"
53
            expect {
54
                -re ".*$shell_prompt.*$" {
55
                    verbose "Got prompt\n"
56
                    set result 0
57
                    incr tries
58
                }
59
                timeout {
60
                    warning "Never got prompt."
61
                    set result -1
62
                    incr tries
63
                    if $tries<=2 {
64
                        exp_continue
65
                    }
66
                }
67
            }
68
        }
69
        -re "all ports busy.*$" {
70
            set result -1
71
            perror "All ports busy."
72
            incr tries
73
            if { $tries <= 2 } {
74
                exp_continue
75
            }
76
        }
77
        -re "Connection Closed.*$" {
78
            perror "Never connected."
79
            set result -1
80
            incr tries
81
            if { $tries <= 2 } {
82
                exp_continue
83
            }
84
        }
85
        -re ".*: Permission denied.*link down.*$" {
86
            perror "Link down."
87
            set result -1
88
            incr tries
89
        }
90
        timeout {
91
            perror "Timed out trying to connect."
92
            set result -1
93
            incr tries
94
            if { $tries <= 2 } {
95
                exp_continue
96
            }
97
        }
98
        eof {
99
            perror "Got unexpected EOF from tip."
100
            set result -1
101
            incr tries
102
        }
103
    }
104
 
105
    send "\n~s"
106
    expect {
107
        "~\[set\]*" {
108
            verbose "Setting verbose mode" 1
109
            send "verbose\n\n\n"
110
        }
111
    }
112
 
113
    if { $result < 0 } {
114
        perror "Couldn't connect after $tries tries."
115
        return -1
116
    } else {
117
        set board_info($hostname,fileid) $spawn_id
118
        return $spawn_id
119
    }
120
}
121
 
122
#
123
# Downloads using the ~put command under tip
124
#     arg - is a full path name to the file to download
125
#     returns -1 if an error occured, otherwise it returns 0.
126
#
127
proc tip_download { dest file args } {
128
    global verbose
129
    global decimal
130
    global expect_out
131
 
132
    if [board_info $dest exists shell_prompt] {
133
        set shell_prompt [board_info $dest shell_prompt];
134
    } else {
135
        set shell_prompt ".*>"
136
    }
137
 
138
    set result ""
139
    if ![board_info $dest exists fileid] {
140
        perror "tip_download: no connection to $dest."
141
        return $result;
142
    }
143
    set shell_id [board_info $dest fileid];
144
 
145
    if ![file exists $file] {
146
        perror "$file doesn't exist."
147
        return $result
148
    }
149
 
150
    send -i $shell_id "\n~p"
151
    expect {
152
        -i $shell_id "~\[put\]*" {
153
            verbose "Downloading $file, please wait" 1
154
            send -i $shell_id "$file\n"
155
            set timeout 50
156
            expect {
157
                -i $shell_id -re ".*$file.*$" {
158
                    exp_continue
159
                }
160
                -i $shell_id -re ".*lines transferred in.*minute.*seconds.*$shell_prompt.*$" {
161
                    verbose "Download $file successfully" 1
162
                    set result $file;
163
                }
164
                -i $shell_id -re ".*Invalid command.*$shell_prompt$" {
165
                    warning "Got an invalid command to the remote shell."
166
                }
167
                -i $shell_id -re ".*$decimal\r" {
168
                    if [info exists expect_out(buffer)] {
169
                        verbose "$expect_out(buffer)"
170
                        exp_continue
171
                    }
172
                }
173
                -i $shell_id timeout {
174
                    perror "Timed out trying to download."
175
                }
176
            }
177
        }
178
        timeout {
179
            perror "Timed out waiting for response to put command."
180
        }
181
    }
182
    set timeout 10
183
    return $result
184
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.