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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [boards/] [or32-linux-sim.exp] - Blame information for rev 858

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

Line No. Rev Author Line
1 453 jeremybenn
#!/bin/bash
2
 
3
# Copyright (C) 2010 Embecosm Limited
4
 
5
# Contributor Jeremy Bennett 
6
# Contributor Joern Rennecke 
7
 
8
# This file is a board description for testing OpenRISC with uClibc and
9
# Or1ksim running Linux.
10
 
11
# This program is free software; you can redistribute it and/or modify it
12
# under the terms of the GNU General Public License as published by the Free
13
# Software Foundation; either version 3 of the License, or (at your option)
14
# any later version.
15
 
16
# This program is distributed in the hope that it will be useful, but WITHOUT
17
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
# more details.
20
 
21
# You should have received a copy of the GNU General Public License along
22
# with this program.  If not, see .
23
 
24 473 jeremybenn
# -----------------------------------------------------------------------------
25
# For telnet targets we need to define some functions.
26 453 jeremybenn
 
27 473 jeremybenn
# -----------------------------------------------------------------------------
28
# Custom proc to close a telnet session
29 453 jeremybenn
 
30 553 jeremybenn
# @param[in] connhost  The connected host being closed.
31
# -----------------------------------------------------------------------------
32
proc telnet_close {connhost} {
33 565 jeremybenn
    global board_info
34 553 jeremybenn
 
35
    verbose "telnet_close: connhost $connhost" 3
36
 
37 565 jeremybenn
    # Close the session
38
    set spawn_id [board_info $connhost fileid]
39
    catch close -i $spawn_id
40
    catch wait -i $spawn_id
41
 
42
    # Check we really succeeded in closing
43
    if [board_info $connhost exists fileid] {
44
        verbose "telnet_close: deleting remaining fileid"
45
        unset board_info(${connhost},fileid)
46
    }
47 553 jeremybenn
}
48
 
49
 
50
# -----------------------------------------------------------------------------
51
# Custom proc to check if we have had too many failures
52
 
53 473 jeremybenn
# @param[in] boardname  The board being closed.
54
# -----------------------------------------------------------------------------
55 553 jeremybenn
proc telnet_failure_check { connhost errmess } {
56 555 jeremybenn
    global board_info
57 453 jeremybenn
 
58 553 jeremybenn
    # Get the maximum failure count
59
    set max_fc 10
60 548 jeremybenn
 
61 553 jeremybenn
    if [board_info $connhost exists max_failure_count] {
62
        set max_fc [board_info $connhost max_failure_count]
63 490 jeremybenn
    }
64 553 jeremybenn
    verbose "telnet_failure_check: Max failure count $max_fc"
65 453 jeremybenn
 
66 553 jeremybenn
    # Increment the current failure count
67
    set fc 1
68
    if [board_info $connhost exists failure_count] {
69
        verbose "telnet_failure_check: Incrementing failure count"
70
        set fc [expr [board_info $connhost failure_count] + 1]
71 548 jeremybenn
    }
72 553 jeremybenn
    set board_info($connhost,failure_count) $fc
73 554 jeremybenn
    verbose "telnet_failure_check: current failure count is $fc"
74 548 jeremybenn
 
75 553 jeremybenn
    # Die if we are over the limit
76
    if {$fc >= $max_fc} {
77
        error "Too many failures: $errmess"
78
    }
79 453 jeremybenn
}
80
 
81
 
82 473 jeremybenn
# -----------------------------------------------------------------------------
83 453 jeremybenn
# Custom proc to exec programs using telnet
84 473 jeremybenn
 
85
# We seem to only pass in the first of the arguments supplied to the command.
86
 
87 522 jeremybenn
# The timeout is a mess. It seems to always be 10, not the timeout needed to
88 555 jeremybenn
# execute a regression test (typicall 300 seconds). Fixed by not making it
89
# global and using our own timeout data.
90 473 jeremybenn
 
