home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / lib / dejagnu / runtest.exp < prev    next >
Encoding:
Text File  |  1996-10-12  |  22.4 KB  |  807 lines

  1. # Test Framework Driver
  2. #   Copyright (C) 1988, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  15.  
  16. # Please email any bugs, comments, and/or additions to this file to:
  17. # bug-dejagnu@prep.ai.mit.edu
  18.  
  19. # This file was written by Rob Savoye. (rob@cygnus.com)
  20.     
  21. set frame_version    1.2
  22. if ![info exists argv0] then {
  23.     send_error "Must use a version of Expect greater than 5.0\n"
  24.     exit 1
  25. }
  26.  
  27. #
  28. # trap some signals so we know whats happening. These definitions are only
  29. # temporary until we read in the library stuff
  30. #
  31. trap { send_user "\nterminated\n";             exit 1 } SIGTERM
  32. trap { send_user "\ninterrupted by user\n";    exit 1 } SIGINT
  33. trap { send_user "\nsegmentation violation\n"; exit 1 } SIGSEGV
  34. trap { send_user "\nsigquit\n";                exit 1 } SIGQUIT
  35.  
  36. #
  37. # initialize a few global variables used by all tests
  38. #
  39. set mail_logs   0        ;# flag for mailing of summary and diff logs
  40. set psum_file   "latest"    ;# file name of previous summary to diff against
  41. set testcnt    0        ;# number of testcases that ran
  42. set passcnt    0        ;# number of testcases that passed
  43. set failcnt    0        ;# number of testcases that failed
  44. set xfailcnt    0        ;# number of testcases expected to fail which did
  45. set xpasscnt    0        ;# number of testcases that passed unexpectedly
  46. set warncnt     0               ;# number of warnings
  47. set errcnt      0               ;# number of errors
  48. set unsupportedcnt 0
  49. set untestedcnt 0
  50. set exit_status    0        ;# exit code returned by this program
  51. set xfail_flag  0
  52. set xfail_prms    0
  53. set sum_file    ""        ;# name of the file that contains the summary log
  54. set base_dir    ""        ;# the current working directory
  55. set logname     ""        ;# the users login name
  56. set passwd      ""
  57. set prms_id    0               ;# GNATS prms id number
  58. set bug_id    0               ;# optional bug id number
  59. set test_name    ""        ;# name of the test driver to be run
  60. set dir        ""        ;# temp variable for directory names
  61. set srcdir      "."        ;# source directory containing the test suite
  62. set ignoretests ""        ;# list of tests to not execute
  63. set target      ""        ;# type of architecture to run tests on
  64. set host        ""        ;# type of architecture to run tests from
  65. set objdir    "."        ;# directory where test case binaries live
  66. set makevars    ""
  67. set reboot      0
  68. set configfile  site.exp
  69. #
  70. # set communication parameters here
  71. #
  72. set netport     ""
  73. set targetname  ""
  74. set connectmode ""
  75. set serialport  ""
  76. set baud        ""
  77.  
  78. #
  79. # some convenience abbreviations
  80. #
  81. if ![info exists hex] then {
  82.     set hex "0x\[0-9A-Fa-f\]+"
  83. }
  84. if ![info exists decimal] then {
  85.     set decimal "\[0-9\]+"
  86. }
  87.  
  88. #
  89. # set the base dir (current working directory)
  90. #
  91. set base_dir [pwd]
  92.  
  93. #
  94. # These are tested in case they are not initialized in site.exp. They are
  95. # tested here instead of the init module so they can be overridden by command
  96. # line options.
  97. #
  98. if ![info exists all_flag] then {
  99.     set all_flag    0
  100. }
  101. if ![info exists binpath] then {
  102.     set binpath    ""
  103. }
  104. if ![info exists debug] then {
  105.     set debug  0
  106. }
  107. if ![info exists options] then {
  108.     set options    ""
  109. }
  110. if ![info exists outdir] then {
  111.     set outdir      "."
  112. }
  113. if ![info exists reboot] then {
  114.     set reboot    1
  115. }
  116. if ![info exists runtests] then {
  117.     set runtests    ""
  118. }
  119. if ![info exists tracelevel] then {
  120.     set tracelevel  0
  121. }
  122. if ![info exists verbose] then {
  123.     set verbose    0
  124. }
  125.  
  126. #
  127. # verbose
  128. #        prints a message if the message level is greater than or equal to 
  129. #        the verbose level. This is defined here rather than in framework.exp
  130. #        so we can use it while still loading in the support files.
  131. #
  132. proc verbose  { args } {
  133.     global verbose
  134.     
  135.     set level 1
  136.     
  137.     if [llength $args]!=1 then {
  138.     set level [lindex $args 1]
  139.     }
  140.     set message [lindex $args 0]
  141.     
  142.     if { [string compare $verbose $level] >= 0 } then {
  143.     send_user "$message\n"
  144.     }
  145. }
  146.  
  147. #
  148. # transform -- transform a tool name to get the installed name. We only define
  149. #              this if there wasn't one. This way the global config file can
  150. #              override how the tool names are calculated.
  151. #
  152. proc transform { name } {
  153.     global target_triplet
  154.     global host_triplet
  155.     
  156.     if [string match $target_triplet $host_triplet] then {
  157.     return $name
  158.     }
  159.     if [string match "native" $target_triplet] then {
  160.     return $name
  161.     }
  162.     if [string match "" $target_triplet] then {
  163.     return $name
  164.     } else {
  165.     regsub "(unknown|wrs|hitachi|lynxos|fujitsu|none)-" ${target_triplet}-$name "" tmp
  166.     verbose "Transforming $name to $tmp"
  167.     return $tmp
  168.     }
  169. }
  170.  
  171. #
  172. # findfile -- find a file and see if it exists. If you only care
  173. #             about the false condition, then you'll need to pass
  174. #             a null "" for arg1.
  175. #             arg0 is the filename to look for. If the only arg,
  176. #                  then that's what gets returned. If this is the
  177. #                  only arg, then if it exists, arg0 gets returned.
  178. #                  if it doesn't exist, return only the prog name.
  179. #             arg1 is optional, and it's what gets returned if
  180. #                  the file exists.
  181. #             arg2 is optional, and it's what gets returned if
  182. #                 the file doesn't exist.
  183. #
  184. proc findfile { args } {    
  185.     # look for the file
  186.     verbose "Seeing if [lindex $args 0] exists." 2
  187.     if [file exists [lindex $args 0]] then {
  188.     if [llength $args]>1 then {
  189.         verbose "Found file, returning [lindex $args 1]"
  190.         return [lindex $args 1]
  191.     } else {
  192.         verbose "Found file, returning [lindex $args 0]"
  193.         return [lindex $args 0]
  194.     }
  195.     } else {
  196.     if [llength $args]>2 then {
  197.         verbose "Didn't find file, returning [lindex $args 2]"
  198.         return [lindex $args 2]
  199.     } else {
  200.         verbose "Didn't find file, returning [file tail [lindex $args 0]]"
  201.         return [transform [file tail [lindex $args 0]]]
  202.     }
  203.     }
  204. }
  205.  
  206. #
  207. # get the users login name
  208. #
  209. if [string match "" $logname] then {
  210.     if [info exists env(USER)] then {
  211.     set logname $env(USER)
  212.     } else {
  213.     if [info exists env(LOGNAME)] then {
  214.         set logname $env(LOGNAME)
  215.     } else {
  216.         # try getting it with whoami
  217.         catch set logname [exec whoami] tmp
  218.         if [string match "*couldn't find*to execute*" $tmp] then {
  219.         # try getting it with who am i
  220.         unset tmp
  221.         catch set logname [exec who am i] tmp
  222.         if [string match "*Command not found*" $tmp] then {    
  223.             send_user "ERROR: couldn't get the users login name\n"
  224.             set logname "Unknown"
  225.         } else {
  226.             set logname [lindex [split $logname " !"] 1]
  227.         }
  228.         }
  229.     }
  230.     }
  231. }
  232. verbose "Login name is $logname"
  233.  
  234. #
  235. # The current search order says ~/.dejagnurc is done first.
  236. # For the normal case, we rely on the config file in base_dir to set
  237. # host_triplet and target_triplet.  Fetch it now so command line options
  238. # can override.
  239. #
  240. foreach file "~/.dejagnurc $base_dir/site.exp" {
  241.     verbose "Looking for $file" 2
  242.     if [file exists $file] then {
  243.     verbose "Found $file"
  244.     if [expr "[catch "source $file"] == 1" ] then {
  245.         if [info exists errorInfo] then {
  246.         send_error "ERROR: errors in $file\n"
  247.         send_error "$errorInfo"
  248.         exit 1
  249.         }
  250.     }
  251.     }
  252. }
  253.  
  254. #
  255. # Parse these configuration args so the global config file can use these values
  256. # in the absence of a local site.exp.  We need to get these values here so we
  257. # can use them for loading the support files.
  258. #
  259. set match 0
  260. set argc [ llength $argv ]
  261. for { set i 0 } { $i < $argc } { incr i } {
  262.     global host_triplet target_triplet; 
  263.  
  264.     set sub_arg [ lindex $argv $i ]
  265.     case $sub_arg in {
  266.  
  267.     { "-sr*" "--sr*" } {            # (--srcdir) where the testsuite source code lives
  268.         incr i
  269.         set srcdir [lindex $argv $i]
  270.         verbose "Using test sources in $srcdir"
  271.         continue
  272.     }
  273.     
  274.     { "-ho*" "--ho*" } {            # (--host) the host configuration
  275.         incr i
  276.         set host_triplet [lindex $argv $i]
  277.         verbose "The host is now $host_triplet"
  278.         continue
  279.     }
  280.     
  281.     { "-v*" "--v*" "*-verb*" } {        # (--verbose) verbose output
  282.         incr verbose
  283.         verbose "Verbose is now at level $verbose"
  284.         continue
  285.     }
  286.         
  287.     { "-ta*" "--ta*" } {            # (--target) the target configuration
  288.         incr i
  289.         set target_triplet [lindex $argv $i]
  290.         verbose "The target is now $target_triplet"
  291.         continue
  292.           # override local site file and load the configuration of 
  293.         # a different target
  294.     }
  295.     }
  296. }
  297.  
  298. set execpath     [file dirname $argv0]
  299. set libdir        [file dirname $execpath]/dejagnu
  300. if [info exists env(DEJAGNULIBS)] then {
  301.     set libdir $env(DEJAGNULIBS)
  302. }
  303. verbose "Using $libdir to find libraries"
  304.  
  305. # If objdir didn't get set in $base_dir/site.exp, set it to $base_dir.
  306. if [string match "." $objdir] then {
  307.     set objdir $base_dir
  308. }
  309.  
  310. #
  311. # set the host type. If it hadn't been specified by now, use config.guess
  312. #
  313.  
  314. # find config.guess
  315. if ![info exists host_triplet] then {
  316.     foreach dir "$libdir $libdir/.. $srcdir/.. $srcdir/../.." {
  317.     verbose "Looking for $dir" 2
  318.     if [file exists $dir/config.guess] then {
  319.         set config_guess $dir/config.guess
  320.         verbose "Found $dir/config.guess"
  321.     }
  322.     }
  323.     
  324.     # get the canonical config name
  325.     if ![info exists config_guess] then {
  326.     verbose "WARNING: Couldn't guess configuration"
  327.     return
  328.     }
  329.     catch "exec $config_guess" host_triplet
  330.     case $host_triplet in {
  331.     { "No uname command or uname output not recognized" "Unable to guess system type" } {
  332.         verbose "WARNING: Uname output not recognized"
  333.         set host_triplet unknown
  334.     }
  335.     }
  336.     verbose "Set host to $host_triplet"
  337. }
  338.  
  339. # if the target hasn't been specified or sourced, then we have to assume
  340. # we are native
  341. if ![info exists target_triplet] then {
  342.     set target_triplet $host_triplet
  343.     verbose "Set target to $target_triplet"
  344. }
  345.  
  346. #
  347. # set the now unused target_alias so all config files don't break.
  348. #
  349. if ![info exists target_alias] then {
  350.     set target_alias $host_triplet
  351. }
  352.  
  353. #
  354. # Load the global config files here. This way the other config files can set
  355. # configuration values that are used by the config files.
  356. # All are sourced in order.
  357. #
  358. # Search order:
  359. #    $HOME(done)-> base_dir(done)-> objdir-> installed-> DEJAGNU
  360. #
  361. # ??? Doing objdir at all is problematic (What if it overrides some command
  362. # line options?  Also, quite often it is the same as $base_dir).
  363. # Try to remove, clarify, or rework.
  364. #
  365. # ??? It might be nice to do $HOME last as it would allow it to be the
  366. # ultimate override.  Though at present there is still $DEJAGNU.
  367. #
  368.  
  369. foreach file "$objdir/site.exp" {
  370.     verbose "Looking for $file" 2
  371.     if [file exists $file] then {
  372.     verbose "Found $file"
  373.     if [expr "[catch "source $file"] == 1" ] then {
  374.         if [info exists errorInfo] then {
  375.         send_error "ERROR: errors in $file\n"
  376.         send_error "$errorInfo"
  377.         exit 1
  378.         }
  379.     }
  380.     }
  381. }
  382.  
  383. set found 0
  384. foreach dir "$libdir/site.exp $libdir/site.tmpl [file dirname $srcdir]/dejagnu/site.tmpl [file dirname [file dirname $srcdir]]/dejagnu/site.tmpl" {
  385.     verbose "Looking for $dir" 2
  386.     if [file exists $dir] then {
  387.     if [expr "[catch "source $dir"] == 1" ] then {
  388.         if [info exists errorInfo] then {
  389.         send_error "ERROR: errors in $dir\n"
  390.         send_error "$errorInfo"
  391.         }
  392.     } else {
  393.         set found 1
  394.         verbose "Found $dir"
  395.         break
  396.     }
  397.     }
  398. }
  399.  
  400. # test if we found a site.exp file
  401. if { $found == 0 } then {
  402.     send_user "ERROR: Couldn't find the global config file, site.exp.\n"
  403.     exit 1
  404. } else {
  405.     unset found
  406. }
  407.  
  408. # find and load the global config file if it exists.
  409. #
  410. if [info exists env(DEJAGNU)] then {
  411.     set configfile $env(DEJAGNU)
  412.     verbose "Looking for $configfile" 2
  413.     if [file exists $configfile] then {
  414.     verbose "Found $configfile"
  415.     if [expr "[catch "source $configfile"] == 1" ] then {
  416.         if [info exists errorInfo] then {
  417.         send_error "ERROR: errors in $configfile\n"
  418.         send_error "$errorInfo"
  419.         exit 1
  420.         }
  421.     }
  422.     }   
  423. }
  424.  
  425. #
  426. # parse the command line arguments
  427. #
  428. set match 0
  429. set argc [ llength $argv ]
  430. for { set i 0 } { $i < $argc } { incr i } {
  431.     set sub_arg [ lindex $argv $i ]
  432.     case $sub_arg in {
  433.     
  434.     { "-v*" "--v*" "*-verb*" } {    # (--verbose) verbose output
  435.         # Already parsed.
  436.         continue
  437.     }
  438.  
  439.     { "-ho*" "--ho*" } {            # (--host) the host configuration
  440.         # Already parsed.
  441.         incr i
  442.         continue
  443.     }
  444.     
  445.     { "-ta*" "--ta*" } {            # (--target) the target configuration
  446.         # Already parsed.
  447.         incr i
  448.         continue
  449.     }
  450.     
  451.     { "-a*" "--a*" } {            # (--all) print all test output to screen
  452.         set all_flag 1
  453.         verbose "Print all test output to screen"
  454.         continue
  455.     }
  456.     
  457.         { "-b*" "--b*" } {            # (--baud) the baud to use for a serial line
  458.         incr i
  459.         set baud [lindex $argv $i]
  460.         verbose "The baud rate is now $baud"
  461.         continue
  462.     }
  463.     
  464.     { "-co*" "--co*" } {            # (--connect) the connection mode to use
  465.         incr i
  466.         set connectmode [lindex $argv $i]
  467.         verbose "Comm method is $connectmode"
  468.         continue
  469.     }
  470.     
  471.     { "-d*" "--d*" } {            # (--debug) expect internal debugging
  472.         if [file exists ./dbg.log] then {
  473.         catch "exec rm -f ./dbg.log"
  474.         }
  475.         if $verbose>2 then {
  476.         exp_internal -f dbg.log 1
  477.         } else {
  478.         exp_internal -f dbg.log 0
  479.         }
  480.         verbose "Expect Debugging is ON"
  481.         continue
  482.     }
  483.     
  484.     { "-D[01]" "--D[01]" } {             # (-Debug) turn on Tcl debugger
  485.         verbose "Tcl debugger is ON"
  486.         continue
  487.     }
  488.     
  489.     { "-m*" "--m*" } {            # (--mail) mail the output
  490.         incr i
  491.         set mailing_list [lindex $argv $i]
  492.             set mail_logs 1
  493.         verbose "Mail results to $mailing_list"
  494.         continue
  495.     }
  496.     
  497.     { "-r*" "--r*" } {            # (--reboot) reboot the target
  498.         set reboot 1
  499.         verbose "Will reboot the target (if supported)"
  500.         continue
  501.     }
  502.     
  503.     { "-ob*" "--ob*" } {            # (--objdir) where the test case object code lives
  504.         incr i
  505.         set objdir [lindex $argv $i]
  506.         verbose "Using test binaries in $objdir"
  507.         continue
  508.     }
  509.     
  510.     { "-ou*" "--ou*" } {            # (--outdir) where to put the output files
  511.         incr i
  512.         set outdir [lindex $argv $i]
  513.         verbose "Test output put in $outdir"
  514.         continue
  515.     }
  516.     
  517.     { "*.exp" "*.C" "*.c" "*.s" "*.o" } {        #  specify test names to run
  518.         lappend runtests [lindex $argv $i]
  519.         verbose "Running only tests $runtests"
  520.         continue
  521.     }
  522.     
  523.     { "-i*" "--i*" }  {            #  (--ignore) specify test names to exclude
  524.         incr i
  525.         set ignoretests [lindex $argv $i]
  526.         verbose "Ignoring test $ignoretests"
  527.         continue
  528.     }
  529.     
  530.  
  531.     { "-sr*" "--sr*" } {            # (--srcdir) where the testsuite source code lives
  532.         # Already parsed, but parse again to make sure command line
  533.         # options override any config file.
  534.         incr i
  535.         set srcdir [lindex $argv $i]
  536.         continue
  537.     }
  538.     
  539.     { "-st*" "--st*" } {            # (--strace) expect trace level
  540.         incr i
  541.         set tracelevel [ lindex $argv $i ]
  542.         strace $tracelevel
  543.         verbose "Source Trace level is now $tracelevel"
  544.         continue
  545.     }
  546.     
  547.     { "-n*" "--n*" } {            # (--name) the target's name
  548.         incr i
  549.         set targetname [lindex $argv $i]
  550.         verbose "Testing target $targetname"
  551.         continue
  552.     }
  553.     
  554.     { "-to*" "--to*" } {            # (--tool) specify tool name
  555.         incr i
  556.         set tool [lindex $argv $i]
  557.         verbose "Testing $tool"
  558.         continue
  559.         }
  560.     
  561.     { "*-V*" "*-vers*" } {            # (--version) version numbers
  562.         send_user "Expect version is\t[exp_version]\n"
  563.         send_user "Tcl version is\t\t[ info tclversion ]\n"
  564.         send_user "Framework version is\t$frame_version\n"
  565.         exit
  566.     }
  567.     
  568.     { "[A-Z]*=*" } {                    # process makefile style args like CC=gcc, etc...
  569.         set tmp [split $sub_arg "="]
  570.         set [lindex $tmp 0] [lindex $tmp 1]
  571.         verbose "[lindex $tmp 0] is now [lindex $tmp 1]"
  572.         append makevars "set [lindex $tmp 0] [lindex $tmp 1];"
  573.         unset tmp
  574.         continue
  575.     }
  576.     
  577.     { "-he*" "--he*" } {        # (--help) help text
  578.         send_user "USAGE: runtest \[options...\]\n"
  579.         send_user "\t--all (-a)\t\tPrint all test output to screen\n"
  580.         send_user "\t--baud (-b)\t\tThe baud rate\n"
  581.         send_user "\t--connect (-co)\t\[type\]\tThe type of connection to use\n"
  582.         send_user "\t--debug (-de)\t\tSet expect debugging ON\n"
  583.         send_user "\t--help (-he)\t\tPrint help text\n"
  584.         send_user "\t--mail \[name(s)\]\tWho to mail the results to\n"
  585.         send_user "\t--reboot \[name\]\t\tReboot the target (if supported)\n"
  586.             send_user "\t--objdir \[name\]\t\tThe test suite binary directory\n"
  587.         send_user "\t--outdir \[name\]\t\tThe directory to put logs in\n"
  588.         send_user "\t--ignore \[name(s)\]\tThe names of specific tests to ignore\n"
  589.         send_user "\t--srcdir \[name\]\t\tThe test suite source code directory\n"
  590.         send_user "\t--strace \[number\]\tSet expect tracing ON\n"
  591.         send_user "\t--name \[name\]\t\tThe hostname of the target board\n"
  592.         send_user "\t--target \[string\]\tThe canonical config name of the target board\n"
  593.         send_user "\t--host \[string\]\t\tThe canonical config name of the host machine\n"
  594.         send_user "\t--tool\[name(s)\]\t\tRun tests on these tools\n"
  595.         send_user "\t--verbose (-v)\t\tEmit verbose output\n"
  596.         send_user "\t--version (-V)\t\tEmit all version numbers\n"
  597.         send_user "\t--D\[0-1\]\t\tTcl debugger\n"
  598.         send_user "\tMakefile style arguments can also be used, ex. CC=gcc\n\n"
  599.         exit 0    
  600.     }
  601.     
  602.     default {        # default
  603.         send_user "\nIllegal Argument \"$sub_arg\"\n"
  604.         send_user "try \"runtest --help\" for option list\n"
  605.         exit 0
  606.     }
  607.     
  608.     }
  609. }
  610.  
  611. #
  612. # check for a few crucial variables
  613. #
  614. if ![info exists tool] then {
  615.     send_error "ERROR: No tool specified, use the --tool option\n"
  616.     exit 1
  617. }
  618.  
  619. if ![info exists target_triplet] then {
  620.     send_error "ERROR: No target configuration. Check the config file.\n"
  621.     exit 1
  622. }
  623.  
  624. if ![info exists host_triplet] then {
  625.     send_error "WARNING: No host configuration. Check the config file.\n"
  626. }
  627.  
  628. #
  629. # initialize a few Tcl variables to something other than their default
  630. #
  631. if { $verbose > 2 } then {
  632.     log_user 1
  633. } else {
  634.     log_user 0
  635. }
  636.  
  637. set timeout     10
  638.  
  639. #
  640. # load_lib 
  641. #        loads a library by sourcing it. If there a multiple files with
  642. #        the same name, they all get sourced in order. The order is first
  643. #        look in the install dir, then in a parallel dir in the source tree,
  644. #     (up one or two levels), then in the current dir.
  645. #
  646. proc load_lib { file } {
  647.     global verbose libdir srcdir base_dir execpath tool;
  648.     
  649.     set found 0
  650.     set tmp   ""
  651.     foreach dir "$libdir $libdir/lib [file dirname [file dirname $srcdir]]/dejagnu/lib $srcdir/lib ." {
  652.     verbose "Looking for library file $dir/$file" 2
  653.     if [file exists $dir/$file] then {
  654.          verbose "Loading library file $dir/$file"
  655.         if [expr "[catch "uplevel #0 source $dir/$file"] == 1" ] then {
  656.         if [info exists errorInfo] then {
  657.             send_error "ERROR: errors in library file $dir/file\n"
  658.             send_error "$errorInfo"
  659.         exit 1
  660.         }
  661.         } else {
  662.         set found 1
  663.         break
  664.         }
  665.     }
  666.     }
  667.     if { $found == 0 } then {
  668.     send_user "ERROR: Couldn't load library file $file.\n"
  669.     exit 1
  670.     }
  671.     unset found
  672.     unset tmp
  673. }
  674.  
  675. #
  676. # load the testing framework libraries
  677. #
  678. load_lib utils.exp
  679. load_lib framework.exp
  680. load_lib debugger.exp
  681.  
  682. #
  683. # open log files
  684. #
  685. open_logs
  686.  
  687. clone_output "Test Run By $logname on [exec date]"
  688. if ![string match $target_triplet $host_triplet] then {
  689.     clone_output "Target is $target_triplet"
  690.     clone_output "Host   is $host_triplet"
  691. } else {
  692.     clone_output "Native configuration is $host_triplet"
  693. }
  694. clone_output "\n\t\t=== $tool tests ===\n"
  695.  
  696. #
  697. # Find the tool init file. This is in the config directory of the tool's
  698. # testsuite directory. These used to all be named $target_abbrev-$tool.exp,
  699. # but as the $tool variable goes away, it's now just $target_abbrev.exp.
  700. # First we look for a file named with both the abbrev and the tool names.
  701. # Then we look for one named with just the abbrev name. Finally, we look for
  702. # a file called default, which is the default actions, as some tools could
  703. # be purely host based. Unknown is mostly for error trapping.
  704. #
  705.  
  706. set found 0 
  707. foreach initfile "${target_abbrev}-${tool}.exp ${target_abbrev}.exp default.exp unknown.exp" {
  708.     verbose "Looking for tool init file $srcdir/config/$initfile" 2
  709.     if [file exists $srcdir/config/$initfile] then {
  710.     verbose "Using $srcdir/config/$initfile as tool init file."
  711.     if [catch "uplevel #0 source $srcdir/config/$initfile"]==1 then {
  712.         if [info exists errorInfo] then {
  713.         send_error "ERROR: errors in tool init file $srcdir/config/$initfile\n"
  714.         send_error "$errorInfo"
  715.         exit 1
  716.         }
  717.     }
  718.     set found 1
  719.     break
  720.     }
  721. }
  722.  
  723. if $found==0 then {
  724.     send_error "ERROR: Couldn't find tool init file $srcdir/config/$initfile.\n"
  725.     exit 1
  726. }
  727. unset found
  728. if [info exists errorInfo] then {
  729.     unset errorInfo
  730. }
  731.  
  732. #
  733. # trap some signals so we know whats happening. These replace the previous
  734. # ones because we've now loaded the library stuff.
  735. #
  736. foreach sig "{SIGTERM {terminated}} \
  737.              {SIGINT {interrupted by user}} \
  738.              {SIGQUIT {interrupted by user}} \
  739.              {SIGSEGV {segmentation violation}}" {
  740.     trap {
  741.     send_error "Got a [trap -name] signal\n"
  742.     log_summary
  743.     } [lindex $sig 0]
  744. }
  745.  
  746. #
  747. # main test execution loop
  748. #
  749. reset_vars
  750. append srcdir "/"
  751.  
  752. foreach dir [lsort [getdirs $srcdir $tool*]] {
  753.     foreach test_name [lsort [find $dir *.exp]] {
  754.     # make sure we have only single path delimiters
  755.     regsub -all "//" $srcdir "/" srcdir
  756.     # get the path part after the $srcdir so we know the subdir we're in
  757.     regsub $srcdir [file dirname $test_name] "" subdir
  758.     if [string match "" ${test_name}] then {
  759.         continue
  760.     }
  761.     # check to see if the range of tests is limited 
  762.     if ![string match "" $runtests] then {
  763.         if ![expr 0<=[lsearch $runtests [file tail ${test_name}]]] then {
  764.         continue
  765.         }
  766.     }
  767.     if ![string match "" $ignoretests] then {
  768.         if [expr 0<=[lsearch $ignoretests [file tail ${test_name}]]] then {
  769.         continue
  770.         }
  771.     }
  772.     if [string match "" $test_name] then {
  773.         perror "$test_name does not exist."
  774.     } else {
  775.         clone_output "Running ${test_name} ..."
  776.     }
  777.     set prms_id    0
  778.     set bug_id    0
  779.     set test_result ""
  780.     if [file exists $test_name] then {
  781.         if [expr "[catch "uplevel #0 source ${test_name}"] == 1" ] then {
  782.                 if [info exists errorInfo] then {
  783.             send_error "$errorInfo"
  784.             unset errorInfo
  785.         }
  786.         continue
  787.         } 
  788.     } else {
  789.         perror "$test_name does not exist."
  790.     }
  791.     }    
  792. }
  793.  
  794. #
  795. # all done, cleanup
  796. #
  797. if { [info procs ${tool}_exit] != "" } then {
  798.     if {[catch "${tool}_exit" tmp]} {
  799.     warning "${tool}_exit failed:\n$tmp"
  800.     }
  801. }
  802.  
  803. log_summary
  804.