1 # Simulator dejagnu utilities.
3 # Print the version of the simulator being tested.
8 set program [board_info target sim]
9 clone_output "$program $version\n"
12 # Cover function to target_compile.
13 # Copied from gdb_compile.
15 proc sim_compile { source dest type options } {
16 set result [target_compile $source $dest $type $options]
17 regsub "\[\r\n\]*$" "$result" "" result
18 regsub "^\[\r\n\]*" "$result" "" result
19 if { $result != "" } {
20 clone_output "sim compile failed, $result"
25 # Run a program on the simulator.
26 # Required by dejagnu (at least ${tool}_run used to be).
27 # FIXME: What should we do with `redir'?
28 # The result is a list of two elements.
29 # The first is one of pass/fail/etc.
30 # The second is the program's output.
32 # This is different than the sim_load routine provided by
33 # dejagnu/config/sim.exp. It's not clear how to pass arguments to the
34 # simulator (not the simulated program, the simulator) with sim_load.
36 proc sim_run { prog sim_opts redir } {
39 # FIXME: The timeout value we actually want is a function of
40 # host, target, and testcase.
41 set testcase_timeout [board_info target sim_time_limit]
42 if { "$testcase_timeout" == "" } {
43 set testcase_timeout [board_info host testcase_timeout]
45 if { "$testcase_timeout" == "" } {
46 set testcase_timeout 240 ;# 240 same as in dejagnu/config/sim.exp.
49 set sim [board_info target sim]
51 remote_spawn host "$sim $SIMFLAGS $sim_opts $prog"
52 set result [remote_wait host $testcase_timeout]
54 set return_code [lindex $result 0]
55 set output [lindex $result 1]
56 # Remove the \r part of "\r\n" so we don't break all the patterns
58 regsub -all -- "\r" $output "" output
60 # ??? Not sure the test for pass/fail is right.
61 # We just care that the simulator ran correctly, not whether the simulated
62 # program return 0 or non-zero from `main'.
64 if { $return_code == 0 } {
68 return [list $status $output]
71 # Initialize the testrun.
72 # Required by dejagnu.
74 proc sim_init { args } {
75 # Need to return an empty string (copied from GAS).
80 # NAME is either a fully specified file name, or just the file name in which
81 # case $srcdir/$subdir will be prepended.
82 # The file can contain options in the form "# option(mach list): value"
84 # mach(): machine names
85 # as(mach): <assembler options>
86 # ld(mach): <linker options>
87 # sim(mach): <simulator options>
88 # output(): program output pattern to match with string-match
89 # If `output' is not specified, the program must output "pass".
91 proc run_sim_test { name } {
93 global AS ASFLAGS LD LDFLAGS SIMFLAGS
96 if [string match "*/*" $name] {
98 set name [file tail $name]
100 set file "$srcdir/$subdir/$name"
103 set opt_array [slurp_options "${file}"]
104 if { $opt_array == -1 } {
105 unresolved $subdir/$name
114 foreach i $opt_array {
115 set opt_name [lindex $i 0]
116 set opt_machs [lindex $i 1]
117 set opt_val [lindex $i 2]
118 if ![info exists opts($opt_name)] {
119 perror "unknown option $opt_name in file $file"
120 unresolved $subdir/$name
123 foreach m $opt_machs {
124 set opts($opt_name,$m) $opt_val
126 if { "$opt_machs" == "" } {
127 set opts($opt_name) $opt_val
133 if { $opts(output) == "" } {
134 set opts(output) "pass\n"
137 foreach mach $opts(mach) {
138 verbose "Testing $name on $mach."
140 if ![info exists opts(as,$mach)] {
141 set opts(as,$mach) $opts(as)
143 send_log "$AS $ASFLAGS $opts(as,$mach) -I$srcdir/$subdir -o ${name}.o $sourcefile\n"
144 catch "exec $AS $ASFLAGS $opts(as,$mach) -I$srcdir/$subdir -o ${name}.o $sourcefile" comp_output
146 if ![string match "" $comp_output] {
147 verbose -log "$comp_output" 3
148 fail "$mach $testname"
152 if ![info exists opts(ld,$mach)] {
153 set opts(ld,$mach) $opts(ld)
155 send_log "$LD $LDFLAGS $opts(ld,$mach) -o ${name}.x ${name}.o\n"
156 catch "exec $LD $LDFLAGS $opts(ld,$mach) -o ${name}.x ${name}.o" comp_output
158 if ![string match "" $comp_output] {
159 verbose -log "$comp_output" 3
160 fail "$mach $testname"
164 # If no machine specific options, default to the general version.
165 if ![info exists opts(sim,$mach)] {
166 set opts(sim,$mach) $opts(sim)
169 set result [sim_run ${name}.x "$opts(sim,$mach)" ""]
170 set status [lindex $result 0]
171 set output [lindex $result 1]
173 if { "$status" == "pass" } {
174 if ![string match $opts(output) $output] {
175 verbose -log "output: $output" 3
176 verbose -log "pattern: $opts(output)" 3
180 $status "$mach $testname"
184 # Subroutine of run_sim_test to process options in FILE.
186 proc slurp_options { file } {
187 if [catch { set f [open $file r] } x] {
188 #perror "couldn't open `$file': $x"
193 # whitespace expression
196 # whitespace is ignored anywhere except within the options list;
197 # option names are alphabetic only
198 set pat "^#${ws}(\[a-zA-Z\]*)\\((.*)\\)$ws:${ws}(.*)$ws\$"
199 # Allow comment as first line of file.
201 while { [gets $f line] != -1 } {
202 set line [string trim $line]
203 # Whitespace here is space-tab.
204 if [regexp $pat $line xxx opt_name opt_machs opt_val] {
206 lappend opt_array [list $opt_name $opt_machs $opt_val]
208 if { ! $firstline } {