1 # runtest.exp -- Test framework driver
2 # Copyright (C) 1992-2019, 2020, 2022, 2023, 2024
3 # Free Software Foundation, Inc.
5 # This file is part of DejaGnu.
7 # DejaGnu is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # DejaGnu is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with DejaGnu. If not, see <http://www.gnu.org/licenses/>.
20 # This file was written by Rob Savoye <rob@welcomehome.org>.
22 set frame_version 1.6.4-git
23 if {![info exists argv0]} {
24 send_error "Must use a version of Expect greater than 5.0\n"
28 # trap some signals so we know whats happening. These definitions are only
29 # temporary until we read in the library stuff
31 trap { send_user "\ninterrupted by user\n"; exit 130 } SIGINT
32 trap { send_user "\nquit\n"; exit 131 } SIGQUIT
33 trap { send_user "\nterminated\n"; exit 143 } SIGTERM
36 # Initialize a few global variables used by all tests.
37 # `reset_vars' resets several of these, we define them here to document their
38 # existence. In fact, it would be nice if all globals used by some interface
39 # of dejagnu proper were documented here.
41 # Keep these all lowercase. Interface variables used by the various
42 # testsuites (eg: the gcc testsuite) should be in all capitals
43 # (eg: TORTURE_OPTIONS).
45 set mail_logs 0 ;# flag for mailing of summary and diff logs
46 set psum_file "latest" ;# file name of previous summary to diff against
48 set exit_status 0 ;# exit code returned by this program
50 set xfail_flag 0 ;# indicates that a failure is expected
51 set xfail_prms 0 ;# GNATS prms id number for this expected failure
52 set kfail_flag 0 ;# indicates that it is a known failure
53 set kfail_prms 0 ;# bug id for the description of the known failure
54 set sum_file "" ;# name of the file that contains the summary log
55 set base_dir "" ;# the current working directory
56 set xml_file "" ;# handle on the XML file if requested
57 set xml 0 ;# flag for requesting xml
58 set logname "" ;# the users login name
59 set prms_id 0 ;# GNATS prms id number
60 set bug_id 0 ;# optional bug id number
61 set dir "" ;# temp variable for directory names
62 set srcdir "." ;# source directory containing the test suite
63 set ignoretests "" ;# list of tests to not execute
64 set objdir "." ;# directory where test case binaries live
66 set multipass "" ;# list of passes and var settings
68 set exit_error 1 ;# Toggle for whether to set the exit status
69 ;# on Tcl bugs in test case drivers.
71 # These describe the host and target environments.
73 set build_triplet "" ;# type of architecture to run tests on
74 set build_os "" ;# type of os the tests are running on
75 set build_vendor "" ;# vendor name of the OS or workstation the test are running on
76 set build_cpu "" ;# type of the cpu tests are running on
77 set host_triplet "" ;# type of architecture to run tests on, sometimes remotely
78 set host_os "" ;# type of os the tests are running on
79 set host_vendor "" ;# vendor name of the OS or workstation the test are running on
80 set host_cpu "" ;# type of the cpu tests are running on
81 set target_triplet "" ;# type of architecture to run tests on, final remote
82 set target_os "" ;# type of os the tests are running on
83 set target_vendor "" ;# vendor name of the OS or workstation the test are running on
84 set target_cpu "" ;# type of the cpu tests are running on
85 set target_alias "" ;# standard abbreviation of target
86 set compiler_flags "" ;# the flags used by the compiler
89 # These set configuration file names and are local to this file.
91 set local_init_file site.exp ;# testsuite-local init file name
92 set global_init_file site.exp ;# global init file name
95 # These are used to locate parts of the testsuite.
97 set testsuitedir "testsuite" ;# top-level testsuite source directory
98 set testbuilddir "testsuite" ;# top-level testsuite object directory
103 namespace eval ::dejagnu::error {
104 # list of { file message errorCode errorInfo } lists
108 # Various ccache versions provide incorrect debug info such as ignoring
109 # different current directory, breaking GDB testsuite.
110 set env(CCACHE_DISABLE) 1
111 unset -nocomplain env(CCACHE_NODISABLE)
114 # some convenience abbreviations
116 set hex "0x\[0-9A-Fa-f\]+"
117 set decimal "\[0-9\]+"
120 # set the base dir (current working directory)
125 # These are set here instead of the init module so they can be overridden
126 # by command line options.
139 # verbose [-n] [-log] [--] message [level]
141 # Print MESSAGE if the verbose level is >= LEVEL.
142 # The default value of LEVEL is 1.
143 # "-n" says to not print a trailing newline.
144 # "-log" says to add the text to the log file even if it won't be printed.
145 # Note that the apparent behaviour of `send_user' dictates that if the message
146 # is printed it is also added to the log file.
147 # Use "--" if MESSAGE begins with "-".
149 # This is defined here rather than in framework.exp so we can use it
150 # while still loading in the support files.
152 proc verbose { args } {
158 if { [string index [lindex $args 0] 0] eq "-" } {
159 for { set i 0 } { $i < [llength $args] } { incr i } {
160 if { [lindex $args $i] eq "--" } {
163 } elseif { [lindex $args $i] eq "-n" } {
165 } elseif { [lindex $args $i] eq "-log" } {
167 } elseif { [lindex $args $i] eq "-x" } {
169 } elseif { [string index [lindex $args $i] 0] eq "-" } {
170 clone_output "ERROR: verbose: illegal argument: [lindex $args $i]"
176 if { [llength $args] == $i } {
177 clone_output "ERROR: verbose: nothing to print"
183 if { [llength $args] > $i + 1 } {
184 set level [lindex $args [expr { $i + 1 }]]
186 set message [lindex $args $i]
188 if { $verbose >= $level } {
189 # We assume send_user also sends the text to the log file (which
190 # appears to be the case though the docs aren't clear on this).
192 send_user -- "$message\n"
194 send_user -- $message
196 } elseif { $logfile } {
198 send_log -- "$message\n"
206 # Transform a tool name to get the installed name.
207 # target_triplet is the canonical target name. target_alias is the
208 # target name used when configure was run.
210 proc transform { name } {
211 global target_triplet
216 if { $target_triplet eq $host_triplet } {
219 if { $target_triplet eq "native" } {
222 if {[board_info host exists no_transform_name]} {
225 if { $target_triplet eq "" } {
228 if {[info exists board]} {
229 if {[board_info $board exists target_install]} {
230 set target_install [board_info $board target_install]
233 if {[target_info exists target_install]} {
234 set target_install [target_info target_install]
236 if {$target_alias ne ""} {
237 set tmp $target_alias-$name
238 } elseif {[info exists target_install]} {
239 if { [lsearch -exact $target_install $target_alias] >= 0 } {
240 set tmp $target_alias-$name
242 set tmp "[lindex $target_install 0]-$name"
245 # There appears to be a possibility for tmp to be unset at this
246 # point, which will cause a Tcl error, but this can only occur if
247 # the init files invoke transform prior to defining target_alias,
248 # since the target_alias will be defaulted to the value of
249 # target_triplet before tests are run. If target_triplet is also
250 # empty, this point will not be reached; see test above.
251 verbose "Transforming $name to $tmp"
257 # findfile arg0 [arg1] [arg2]
259 # Find a file and see if it exists. If you only care about the false
260 # condition, then you'll need to pass a null "" for arg1.
261 # arg0 is the filename to look for. If the only arg,
262 # then that's what gets returned. If this is the
263 # only arg, then if it exists, arg0 gets returned.
264 # if it doesn't exist, return only the prog name.
265 # arg1 is optional, and it's what gets returned if
267 # arg2 is optional, and it's what gets returned if
268 # the file doesn't exist.
270 proc findfile { args } {
272 verbose "Seeing if [lindex $args 0] exists." 2
273 if {[file exists [lindex $args 0]]} {
274 if { [llength $args] > 1 } {
275 verbose "Found file, returning [lindex $args 1]"
276 return [lindex $args 1]
278 verbose "Found file, returning [lindex $args 0]"
279 return [lindex $args 0]
282 if { [llength $args] > 2 } {
283 verbose "Didn't find file [lindex $args 0], returning [lindex $args 2]"
284 return [lindex $args 2]
286 verbose "Didn't find file, returning [file tail [lindex $args 0]]"
287 return [transform [file tail [lindex $args 0]]]
293 # load_file [-1] [--] file1 [ file2 ... ]
295 # Utility to source a file. All are sourced in order unless the flag "-1"
296 # is given in which case we stop after finding the first one.
297 # The result is 1 if a file was found, 0 if not.
298 # If a tcl error occurs while sourcing a file, we print an error message
301 proc load_file { args } {
304 if { [lindex $args $i] eq "-1" } {
308 if { [lindex $args $i] eq "--" } {
313 foreach file [lrange $args $i end] {
314 verbose "Looking for $file" 2
315 # In Tcl, "file exists" fails if the filename looks like
316 # ~/FILE and the environment variable HOME does not exist.
317 if {! [catch {file exists $file} result] && $result} {
319 verbose "Found $file"
320 if { [catch "uplevel #0 source $file"] == 1 } {
321 send_error "ERROR: tcl error sourcing $file.\n"
323 if {[info exists errorInfo]} {
324 send_error "$errorInfo\n"
337 # search_and_load_file -- search DIRLIST looking for FILELIST.
338 # TYPE is used when displaying error and progress messages.
340 proc search_and_load_file { type filelist dirlist } {
343 foreach dir $dirlist {
344 foreach initfile $filelist {
345 set filename [file join $dir $initfile]
346 verbose "Looking for $type $filename" 2
347 if {[file exists $filename]} {
350 if { $type ne "library file" } {
351 send_user "Using $filename as $type.\n"
353 verbose "Loading $filename"
355 if {[catch "uplevel #0 source $filename" error] == 1} {
357 send_error "ERROR: tcl error sourcing $type $filename.\n$error\n"
358 if {[info exists errorInfo]} {
359 send_error "$errorInfo\n"
374 # Give a usage statement.
379 send_user "USAGE: runtest \[options...\]\n"
380 send_user "\t--all, -a\t\tPrint all test output to screen\n"
381 send_user "\t--build \[triplet\]\tThe canonical triplet of the build machine\n"
382 send_user "\t--debug\t\t\tSet expect debugging ON\n"
383 send_user "\t--directory name\tRun only the tests in directory 'name'\n"
384 send_user "\t--global_init \[name\]\tThe file to load for global configuration\n"
385 send_user "\t--help\t\t\tPrint help text\n"
386 send_user "\t--host \[triplet\]\tThe canonical triplet of the host machine\n"
387 send_user "\t--host_board \[name\]\tThe host board to use\n"
388 send_user "\t--ignore \[name(s)\]\tThe names of specific tests to ignore\n"
389 send_user "\t--local_init \[name\]\tThe file to load for local configuration\n"
390 send_user "\t--log_dialog\t\t\Emit Expect output on stdout\n"
391 send_user "\t--mail \[name(s)\]\tWhom to mail the results to\n"
392 send_user "\t--objdir \[name\]\t\tThe test suite binary directory\n"
393 send_user "\t--outdir \[name\]\t\tThe directory to put logs in\n"
394 send_user "\t--reboot\t\tReboot the target (if supported)\n"
395 send_user "\t--srcdir \[name\]\t\tThe test suite source code directory\n"
396 send_user "\t--status\t\tSet the exit status to fail on Tcl errors\n"
397 send_user "\t--strace \[number\]\tTurn on Expect tracing\n"
398 send_user "\t--target \[triplet\]\tThe canonical triplet of the target board\n"
399 send_user "\t--target_board \[name(s)\] The list of target boards to run tests on\n"
400 send_user "\t--tool \[name(s)\]\tRun tests on these tools\n"
401 send_user "\t--tool_exec \[name\]\tThe path to the tool executable to test\n"
402 send_user "\t--tool_opts \[options\]\tA list of additional options to pass to the tool\n"
403 send_user "\t--verbose, -v\t\tProduce verbose output\n"
404 send_user "\t--version, -V\t\tPrint all relevant version numbers\n"
405 send_user "\t--xml, -x\t\tWrite out an XML results file\n"
406 send_user "\t--D\[0-1\]\t\tTcl debugger\n"
407 send_user "\tscript.exp\[=arg(s)\]\tRun these tests only\n"
408 if { [info exists tool] } {
409 if { [info procs ${tool}_option_help] ne "" } {
416 # Parse the arguments the first time looking for these. We will ultimately
417 # parse them twice. Things are complicated because:
418 # - we want to parse --verbose early on
419 # - we don't want config files to override command line arguments
420 # (eg: $base_dir/$local_init_file vs --host/--target)
421 # - we need some command line arguments before we can process some config files
422 # (eg: --objdir before $objdir/$local_init_file, --host/--target before $DEJAGNU)
423 # The use of `arg_host_triplet' and `arg_target_triplet' lets us avoid parsing
424 # the arguments three times.
427 namespace eval ::dejagnu::command_line {
428 variable cmd_var_list [list]
430 proc save_cmd_var {name} {
431 variable cmd_var_list
433 upvar 1 $name target_var
434 lappend cmd_var_list $name $target_var
437 proc restore_cmd_vars {} {
438 variable cmd_var_list
440 foreach {name value} $cmd_var_list {
441 uplevel 1 [list set $name $value]
443 verbose "Variables set by command line arguments restored." 4
446 proc dump_cmd_vars {} {
447 variable cmd_var_list
449 verbose "Variables set by command line arguments:" 4
450 foreach {name value} $cmd_var_list {
451 verbose " $name -> $value" 4
456 set arg_host_triplet ""
457 set arg_target_triplet ""
458 set arg_build_triplet ""
459 set argc [ llength $argv ]
460 for { set i 0 } { $i < $argc } { incr i } {
461 set option [lindex $argv $i]
463 # make all options have two hyphens
464 switch -glob -- $option {
468 set option "-$option"
472 # split out the argument for options that take them
473 switch -glob -- $option {
475 regexp {^[^=]*=(.*)$} $option nil optarg
491 set optarg [lindex $argv $i]
495 switch -glob -- $option {
497 "--vers*" { # (--version) version numbers
498 send_user "DejaGnu version\t$frame_version\n"
499 send_user "Expect version\t[exp_version]\n"
500 send_user "Tcl version\t[ info tclversion ]\n"
504 "--bu*" { # (--build) the build host configuration
505 set arg_build_triplet $optarg
506 ::dejagnu::command_line::save_cmd_var arg_build_triplet
510 "--g*" { # (--global_init) the global init file name
511 set global_init_file $optarg
512 ::dejagnu::command_line::save_cmd_var global_init_file
517 set host_board $optarg
518 ::dejagnu::command_line::save_cmd_var host_board
522 "--ho*" { # (--host) the host configuration
523 set arg_host_triplet $optarg
524 ::dejagnu::command_line::save_cmd_var arg_host_triplet
528 "--loc*" { # (--local_init) the local init file name
529 set local_init_file $optarg
530 ::dejagnu::command_line::save_cmd_var local_init_file
534 "--ob*" { # (--objdir) where the test case object code lives
536 ::dejagnu::command_line::save_cmd_var objdir
540 "--sr*" { # (--srcdir) where the testsuite source code lives
542 ::dejagnu::command_line::save_cmd_var srcdir
547 set target_list $optarg
548 ::dejagnu::command_line::save_cmd_var target_list
552 "--ta*" { # (--target) the target configuration
553 set arg_target_triplet $optarg
554 ::dejagnu::command_line::save_cmd_var arg_target_triplet
559 set TOOL_OPTIONS $optarg
560 ::dejagnu::command_line::save_cmd_var TOOL_OPTIONS
565 set TOOL_EXECUTABLE $optarg
566 ::dejagnu::command_line::save_cmd_var TOOL_EXECUTABLE
570 "--to*" { # (--tool) specify tool name
572 set comm_line_tool $optarg
573 ::dejagnu::command_line::save_cmd_var tool
574 ::dejagnu::command_line::save_cmd_var comm_line_tool
579 set cmdline_dir_to_run $optarg
580 ::dejagnu::command_line::save_cmd_var cmdline_dir_to_run
585 "--verb*" { # (--verbose) verbose output
590 "[A-Z0-9_-.]*=*" { # process makefile style args like CC=gcc, etc...
591 if {[regexp "^(\[A-Z0-9_-\]+)=(.*)$" $option junk var val]} {
593 verbose "$var is now $val"
594 append makevars "set $var $val;" ;# FIXME: Used anywhere?
597 send_error "Illegal variable specification:\n"
598 send_error "$option\n"
605 verbose "Verbose level is $verbose"
607 verbose [concat "Initial working directory is" [pwd]]
609 ::dejagnu::command_line::dump_cmd_vars
612 # get the users login name
614 if { [info exists env(USER)] } {
615 set logname $env(USER)
616 } elseif { [info exists env(LOGNAME)] } {
617 set logname $env(LOGNAME)
618 } elseif { [catch {exec whoami} logname] == 0 } {
620 } elseif { [catch {exec who am i} logname] == 0 } {
621 # systems using "who am i" apparently return some associated garbage
622 set logname [lindex [split $logname " !"] 1]
624 # if we get here, logname contains an error message; erase it
628 # on the GNU system, "who am i" can successfully return an empty string
629 if { $logname eq "" } {
630 send_user "ERROR: couldn't get the user's login name\n"
631 set logname "Unknown"
634 verbose "Login name is $logname"
637 # lookfor_file -- try to find a file by searching up multiple directory levels
639 proc lookfor_file { dir name } {
640 foreach x [list . .. ../.. ../../.. ../../../..] {
641 verbose $dir/$x/$name 2
642 if {[file exists [file join $dir $name]]} {
643 return [file join $dir $name]
645 set dir [remote_file build dirname $dir]
651 # load_lib -- load a library by sourcing it
653 # If there a multiple files with the same name, stop after the first one found.
654 # The order is first look in the install dir, then in a parallel dir in the
655 # source tree (up one or two levels), then in the current dir.
657 proc load_lib { file } {
658 global verbose execpath tool
659 global libdir libdirs srcdir testsuitedir base_dir
662 if {[info exists loaded_libs($file)]} {
666 set loaded_libs($file) ""
667 set search_dirs [list ../lib $libdir $libdir/lib]
668 lappend search_dirs [file dirname [file dirname $srcdir]]/dejagnu/lib
669 lappend search_dirs $testsuitedir/lib
670 lappend search_dirs $execpath/lib "."
671 lappend search_dirs [file dirname [file dirname [file dirname $srcdir]]]/dejagnu/lib
672 if {[info exists libdirs]} {
673 lappend search_dirs $libdirs
675 if { [search_and_load_file "library file" $file $search_dirs ] == 0 } {
676 send_error "ERROR: Couldn't find library file $file.\n"
682 # Begin sourcing the config files.
683 # All are sourced in order.
686 # (local) $base_dir/$local_init_file -> $objdir/$local_init_file ->
687 # (global) installed($global_init_file) -> $DEJAGNU -> $HOME/.dejagnurc
689 # For the normal case, we expect $base_dir/$local_init_file to set
690 # host_triplet and target_triplet.
693 load_file [file join $base_dir $local_init_file]
695 # Ensure that command line parameters override testsuite init files.
696 ::dejagnu::command_line::restore_cmd_vars
699 # If objdir didn't get set in $base_dir/$local_init_file, set it to
700 # $base_dir. Make sure we source $objdir/$local_init_file in case
701 # $base_dir/$local_init_file doesn't exist and objdir was given on the
705 if { $objdir eq "." || $objdir eq $srcdir } {
708 load_file [file join $objdir $local_init_file]
711 # Ensure that command line parameters override testsuite init files.
712 ::dejagnu::command_line::restore_cmd_vars
715 # Find the testsuite.
718 # The DejaGnu manual has always stated that a testsuite must be in a
719 # testsuite/ subdirectory.
721 verbose "Finding testsuite ..." 3
722 verbose "\$base_dir -> $base_dir" 3
723 verbose "\$srcdir -> $srcdir" 3
724 verbose "\$objdir -> $objdir" 3
725 verbose [concat "file tail \$srcdir -> " [file tail $srcdir]] 3
726 verbose [concat "file join \$srcdir testsuite -> " \
727 [file join $srcdir testsuite]] 3
728 verbose [concat "file isdirectory [file join \$srcdir testsuite] -> " \
729 [file isdirectory [file join $srcdir testsuite]]] 3
730 verbose [concat "file tail \$base_dir -> " [file tail $base_dir]] 3
732 if { [file tail $srcdir] eq "testsuite" } {
733 # Subdirectory case -- $srcdir includes testsuite/
734 set testsuitedir $srcdir
735 set testbuilddir $objdir
736 } elseif { [file tail $srcdir] ne "testsuite"
737 && [file isdirectory [file join $srcdir testsuite]] } {
738 # Top-level case -- testsuite in $srcdir/testsuite/
739 set testsuitedir [file join $srcdir testsuite]
740 set testbuilddir [file join $objdir testsuite]
741 } elseif { $srcdir eq "." && [file tail $base_dir] eq "testsuite" } {
742 # Development scaffold case -- testsuite in ".", but "." is "testsuite"
743 set testsuitedir $base_dir
744 set testbuilddir $base_dir
746 if { $testsuitedir eq "testsuite" && $testbuilddir eq "testsuite" } {
747 # Broken legacy case -- testsuite not actually in testsuite/
748 # Produce a warning, but continue.
749 send_error "WARNING: testsuite is not in a testsuite/ directory.\n"
750 set testsuitedir $srcdir
751 set testbuilddir $objdir
753 # Custom case -- all variables are assumed to have been set correctly
757 verbose "Finding testsuite ... done" 3
759 # Well, this just demonstrates the real problem...
760 if {![info exists tool_root_dir]} {
761 set tool_root_dir [file dirname $objdir]
762 if {[file exists [file join $tool_root_dir testsuite]]} {
763 set tool_root_dir [file dirname $tool_root_dir]
767 verbose "Using test sources in $srcdir"
768 verbose "Using test binaries in $objdir"
769 verbose "Testsuite root is $testsuitedir"
770 verbose "Tool root directory is $tool_root_dir"
772 set execpath [file dirname $argv0]
774 # The runtest.exp file is installed directly in libdir.
775 # Conveniently, the source tree layout is the same as the installed libdir.
776 set libdir [file dirname $argv0]
777 if {[info exists env(DEJAGNULIBS)]} {
778 set libdir $env(DEJAGNULIBS)
780 # list of extra search directories used by load_lib to look for libs
783 verbose "Using $libdir to find libraries"
786 # If the host or target was given on the command line, override the above
787 # config files. We allow $DEJAGNU to massage them though in case it would
788 # ever want to do such a thing.
790 if { $arg_host_triplet ne "" } {
791 set host_triplet $arg_host_triplet
793 if { $arg_build_triplet ne "" } {
794 set build_triplet $arg_build_triplet
797 # If we only specify --host, then that must be the build machine too,
798 # and we're stuck using the old functionality of a simple cross test.
799 if {[expr { $build_triplet eq "" && $host_triplet ne "" } ]} {
800 set build_triplet $host_triplet
802 # If we only specify --build, then we'll use that as the host too.
803 if {[expr { $build_triplet ne "" && $host_triplet eq "" } ]} {
804 set host_triplet $build_triplet
806 unset arg_host_triplet arg_build_triplet
809 # If the build machine type hasn't been specified by now, use config.guess.
812 if {[expr {$build_triplet eq "" && $host_triplet eq ""}]} {
814 foreach dir [list $libdir $libdir/libexec $libdir/.. $execpath $srcdir $srcdir/.. $srcdir/../..] {
815 verbose "Looking for $dir/config.guess" 2
816 if {[file exists [file join $dir config.guess]]} {
817 set config_guess [file join $dir config.guess]
818 verbose "Found [file join $dir config.guess]"
823 # get the canonical triplet
824 if {![info exists config_guess]} {
825 send_error "ERROR: Couldn't find config.guess program.\n"
828 if { [info exists ::env(CONFIG_SHELL)] } {
829 if { [catch {exec $::env(CONFIG_SHELL) $config_guess} build_triplet] } {
830 if { [lindex $::errorCode 0] eq "CHILDSTATUS" } {
831 send_error "ERROR: Running config.guess with\
832 CONFIG_SHELL=$::env(CONFIG_SHELL)\
834 [lindex $::errorCode 2].\n"
836 send_error "ERROR: Running config.guess with\
837 CONFIG_SHELL=$::env(CONFIG_SHELL)\
839 send_error " $::errorCode\n"
842 } elseif { [info exists ::env(SHELL)] } {
843 if { [catch {exec $::env(SHELL) $config_guess} build_triplet] } {
844 if { [lindex $::errorCode 0] eq "CHILDSTATUS" } {
845 send_error "ERROR: Running config.guess with\
848 [lindex $::errorCode 2].\n"
850 send_error "ERROR: Running config.guess with\
853 send_error " $::errorCode\n"
857 if { [catch {exec $config_guess} build_triplet] } {
858 if { [lindex $::errorCode 0] eq "CHILDSTATUS" } {
859 send_error "ERROR: Running config.guess exited on code\
860 [lindex $::errorCode 2].\n"
862 send_error "ERROR: Running config.guess produced error:\n"
863 send_error " $::errorCode\n"
867 if { ![regexp -- {^[[:alnum:]_.]+(-[[:alnum:]_.]+)+$} $build_triplet] } {
868 send_error "ERROR: Running config.guess produced bogus build triplet:\n"
869 send_error " $build_triplet\n"
870 send_error " (Perhaps you need to set CONFIG_SHELL or\
871 SHELL in your environment\n"
872 send_error " to the absolute file name of a POSIX shell?)\n"
875 verbose "Assuming build host is $build_triplet"
876 if { $host_triplet eq "" } {
877 set host_triplet $build_triplet
882 # Figure out the target. If the target hasn't been specified, then we have to
883 # assume we are native.
885 if { $arg_target_triplet ne "" } {
886 set target_triplet $arg_target_triplet
887 } elseif { $target_triplet eq "" } {
888 set target_triplet $build_triplet
889 verbose "Assuming native target is $target_triplet" 2
891 unset arg_target_triplet
893 # Default target_alias to target_triplet.
895 if {$target_alias eq ""} {
896 set target_alias $target_triplet
899 proc get_local_hostname { } {
900 if {[catch "info hostname" hb]} {
903 regsub "\\..*$" $hb "" hb
905 verbose "hostname=$hb" 3
910 # We put these here so that they can be overridden later by site.exp or
913 # Set up the target as machine NAME. We also load base-config.exp as a
914 # default configuration. The config files are sourced with the global
915 # variable $board set to the name of the current target being defined.
917 proc setup_target_hook { whole_name name } {
921 if {[info exists host_board]} {
924 set hb [get_local_hostname]
927 set board $whole_name
930 set board_type "target"
932 load_config base-config.exp
933 if {![load_board_description $name $whole_name $hb]} {
934 if { $name ne "unix" } {
935 perror "couldn't load description file for $name"
938 load_generic_config "unix"
942 if {[board_info $board exists generic_name]} {
943 load_tool_target_config [board_info $board generic_name]
949 push_target $whole_name
951 if { [info procs ${whole_name}_init] ne "" } {
952 ${whole_name}_init $whole_name
955 if { ![isnative] && ![isremote target] } {
956 global env build_triplet target_triplet
957 if { (![info exists env(DEJAGNU)]) && ($build_triplet ne $target_triplet) } {
958 warning "Assuming target board is the local machine (which is probably wrong).\nYou may need to set your DEJAGNU environment variable."
964 # Clean things up afterwards.
966 proc cleanup_target_hook { name } {
968 # Clean up the target board.
969 if { [info procs ${name}_exit] ne "" } {
972 # We also call the tool exit routine here.
973 if {[info exists tool]} {
974 if { [info procs ${tool}_exit] ne "" } {
982 proc setup_host_hook { name } {
988 set board_type "host"
990 load_board_description $name
994 if { [info procs ${name}_init] ne "" } {
999 proc setup_build_hook { name } {
1005 set board_type "build"
1007 load_board_description $name
1011 if { [info procs ${name}_init] ne "" } {
1017 # Find and load the global config file if it exists.
1018 # The global config file is used to set the connect mode and other
1019 # parameters specific to each particular target.
1020 # These files assume the host and target have been set.
1023 if { [load_file -- [file join $libdir $global_init_file]] == 0 } {
1024 # If $DEJAGNU isn't set either then there isn't any global config file.
1025 # Warn the user as there really should be one.
1026 if { ! [info exists env(DEJAGNU)] } {
1027 send_error "WARNING: Couldn't find the global config file.\n"
1031 if {[info exists env(DEJAGNU)]} {
1032 if { [load_file -- $env(DEJAGNU)] == 0 } {
1033 # It may seem odd to only issue a warning if there isn't a global
1034 # config file, but issue an error if $DEJAGNU is erroneously defined.
1035 # Since $DEJAGNU is set there is *supposed* to be a global config file,
1036 # so the current behaviour seems reasonable.
1037 send_error "ERROR: global config file $env(DEJAGNU) not found.\n"
1040 if {![info exists boards_dir]} {
1041 set boards_dir "[file dirname $env(DEJAGNU)]/boards"
1045 # Load user .dejagnurc file last as the ultimate override.
1046 load_file ~/.dejagnurc
1048 if {![info exists boards_dir]} {
1053 # parse out the config parts of the triplet name
1057 if { $build_cpu eq "" } {
1058 regsub -- "-.*-.*" $build_triplet "" build_cpu
1060 if { $build_vendor eq "" } {
1061 regsub -- "^\[a-z0-9\]*-" $build_triplet "" build_vendor
1062 regsub -- "-.*" $build_vendor "" build_vendor
1064 if { $build_os eq "" } {
1065 regsub -- ".*-.*-" $build_triplet "" build_os
1069 if { $host_cpu eq "" } {
1070 regsub -- "-.*-.*" $host_triplet "" host_cpu
1072 if { $host_vendor eq "" } {
1073 regsub -- "^\[a-z0-9\]*-" $host_triplet "" host_vendor
1074 regsub -- "-.*" $host_vendor "" host_vendor
1076 if { $host_os eq "" } {
1077 regsub -- ".*-.*-" $host_triplet "" host_os
1081 if { $target_cpu eq "" } {
1082 regsub -- "-.*-.*" $target_triplet "" target_cpu
1084 if { $target_vendor eq "" } {
1085 regsub -- "^\[a-z0-9\]*-" $target_triplet "" target_vendor
1086 regsub -- "-.*" $target_vendor "" target_vendor
1088 if { $target_os eq "" } {
1089 regsub -- ".*-.*-" $target_triplet "" target_os
1093 # Load the primary tool initialization file.
1096 proc load_tool_init { file } {
1097 global srcdir testsuitedir
1100 if {[info exists loaded_libs(tool/$file)]} {
1104 set loaded_libs(tool/$file) ""
1106 lappend searchpath [file join $testsuitedir lib tool]
1107 lappend searchpath [file join $testsuitedir lib]
1108 # for legacy testsuites that might have files in lib/ instead of
1109 # testsuite/lib/ in the package source tree; deprecated
1110 lappend searchpath [file join $srcdir lib]
1112 if { ![search_and_load_file "tool init file" [list $file] $searchpath] } {
1113 warning "Couldn't find tool init file"
1118 # load the testing framework libraries
1121 load_lib framework.exp
1122 load_lib debugger.exp
1125 load_lib targetdb.exp
1126 load_lib libgloss.exp
1128 # Initialize the test counters and reset them to 0.
1133 # Parse the command line arguments.
1136 # Load the tool initialization file. Allow the --tool option to override
1137 # what's set in the site.exp file.
1138 if {[info exists comm_line_tool]} {
1139 set tool $comm_line_tool
1142 if {[info exists tool]} {
1143 load_tool_init ${tool}.exp
1146 set argc [ llength $argv ]
1147 for { set i 0 } { $i < $argc } { incr i } {
1148 set option [ lindex $argv $i ]
1150 # make all options have two hyphens
1151 switch -glob -- $option {
1155 set option "-$option"
1159 # split out the argument for options that take them
1160 switch -glob -- $option {
1162 regexp {^[^=]*=(.*)$} $option nil optarg
1178 set optarg [lindex $argv $i]
1182 switch -glob -- $option {
1183 "--v*" { # (--verbose) verbose output
1188 "--g*" { # (--global_init) the global init file name
1189 # Already parsed (and no longer useful). The file has been loaded.
1193 "--loc*" { # (--local_init) the local init file name
1194 # Already parsed (and no longer useful). The file has been loaded.
1198 "--bu*" { # (--build) the build host configuration
1199 # Already parsed (and don't set again). Let $DEJAGNU rename it.
1203 "--ho*" { # (--host) the host configuration
1204 # Already parsed (and don't set again). Let $DEJAGNU rename it.
1209 # Set it again, father knows best.
1210 set target_list $optarg
1214 "--ta*" { # (--target) the target configuration
1215 # Already parsed (and don't set again). Let $DEJAGNU rename it.
1219 "--a*" { # (--all) print all test output to screen
1221 verbose "Print all test output to screen"
1226 # Already parsed (and don't set again). Let $DEJAGNU rename it.
1231 "--de*" { # (--debug) expect internal debugging
1232 if {[file exists ./dbg.log]} {
1233 catch [file delete -force -- dbg.log]
1235 if { $verbose > 2 } {
1236 exp_internal -f dbg.log 1
1238 exp_internal -f dbg.log 0
1240 verbose "Expect Debugging is ON"
1244 "--D[01]" { # (-Debug) turn on Tcl debugger
1245 # The runtest shell script handles this option, but it
1246 # still appears in the options in the Tcl code.
1247 verbose "Tcl debugger is ON"
1251 "--m*" { # (--mail) mail the output
1252 set mailing_list $optarg
1254 verbose "Mail results to $mailing_list"
1258 "--r*" { # (--reboot) reboot the target
1260 verbose "Will reboot the target (if supported)"
1264 "--ob*" { # (--objdir) where the test case object code lives
1265 # Already parsed, but parse again to make sure command line
1266 # options override any config file.
1268 verbose "Using test binaries in $objdir"
1272 "--ou*" { # (--outdir) where to put the output files
1274 verbose "Test output put in $outdir"
1283 "*.exp" { # specify test names to run
1284 set all_runtests($option) ""
1285 verbose "Running only tests $option"
1289 "*.exp=*" { # specify test names to run
1290 set tmp [split $option "="]
1291 set all_runtests([lindex $tmp 0]) [lindex $tmp 1]
1292 verbose "Running only tests $option"
1297 "--ig*" { # (--ignore) specify test names to exclude
1298 set ignoretests $optarg
1299 verbose "Ignoring test $ignoretests"
1303 "--sr*" { # (--srcdir) where the testsuite source code lives
1304 # Already parsed, but parse again to make sure command line
1305 # options override any config file.
1311 "--str*" { # (--strace) expect trace level
1312 set tracelevel $optarg
1314 verbose "Source Trace level is now $tracelevel"
1318 "--sta*" { # (--status) exit status flag
1319 # preserved for compatability, do nothing
1328 set TOOL_EXECUTABLE $optarg
1332 "--to*" { # (--tool) specify tool name
1334 verbose "Testing $tool"
1340 verbose "XML logging turned on"
1344 "--he*" { # (--help) help text
1349 "[A-Z0-9_-.]*=*" { # skip makefile style args like CC=gcc, etc... (processed in first pass)
1354 if {[info exists tool]} {
1355 if { [info procs ${tool}_option_proc] ne "" } {
1356 if {[${tool}_option_proc $option]} {
1361 send_error "\nIllegal Argument \"$option\"\n"
1362 send_error "try \"runtest --help\" for option list\n"
1369 # check for a few crucial variables
1371 if {![info exists tool]} {
1372 send_error "WARNING: No tool specified\n"
1377 # initialize a few Tcl variables to something other than their default
1379 if { $verbose > 2 || $log_dialog } {
1394 # print the config info
1395 clone_output "Test run by $logname on [timestamp -format %c]"
1397 clone_output "Target is $target_triplet"
1398 clone_output "Host is $host_triplet"
1399 clone_output "Build is $build_triplet"
1402 clone_output "Native configuration is $target_triplet"
1404 clone_output "Target is $target_triplet"
1405 clone_output "Host is $host_triplet"
1409 clone_output "\n\t\t=== $tool tests ===\n"
1412 # Look for the generic board configuration file. It searches in several
1413 # places: $libdir/config, $libdir/../config, and $boards_dir.
1416 proc load_generic_config { name } {
1423 if {[info exists board]} {
1424 if {![info exists board_info($board,generic_name)]} {
1425 set board_info($board,generic_name) $name
1429 if {[info exists board_type]} {
1430 set type "for $board_type"
1435 set dirlist [concat $libdir/config [file dirname $libdir]/config $boards_dir]
1436 set result [search_and_load_file "generic interface file $type" $name.exp $dirlist]
1442 # Load the tool-specific target description.
1444 proc load_config { args } {
1449 return [search_and_load_file "tool-and-target-specific interface file" $args [list $testsuitedir/config $testsuitedir/../config $testsuitedir/../../config $testsuitedir/../../../config]]
1453 # Find the files that set up the configuration for the target. There
1454 # are assumed to be two of them; one defines a basic set of
1455 # functionality for the target that can be used by all tool
1456 # testsuites, and the other defines any necessary tool-specific
1457 # functionality. These files are loaded via load_config.
1459 # These used to all be named $target_abbrev-$tool.exp, but as the
1460 # $tool variable goes away, it's now just $target_abbrev.exp. First
1461 # we look for a file named with both the abbrev and the tool names.
1462 # Then we look for one named with just the abbrev name. Finally, we
1463 # look for a file called default, which is the default actions, as
1464 # some tools could be purely host based. Unknown is mostly for error
1468 proc load_tool_target_config { name } {
1469 global target_os libdir testsuitedir
1471 set found [load_config $name.exp $target_os.exp "default.exp" "unknown.exp"]
1473 if { $found == 0 } {
1474 send_error "WARNING: Couldn't find tool config file for $name, using default.\n"
1475 # If we can't load the tool init file, this must be a simple natively hosted
1476 # test suite, so we use the default procs for Unix.
1477 if { [search_and_load_file "library file" default.exp [list $libdir $libdir/config [file dirname [file dirname $testsuitedir]]/dejagnu/config $testsuitedir/config . [file dirname [file dirname [file dirname $testsuitedir]]]/dejagnu/config]] == 0 } {
1478 send_error "ERROR: Couldn't find default tool init file.\n"
1485 # Find the file that describes the machine specified by board_name.
1488 proc load_board_description { board_name args } {
1497 if { [llength $args] > 0 } {
1498 set whole_name [lindex $args 0]
1500 set whole_name $board_name
1503 set board_info($whole_name,name) $whole_name
1504 if {![info exists board]} {
1505 set board $whole_name
1512 if { [llength $args] > 1 } {
1513 set suffix [lindex $args 1]
1514 if { $suffix ne "" } {
1515 foreach x $boards_dir {
1516 lappend dirlist $x/$suffix
1518 lappend dirlist $libdir/baseboards/$suffix
1521 set dirlist [concat $dirlist $boards_dir]
1522 lappend dirlist $libdir/baseboards
1523 verbose "dirlist is $dirlist"
1524 if {[info exists board_type]} {
1525 set type "for $board_type"
1529 if {![info exists board_info($whole_name,isremote)]} {
1530 set board_info($whole_name,isremote) 1
1531 if {[info exists board_type]} {
1532 if { $board_type eq "build" } {
1533 set board_info($whole_name,isremote) 0
1536 if { $board_name eq [get_local_hostname] } {
1537 set board_info($whole_name,isremote) 0
1540 search_and_load_file "standard board description file $type" standard.exp $dirlist
1541 set found [search_and_load_file "board description file $type" $board_name.exp $dirlist]
1542 if { $board_set != 0 } {
1550 # Find the base-level file that describes the machine specified by args. We
1551 # only look in one directory, $libdir/baseboards.
1554 proc load_base_board_description { board_name } {
1561 set board_info($board_name,name) $board_name
1562 if {![info exists board]} {
1563 set board $board_name
1566 if {[info exists board_type]} {
1567 set type "for $board_type"
1571 if {![info exists board_info($board_name,isremote)]} {
1572 set board_info($board_name,isremote) 1
1573 if {[info exists board_type]} {
1574 if { $board_type eq "build" } {
1575 set board_info($board_name,isremote) 0
1580 if { $board_name eq [get_local_hostname] } {
1581 set board_info($board_name,isremote) 0
1583 set found [search_and_load_file "board description file $type" $board_name.exp [list $libdir/baseboards]]
1584 if { $board_set != 0 } {
1592 # Source the testcase in TEST_FILE_NAME.
1595 proc runtest { test_file_name } {
1599 global errcnt warncnt
1605 clone_output "Running $test_file_name ..."
1612 # set testdir so testsuite file -test has a starting point
1613 set testdir [file dirname $test_file_name]
1615 if {[file exists $test_file_name]} {
1616 set timestart [timestamp]
1618 if {[info exists tool]} {
1619 if { [info procs ${tool}_init] ne "" } {
1620 ${tool}_init $test_file_name
1624 if { [catch "uplevel #0 source $test_file_name" msg] == 1 } {
1625 # If we have a Tcl error, propagate the exit status so
1626 # that 'make' (if it invokes runtest) notices the error.
1627 global exit_status exit_error
1628 # exit error is set by the --status command line option
1629 if { $exit_status == 0 } {
1632 set new_error [list $test_file_name $msg]
1633 # We can't call `perror' here, it resets `errorInfo'
1634 # before we want to look at it. Also remember that perror
1635 # increments `errcnt'. If we do call perror we'd have to
1636 # reset errcnt afterwards.
1637 clone_output "ERROR: tcl error sourcing $test_file_name."
1638 if {[info exists errorCode]} {
1639 clone_output "ERROR: tcl error code $errorCode"
1640 lappend new_error $errorCode
1642 lappend new_error [list]
1644 if {[info exists errorInfo]} {
1645 clone_output "ERROR: $errorInfo"
1646 lappend new_error $errorInfo
1649 lappend new_error [list]
1651 lappend ::dejagnu::error::list $new_error
1652 unresolved "testcase '$test_file_name' aborted due to Tcl error"
1655 if {[info exists tool]} {
1656 if { [info procs ${tool}_finish] ne "" } {
1660 set timeend [timestamp]
1661 set timediff [expr {$timeend - $timestart}]
1662 verbose -log "testcase $test_file_name completed in $timediff seconds" 4
1664 # This should never happen, but maybe if the file got removed
1665 # between the `find' above and here.
1666 perror "$test_file_name does not exist." 0
1670 # Trap some signals so we know what's happening. These replace the previous
1671 # ones because we've now loaded the library stuff.
1674 foreach sig {{SIGINT {interrupted by user} 130} \
1675 {SIGQUIT {interrupted by user} 131} \
1676 {SIGTERM {terminated} 143}} {
1677 set signal [lindex $sig 0]
1678 set str [lindex $sig 1]
1679 set code [lindex $sig 2]
1680 trap "send_error \"got a \[trap -name\] signal, $str \\n\"; set exit_status $code; log_and_exit;" $signal
1681 verbose "setting trap for $signal to $str" 1
1683 unset signal str sig
1687 # Given a list of targets, process any iterative lists.
1689 proc process_target_variants { target_list } {
1691 foreach x $target_list {
1692 if {[regexp "\\(" $x]} {
1693 regsub {^.*\(([^()]*)\)$} $x {\1} variant_list
1694 regsub {\([^(]*$} $x "" x
1695 set list [process_target_variants $x]
1698 set result [concat $result [iterate_target_variants $x [split $variant_list ","]]]
1700 } elseif {[regexp "\{" $x]} {
1701 regsub "^.*\{(\[^\{\}\]*)\}$" $x {\1} variant_list
1702 regsub "\{\[^\{\]*$" $x "" x
1703 set list [process_target_variants $x]
1705 foreach i [split $variant_list ","] {
1710 lappend result $name
1720 proc iterate_target_variants { target variants } {
1721 return [iterate_target_variants_two $target $target $variants]
1725 # Given a list of variants, produce the list of all possible combinations.
1727 proc iterate_target_variants_two { orig_target target variants } {
1729 if { [llength $variants] == 0 } {
1730 return [list $target]
1732 if { [llength $variants] > 1 } {
1733 set result [iterate_target_variants_two $orig_target $target [lrange $variants 1 end]]
1735 if { $target ne $orig_target } {
1736 set result [list $target]
1741 if { [lindex $variants 0] ne "" } {
1742 append target "/" [lindex $variants 0]
1743 return [concat $result [iterate_target_variants_two $orig_target $target [lrange $variants 1 end]]]
1745 return [concat $result $target]
1750 setup_build_hook [get_local_hostname]
1752 if {[info exists host_board]} {
1753 setup_host_hook $host_board
1755 set hb [get_local_hostname]
1762 # main test execution loop
1765 if {[info exists errorInfo]} {
1770 # make sure we have only single path delimiters
1771 regsub -all {([^/])//*} $srcdir {\1/} srcdir
1772 regsub -all {([^/])//*} $objdir {\1/} objdir
1773 regsub -all {([^/])//*} $testsuitedir {\1/} testsuitedir
1774 regsub -all {([^/])//*} $testbuilddir {\1/} testbuilddir
1776 if {![info exists target_list]} {
1777 # Make sure there is at least one target machine. It's probably a Unix box,
1778 # but that's just a guess.
1779 set target_list { "unix" }
1781 verbose "target list is $target_list"
1785 # Iterate through the list of targets.
1787 global current_target
1789 set target_list [process_target_variants $target_list]
1791 set target_count [llength $target_list]
1793 clone_output "Schedule of variations:"
1794 foreach current_target $target_list {
1795 clone_output " $current_target"
1800 foreach current_target $target_list {
1801 verbose "target is $current_target"
1802 set current_target_name $current_target
1803 set tlist [split $current_target /]
1804 set current_target [lindex $tlist 0]
1805 set board_variant_list [lrange $tlist 1 end]
1807 # Set the counts for this target to 0.
1809 clone_output "Running target $current_target_name"
1811 setup_target_hook $current_target_name $current_target
1813 # If multiple passes requested, set them up. Otherwise prepare just one.
1814 # The format of `MULTIPASS' is a list of elements containing
1815 # "{ name var1=value1 ... }" where `name' is a generic name for the pass and
1816 # currently has no other meaning.
1820 if { [info exists MULTIPASS] } {
1821 set multipass $MULTIPASS
1823 if { $multipass eq "" } {
1824 set multipass { "" }
1827 # If PASS is specified, we want to run only the tests specified.
1828 # Its value should be a number or a list of numbers that specify
1829 # the passes that we want to run.
1830 if {[info exists PASS]} {
1839 foreach multipass_elem $multipass {
1840 set multipass_name [lindex $multipass_elem 0]
1841 if {$p == $multipass_name} {
1842 lappend passes $multipass_elem
1847 set multipass $passes
1850 foreach pass $multipass {
1852 # multipass_name is set for `record_test' to use (see framework.exp).
1853 if { [lindex $pass 0] ne "" } {
1854 set multipass_name [lindex $pass 0]
1855 clone_output "Running pass `$multipass_name' ..."
1857 set multipass_name ""
1860 foreach varval [lrange $pass 1 end] {
1861 set tmp [string first "=" $varval]
1862 set var [string range $varval 0 [expr {$tmp - 1}]]
1863 # Save previous value.
1864 if {[info exists $var]} {
1865 lappend restore "$var [list [eval concat \$$var]]"
1867 lappend restore $var
1869 # Handle "CFLAGS=$CFLAGS foo".
1870 eval set $var \[string range \"$varval\" [expr {$tmp + 1}] end\]
1871 verbose "$var is now [eval concat \$$var]"
1875 # look for the top level testsuites. if $tool doesn't
1876 # exist and there are no subdirectories in $testsuitedir, then
1877 # we print a warning and default to srcdir.
1878 set test_top_dirs [lsort [getdirs -all $testsuitedir $tool*]]
1879 if { $test_top_dirs eq "" } {
1880 send_error "WARNING: could not find testsuite; trying $srcdir.\n"
1881 set test_top_dirs [list $srcdir]
1884 # DejaGNU's notion of test tree and test files is very
1886 # given $testsuitedir and $tool, any subdirectory (at any
1887 # level deep) with the "$tool" prefix starts a test tree
1888 # given a test tree, any *.exp file underneath (at any
1889 # level deep) is a test file.
1891 # For test tree layouts with $tool prefix on
1892 # both a parent and a child directory, we need to eliminate
1893 # the child directory entry from test_top_dirs list.
1894 # e.g. gdb.hp/gdb.base-hp/ would result in two entries
1895 # in the list: gdb.hp, gdb.hp/gdb.base-hp.
1896 # If the latter not eliminated, test files under
1897 # gdb.hp/gdb.base-hp would be run twice (since test files
1898 # are gathered from all sub-directories underneath a
1901 # Since $tool may be g++, etc. which could confuse
1902 # regexp, we cannot do the simpler test:
1904 # if [regexp "$testsuitedir/.*$tool.*/.*$tool.*" $dir]
1906 # instead, we rely on the fact that test_top_dirs is
1907 # a sorted list of entries, and any entry that contains
1908 # the previous valid test top dir entry in its own pathname
1911 set temp_top_dirs [list]
1913 foreach dir $test_top_dirs {
1914 if { $prev_dir eq ""
1915 || [string first $prev_dir/ $dir] == -1 } {
1916 # the first top dir entry, or an entry that
1917 # does not share the previous entry's entire
1918 # pathname, record it as a valid top dir entry.
1920 lappend temp_top_dirs $dir
1924 set test_top_dirs $temp_top_dirs
1926 verbose "Top level testsuite dirs are $test_top_dirs" 2
1928 if {[array exists all_runtests]} {
1929 foreach x [array names all_runtests] {
1930 verbose "trying to glob $testsuitedir/$x" 2
1931 set s [glob -nocomplain $testsuitedir/$x]
1933 set testlist [concat $testlist $s]
1938 # If we have a list of tests, run all of them.
1940 if { $testlist ne "" } {
1941 foreach test_name $testlist {
1942 if { $ignoretests ne "" } {
1943 if { 0 <= [lsearch $ignoretests [file tail $test_name]]} {
1948 # set subdir to the tail of the dirname after $srcdir,
1949 # for the driver files that want it. XXX this is silly.
1950 # drivers should get a single var, not $srcdir/$subdir
1951 set subdir [relative_filename $srcdir \
1952 [file dirname $test_name]]
1954 # XXX not the right thing to do.
1955 set runtests [list [file tail $test_name] ""]
1961 # Go digging for tests.
1963 foreach dir $test_top_dirs {
1964 if { $dir ne $testsuitedir } {
1965 # Ignore this directory if is a directory to be
1967 if {[info exists ignoredirs] && $ignoredirs ne ""} {
1969 foreach directory $ignoredirs {
1970 if {[string match *$directory* $dir]} {
1980 # Run the test if dir_to_run was specified as a
1981 # value (for example in MULTIPASS) and the test
1982 # directory matches that directory.
1983 if {[info exists dir_to_run] && $dir_to_run ne ""} {
1984 # JYG: dir_to_run might be a space delimited list
1985 # of directories. Look for match on each item.
1987 foreach directory $dir_to_run {
1988 if {[string match *$directory* $dir]} {
1998 # Run the test if cmdline_dir_to_run was specified
1999 # by the user using --directory and the test
2000 # directory matches that directory
2001 if {[info exists cmdline_dir_to_run] \
2002 && $cmdline_dir_to_run ne ""} {
2003 # JYG: cmdline_dir_to_run might be a space delimited
2004 # list of directories. Look for match on each item.
2006 foreach directory $cmdline_dir_to_run {
2007 # Look for a directory that ends with the
2008 # provided --directory name.
2009 if {[string match $directory $dir]
2010 || [string match "*/$directory" $dir]} {
2020 foreach test_name [lsort [find $dir *.exp]] {
2021 if { $test_name eq "" } {
2024 # Ignore this one if asked to.
2025 if { $ignoretests ne "" } {
2026 if { 0 <= [lsearch $ignoretests [file tail $test_name]]} {
2031 # Get the path after the $srcdir so we know
2032 # the subdir we're in.
2033 set subdir [relative_filename $srcdir \
2034 [file dirname $test_name]]
2035 # Check to see if the range of tests is limited,
2036 # set `runtests' to a list of two elements: the script name
2037 # and any arguments ("" if none).
2038 if {[array exists all_runtests]} {
2039 verbose "searching for $test_name in [array names all_runtests]" 2
2040 if { 0 > [lsearch [array names all_runtests] [file tail $test_name]]} {
2041 if { 0 > [lsearch [array names all_runtests] $test_name] } {
2045 set runtests [list [file tail $test_name] $all_runtests([file tail $test_name])]
2047 set runtests [list [file tail $test_name] ""]
2055 # Restore the variables set by this pass.
2056 foreach varval $restore {
2057 if { [llength $varval] > 1 } {
2058 verbose "Restoring [lindex $varval 0] to [lindex $varval 1]" 4
2059 set [lindex $varval 0] [lindex $varval 1]
2061 verbose "Restoring [lindex $varval 0] to `unset'" 4
2062 unset -- [lindex $varval 0]
2066 cleanup_target_hook $current_target
2067 if { $target_count > 1 } {