91 553 jeremybenn
# It also seems that only the first argument is passed.
92
 
93 490 jeremybenn
# @param[in] hostname  The board we are telnetting to
94 473 jeremybenn
# @param[in] cmd        The command to run
95
# @param[in] args       Arguments to the command
96
 
97
# @return  A list of the return code (-1 on failure) and any error message.
98
# -----------------------------------------------------------------------------
99 490 jeremybenn
proc telnet_exec {hostname cmd args} {
100 555 jeremybenn
    global board_info
101 553 jeremybenn
    global verbose
102 453 jeremybenn
 
103 553 jeremybenn
    # Get the connected host name, if it exists. This code matches
104
    # telnet_open.
105
    verbose "telnet_exec: original hostname is $hostname"
106 522 jeremybenn
 
107 553 jeremybenn
    if {[board_info $hostname exists name]} {
108
        set connhost [board_info $hostname name]
109
    } else {
110
        set connhost $hostname
111
    }
112
    verbose "telnet_exec: connhost is $connhost"
113 453 jeremybenn
 
114 553 jeremybenn
    if [board_info $connhost exists hostname] {
115
        set hostname [board_info $connhost hostname]
116
    }
117
    verbose "telnet_exec: hostname is $hostname"
118
 
119 473 jeremybenn
    # Get the first argument, if any.
120 453 jeremybenn
    if { [llength $args] > 0 } {
121
        set pargs [lindex $args 0];
122
    } else {
123
        set pargs ""
124
    }
125
 
126 553 jeremybenn
    verbose "telnet_exec: executing on $connhost, command \"$cmd\", pargs \"$pargs\""
127
 
128
    # Just check if we have more args. Potentially a second arg is an input
129
    # file.
130
    if { [llength $args] > 1 } {
131
        set tinp [lindex $args 1]
132
        if {$tinp != {}} {
133
            verbose "telnet_exec: long args: $args"
134
        }
135
    }
136
 
137 473 jeremybenn
    # Set the shell prompt
138 553 jeremybenn
    if [board_info $connhost exists shell_prompt] {
139
        set shell_prompt [board_info $connhost shell_prompt]
140
    } elseif ![info exists shell_prompt] {
141
        # if no prompt, then set it to something generic
142
        set shell_prompt "\[^\r\n\]*\[$#\] "
143 453 jeremybenn
    }
144
 
145 473 jeremybenn
    # Start a new telnet session if one doesn't already exist. If sucessful
146 553 jeremybenn
    # the fileid field associated with $connhost will be set to the spawn_id
147 473 jeremybenn
    # of the new telnet process.
148 553 jeremybenn
    if ![board_info $connhost exists fileid] {
149 565 jeremybenn
        verbose "telnet_exec: opening new telnet connection"
150 553 jeremybenn
        if {[telnet_open $connhost] == -1} {
151
            return [list -1 "telnet to $hostname failed for $cmd, couldn't begin telnet session"]
152 453 jeremybenn
        }
153
    }
154
 
155 565 jeremybenn
    # The spawn_id we'll use throughout
156 553 jeremybenn
    set spawn_id [board_info $connhost fileid]
157 565 jeremybenn
    verbose "telnet_exec: spawn_id is now $spawn_id"
158
 
159
    # Use a relatively short timeout for most operations. Only the command
160
    # itself uses a long timeout.
161 553 jeremybenn
    set timeout 30
162 453 jeremybenn
 
163
    #Hit enter to make sure you get a shell prompt
164 565 jeremybenn
    send -i $spawn_id "\r"
165 453 jeremybenn
 
166
    expect {
167 473 jeremybenn
        # A prompt indicates the current session is alive
168 565 jeremybenn
        -i $spawn_id -re "$shell_prompt" {
169 553 jeremybenn
            verbose "telnet_exec: got prompt at start"
170 453 jeremybenn
        }
171 565 jeremybenn
        -i $spawn_id default {
172 553 jeremybenn
            # Timeout or EOF. Die if we have had too many failures
173
            telnet_failure_check $connhost "no prompt at telnet start"
174
 
175
            # Try closing the connection and reopening.
176
            telnet_close $connhost
177
            if {[telnet_open $connhost] != -1} {
178
                set spawn_id [board_info $connhost fileid]
179
                verbose "telnet_exec: new telnet session, spawn_id: $spawn_id"
180 565 jeremybenn
                send -i $spawn_id "\r"
181 453 jeremybenn
                exp_continue
182
            } else {
183 553 jeremybenn
                return [list -1 "telnet to $hostname failed for $cmd, couldn't get a shell prompt"]
184 453 jeremybenn
            }
185
        }
186
    }
187 473 jeremybenn
 
188 553 jeremybenn
    # Send the command. We can't cope with any input, so only the first
189
    # argument (group) is sent.
190 565 jeremybenn
    send -i $spawn_id -- "$cmd $pargs\r"
191 553 jeremybenn
 
192
    # We really should get the command echoed back immediately. This is a good
193
    # way of slurping up unexpected prompts. We first swap out any characters
194
    # from the command and args that might cause us grief.
195
    regsub -all "\\+" "$cmd $pargs" "." cmdpargs
196 555 jeremybenn
    verbose "telnet_exec: command match string is \"$cmdpargs\""
197 553 jeremybenn
 
198
    expect {
199 565 jeremybenn
        -i $spawn_id -re "$cmdpargs" {
200 553 jeremybenn
            verbose "telnet_exec: got command echoed back"
201
        }
202 565 jeremybenn
        -i $spawn_id default {
203 555 jeremybenn
            verbose "telnet_exec: command not echoed: command expect_out(buffer): \"$expect_out(buffer)\""
204
        }
205 553 jeremybenn
    }
206
 
207 555 jeremybenn
    # Set the telnet command custom timeout to wait for the command to
208
    # complete executing.
209 553 jeremybenn
    if [board_info $connhost exists telnet_exec_timeout] {
210
        set timeout [board_info $connhost telnet_exec_timeout]
211
        verbose "telnet_exec: command timeout set to $timeout"
212 522 jeremybenn
    } else {
213
        # Appropriate default
214
        set timeout 300
215 553 jeremybenn
        verbose "telnet_exec: command timeout set to default value $timeout"
216 522 jeremybenn
    }
217
 
218 453 jeremybenn
    expect {
219 565 jeremybenn
        -i $spawn_id -re "$shell_prompt" {
220 553 jeremybenn
            verbose "telnet_exec: got prompt after command"
221 453 jeremybenn
        }
222 565 jeremybenn
        -i $spawn_id default {
223 553 jeremybenn
            # Give up on timeout or EOF
224
            telnet_close $connhost
225 490 jeremybenn
            return [list -1 "telnet to $hostname for $cmd $pargs failed (timeout)"]
226
        }
227 453 jeremybenn
    }
228 473 jeremybenn
 
229 553 jeremybenn
    # Remove unnecessary strings from the output string
230
    verbose "telnet_exec: command expect_out(buffer): \"$expect_out(buffer)\""
231
    regsub -all $cmdpargs "$expect_out(buffer)" {} output
232
    regsub "$shell_prompt" $output {} output
233 453 jeremybenn
    regsub -all "\[\r\n\]" $output {} output
234
 
235 553 jeremybenn
    if {$output == ""} {
236
        set output "(no output)"
237
    } else {
238
        set output "\"$output\""
239
    }
240
 
241
    verbose "telnet_exec: command output $output"
242
 
243 555 jeremybenn
    # Check the return status. Use a short timeout for this and following
244
    # commands.
245 453 jeremybenn
    set timeout 30
246 565 jeremybenn
    send -i $spawn_id "echo \$?\r"
247 453 jeremybenn
 
248 553 jeremybenn
    # Once again, look for the "echo" reflected back as a way of slurping up
249
    # unexpected prompts. We don't worry about timeout here - we'll sort that
250 555 jeremybenn
    # out later.
251 553 jeremybenn
    expect {
252 565 jeremybenn
        -i $spawn_id -re "echo \\$\\?" {
253 553 jeremybenn
            verbose "telnet_exec: got \"echo\" echoed back"
254
        }
255 565 jeremybenn
        -i $spawn_id default {
256 555 jeremybenn
            verbose "telnet_exec: echo not echoed: command expect_out(buffer): \"$expect_out(buffer)\""
257
        }
258 553 jeremybenn
    }
259
 
260 555 jeremybenn
    # Look for the shell prompt. Don't worry about timeout for now. It only
261
    # really matters if we don't get a valid status, which we'll discover
262
    # below.
263 553 jeremybenn
    expect {
264 565 jeremybenn
        -i $spawn_id -re "$shell_prompt" {
265 553 jeremybenn
            verbose "telnet_exec: got status shell prompt"
266
        }
267 565 jeremybenn
        -i $spawn_id default {
268 555 jeremybenn
            verbose "telnet_exec: no status shell prompt: command expect_out(buffer): \"$expect_out(buffer)\""
269 553 jeremybenn
        }
270
    }
271
 
272
    # Regsub the output to get the status number
273
    verbose "telnet_exec: status expect_out(buffer): \"$expect_out(buffer)\""
274 453 jeremybenn
    regsub -all {echo \$\?} $expect_out(buffer) {} status
275 553 jeremybenn
    regsub "$shell_prompt" $status {} status
276 453 jeremybenn
    regsub -all "\[\r\n \]" $status {} status
277 553 jeremybenn
    verbose "telnet_exec: status \"$status\""
278 453 jeremybenn
 
279 553 jeremybenn
    # This shouldn't be neccessary...
280 453 jeremybenn
    if {[regexp {[0123456789]+} $status] != 1} {
281 553 jeremybenn
        warning "status not a number (\"$status\"), setting to 1"
282
        verbose "telnet_exec: status (\"$status\"), expect_out(buffer): \"$expect_out(buffer)\""
283 453 jeremybenn
        set status 1
284 553 jeremybenn
 
285
        # Die if we have had too many failures like this.
286
        telnet_failure_check $connhost "bad status"
287 453 jeremybenn
    }
288
 
289
    if {$status == 0} {
290
        return [list "0" "$output"]
291
    } else {
292
        return [list "1" "$output"]
293
    }
294
}
295
 
