aboutsummaryrefslogtreecommitdiff
path: root/config/netware.exp
blob: a78faa9e1d408f39c202f44f6f50a90f521de84c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
# 2002, 2003, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
#
# This file is part of DejaGnu.
#
# DejaGnu is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# DejaGnu is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with DejaGnu; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.

# This file was written by J.T. Conklin. (jtc@cygnus.com)

#
# load support libraries
#
load_lib remote.exp

# set target variables only if needed

proc ${board}_init { args } {
    global NLMCONV

    # FIXME: rootme is undefined.
    if {![info exists NLMCONV]} then {
	set NLMCONV [findfile "$rootme/../binutils/nlmconv"]
    }
    global LD
    if {![info exists LD]} then {
	set LD [findfile "$rootme/../ld/ld-new" "$rootme/../ld/ld-new" [transform "ld"]]
    }

    set shell_prompt "Password:"
    set shell_id [remote_open target]
    if {[target_info exists passwd]} {
	set passwd [target_info passwd]
    } else {
	set passwd ""
    }
    if {$shell_id < 0} then {
	warning "Couldn't connect to target"
	return -1
    }

    if {[string match "" $passwd]} then {
	stty -echo
	send_user "Password: "
	expect_user -re "(.*)\n"
	send_user "\n"
	set passwd "$expect_out(1,string)"
	stty echo
    }

    send -i $shell_id "$passwd\n"
    expect {
	-i $shell_id ":" {
	    verbose "Got termtype prompt" 0
	}

	-i $shell_id timeout {
	    warning "Connection timed out"
	    return -1
	}
    }

    # FIXME
    set shell_prompt "[string toupper [target_info name]]:"
    send -i $shell_id "1\n"

    expect {
	-i $shell_id -re "$shell_prompt" {}
	-i $shell_id timeout {
	    warning "Connection timed out"
	    return -1
	}
    }
}


#
# ${board}_load -- load the program and execute it
#
# See default.exp for explanation of arguments and results.
#

proc ${board}_load { dest prog args } {
    global LD NLMCONV
    global tmpdir
    global errorCode

    if {[board_info $dest exists fileid]} {
	set shell_id [board_info $dest fileid]
    } else {
	set shell_id -1
    }

    set output ""

    if {$shell_id < 0} then {
	verbose -log "$prog not executed because there is no target" 3
	return "untested"
    }

    #
    set exe [file tail $prog]

    # We can't blindly append a suffix to the object name, because the
    # result may not be valid on netware's 8.3 filesystem.
    #
    # FIXME: tmpdir is undefined.
    set nlm "$tmpdir/x.nlm"
    set lnk "$tmpdir/x.lnk"

    # build *.lnk file
    set fd [open $lnk w]
    puts $fd "description \"$exe\""
    puts $fd "screenname \"System Console\""
    puts $fd "module clib.nlm"
    puts $fd "module mathlib.nlm"
    puts $fd "stack 65536"
    puts $fd "debug"
    # FIXME: don't hardcode location of prelude.o
    puts $fd "input /s1/cygnus/dejagnu/i386-netware/lib/prelude.o"
    puts $fd "input $prog"
    puts $fd "output $nlm"
    close $fd

    # run nlmconv
    verbose "Executing: $NLMCONV -l$LD -T$lnk" 1
    catch "exec $NLMCONV -l$LD -T$lnk" output
    if {![string match "" $output]} then {
	verbose $output 1
    }
    if {![string match "NONE" $errorCode]} {
	verbose -log "Can't link $prog" 3
	return "fail"
    }

    # download
    verbose "Downloading $nlm" 1
    catch "exec cp $nlm /.NetWare/[board_info $dest name].nws/sys.nwv/tmp/x.nlm" output
    if {![string match "" $output]} then {
	verbose $output 1
	verbose -log "cp failed for $nlm" 3
	return "unresolved"
    }

    # Wait a second for the file to "settle" on the NetWare server.
    # I've encountered unexplained failures without this delay.
    #    sleep 1


    # The NetWare remote console expects to be connected to a vt100
    # compatible terminal.  It isn't very efficent, and it seems to
    # send screen repaints for no reason.  So we have to clear the
    # screen as we run each test, otherwise a shell prompt or abort
    # message from a previous test could cause incorrect results.
    send -i $shell_id "CLS\r\n"
    set timeout 1
    expect {
	-i $shell_id -re "$shell_prompt" {
	    exp_continue
	}
    }
    set timeout 10


    # Netware does not support exit status.  The best we can do to
    # detect failures is to look for the "ABNORMAL NLM TERMINATION"
    # message printed by abort().
    set ret 0
    send -i $shell_id "LOAD X.NLM\r\n"
    expect {
	-i $shell_id "ABNORMAL NLM TERMINATION" {
	    set ret 1
	    exp_continue
	}
	-i $shell_id "Unable to find load file" {
	    perror "Couldn't execute program"
	    verbose -log "Couldn't execute program" 3
	    return "unresolved"
	}
	-i $shell_id timeout {
	    perror "Couldn't execute program (timed out)"
	    verbose -log "Couldn't execute program (timed out)" 3
	    return "unresolved"
	}
	-i $shell_id -re "[format "%sLOAD" $shell_prompt]" {
	    exp_continue
	}
	-i $shell_id -re "$shell_prompt" {}
    }

    catch [exec rm -f $lnk]
    catch [exec rm -f $nlm]

    if { $ret == 0 } {
	return "pass"
    } else {
	return "fail"
    }
}

#
# ${tool}_exit -- shutdown the connection
#

proc ${board}_exit {} {
    remote_close target
}