1# Copyright (C) 1992-2016 Free Software Foundation, Inc. 2# 3# This file is part of DejaGnu. 4# 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. 9# 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. 14# 15# You should have received a copy of the GNU General Public License 16# along with DejaGnu; if not, write to the Free Software Foundation, 17# Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. 18 19# 20# sim_load -- load the program and execute it 21# 22# See default.exp for explanation of arguments and results. 23# 24 25proc sim_spawn { dest cmdline args } { 26 if {![board_info $dest exists sim]} { 27 perror "no simulator defined for [board_info $dest name]" 28 exit 1 29 } else { 30 set sim [board_info $dest sim] 31 } 32 33 if {[board_info $dest exists sim,options]} { 34 set simflags [board_info $dest sim,options] 35 } else { 36 set simflags "" 37 } 38 39 if {![isremote host]} { 40 if { [which $sim] == 0 } { 41 verbose -log "Simulator $sim missing." 3 42 return -1 43 } 44 } 45 46 if {[isremote host]} { 47 # download the program to remote. 48 # we're assuming the program is the first word in the command. 49 # FIXME: "prog < infile" won't work until we download infile. 50 set prog [lindex $cmdline 0] 51 set prog [remote_download host $prog a.out] 52 set cmdline [lreplace $cmdline 0 0 $prog] 53 } 54 55 return [eval remote_spawn host \{ $sim $simflags $cmdline \} $args] 56} 57 58proc sim_wait { dest timeout } { 59 return [remote_wait host $timeout] 60} 61 62proc sim_load { dest prog args } { 63 set inpfile "" 64 if { [llength $args] > 1 } { 65 if { [lindex $args 1] ne "" } { 66 set inpfile "[lindex $args 1]" 67 } 68 } 69 70 if {![file exists $prog]} then { 71 perror "sim.exp: $prog to be downloaded does not exist." 72 verbose -log "$prog to be downloaded does not exist." 3 73 return [list "untested" ""] 74 } 75 76 if {[board_info $dest exists sim_time_limit]} { 77 set sim_time_limit [board_info $dest sim_time_limit] 78 } else { 79 set sim_time_limit 240 80 } 81 82 set output "" 83 84 if { [board_info target sim,protocol] eq "sid" } { 85 set cmd "-e \"set cpu-loader file [list $prog]\"" 86 } elseif { [board_info target sim,protocol] eq "rawsid" } { 87 set cmd "--load=$prog" 88 } else { 89 set cmd $prog 90 } 91 92 # Run the program with a limited amount of real time. While 93 # this isn't as nice as limiting the amount of CPU time, it 94 # will have to do. 95 if { $inpfile ne "" } { 96 set res [remote_spawn target "$cmd < $inpfile" "readonly"] 97 } else { 98 set res [remote_spawn target $cmd] 99 } 100 101 if { $res <= 0 } { 102 return [list "fail" "remote_spawn failed"] 103 } 104 105 set state [remote_wait target $sim_time_limit] 106 set status [lindex $state 0] 107 set output [lindex $state 1] 108 verbose "Output is $output" 109 110 set status2 [check_for_board_status output] 111 if { $status2 >= 0 } { 112 set status $status2 113 } 114 115 verbose "Return status was: $status" 2 116 if { $status == 0 } { 117 set result "pass" 118 } else { 119 set result "fail" 120 } 121 return [list $result $output] 122} 123 124proc sim_download { dest file args } { 125 return [remote_download host $file $args] 126} 127 128proc sim_upload { dest srcfile args } { 129 return [remote_upload host $srcfile $args] 130} 131 132proc sim_exec { dest srcfile args } { 133 perror "Remote execution for simulators not implemented." 134 verbose -log "Remote execution for simulators not implemented." 135 return -1 136} 137 138proc sim_file { board args } { 139 return [eval [list remote_file host] $args] 140} 141 142set_board_info protocol "sim" 143 144# By default, assume the simulator is slow. This causes some tests 145# to either be simplified or skipped completely. 146set_board_info slow_simulator 1 147