296 490 jeremybenn
 
297
# -----------------------------------------------------------------------------
298
# For FTP we need to redefine some existing functions to add additional
299
# features.
300
 
301
# -----------------------------------------------------------------------------
302 522 jeremybenn
# Upload REMOTEFILE from HOST as LOCALFILE by FTP
303
 
304
# This version swaps the argument order, which is what the regression test
305
# seems to expect.
306
 
307
# Also allows a custom timeout to be set.
308
 
309
# @param[in] host        The host we are connected to.
310
# @param[in] localfile   The local file to send
311
# @param[in] remotefile  Name of file at remote end.
312
# -----------------------------------------------------------------------------
313
proc ftp_upload {host localfile remotefile} {
314 555 jeremybenn
    global board_info
315
 
316 522 jeremybenn
    set prompt "ftp>"
317
    verbose "ftping $remotefile from $host to $localfile"
318
 
319
    # JPB to set custom timeout (not marked global, so we don't need to save
320
    # and restore)
321
    if [board_info $host exists ftp_upload_timeout] {
322
        set timeout [board_info $host ftp_upload_timeout]
323
        verbose "FTP upload timeout set to $timeout"
324
    } else {
325
        # Appropriate default
326
        set timeout 15
327
        verbose "FTP upload timeout set to default value $timeout"
328
    }
329
 
330
    set spawn_id [ftp_open $host]
331
    if {$spawn_id < 0} {
332
        return ""
333
    }
334
    set loop 1
335
 
336
    while {$loop} {
337
        send -i $spawn_id "get $remotefile $localfile\n"
338
        expect {
339
            -i $spawn_id -re ".*Too many open files.*$prompt" {
340
                ftp_close $host
341
            }
342
            -i $spawn_id -re ".*No such file or directory.*$prompt" {
343
                set loop 0
344
                set remotefile ""
345
            }
346
            -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {set loop 0}
347
            -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
348
                set loop 0
349
                set remotefile ""
350
            }
351
            -i $spawn_id default {
352
                ftp_close $host
353
            }
354
        }
355
        if {$loop} {
356
            set spawn_id [ftp_open $host]
357
            if {$spawn_id < 0} {
358
                return ""
359
            }
360
        }
361
    }
