1 # Copyright (C) 1992-2016 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/>.
19 # sim_load -- load the program and execute it
21 # See default.exp for explanation of arguments and results.
24 proc sim_spawn { dest cmdline args } {
25 if {![board_info $dest exists sim]} {
26 perror "no simulator defined for [board_info $dest name]"
29 set sim [board_info $dest sim]
32 if {[board_info $dest exists sim,options]} {
33 set simflags [board_info $dest sim,options]
38 if {![isremote host]} {
39 if { [which $sim] == 0 } {
40 verbose -log "Simulator $sim missing." 3
45 if {[isremote host]} {
46 # download the program to remote.
47 # we're assuming the program is the first word in the command.
48 # FIXME: "prog < infile" won't work until we download infile.
49 set prog [lindex $cmdline 0]
50 set prog [remote_download host $prog a.out]
51 set cmdline [lreplace $cmdline 0 0 $prog]
54 return [eval remote_spawn host \{ $sim $simflags $cmdline \} $args]
57 proc sim_wait { dest timeout } {
58 return [remote_wait host $timeout]
61 proc sim_load { dest prog args } {
65 if { [llength $args] > 1 } {
66 if { [lindex $args 1] ne "" } {
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]
79 } elseif {[info exists test_timeout]} {
80 set sim_time_limit $test_timeout
82 set sim_time_limit 240
87 if { [board_info target sim,protocol] eq "sid" } {
88 set cmd "-e \"set cpu-loader file [list $prog]\""
89 } elseif { [board_info target sim,protocol] eq "rawsid" } {
90 set cmd "--load=$prog"
95 verbose -log "Executing on $dest: $prog (timeout = $sim_time_limit)" 2
97 # Run the program with a limited amount of real time. While
98 # this isn't as nice as limiting the amount of CPU time, it
100 if { $inpfile ne "" } {
101 set res [remote_spawn target "$cmd < $inpfile" "readonly"]
103 set res [remote_spawn target $cmd]
107 return [list "fail" "remote_spawn failed"]
110 set state [remote_wait target $sim_time_limit]
111 set status [lindex $state 0]
112 set output [lindex $state 1]
113 verbose "Output is $output"
115 set status2 [check_for_board_status output]
116 if { $status2 >= 0 } {
120 verbose "Return status was: $status" 2
121 if { $status == 0 } {
126 return [list $result $output]
129 proc sim_download { dest file args } {
130 return [remote_download host $file $args]
133 proc sim_upload { dest srcfile args } {
134 return [remote_upload host $srcfile $args]
137 proc sim_exec { dest srcfile args } {
138 perror "Remote execution for simulators not implemented."
139 verbose -log "Remote execution for simulators not implemented."
143 proc sim_file { board args } {
144 return [eval [list remote_file host] $args]
147 set_board_info protocol "sim"
149 # By default, assume the simulator is slow. This causes some tests
150 # to either be simplified or skipped completely.
151 set_board_info slow_simulator 1