Fix typo in reference manual
[dejagnu.git] / lib / tip.exp
blobc649ffe6c1245d240383d54723c1ee780ab203bd
1 # Copyright (C) 1992-2019, 2020 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, see <http://www.gnu.org/licenses/>.
18 # Connect to HOSTNAME using tip(1). Sets the board's fileid field
19 # with the spawn_id on success and returns the spawn id, otherwise
20 # returns -1.
22 proc tip_open { hostname } {
23 global verbose
24 global spawn_id
26 set tries 0
27 set result -1
29 if {[board_info $hostname exists name]} {
30 set hostname [board_info $hostname name]
32 set port [board_info $hostname tipname]
33 if {[board_info $hostname exists shell_prompt]} {
34 set shell_prompt [board_info $hostname shell_prompt]
35 } else {
36 # Pick something reasonably generic.
37 set shell_prompt ".*> "
40 if {[board_info $hostname exists fileid]} {
41 unset board_info($hostname,fileid)
43 spawn tip -v $port
44 if { $spawn_id < 0 } {
45 perror "invalid spawn id from tip"
46 return -1
48 expect {
49 -re ".*connected.*$" {
50 send "\r\n"
51 expect {
52 -re ".*$shell_prompt.*$" {
53 verbose "Got prompt\n"
54 set result 0
55 incr tries
57 timeout {
58 warning "Never got prompt."
59 set result -1
60 incr tries
61 if { $tries <= 2 } {
62 exp_continue
67 -re "all ports busy.*$" {
68 set result -1
69 perror "All ports busy."
70 incr tries
71 if { $tries <= 2 } {
72 exp_continue
75 -re "Connection Closed.*$" {
76 perror "Never connected."
77 set result -1
78 incr tries
79 if { $tries <= 2 } {
80 exp_continue
83 -re ".*: Permission denied.*link down.*$" {
84 perror "Link down."
85 set result -1
86 incr tries
88 timeout {
89 perror "Timed out trying to connect."
90 set result -1
91 incr tries
92 if { $tries <= 2 } {
93 exp_continue
96 eof {
97 perror "Got unexpected EOF from tip."
98 set result -1
99 incr tries
103 send "\n~s"
104 expect {
105 "~\[set\]*" {
106 verbose "Setting verbose mode" 1
107 send "verbose\n\n\n"
111 if { $result < 0 } {
112 perror "Couldn't connect after $tries tries."
113 return -1
114 } else {
115 set board_info($hostname,fileid) $spawn_id
116 return $spawn_id
120 # Download FILE to DEST using the ~put command in tip(1).
121 # Returns -1 if an error occurred, otherwise returns 0.
123 proc tip_download { dest file args } {
124 global verbose
125 global decimal
126 global expect_out
128 if {[board_info $dest exists shell_prompt]} {
129 set shell_prompt [board_info $dest shell_prompt]
130 } else {
131 set shell_prompt ".*>"
134 set result ""
135 if {![board_info $dest exists fileid]} {
136 perror "tip_download: no connection to $dest."
137 return $result
139 set shell_id [board_info $dest fileid]
141 if {![file exists $file]} {
142 perror "$file doesn't exist."
143 return $result
146 send -i $shell_id "\n~p"
147 expect {
148 -i $shell_id "~\[put\]*" {
149 verbose "Downloading $file, please wait" 1
150 send -i $shell_id "$file\n"
151 set timeout 50
152 expect {
153 -i $shell_id -re ".*$file.*$" {
154 exp_continue
156 -i $shell_id -re ".*lines transferred in.*minute.*seconds.*$shell_prompt.*$" {
157 verbose "Download $file successfully" 1
158 set result $file
160 -i $shell_id -re ".*Invalid command.*$shell_prompt$" {
161 warning "Got an invalid command to the remote shell."
163 -i $shell_id -re ".*$decimal\r" {
164 if {[info exists expect_out(buffer)]} {
165 verbose $expect_out(buffer)
166 exp_continue
169 -i $shell_id timeout {
170 perror "Timed out trying to download."
174 timeout {
175 perror "Timed out waiting for response to put command."
178 set timeout 10
179 return $result