362
    return $localfile
363
}
364
 
365
 
366
# -----------------------------------------------------------------------------
367 490 jeremybenn
# Download LOCALFILE to HOST as REMOTEFILE by FTP
368 522 jeremybenn
 
369 490 jeremybenn
# This version takes a user specified timeout, which we need for our slow
370
# simulated connection.
371
 
372
# @param[in] host        The host we are connected to.
373
# @param[in] localfile   The local file to send
374
# @param[in] remotefile  Name of file at remote end.
375
# -----------------------------------------------------------------------------
376
proc ftp_download {host localfile remotefile} {
377 555 jeremybenn
    global board_info
378
 
379 490 jeremybenn
    set prompt "ftp>"
380
 
381
    verbose "putting $localfile $remotefile"
382
 
383
    if [board_info $host exists hostname] {
384
        set remotehost [board_info $host hostname]
385
    } else {
386
        set remotehost $host
387
    }
388
 
389
    set spawn_id [ftp_open $host]
390
    if {$spawn_id < 0} {
391
        return ""
392
    }
393
    set loop 1
394
 
395
    # JPB to set custom timeout (not marked global, so we don't need to save
396
    # and restore)
397
    if [board_info $host exists ftp_download_timeout] {
398
        set timeout [board_info $host ftp_download_timeout]
399
        verbose "FTP download timeout set to $timeout"
400 522 jeremybenn
    } else {
401
        # Appropriate default
402
        set timeout 15
403
        verbose "FTP download timeout set to default value $timeout"
404 490 jeremybenn
    }
405
 
406
    while {$loop} {
407
        send -i $spawn_id "put $localfile $remotefile\n"
408
        expect {
409
            -i $spawn_id -re ".*Too many open files.*$prompt" {
410
                ftp_close $host
411
            }
412
            -i $spawn_id -re ".*No such file or directory.*$prompt" {
413
                set loop 0
414
                set remotefile ""
415
            }
416
            -re "(^|\[\r\n\])150.*connection for (.*) \[(\]\[0-9.,\]+\\)\[\r\n\]" {
417
                set remotefile $expect_out(2,string)
418
                exp_continue
419
            }
420
            -i $spawn_id -re "(^|\[\r\n\])226.*$prompt" {
421
                set loop 0
422
            }
423
            -i $spawn_id -re "Timeout.*$prompt" {
424
                ftp_close $host
425
            }
426
            -i $spawn_id -re "(^|\[\r\n\])\[0-9\]\[0-9\]\[0-9\].*$prompt" {
427
                set loop 0
428
                set remotefile ""
429
            }
430
            -i $spawn_id default {
431
                ftp_close $host
432
            }
433
        }
434
        if {$loop} {
435
            set spawn_id [ftp_open $host]
436
            if {$spawn_id < 0} {
437
                return ""
438
            }
439
        }
440
    }
441
    return $remotefile
442
}
443
 
