#!/usr/local/bin/perl select STDOUT; $|=1; $usr{"hollingd"} = "Dave H."; $username = `whoami`; chomp ($username); $testbase = "/cs/hollingd/public.html/netprog/hw/hw2/testcode"; $wrap = "$testbase/wrap.pl"; $testclient = "$testbase/testclient"; $testdir = "$testbase/tests"; # clear zombie processes first $tmp=`/usr/bin/ps -u $username -o s,pid | grep Z | awk '{print \$2}'`; chomp ($tmp); if ($tmp) { print ("Zombie processes exist. Clean them first.\n"); exit; } my $grader = $usr{$username}; my $i; if (-e "grading.results") { system ("mv grading.results grading.results.old"); } open(G,">grading.results") || die $!; $zombie = 0; $memleak = 0; sub logout { print @_; print G @_; } sub DoTest { my $pid; my $pid2; my $tmp; my $pass = 0; my $failonce = 0; my $test = shift; # clean up in case logout ("Cleaning proxy processes before running test.\n"); my $t1 = `/usr/bin/ps -u $username -o pid,comm | grep proxy | awk '{print \$1}'`; chomp ($t1); my @t2 = split (/\s+/, $t1); for (@t2) { system ("kill", "-9", "$_") if $_; } logout "Doing test $test ... \n"; $port = int (rand (64000)) + 1025; system ("./proxy $port $filter &"); $username=`whoami`; chomp ($username); # wait for proxy to start my $try = 0; do { logout ("Waiting for proxy to start ... "); $pid = `/usr/bin/ps -u $username -o comm,pid | grep proxy | awk '{print \$2}'`; chomp ($pid); sleep 1 if (! $pid); ++ $try; } while (! $pid && $try < 20); if ($try == 20) { logout ("Proxy failed to start.\n"); return -1; } else { logout ("OK.\n"); } # $memsize=`/usr/bin/ps -p $pid -o vsz=`; # chomp ($memsize); if ($pid2 = open(CHILD, "-|")) { while () { logout $_; } close (CHILD); waitpid ($pid2, 0); } else { die "== Proj 2 grading test cannot fork: $!" unless defined $pid2; $SIG{INT} = "IGNORE"; exec("$wrap $testclient localhost $port $testdir/$test") or die "== Proj 2 grading test cannot exec program: $!\n"; } sleep 1; if ($test eq "image") { $memsize=`/usr/bin/ps -p $pid -o vsz=`; chomp ($memsize); } # Check for mem and zombie only if test is stress if ($test eq "stress") { $memsize2=`/usr/bin/ps -p $pid -o vsz=`; chomp ($memsize2); if ($memsize2 > $memsize + 200) { $memleak = 1; logout "== Proj 2 grading test : memory leak found. $memsize, $memsize2\n"; } $tmp=`/usr/bin/ps -u $username -o pid,comm,s | grep Z`; chomp ($tmp); if ($tmp) { $zombie = 1; logout "== Proj 2 grading test : zombie process found.\n"; logout "$tmp\n"; } } # clean up in case # print ("Cleaning proxy processes.\n"); kill 9 => $pid; $t1 = `/usr/bin/ps -u $username -o pid,comm | grep proxy | awk '{print \$1}'`; chomp ($t1); @t2 = split (/\s+/, $t1); for (@t2) { system ("kill", "-9", "$_") if $_; } sleep 1; return $pass if ($pass < 0) ; if ($test =~ /stress/) { return $failonce ? 0 : $pass; } return $pass; } @tests = ( "doc", "image", "port", "error", "tcpread", "epipe", "smallpost", "bigpost", "garbage", "badmethod", "nonsense", "servernocl", "servernostat", "servernulls", "stress" ); foreach $i (@tests) { DoTest($i); } $filter = "yahoo.com cs.rpi.edu www.google.com"; DoTest("filterallow"); DoTest("filterdeny"); close(G); exit;