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

  1. # Copyright (C) 1988, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  2.  
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software
  13. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  14.  
  15. # Please email any bugs, comments, and/or additions to this file to:
  16. # bug-dejagnu@prep.ai.mit.edu
  17.  
  18. # This file was written by Rob Savoye. (rob@cygnus.com)
  19. #
  20.  
  21. proc mail_file { file to subject } {
  22.     if [file readable $file] then {
  23.     catch "exec mail -s \"$subject\" $to < $file"
  24.     }
  25. }
  26.  
  27. #
  28. # open_logs -- open the output logs
  29. #
  30. proc open_logs { } {
  31.     global outdir
  32.     global tool
  33.     global sum_file
  34.     
  35.     catch "exec rm -f $outdir/$tool.sum"
  36.     set sum_file [open "$outdir/$tool.sum" w]
  37.     catch "exec rm -f $outdir/$tool.log"
  38.     log_file -a "$outdir/$tool.log"
  39.     verbose "Opening log files in $outdir"
  40. }
  41.  
  42.  
  43. #
  44. # close_logs -- close the output logs
  45. #
  46. proc close_logs { } {
  47.     global sum_file
  48.     
  49.     catch "close $sum_file"
  50. }
  51.  
  52. #
  53. # ishost -- check  host triplet for pattern. With no arguments
  54. #             it returns the triplet string.
  55. #
  56. proc ishost { args } {
  57.     global host_triplet
  58.     
  59.     if [string match "" $args] then {
  60.     return $host_triplet
  61.     }
  62.     verbose "Checking pattern \"$args\" with $host_triplet"
  63.     
  64.     if [string match "$args" $host_triplet] then {
  65.     return 1
  66.     } else {
  67.     return 0
  68.     }
  69. }
  70.  
  71. #
  72. # istarget -- check target triplet for pattern. With no arguments
  73. #             it returns the triplet string.
  74. #             returns 1 if the target looked for, or
  75. #                     0 if not.
  76. #
  77. proc istarget { args } {
  78.     global target_triplet
  79.     
  80.     # if no arg, return the config string
  81.     if [string match "" $args] then {
  82.     if [info exists target_triplet] then {
  83.         return $target_triplet
  84.     } else {
  85.         perror "No target configuration names found."
  86.     }
  87.     }
  88.  
  89.     # now check against the cannonical name
  90.     if [info exists target_triplet] then {
  91.     verbose "Checking \"$args\" against \"$target_triplet\"" 2
  92.     if [string match "$args" $target_triplet] then {
  93.         return 1
  94.     }
  95.     }
  96.  
  97.     # nope, no match
  98.     return 0
  99. }
  100.  
  101. #
  102. # isnative --    check to see if we're running the tests in a native
  103. #        environment.
  104. #        returns 1 if it is running native
  105. #            0 if on a target.
  106. #
  107. proc isnative { } {
  108.     global target_triplet
  109.     global host_triplet
  110.     
  111.     if [string match $host_triplet $target_triplet] then {
  112.     return 1
  113.     }
  114.     return 0
  115. }
  116.  
  117. #
  118. # unknown -- called by expect if a proc is called that doesn't exist
  119. #
  120. proc unknown { args } {
  121.     global errorCode
  122.     global errorInfo
  123.     global exit_status
  124.     
  125.     clone_output "ERROR: (DejaGnu) proc \"$args\" does not exist"
  126.     if [info exists errorCode] then {
  127.         send_error "The error code is $errorCode\n"
  128.     }
  129.     if [info exists errorInfo] then {
  130.         send_error "The info on the error is: \n$errorInfo\n"
  131.     }
  132.     log_summary
  133.     close_logs
  134.     cleanup
  135.     exit $exit_status
  136. }
  137.  
  138. #
  139. # clone_output -- print output to stdout and to log file
  140. #                 if the --all_flag (-a) option was used then all
  141. #                 messages go the the screen. Without this, all messages
  142. #                 that start with a keyword are written only to the detail
  143. #                 log file. All messages that go to the screen will also
  144. #                 appear in the detail log. This should only be used by
  145. #                 the framework itself using pass, fail, xfail, xpass,
  146. #                 warning, untested, unresolved, unsupported, or error
  147. #                 procedures.
  148. #
  149. proc clone_output { message } {
  150.     global sum_file
  151.     global all_flag
  152.     
  153.     case [lindex $message 0] in {
  154.     {"PASS:" "XFAIL:" "UNRESOLVED:" "UNSUPPORTED:" "UNTESTED:"}  {
  155.         if $all_flag then {
  156.         send_user  "$message\n"
  157.         } else {
  158.         send_log "$message\n"
  159.         }
  160.     }
  161.     {"ERROR:" "WARNING:"} {
  162.         send_error "$message\n"
  163.     }
  164.     default  {
  165.         send_user  "$message\n"
  166.     }
  167.     }
  168.     puts $sum_file "$message"
  169. }
  170.  
  171. #
  172. # reset_vars
  173. #    reset all globally used variables
  174. #
  175. proc reset_vars {} {
  176.     # test result counters
  177.     global failcnt
  178.     global passcnt
  179.     global testcnt
  180.     global xfailcnt
  181.     global xpasscnt
  182.     global untestedcnt
  183.     global unresolvedcnt
  184.     global unsupportedcnt
  185.     
  186.     # prms id number and test name variables
  187.     global prms_id
  188.     global test_name
  189.     
  190.     # reset all counters, prms_id and test_name 
  191.     set prms_id    0
  192.     set test_name    ""
  193.     
  194.     set failcnt    0
  195.     set passcnt    0
  196.     set testcnt    0
  197.     set xfailcnt    0
  198.     set xpasscnt    0
  199.     set untestedcnt    0
  200.     set unresolvedcnt    0
  201.     set unsupportedcnt    0
  202. }
  203.  
  204. #
  205. # log_summary -- print summary of all pass/fail counts. Calling this exits.
  206. #
  207. proc log_summary {} {
  208.     global tool
  209.     global sum_file
  210.     global exit_status
  211.     global failcnt
  212.     global passcnt
  213.     global testcnt
  214.     global xfailcnt
  215.     global xpasscnt
  216.     global untestedcnt
  217.     global unresolvedcnt
  218.     global unsupportedcnt
  219.     global mail_logs
  220.     global outdir
  221.     global tool.sum
  222.     global mailing_list
  223.     
  224.     if ![info exists totlcnt] then {
  225.     # total all the testcases reported
  226.     set totlcnt [expr $failcnt+$passcnt+$xfailcnt+$xpasscnt]
  227.     set totlcnt [expr $totlcnt+$untestedcnt+$unresolvedcnt+$unsupportedcnt]
  228.     }
  229.     
  230.     clone_output "\n\t\t=== $tool Summary ===\n"
  231.     
  232.     # compare reported number of testcases with expected number
  233.     if { $testcnt > 0 } then {
  234.     if { $testcnt>$totlcnt || $testcnt<$totlcnt } then {
  235.         if { $testcnt > $totlcnt } then {
  236.         set mismatch "unreported  [expr $testcnt-$totlcnt]"
  237.         }
  238.         if { $testcnt < $totlcnt } then {
  239.         set mismatch "misreported [expr $totlcnt-$testcnt]"
  240.         }
  241.     } else {
  242.         verbose "# of testcases run         $testcnt"
  243.     }
  244.     }
  245.     if [info exists mismatch] then {
  246.     clone_output "### ERROR: totals do not equal number of testcases run"
  247.     clone_output "### ERROR: # of testcases expected    $testcnt"
  248.     clone_output "### ERROR: # of testcases reported    $totlcnt"
  249.     clone_output "### ERROR: # of testcases $mismatch\n"
  250.     }
  251.     if { $passcnt > 0 } then {
  252.     clone_output "# of expected passes       $passcnt"
  253.     }
  254.     if { $xfailcnt > 0 } then {
  255.     clone_output "# of expected failures     $xfailcnt"
  256.     }
  257.     if { $xpasscnt > 0 } then {
  258.     clone_output "# of unexpected successes  $xpasscnt"
  259.     }
  260.     if { $failcnt > 0 } then {
  261.     clone_output "# of unexpected failures   $failcnt"
  262.     }
  263.     if { $unresolvedcnt > 0 } then {
  264.     clone_output "# of unresolved testcases  $unresolvedcnt"
  265.     }
  266.     if { $untestedcnt > 0 } then {
  267.     clone_output "# of untested testcases    $untestedcnt"
  268.     }
  269.     if { $unsupportedcnt > 0 } then {
  270.     clone_output "# of unsupported tests     $unsupportedcnt"
  271.     }
  272.     # extract version number
  273.     if {[info procs ${tool}_version] != ""} then {
  274.     if {[catch "${tool}_version" output]} {
  275.         warning "${tool}_version failed:\n$output"
  276.     }
  277.     }
  278.     close_logs
  279.     cleanup
  280.     if $mail_logs then {
  281.     mail_file $outdir/$tool.sum $mailing_list "Dejagnu Summary Log"
  282.     }
  283.     exit $exit_status
  284. }
  285.  
  286. #
  287. # cleanup -- close all open files,
  288. #         remove temp file and core files, and set exit status
  289. #
  290. proc cleanup {} {
  291.     global sum_file
  292.     global exit_status
  293.     global done_list
  294.     global base_dir
  295.     global subdir
  296.     
  297.     #catch "exec rm -f [glob xgdb core *.x *.o *_soc a.out]"
  298.     #catch "exec rm -f [glob -nocomplain $subdir/*.o $subdir/*.x $subdir/*_soc]"
  299. }
  300.  
  301. #
  302. # pass -- prints the default test passed message
  303. #
  304. proc pass { arg } {
  305.     global passcnt
  306.     global prms_id
  307.     global bug_id
  308.     global xfail_flag
  309.     global xfail_prms
  310.     global errcnt
  311.     global warncnt
  312.     
  313.     if $xfail_flag then {
  314.     if $xfail_prms!=0 {
  315.         set prms_id $xfail_prms
  316.     }
  317.     xpass $arg
  318.     set xfail_flag 0
  319.     if $xfail_prms!=0 {
  320.         set prms_id 0
  321.         set xfail_prms 0
  322.     }
  323.     return
  324.     }
  325.  
  326.     incr passcnt
  327.     
  328.     set format "PASS:\t$arg"
  329.  
  330.     # if we have too many warnings or errors, the output of the test can't be considered correct
  331.     if $warncnt>3 then {
  332.     unresolved $format
  333.     set warncnt 0
  334.     set errcnt  0
  335.     return
  336.     }
  337.     if $errcnt>1 then {
  338.     unresolved $format
  339.     set errcnt 0
  340.     set warncnt 0
  341.     return
  342.     }
  343.     
  344.     # reset these so they're ready for the next test case
  345.     set warncnt 0
  346.     set errcnt 0
  347.  
  348.     if $prms_id then {
  349.     set format [concat $format "\t(PRMS $prms_id)"]
  350.     }
  351.     if $bug_id then {
  352.     set format [concat $format "\t(BUG $bug_id)"]
  353.     }
  354.     
  355.     clone_output "$format"
  356. }
  357.  
  358. #
  359. # xpass -- print the the default test passed unlike expected message
  360. #
  361. proc xpass { arg } {
  362.     global xpasscnt
  363.     global prms_id
  364.     global bug_id
  365.     
  366.     incr xpasscnt
  367.  
  368.     set exit_status 1
  369.     
  370.     set format "XPASS:\t$arg"
  371.     if $prms_id then {
  372.     set format [concat $format "\t(PRMS $prms_id)"]
  373.     }
  374.     if $bug_id then {
  375.     set format [concat $format "\t(BUG $bug_id)"]
  376.     }
  377.     
  378.     clone_output "$format"
  379. }
  380.  
  381. #
  382. # xfail -- print the the default test failed like expected message
  383. #
  384. proc xfail { arg } {
  385.     global xfailcnt
  386.     global prms_id
  387.     global bug_id
  388.     
  389.     incr xfailcnt
  390.  
  391.     set exit_status 1
  392.     
  393.     set format "XFAIL:\t$arg"
  394.     if $prms_id then {
  395.     set format [concat $format "\t(PRMS $prms_id)"]
  396.     }
  397.     if $bug_id then {
  398.     
  399.     set format [concat $format "\t(BUG $bug_id)"]
  400.     }
  401.     
  402.     clone_output "$format"
  403. }
  404.  
  405. #
  406. # setup_xfail -- setup a flag to control whether a failure
  407. #                is expected or not.`
  408. #
  409. # Multiple target triplet patterns can be specified for targets
  410. # for which the test fails.  A decimal number can be specified,
  411. # which is the PRMS number.
  412. #
  413. proc setup_xfail { args } {
  414.     global xfail_flag
  415.     global xfail_prms
  416.     global decimal
  417.     
  418.     set argc [ llength $args ]
  419.     for { set i 0 } { $i < $argc } { incr i } {
  420.     set sub_arg [ lindex $args $i ]
  421.     # is a prms number. we assume this is a number with no characters
  422.     if [regexp "^\[0-9\]+$" $sub_arg] then { 
  423.         set xfail_prms $sub_arg
  424.         continue
  425.     }
  426.     if [istarget $sub_arg] then {
  427.         set xfail_flag 1
  428.         continue
  429.     }
  430.     }
  431. }
  432.  
  433. #
  434. # clear_xfail -- clear the xfail flag for a particular target.
  435. #
  436. proc clear_xfail { args } {
  437.     global xfail_flag
  438.     global xfail_prms
  439.     global decimal
  440.     
  441.     set argc [ llength $args ]
  442.     for { set i 0 } { $i < $argc } { incr i } {
  443.     set sub_arg [ lindex $args $i ]
  444.     case $sub_arg in {
  445.         "*-*-*" {            # is a configuration triplet
  446.         if [istarget $sub_arg] then {
  447.             set xfail_flag 0
  448.             set xfail_prms 0
  449.         }
  450.         continue
  451.         }
  452.     }
  453.     }
  454. }
  455.  
  456. #
  457. # fail -- prints the default test failed message
  458. #
  459. proc fail { arg } {
  460.     global failcnt
  461.     global prms_id
  462.     global bug_id
  463.     global exit_status
  464.     global xfail_flag
  465.     global xfail_prms
  466.     global errcnt
  467.     global warncnt
  468.  
  469.     if $xfail_flag then {
  470.     if $xfail_prms!=0 {
  471.         set prms_id $xfail_prms
  472.     }
  473.     xfail $arg
  474.     set xfail_flag 0
  475.     if $xfail_prms!=0 {
  476.         set prms_id 0
  477.         set xfail_prms 0
  478.     }
  479.     return
  480.     }
  481.     
  482.     incr failcnt
  483.  
  484.     set exit_status 1
  485.  
  486.     set format "FAIL:\t$arg"
  487.  
  488.     # if we have too many warnings or errors, the output of the test can't be considered correct
  489.     if $warncnt>3 then {
  490.     unresolved $format
  491.     set warncnt 0
  492.     set errcnt  0
  493.     return
  494.     }
  495.     if $errcnt>1 then {
  496.     unresolved $format
  497.     set errcnt  0
  498.     set warncnt 0
  499.     return
  500.     }
  501.     
  502.     # reset these so they're ready for the next test case
  503.     set warncnt 0
  504.     set errcnt 0
  505.  
  506.     if $prms_id then {
  507.     set format [concat $format "\t(PRMS $prms_id)"]
  508.     }
  509.     if $bug_id then {
  510.     set format [concat $format "\t(BUG $bug_id)"]
  511.     }
  512.  
  513.     clone_output "$format"
  514. }
  515.  
  516. #
  517. # warning -- prints a warning messages. These are warnings from the framework,
  518. #            not from the tools being tested.
  519. #
  520. proc warning { message } {
  521.     global verbose
  522.     global warncnt
  523.     
  524.     incr warncnt
  525.     clone_output "WARNING: $message"
  526.     if [info exists errorInfo] then {
  527.     unset errorInfo
  528.     }
  529. }
  530.  
  531. #
  532. # perror -- prints a error messages. These are errors from the framework,
  533. #          not from the tools being tested.
  534. #
  535. proc perror { message } {
  536.     global verbose
  537.     global errcnt
  538.     
  539.     incr errcnt
  540.     clone_output "ERROR: $message"
  541.     if [info exists errorInfo] then {
  542.     unset errorInfo
  543.     }
  544. }
  545.  
  546. #
  547. # untested -- For some reason this test case is untested.
  548. #
  549. proc untested { arg } {
  550.     global untestedcnt
  551.     global prms_id
  552.     global bug_id
  553.     global exit_status
  554.     global xfail_flag
  555.     global xfail_prms
  556.     
  557.     if $xfail_flag then {
  558.         if $xfail_prms!=0 {
  559.         set prms_id $xfail_prms
  560.     }
  561.         xfail $arg
  562.         set xfail_flag 0
  563.         if $xfail_prms!=0 {
  564.         set prms_id 0
  565.         set xfail_prms 0
  566.     }
  567.         return
  568.     }
  569.     
  570.     incr untestedcnt
  571.  
  572.     set exit_status 1
  573.     
  574.     set format "UNTESTED:\t$arg"
  575.     if $prms_id then {
  576.         set format [concat $format "\t(PRMS $prms_id)"]
  577.     }
  578.     if $bug_id then {
  579.         set format [concat $format "\t(BUG $bug_id)"]
  580.     }
  581.     
  582.     clone_output "$format"
  583. }
  584.  
  585. #
  586. # unresolved -- The test vcase has an unresolved outcome.
  587. #
  588. proc unresolved { arg } {
  589.     global unresolvedcnt
  590.     global prms_id
  591.     global bug_id
  592.     global exit_status
  593.     global xfail_flag
  594.     global xfail_prms
  595.     
  596.     if $xfail_flag then {
  597.         if $xfail_prms!=0 {
  598.         set prms_id $xfail_prms
  599.     }
  600.         xfail $arg
  601.         set xfail_flag 0
  602.         if $xfail_prms!=0 {
  603.         set prms_id 0
  604.         set xfail_prms 0
  605.     }
  606.         return
  607.     }
  608.     
  609.     incr unresolvedcnt
  610.  
  611.     set exit_status 1
  612.     
  613.     set format "UNRESOLVED:\t$arg"
  614.     if $prms_id then {
  615.         set format [concat $format "\t(PRMS $prms_id)"]
  616.     }
  617.     if $bug_id then {
  618.         set format [concat $format "\t(BUG $bug_id)"]
  619.     }
  620.     
  621.     clone_output "$format"
  622. }
  623.  
  624. #
  625. # unsupported -- The test case is unsupported. Usually this is used for a test
  626. #                that is missing OS support.
  627. #
  628. proc unsupported { arg } {
  629.     global unsupportedcnt
  630.     global prms_id
  631.     global bug_id
  632.     global exit_status
  633.     global xfail_flag
  634.     global xfail_prms
  635.  
  636.     if $xfail_flag then {
  637.         if $xfail_prms!=0 {
  638.         set prms_id $xfail_prms
  639.     }
  640.         xfail $arg
  641.         set xfail_flag 0
  642.         if $xfail_prms!=0 {
  643.         set prms_id 0
  644.         set xfail_prms 0
  645.     }
  646.         return
  647.     }
  648.     
  649.     incr unsupportedcnt
  650.  
  651.     set exit_status 1
  652.     
  653.     set format "UNSUPPORTED:\t$arg"
  654.     if $prms_id then {
  655.         set format [concat $format "\t(PRMS $prms_id)"]
  656.     }
  657.     if $bug_id then {
  658.         set format [concat $format "\t(BUG $bug_id)"]
  659.     }
  660.     
  661.     clone_output "$format"
  662. }
  663.  
  664. #
  665. # exp_continue -- create this if it doesn't exist. For compatablity
  666. #                 with old versions.
  667. #
  668. global argv0
  669. if ![info exists argv0] then {
  670.     proc exp_continue { } {
  671.     continue -expect
  672.     }
  673. }
  674.