444
 
445 473 jeremybenn
# This is a list of toolchains that are supported on this board.
446
set_board_info target_install {or32-linux}
447
 
448
# No multilib options needed by default.
449
process_multilib_options ""
450
 
451
# Load the generic configuration for this board. This will define a basic set
452
# of routines needed by the tool to communicate with the board.
453
load_generic_config "unix"
454
 
455 490 jeremybenn
# Set up remote target info. We select the IP address using an external
456
# program which knows about all available Linuxes.
457 522 jeremybenn
set linux_hostname [exec [file dirname $env(DEJAGNU)]/get-ip.sh --rotate]
458 490 jeremybenn
set_board_info hostname $linux_hostname
459 522 jeremybenn
send_user "OR32 target hostname is $linux_hostname\n"
460 490 jeremybenn
 
461 473 jeremybenn
set_board_info username root
462
 
463
# Use the installed compilers to ensure we get search paths that will find
464
# uClibc.
465
send_user "set_board_info compiler /opt/or32-new/bin/or32-linux-gcc\n"
466
global GCC_UNDER_TEST
467
set GCC_UNDER_TEST "/opt/or32-new/bin/or32-linux-gcc"
468
global GXX_UNDER_TEST
469
set GXX_UNDER_TEST "/opt/or32-new/bin/or32-linux-g++"
470
set_board_info compiler /opt/or32-new/bin/or32-linux-gcc
471
set_board_info c++compiler /opt/or32-new/bin/or32-linux-g++
472
set target_alias "or32-linux"
473
 
