3 # In general, this belongs in a file in $tool/testsuite/lib,
4 # but that doesn't exist [nor do we want to create N lib directories].
6 # Run the tests that match PATTERN using the sid executable.
7 # Each testcase must have a `sim' entry specifying the sid configuration file.
8 # See the docs for run-one-sid-test.
10 set build_ltldpath [join [glob "../*" "$srcdir/../*"] ":"]
11 set install_ltldpath "$prefix/lib/sidcomp"
12 set sid_run_repetitions 1
14 proc run-sid-tests { toolchain-prefix all-machs testcase-srcdir pattern as-opts ld-opts sid-opts exe-suffix } {
15 set as-prog [sid_find_gas ${toolchain-prefix}]
16 set ld-prog [sid_find_ld ${toolchain-prefix}]
17 set sid-prog [sid_find_sid]
20 ${as-prog} ${as-opts} \
21 ${ld-prog} ${ld-opts} \
23 ${sid-prog} ${sid-opts} \
24 ${all-machs} ${testcase-srcdir} $pattern ${exe-suffix} \
28 # Run the tests that match PATTERN using the ${toolchain-prefix}-run
31 proc run-sid-bsp-tests { toolchain-prefix all-machs testcase-srcdir pattern as-opts ld-opts sid-opts exe-suffix } {
32 set as-prog [sid_find_gas ${toolchain-prefix}]
33 set ld-prog [sid_find_ld ${toolchain-prefix}]
34 set sid-bsp-prog [sid_find_sid_bsp ${toolchain-prefix}]
37 ${as-prog} ${as-opts} \
38 ${ld-prog} ${ld-opts} \
40 ${sid-bsp-prog} ${sid-opts} \
41 ${all-machs} ${testcase-srcdir} $pattern ${exe-suffix} \
45 # Run the tests that match PATTERN using the ${toolchain-prefix}-run
48 proc run-sid-c-bsp-tests { toolchain-prefix all-machs testcase-srcdir pattern gcc-opts sid-opts exe-suffix } {
49 set gcc-prog [sid_find_gcc ${toolchain-prefix}]
50 set sid-bsp-prog [sid_find_sid_bsp ${toolchain-prefix}]
55 ${gcc-prog} ${gcc-opts} \
56 ${sid-bsp-prog} ${sid-opts} \
57 ${all-machs} ${testcase-srcdir} $pattern ${exe-suffix} \
62 proc run-sid-test { as as-opts ld ld-opts gcc gcc-opts sid sid-opts all-machs testcase-srcdir pattern exe-suffix runner } {
65 verbose "as = $as ${as-opts}"
66 verbose "ld = $ld ${ld-opts}"
67 verbose "gcc = $gcc ${gcc-opts}"
68 verbose "sid = $sid ${sid-opts}"
69 verbose "all-machs = ${all-machs}"
70 verbose "testcase-srcdir = ${testcase-srcdir}"
71 verbose "pattern = ${pattern}"
73 foreach src [lsort [glob -nocomplain ${testcase-srcdir}/$pattern]] {
74 # If we're only testing specific files and this isn't one of them,
76 if ![runtest_file_p $runtests $src] {
85 ${all-machs} $src ${exe-suffix} \
90 # Argument to run-one-sid-test to compute the command_line argument for
91 # testcases using a .conf file.
93 proc sid-run-conf { sid sid-opts conf-file test-prog run-options } {
96 # Install a usable .conf file in the build directory.
97 set filename [file tail ${conf-file}]
98 set rc [remote_download host $srcdir/$subdir/${conf-file} ${filename}.in]
100 verbose -log "download failed, $srcdir/$subdir/${conf-file}"
101 return [list unresolved ""]
103 set remote-conf-file $rc
104 # s/@-prefix-@/$prefix/
105 # ??? Another way to do this would be to do it entirely in tcl [open,
106 # read,regsub,write].
107 # ??? Another way would be to be able to pass command line arguments
108 # to sid that are usable in the .conf file.
109 set rc [remote_exec host sed "-e s,@-prefix-@,$prefix, -e s,@-srcdir-@,$srcdir, -e s,@-testprog-@,${test-prog}, " \
110 "${remote-conf-file}" "${filename}" 10]
111 if { [lindex $rc 0] == -1 } {
112 verbose -log "@-prefix-@ substitution failed, [lindex $rc 1]"
113 return [list unresolved ""]
116 # compute component library search path: build tree, then install tree
117 global prefix build_ltldpath install_ltldpath
118 set sidpath [sid_find_sid]
119 global build_ltldpath
120 set ltldpath ":$build_ltldpath:$install_ltldpath:"
121 return [sid_run "$sid ${sid-opts} ${conf-file}" "" "" "${run-options} \"env(SID)=$sidpath\" \"env(SID_LIBRARY_PATH)=$ltldpath\""]
124 # Argument to run-one-sid-test to compute the command_line argument for
125 # testcases using ${target-alias}-run.
127 proc sid-run-bsp { sid sid-opts sid-mach-opts test-prog run-options } {
128 # compute component library search path: build tree, then install tree
129 global prefix build_ltldpath install_ltldpath
130 set ltldpath ":$build_ltldpath:$install_ltldpath:"
131 set sidpath [sid_find_sid]
133 return [sid_run "$sid ${sid-opts} ${sid-mach-opts} ${test-prog}" "" "" "${run-options} \"env(SID)=$sidpath\" \"env(SID_LIBRARY_PATH)=$ltldpath\""]
137 # SRC is a fully specified file name.
138 # AS,LD,GCC,SID are file names of their respective executables.
139 # EXE-SUFFIX is the suffix to give the executable. This is to distinguish the
140 # same testcase being used multiple times (each with different compilation
143 # This works with either the main sid executable (that takes a configuration
144 # file for an argument) or with the easy-to-use(TM) ${target-alias}-run cover
147 # ALL_MACHS is a list of machs to use if "mach: all" is specified in the file.
148 # The file can contain options in the form "# option(mach list): value"
150 # mach: [all | machine names]
151 # as[(mach-list)]: <assembler options>
152 # ld[(mach-list)]: <linker options>
153 # sim[(mach-list)]: <simulator options>
154 # output[(mach-list)]: program output pattern to match with string-match
155 # xerror[(mach-list)]: program is expected to return with a "failure" exit code
156 # If `output' is not specified, the program must output "pass" if !xerror or
158 # The parens in "optname()" are optional if the specification is for all machs.
160 proc run-one-sid-test { as as-opts ld ld-opts gcc gcc-opts sid sid-opts all-machs src exe-suffix runner } {
161 verbose "Testing $src."
164 set name [file tail $src]
165 set testcase-dir [file dirname $src]
167 set opt_array [slurp_options "${file}"]
168 if { $opt_array == -1 } {
179 set opts(xerror) "no"
181 foreach i $opt_array {
182 set opt_name [lindex $i 0]
183 set opt_machs [lindex $i 1]
184 set opt_val [lindex $i 2]
185 if ![info exists opts($opt_name)] {
186 perror "unknown option $opt_name in file $file"
190 foreach m $opt_machs {
191 set opts($opt_name,$m) $opt_val
193 if { "$opt_machs" == "" } {
194 set opts($opt_name) $opt_val
198 set testname "$name (${as-opts},${ld-opts},${gcc-opts},${sid-opts})"
200 if { $opts(output) == "" } {
201 if { "$opts(xerror)" == "no" } {
202 set opts(output) "pass\n"
204 set opts(output) "fail\n"
207 # Change \n sequences to newline chars.
208 regsub -all "\\\\n" $opts(output) "\n" opts(output)
210 # ??? Need a mach-suffix to go with exe-suffix.
211 if {$opts(mach) == "all"} then { set opts(mach) ${all-machs} }
212 foreach mach $opts(mach) {
213 verbose "Testing $name on $mach."
215 set test "$mach $testname"
217 set exe-name ${name}.${exe-suffix}
219 if [string match "*.c" $sourcefile] {
220 if ![info exists opts(gcc,$mach)] {
221 set opts(gcc,$mach) $opts(gcc)
223 send_log "$gcc ${gcc-opts} $opts(gcc,$mach) -I${testcase-dir} -o ${exe-name} $sourcefile\n"
224 catch "exec $gcc ${gcc-opts} $opts(gcc,$mach) -I${testcase-dir} -o ${exe-name} $sourcefile" comp_output
226 if ![string match "" $comp_output] {
227 verbose -log "$comp_output" 3
228 perror "$mach $testname - compile failed"
232 if ![info exists opts(as,$mach)] {
233 set opts(as,$mach) $opts(as)
235 send_log "$as ${as-opts} $opts(as,$mach) -I${testcase-dir} -o ${name}.o $sourcefile\n"
236 catch "exec $as ${as-opts} $opts(as,$mach) -I${testcase-dir} -o ${name}.o $sourcefile" comp_output
238 if ![string match "" $comp_output] {
239 verbose -log "$comp_output" 3
240 perror "$mach $testname - assembly failed"
244 if ![info exists opts(ld,$mach)] {
245 set opts(ld,$mach) $opts(ld)
247 send_log "$ld ${ld-opts} $opts(ld,$mach) -o ${exe-name} ${name}.o\n"
248 catch "exec $ld ${ld-opts} $opts(ld,$mach) -o ${exe-name} ${name}.o" comp_output
250 if ![string match "" $comp_output] {
251 verbose -log "$comp_output" 3
252 perror "$mach $testname - linking failed"
257 # If no machine specific options, default to the general version.
258 if ![info exists opts(sim,$mach)] {
259 set opts(sim,$mach) $opts(sim)
262 # Build the options argument.
264 if { "$opts(timeout)" != "" } {
265 set options "$options timeout=$opts(timeout)"
268 global sid_run_repetitions
269 global last_sid_run_time
270 set last_sid_run_time 99999
271 for {set iter 0} {$iter < $sid_run_repetitions} {incr iter} {
272 set result [$runner $sid "${sid-opts}" "$opts(sim,$mach)" ${exe-name} "$options"]
274 set min_sid_run_time $last_sid_run_time
275 } elseif {$last_sid_run_time < $min_sid_run_time} {
276 set min_sid_run_time $last_sid_run_time
278 set status [lindex $result 0]
279 set output [lindex $result 1]
281 if { "$status" == "pass" } {
282 if { "$opts(xerror)" == "no" } {
283 if [string match $opts(output) $output] {
286 verbose -log "output: $output" 3
287 verbose -log "pattern: $opts(output)" 3
288 fail "$mach $testname"
292 verbose -log "`pass' return code when expecting failure" 3
296 } elseif { "$status" == "fail" } {
297 if { "$opts(xerror)" == "no" } {
298 fail "$mach $testname"
301 if [string match $opts(output) $output] {
304 verbose -log "output: $output" 3
305 verbose -log "pattern: $opts(output)" 3
311 $status "$mach $testname"
314 if {$sid_run_repetitions > 1} then {
315 note "$test simulation time: $min_sid_run_time ms"
320 # Run a program on the simulator.
322 # SIM_OPTS are options for the simulator.
323 # PROG_OPTS are options passed to the simulated program.
324 # At present REDIR must be "" or "> foo".
325 # OPTIONS is a list of options internal to this routine.
326 # This is modelled after target_compile. We want to be able to add new
327 # options without having to update all our users.
329 # env(foo)=val - set environment variable foo to val for this run
330 # timeout=val - set the timeout to val for this run
332 # The result is a list of two elements.
333 # The first is one of pass/fail/etc.
334 # The second is the program's output.
336 # This is different than the sim_load routine provided by
337 # dejagnu/config/sim.exp. It's not clear how to pass arguments to the
338 # simulator (not the simulated program, the simulator) with sim_load.
340 # This used to support running dejagnu on a different host, but due to
341 # the need for multiple files and having one file refering to the other files,
342 # this is much more difficult. Thus this support has been deleted. Should
343 # it ever be needed it can be revisited.
344 # REQUIRED_FILES is unused, but it's meant to contain the list of files that
345 # need to be downloaded to the host. The catch is to update the sid .conf
346 # file to point to where they were put.
348 # sim sim_opts prog prog_opts
349 proc sid_run { command_line required_files redir options } {
350 # Set the default value of the timeout.
351 # FIXME: The timeout value we actually want is a function of
352 # host, target, and testcase.
353 set testcase_timeout [board_info target sim_time_limit]
354 if { "$testcase_timeout" == "" } {
355 set testcase_timeout [board_info host testcase_timeout]
357 if { "$testcase_timeout" == "" } {
358 set testcase_timeout 240 ;# 240 same as in dejagnu/config/sim.exp.
361 # Initialize the environment we pass to the testcase.
364 # Process OPTIONS ...
366 if [regexp {^env\((.*)\)=(.*)} $o full var val] {
367 set testcase_env "$testcase_env $var=$val"
368 } elseif [regexp {^timeout=(.*)} $o full val] {
369 set testcase_timeout $val
374 verbose "testcase timeout is set to $testcase_timeout" 1
376 if [is_remote host] {
377 # Let's make this a catastrophic error so should the time ever come
378 # for it's need, the problem stands out.
379 error "remote host operation isn't supported"
382 # FIXME: this works for UNIX only
383 if { "$testcase_env" != "" } {
384 set command_line "env $testcase_env $command_line"
387 send_log "$command_line\n"
389 set start_time [clock clicks]
390 if { "$redir" == "" } {
391 remote_spawn host "$command_line"
393 remote_spawn host "$command_line $redir" writeonly
395 set result [remote_wait host $testcase_timeout]
396 set end_time [clock clicks]
397 set run_time [expr {($end_time - $start_time) / 1000}]
399 global last_sid_run_time
400 set last_sid_run_time $run_time
401 # note "$test simulation time: $run_time ms"
403 set return_code [lindex $result 0]
404 set output [lindex $result 1]
405 # Remove the \r part of "\r\n" so we don't break all the patterns
407 regsub -all -- "\r" $output "" output
409 # ??? Not sure the test for pass/fail is right.
410 # We just care that the simulator ran correctly, not whether the simulated
411 # program return 0 or non-zero from `main'.
413 if { $return_code == 0 } {
417 return [list $status $output]
420 # Subroutine of run_sim_test to process options in FILE.
422 proc slurp_options { file } {
423 #verbose "Slurping $file"
424 if [catch { set f [open $file r] } x] {
425 #perror "couldn't open `$file': $x"
430 # whitespace expression
433 # whitespace is ignored anywhere except within the options list;
434 # option names are alphabetic only
435 set pat "^#${ws}(\[a-zA-Z\]*)\\(?(\[^):\]*)\\)?$ws:${ws}(.*)$ws\$"
436 # Allow comment as first line of file.
438 while { [gets $f line] != -1 } {
439 set line [string trim $line]
440 # Whitespace here is space-tab.
441 if [regexp $pat $line xxx opt_name opt_machs opt_val] {
443 lappend opt_array [list $opt_name $opt_machs $opt_val]
445 if { ! $firstline } {