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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [dejagnu/] [lib/] [rlogin.exp] - Blame information for rev 1774

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

Line No. Rev Author Line
1 578 markom
# Copyright (C) 92, 93, 94, 95, 96, 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., 675 Mass Ave, Cambridge, MA 02139, USA.
16
 
17
# Please email any bugs, comments, and/or additions to this file to:
18
# bug-dejagnu@prep.ai.mit.edu
19
 
20
#
21
# Connect to ARG using rlogin. This is for systems using rlogin to
22
# braindead targets. It returns either the spawn_id or a -1.
23
#
24
 
25
proc rlogin_open { arg } {
26
    global board_info
27
 
28
    set tries 0
29
    set result -1
30
 
31
    if [board_info $arg exists fileid] {
32
        return [board_info $arg fileid];
33
    }
34
 
35
    # get the hostname and port number from the config array
36
    if [board_info $arg exists netport] {
37
        set hostname [lindex [split [board_info $arg netport] ":"] 0]
38
    } else {
39
        set hostname $arg
40
    }
41
 
42
    if ![board_info $arg exists shell_prompt] {
43
        # if no prompt, then set it to something generic
44
        set shell_prompt ".*> "
45
    } else {
46
        set shell_prompt [board_info $arg shell_prompt]
47
    }
48
 
49
    if [board_info $arg exists fileid] {
50
        unset board_info($arg,fileid);
51
    }
52
    # get the right version of rlogin
53
    if ![board_info $arg exists rlogin_prog] {
54
        set RLOGIN rlogin
55
    } else {
56
        set RLOGIN [board_info $arg rlogin_prog];
57
    }
58
 
59
    # start connection and store the spawn_id
60
    verbose "Opening a $RLOGIN connection to $hostname" 2
61
    spawn $RLOGIN $hostname
62
    if { $spawn_id < 0 } {
63
        perror "invalid spawn id from rlogin"
64
        return
65
    }
66
    set board_info($arg,fileid) $spawn_id
67
 
68
    # Try to connect to the target. We give up after 3 attempts.
69
    while { $tries <= 3 } {
70
        expect {
71
            -re ".*$shell_prompt.*$" {
72
                verbose "Got prompt\n"
73
                set result 0
74
                break
75
            }
76
            -re "TERM = .*\\)\[ ]*$" {
77
                send "dumb\r\n"
78
                expect {
79
                    "Terminal type is*$" {
80
                        verbose "rlogin: set the terminal to dumb" 2
81
                    }
82
                    default {
83
                        warning "rlogin: couldn't set terminmal type"
84
                    }
85
                }
86
                set result 10
87
                break
88
            }
89
            "unknown host" {
90
                perror "rlogin: unknown host"
91
                break
92
            }
93
            "has logged on from" {
94
                exp_continue
95
            }
96
            "Terminal type is" {
97
                verbose "rlogin: connected, got terminal prompt" 2
98
                set result 0
99
                break
100
            }
101
            -re "Maximum number of users already logged in.*$" {
102
                warning "rlogin: maximum number of users already logged in"
103
            }
104
            -re "Sorry, shell is locked.*Connection closed.*$" {
105
                warning "rlogin: lready connected."
106
            }
107
            -re "Sorry, this system is engaged.*Connection closed.*$" {
108
                warning "rlogin: system engaged."
109
            }
110
            timeout     {
111
                warning "rlogin: timed out trying to connect."
112
            }
113
            eof {
114
                perror "rlogin: got EOF while trying to connect."
115
                break
116
            }
117
        }
118
        incr tries
119
    }
120
 
121
    # see if we maxed out on errors
122
    if { $result < 0 } {
123
        catch "close -i $spawn_id"
124
        catch "wait -i $spawn_id"
125
        set spawn_id -1
126
    } else {
127
        verbose "rlogin: connected to $hostname" 2
128
    }
129
 
130
    return $spawn_id
131
}
132
 
133
#
134
# Start CMDLINE running on DEST. Return the shell_id associated with
135
# the command.
136
#
137
proc rlogin_spawn { dest cmdline } {
138
    if ![board_info $dest exists shell_prompt] {
139
        set shell_prompt "(^|\[\r\n\])\[^\r\n\]*>";
140
    } else {
141
        set shell_prompt [board_info $dest shell_prompt];
142
    }
143
    set prefix ""
144
    set ok 0;
145
    for {set i 0;} {$i <= 2 && ! $ok} {incr i;} {
146
        set shell_id [remote_open $dest];
147
        if { $shell_id != "" && $shell_id > 0 } {
148
            remote_send $dest "echo k\r";
149
            remote_expect $dest 20 {
150
                -re "\\(gdb\\)" {
151
                    set shell_prompt "\\(gdb\\)";
152
                    # gdb uses 'shell command'.
153
                    set prefix "shell ";
154
                    set ok 1;
155
                }
156
                -re ".*$shell_prompt" {
157
                    set ok 1;
158
                }
159
                default { }
160
            }
161
        }
162
        if { ! $ok } {
163
            remote_close $dest;
164
            remote_reboot $dest;
165
        }
166
    }
167
    if { ! $ok } {
168
        return "unable to start command"
169
    } else {
170
        remote_send $dest "${prefix}${cmdline}\n";
171
        return [board_info $dest fileid];
172
    }
173
}

powered by: WebSVN 2.1.0

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