home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-convex / pt.shar / pt / Test < prev   
Encoding:
Text File  |  1993-05-26  |  1.8 KB  |  122 lines

  1.  
  2. $user = (getpwuid($>))[0];
  3.  
  4. $PT = './pt';
  5.  
  6. $| = 1;
  7.  
  8. print <<EOF;
  9. Running tests for pt..
  10.  
  11. Should anything fail, this make will abort.
  12. if it doesn't look right, just hit ^C.
  13.  
  14. EOF
  15.  
  16. &cr;
  17.  
  18. print "First, I'll run pt on just your processes:\n\n";
  19.  
  20. &run($PT);
  21. while(<PT>) {
  22.     print;
  23.     &test1;
  24. &ran;
  25. &result1;
  26. &cr;
  27.  
  28. print <<EOF;
  29. Ok, next test: run pt on just this process, tracing back to the root:
  30.  
  31. EOF
  32.  
  33. &run ("$PT $$");
  34.  
  35. while (<PT>) {
  36.     print;
  37.     &test2;
  38. &ran;
  39.  
  40. &result2;
  41.  
  42. &cr;
  43.  
  44. print "\nNow for all processes:\n\n";
  45.  
  46. &run("$PT -a");
  47.  
  48. $init = $sawme = $warned = $sawpt = 0;
  49.  
  50. while (<PT>) {
  51.     print;
  52.     &test3;
  53. &ran;
  54. &result3;
  55.  
  56.  
  57. system("touch ./test") && die "can't touch \"test\" semaphore file: $!";
  58.  
  59. print "\nLooks good, now go for the install!\n";
  60.  
  61. sub run {
  62.     $Args = shift;
  63.     print "$ $Args\n";
  64.     open(PT, "$Args |") || die "couldn't fork: $!";
  65.  
  66. sub ran {
  67.     die "\"$Args\" exited badly: $!" unless close(PT);
  68.  
  69. sub cr {
  70.     print "\nHit <CR> to continue, ^C to abort: ";
  71.     <STDIN>;
  72.     print "\n";
  73.  
  74. sub more {
  75.     print "$_[0]; continue? [n] ";
  76.     exit 1 unless <STDIN> =~ /^\s*y/i;
  77.  
  78. sub test1 {
  79.     $sawpt += /pt/;
  80.     $sawme += /\b$user\b/i;
  81.     if (/^\(\d+\)/ && !$warned++) {
  82.     @pw = getpwuid($1);
  83.     if  ($pw[0]) {
  84.         &more("Hmmm, uid $1 didn't convert to $pw[0]");
  85.     } else {
  86.         print "Oops, you don't have a uid $1 here\n";
  87.         &more("Maybe the ps line is mangled;");
  88.     } 
  89.     } 
  90. }
  91.  
  92. sub test2 { 
  93.     $init += /^\w+\s+1\b.+\binit\b/; 
  94. }
  95.  
  96. sub result1 {
  97.     &more("Your uid should have appeared here") unless $sawme;
  98.     &more("The pt program should have appeared here") unless $sawpt;
  99. }
  100.  
  101. sub result2 {
  102.     &more("Didn't see init (process 1)") unless $init;
  103.     &more("Saw init $init times") if $init > 1;
  104. }
  105.  
  106. sub test3 {
  107.     &test1;
  108.     &test2;
  109. }
  110.  
  111. sub result3 {
  112.     &result1;
  113.     &result2;
  114.