1 # Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
4 # This file is part of DejaGnu.
6 # DejaGnu is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # DejaGnu is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with DejaGnu; if not, write to the Free Software Foundation,
18 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 # sim_load -- load the program and execute it
23 # See default.exp for explanation of arguments and results.
26 proc sim_spawn { dest cmdline args } {
27 if ![board_info $dest exists sim] {
28 perror "no simulator defined for [board_info $dest name]"
31 set sim [board_info $dest sim]
34 if [board_info $dest exists sim,options] {
35 set simflags [board_info $dest sim,options]
40 if ![is_remote host] {
41 if { [which $sim] == 0 } {
42 verbose -log "Simulator $sim missing." 3
48 # download the program to remote.
49 # we're assuming the program is the first word in the command.
50 # FIXME: "prog < infile" won't work until we download infile.
51 set prog [lindex $cmdline 0]
52 set prog [remote_download host $prog a.out]
53 set cmdline [lreplace $cmdline 0 0 $prog]
56 return [eval remote_spawn host \{ $sim $simflags $cmdline \} $args]
59 proc sim_wait { dest timeout } {
60 return [remote_wait host $timeout]
63 proc sim_load { dest prog args } {
65 if { [llength $args] > 1 } {
66 if { [lindex $args 1] != "" } {
67 set inpfile "[lindex $args 1]"
71 if ![file exists $prog] then {
72 perror "sim.exp: $prog to be downloaded does not exist."
73 verbose -log "$prog to be downloaded does not exist." 3
74 return [list "untested" ""]
77 if [board_info $dest exists sim_time_limit] {
78 set sim_time_limit [board_info $dest sim_time_limit]
80 set sim_time_limit 240
85 if { [board_info target sim,protocol] == "sid" } {
86 set cmd "-e \"set cpu-loader file [list $prog]\""
87 } elseif { [board_info target sim,protocol] == "rawsid" } {
88 set cmd "--load=$prog"
93 # Run the program with a limited amount of real time. While
94 # this isn't as nice as limiting the amount of CPU time, it
96 if { $inpfile != "" } {
97 set res [remote_spawn target "${cmd} < $inpfile" "readonly"]
99 set res [remote_spawn target "${cmd}"]
103 return [list "fail" "remote_spawn failed"]
106 set state [remote_wait target $sim_time_limit]
107 set status [lindex $state 0]
108 set output [lindex $state 1]
109 verbose "Output is $output"
111 set status2 [check_for_board_status output]
112 if { $status2 >= 0 } {
116 # FIXME: Do we need to examine $status?
117 # Yes, we do--what if the simulator itself gets an error and coredumps?
119 verbose "Return status was: $status" 2
120 if { $status == 0 } {
125 return [list $result $output]
128 set_board_info protocol "sim"
130 # By default, assume the simulator is slow. This causes some tests
131 # to either be simplified or skipped completely.
132 set_board_info slow_simulator 1