aboutsummaryrefslogtreecommitdiff
path: root/config/sim.exp
blob: 3471f27c36b7902c6dcb2932f3e5ed2cc6023013 (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
# Copyright (C) 1993 - 2002, 2003 Free Software Foundation, Inc.

# This program 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 2 of the License, or
# (at your option) any later version.
# 
# This program 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 this program; if not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# Please email any bugs, comments, and/or additions to this file to:
# bug-dejagnu@gnu.org

#
# sim_load -- load the program and execute it
#
# See default.exp for explanation of arguments and results.
#

proc sim_spawn { dest cmdline args } {
    if ![board_info $dest exists sim] {
	perror "no simulator defined for [board_info $dest name]"
	exit 1
    } else {
	set sim [board_info $dest sim]
    }

    if [board_info $dest exists sim,options] {
	set simflags [board_info $dest sim,options]
    } else {
        set simflags ""
    }
    
    if ![is_remote host] {
	if { [which $sim] == 0 } {
	    verbose -log "Simulator $sim missing." 3
	    return -1
	}
    }

    if [is_remote host] {
	# download the program to remote.
	# we're assuming the program is the first word in the command.
	# FIXME: "prog < infile" won't work until we download infile.
	set prog [lindex $cmdline 0]
	set prog [remote_download host $prog a.out]
	set cmdline [lreplace $cmdline 0 0 $prog]
    }

    return [eval remote_spawn host \{ $sim $simflags $cmdline \} $args]
}

proc sim_wait { dest timeout } {
    return [remote_wait host $timeout]
}

proc sim_load { dest prog args } {
    set inpfile ""
    if { [llength $args] > 1 } {
	if { [lindex $args 1] != "" } {
	    set inpfile "[lindex $args 1]"
	}
    }

    if ![file exists $prog] then {
	perror "sim.exp: $prog to be downloaded does not exist."
	verbose -log "$prog to be downloaded does not exist." 3
	return [list "untested" ""]
    }

    if [board_info $dest exists sim_time_limit] {
	set sim_time_limit [board_info $dest sim_time_limit]
    } else {
	set sim_time_limit 240
    }

    set output ""

     if { [board_info target sim,protocol] == "sid" } {
       set cmd "-e \"set cpu-loader file [list $prog]\""
     } elseif { [board_info target sim,protocol] == "rawsid" } {
       set cmd "--load=$prog"
     } else {
       set cmd $prog
     }

    # Run the program with a limited amount of real time. While
    # this isn't as nice as limiting the amount of CPU time, it
    # will have to do.
    if { $inpfile != "" } {
	set res [remote_spawn target "${cmd} < $inpfile" "readonly"]
    } else {
	set res [remote_spawn target "${cmd}"]
    }

    if { $res <= 0 } {
	return [list "fail" "remote_spawn failed"]
    }

    set state [remote_wait target $sim_time_limit]
    set status [lindex $state 0]
    set output [lindex $state 1]
    verbose "Output is $output"

    set status2 [check_for_board_status output]
    if { $status2 >= 0 } {
	set status $status2
    }

    # FIXME: Do we need to examine $status?
    # Yes, we do--what if the simulator itself gets an error and coredumps?

    verbose "Return status was: $status" 2
    if { $status == 0 } {
	set result "pass"
    } else {
	set result "fail"
    }
    return [list $result $output]
}

set_board_info protocol  "sim"

# By default, assume the simulator is slow.  This causes some tests
# to either be simplified or skipped completely.
set_board_info slow_simulator 1