home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tests / process.test < prev    next >
Encoding:
Text File  |  1994-01-23  |  5.5 KB  |  194 lines

  1. #
  2. # process.test
  3. #
  4. # Tests for the fork, execl and  wait commands.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: process.test,v 3.1 1994/01/23 16:58:20 markd Exp $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21. #
  22. # Fork without exec will not work under Tk, skip this test
  23. #
  24. if ![lempty [info commands button]] {
  25.     puts stderr "*************************************************************"
  26.     puts stderr "Process tests are constructed in a way that does not work"
  27.     puts stderr "under Tk.  Test skipped."
  28.     puts stderr "*************************************************************"
  29.     puts stderr ""
  30.     return
  31. }
  32.  
  33. # Test fork, execl, and wait commands.
  34.  
  35. Test process-1.1 {fork, execl, wait tests} {
  36.     set newPid [fork]
  37.     if {$newPid == 0} {
  38.         catch {execl $TCL_PROGRAM {-qc {sleep 1;exit 12}}} msg
  39.         puts stderr "execl failed 1.1: $msg"
  40.         exit 1
  41.     }
  42.     lrange [wait $newPid] 1 end
  43. } 0 {EXIT 12}
  44.  
  45. Test process-1.2 {fork, execl, wait tests} {
  46.     set newPid [ForkLoopingChild]
  47.     sleep 1
  48.  
  49.     kill $newPid
  50.     lrange [wait $newPid] 1 end
  51. } 0 {SIG SIGTERM}
  52.  
  53. set newPid1 [ForkLoopingChild]
  54. set newPid2 [ForkLoopingChild]
  55.  
  56. Test process-1.3 {fork, execl, wait tests} {
  57.     sleep 3 ;# Give em a chance to get going.
  58.  
  59.     kill [list $newPid1 $newPid2]
  60.  
  61.     list [wait $newPid1] [wait $newPid2]
  62.  
  63. } 0 [list "$newPid1 SIG SIGTERM" "$newPid2 SIG SIGTERM"]
  64.  
  65. Test process-1.4 {fork, execl, wait tests} {
  66.     fork foo
  67. } 1 {wrong # args: fork}
  68.  
  69. Test process-1.5 {fork, execl, wait tests} {
  70.     wait baz
  71. } 1 {invalid pid or process group id "baz"}
  72.  
  73. Test process-1.6 {fork, execl, wait tests} {
  74.     set testPid [ForkLoopingChild]
  75.     kill $testPid
  76.     set result [wait $testPid]
  77.     lrange $result 1 end
  78. } 0 {SIG SIGTERM}
  79.  
  80. Test process-1.7 {fork, execl, wait tests} {
  81.     set newPid [fork]
  82.     if {$newPid == 0} {
  83.         catch {
  84.             execl -argv0 FOOPROC $TCL_PROGRAM \
  85.                 {-qc {sleep 1;if {"$argv0" == "FOOPROC"} {exit 10} {exit 18}}}
  86.         } msg
  87.         puts stderr "execl failed 1.7: $msg"
  88.         exit 1
  89.     }
  90.     lrange [wait $newPid] 1 end
  91. } 0 {EXIT 10}
  92.  
  93. # Try execl in various wrong ways.  We try it in a separate process, first,
  94. # in case by error we exec something.
  95.  
  96. Test process-1.8 {fork, execl, wait tests} {
  97.     set newPid [fork]
  98.     if {$newPid == 0} {
  99.     catch {execl -argv0 FOOPROC}
  100.     exit 24
  101.     }
  102.     if {[lrange [wait $newPid] 1 end] == {EXIT 24}} {
  103.     execl -argv0 FOOPROC
  104.     } else {
  105.         concat "appears to have exec-ed something"
  106.     }
  107. } 1 {wrong # args: execl ?-argv0 argv0? prog ?argList?}
  108.  
  109. Test process-1.9 {fork, execl, wait tests} {
  110.     set newPid [fork]
  111.     if {$newPid == 0} {
  112.     catch {execl -argv0 FOOPROC $TCL_PROGRAM {-qc {exit 0}} badarg}
  113.     exit 23
  114.     }
  115.     if {[lrange [wait $newPid] 1 end] == {EXIT 23}} {
  116.     execl -argv0 FOOPROC $TCL_PROGRAM {-qc {exit 0}} badarg
  117.     } else {
  118.         concat "appears to have exec-ed something"
  119.     }
  120. } 1 {wrong # args: execl ?-argv0 argv0? prog ?argList?}
  121.  
  122. Test process-1.10 {fork, execl, wait tests} {
  123.     set newPid [fork]
  124.     if {$newPid == 0} {
  125.     catch {execl $TCL_PROGRAM {-qc {exit 0}} badarg}
  126.     exit 24
  127.     }
  128.     sleep 1
  129.     if {[lrange [wait $newPid] 1 end] == {EXIT 24}} {
  130.     execl ../runtcl {-qc {exit 0}} badarg
  131.     }
  132. } 1 {wrong # args: execl ?-argv0 argv0? prog ?argList?}
  133.  
  134. Test process-1.11 {fork, execl, wait tests} {
  135.     set newPid [fork]
  136.     if {$newPid == 0} {
  137.     catch {execl}
  138.     exit 24
  139.     }
  140.     sleep 1
  141.     if {[lrange [wait $newPid] 1 end] == {EXIT 24}} {
  142.     execl
  143.     } else {
  144.         concat "appears to have exec-ed something"
  145.     }
  146. } 1 {wrong # args: execl ?-argv0 argv0? prog ?argList?}
  147.  
  148. Test process-1.12 {fork, execl, wait tests} {
  149.     set newPid [fork]
  150.     if {$newPid == 0} {
  151.     catch {execl -argv0}
  152.     exit 24
  153.     }
  154.     sleep 1
  155.     if {[lrange [wait $newPid] 1 end] == {EXIT 24}} {
  156.     execl -argv0
  157.     } else {
  158.         concat "appears to have exec-ed something"
  159.     }
  160. } 1 {wrong # args: execl ?-argv0 argv0? prog ?argList?}
  161.  
  162. # Test extended wait functionality, if available.
  163.  
  164. catch {wait -nohang 1} result
  165. if [string match "The \"-nohang\", \"-untraced\"*" $result] {
  166.     echo *** Extended wait functionallity not available on this system"
  167.     echo *** Skipping the remainder of the process tests"
  168.     return
  169. }
  170.  
  171. Test process-2.1 {fork, execl, wait tests} {
  172.     set testPid [ForkLoopingChild]
  173.     set result1 [wait -nohang $testPid]
  174.     kill $testPid
  175.     set result2 [wait $testPid]
  176.     list $result1 [lrange $result2 1 end]
  177. } 0 {{} {SIG SIGTERM}}
  178.  
  179. Test process-2.2 {fork, execl, wait tests} {
  180.     set testPid [ForkLoopingChild 1]
  181.     set result1 [wait -nohang -pgroup $testPid]
  182.     kill $testPid
  183.     set result2 [wait -pgroup $testPid]
  184.     list $result1 [lrange $result2 1 end]
  185. } 0 {{} {SIG SIGTERM}}
  186.  
  187. Test process-2.3 {fork, execl, wait tests} {
  188.     set testPid [ForkLoopingChild 1]
  189.     set result1 [wait -nohang -pgroup -untraced $testPid]
  190.     kill $testPid
  191.     set result2 [wait -pgroup -untraced $testPid]
  192.     list $result1 [lrange $result2 1 end]
  193. } 0 {{} {SIG SIGTERM}}
  194.