474
set_board_info connect telnet
475 553 jeremybenn
set_board_info shell_prompt          "\[^\r\n\]*# "
476 522 jeremybenn
set_board_info telnet_username       "root"
477
set_board_info telnet_password       ""
478 524 jeremybenn
set_board_info telnet_exec_timeout   1200
479 473 jeremybenn
 
480 490 jeremybenn
set_board_info file_transfer         ftp
481
set_board_info ftp_username          root
482
set_board_info ftp_password          ""
483
set_board_info ftp_download_timeout  120
484 522 jeremybenn
set_board_info ftp_upload_timeout    120
485 473 jeremybenn
 
486 453 jeremybenn
# Options for the simulator
487
# set cfg_file [lookfor_file ${srcdir} libgloss/or32/sim.cfg]
488 490 jeremybenn
#set_board_info sim,options "-a \"-f ${cfg_file}\""
489 453 jeremybenn
 
490
# We only support uClibc on this target.  We assume that all multilib options
491
# have been specified before we get here.
492 490 jeremybenn
#set_board_info compiler  "[find_gcc]"
493 453 jeremybenn
 
494 522 jeremybenn
# We need to define this flag to generate default .gcda files if we are using
495
# a stock compiler, without the profopt.exp changes. No problem with doubling
496
# up the argument in normal circumstances.
497
set_board_info cflags    "-fprofile-dir=."
498
set_board_info cxxflags  "-fprofile-dir=."
499 473 jeremybenn
 
500 453 jeremybenn
# No linker script needed.
501
set_board_info ldscript ""
502
 
503
# This simulator isn't slow.
504
set_board_info slow_simulator 0
505
 
506
# Can't pass arguments to programs on this target..
507
set_board_info noargs  1
508
 
509
# Used by a few gcc.c-torture testcases to delimit how large the stack can
510
# be.
511
set_board_info gcc,stack_size 65536
512
 
513
# GDB options
514
 
515
# We can't do input in GDB (yet! HA!). It *will* do output, hurrah.
516
set_board_info gdb,noinferiorio 1
517
# Or pass arguments.
518
set_board_info gdb,noargs  1
519
set_board_info noargs 1
520
# And there's no support for signals.
521
set_board_info gdb,nosignals  1

powered by: WebSVN 2.1.0

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