[Libsysio-commit] HEAD: libsysio/tests cleanup.pl setup.pl test_all.pl test_getcwd.pl test_stats.pl
Brought to you by:
lward
From: Sonja T. <so...@us...> - 2003-10-30 15:22:22
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1:/tmp/cvs-serv8526 Modified Files: test_all.pl test_getcwd.pl test_stats.pl test_symlink.pl Added Files: cleanup.pl setup.pl Log Message: Removed some system dependencies from test_all.pl. test_all.pl can now be ran with a -nosystem option and it will not use the underlying system to do any setup. --- NEW FILE --- #!/usr/bin/perl -w use IPC::Open2; use strict; use FindBin; use lib "$FindBin::Bin"; use helper; sub usage { print "Usage: ./cleanup.pl <cwd> : Remove system directories used for test\n"; exit(-1); } sub do_remove { my ($cmdfh, $outfh, $type, $cwd, $lastdir) = @_; my $cmd; if ($type eq "dir") { $cmd = "rmdir"; } else { $cmd = "unlink"; } my $cmdstr = "CALL $cmd $cwd/$lastdir\n"; # Now remove the file/dir helper::send_cmd($cmdfh, $outfh, $cmd, $cmdstr); # Verify the directory was made correctly helper::verify_cmd($cmdfh, $outfh, $cmd); } my $currarg = 0; my $is_alpha = 0; my $alpha_arg = ""; if (@ARGV == 0) { usage(); } if ((@ARGV > 1) && ($ARGV[$currarg++] eq "-alpha")){ $is_alpha = 1; $alpha_arg = $ARGV[$currarg-1]; } my $cwd = $ARGV[$currarg]; # Get tests directory my $testdir = $0; $testdir =~ s/\/\w+.pl$//; eval { if ($is_alpha == 0) { open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); } else { open2(\*OUTFILE, \*CMDFILE, "yod -batch -quiet -sz 1 $testdir/test_driver --np"); } }; if ($@) { if ($@ =~ /^open2/) { warn "open2 failed: $!\n$@\n"; return; } die; } my $outfh = \*OUTFILE; my $cmdfh = \*CMDFILE; if ($is_alpha == 0) { helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); } # Remove the helper.pms do_remove($cmdfh, $outfh, "file", $cwd, "tmp_dir/helper.pm"); do_remove($cmdfh, $outfh, "file", $cwd, "tmp_dir/test1/helper.pm"); # Remove directories do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir/test1"); do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir/test2"); do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir"); print $cmdfh "exit\n"; close $outfh; # Give test_driver time to finish sleep 0.000001; print STDOUT "cleanup successful\n"; exit 0; --- NEW FILE --- #!/usr/bin/perl -w use IPC::Open2; use strict; use FindBin; use lib "$FindBin::Bin"; use helper; sub usage { print "Usage: ./setup.pl <cwd> : Setup initial system directories for test\n"; exit(-1); } sub do_makedir { my ($cmdfh, $outfh, $cwd, $lastdir) = @_; my $cmd = "CALL mkdir $cwd/$lastdir 0777\n"; # Now create newdir helper::send_cmd($cmdfh, $outfh, "mkdir", $cmd); # Verify the directory was made correctly helper::verify_cmd($cmdfh, $outfh, "mkdir"); } my $currarg = 0; my $is_alpha = 0; my $alpha_arg = ""; if (@ARGV == 0) { usage(); } if ((@ARGV > 1) && ($ARGV[$currarg++] eq "-alpha")){ $is_alpha = 1; $alpha_arg = $ARGV[$currarg-1]; } my $cwd = $ARGV[$currarg]; # Get tests directory my $testdir = $0; $testdir =~ s/\/\w+.pl$//; eval { if ($is_alpha == 0) { open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); } else { open2(\*OUTFILE, \*CMDFILE, "yod -batch -quiet -sz 1 $testdir/test_driver --np"); } }; if ($@) { if ($@ =~ /^open2/) { warn "open2 failed: $!\n$@\n"; return; } die; } my $outfh = \*OUTFILE; my $cmdfh = \*CMDFILE; if ($is_alpha == 0) { helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); } # Create tmp_dir do_makedir($cmdfh, $outfh, $cwd, "tmp_dir"); do_makedir($cmdfh, $outfh, $cwd, "tmp_dir/test1"); do_makedir($cmdfh, $outfh, $cwd, "tmp_dir/test2"); # Copy helper.pm print STDERR "Copying $testdir/helper.pm to $cwd/tmp_dir/test1/helper.pm\n"; my $res = `perl $testdir/test_copy.pl $alpha_arg $testdir/helper.pm $cwd/tmp_dir/test1/helper.pm`; chop($res); if ($res ne "copy test successful") { print STDERR "setup (copy test) failed with message: $res\n"; print $cmdfh "exit\n"; close $outfh; # Give test_driver time to finish sleep 0.000001; print STDOUT "Copying of helper.pm failed\n"; exit 1; } print $cmdfh "exit\n"; close $outfh; # Give test_driver time to finish sleep 0.000001; print STDOUT "setup successful\n"; exit 0; Index: test_all.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_all.pl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -w -b -B -p -r1.5 -r1.6 --- test_all.pl 28 Oct 2003 20:59:39 -0000 1.5 +++ test_all.pl 30 Oct 2003 15:22:19 -0000 1.6 @@ -9,16 +9,21 @@ use strict; use Cwd 'abs_path'; my $alpha_arg = ""; +my $use_system = 1; my $is_broke = 1; # Don't test certain areas known to not work on Cplant -if ((@ARGV > 0) && ($ARGV[0] eq "-alpha")) { +my $arg_count = @ARGV; +foreach my $arg (@ARGV) { + if ($arg eq "-alpha") { $alpha_arg = "-alpha"; -} else { + } elsif ($arg eq "-nosystem") { + $use_system = 0; + } +} my $alpha_env = $ENV{"IS_ALPHA"}; - # If there is no command line arg, check the environment vars +# Check the environment vars if (defined($alpha_env) && ($alpha_env eq "yes")) { $alpha_arg = "-alpha"; } -} my $failures = 0; my $success = 0; @@ -31,7 +36,7 @@ $testdir =~ s/\/\w+.pl$//; my $res; - +if ($use_system == 1) { # Will use this directory... system("mkdir -p $cwd/tmp_dir"); @@ -40,6 +45,15 @@ system("mkdir -p $cwd/tmp_dir/test1"); system("mkdir -p $cwd/tmp_dir/test2"); system("cp $testdir/helper.pm $cwd/tmp_dir/test1"); +} else { + $res = `perl $testdir/setup.pl $alpha_arg $cwd`; + chop($res); + if ($res ne "setup successful") { + print "Test setup failed with $res, bailing out\n"; + exit 1; + } +} + if (($alpha_arg eq "") || ($is_broke == 0)) { # Test getdirentries @@ -114,7 +128,7 @@ if ($res ne "copy test successful") { } # Test stats -$res = `perl $testdir/test_stats.pl $alpha_arg $cwd/tmp_dir/helper.pm`; +$res = `perl $testdir/test_stats.pl $alpha_arg $use_system $cwd/tmp_dir/helper.pm`; chop($res); if ($res ne "stat test successful") { print "stat test failed with message: $res\n"; @@ -149,6 +163,15 @@ if ($res ne "Symlink test successful") { print "$failures tests failed and $success tests succeeded\n"; # cleanup +if ($use_system == 1) { system(`rm -rf $cwd/tmp_dir`); +} else { + $res = `perl $testdir/cleanup.pl $alpha_arg $cwd`; + chop($res); + if ($res ne "cleanup successful") { + print "Test cleanup failed with $res, bailing out\n"; + exit 1; + } +} exit $failures; Index: test_getcwd.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_getcwd.pl,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -b -B -p -r1.3 -r1.4 Index: test_stats.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_stats.pl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -b -B -p -r1.4 -r1.5 --- test_stats.pl 27 Oct 2003 16:50:54 -0000 1.4 +++ test_stats.pl 30 Oct 2003 15:22:19 -0000 1.5 @@ -92,7 +92,7 @@ sub verify_stat sub process_cmd { - my ($file, $is_alpha) = @_; + my ($file, $use_system, $is_alpha) = @_; # Get tests directory my $testdir = $0; @@ -122,9 +122,12 @@ $testdir =~ s/\/\w+.pl$//; if ($is_alpha == 0) { helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); } - # Get stats for file - my @stats = stat($file); + my @stats; + if ($use_system == 1) { + # Get stats for file + @stats = stat($file); + } # Allocate the buffer my $cmdstr = '$buf = ALLOC ( $size = CALL sizeof stat )'."\n"; @@ -136,9 +139,11 @@ $testdir =~ s/\/\w+.pl$//; helper::send_cmd($cmdfh, $outfh, "stat", $cmdstr); helper::verify_cmd($cmdfh, $outfh, "stat"); + if ($use_system == 1) { # Now print the buffer out and verify that it matches # what Perl has verify_stat($cmdfh, $outfh, "stat", $is_alpha, @stats); + } # Open the file $cmdstr = '$fd = CALL open '."$file O_RDONLY\n"; @@ -151,17 +156,22 @@ $testdir =~ s/\/\w+.pl$//; helper::send_cmd($cmdfh, $outfh, "fstat", $cmdstr); helper::verify_cmd($cmdfh, $outfh, "fstat"); + if ($use_system == 1) { verify_stat($cmdfh, $outfh, "fstat", $is_alpha, @stats); + } # Test lstat + if ($use_system == 1) { @stats = lstat($file); + } $cmdstr = 'CALL lstat '."$file ".'$buf'."\n"; helper::send_cmd($cmdfh, $outfh, "lstat", $cmdstr); helper::verify_cmd($cmdfh, $outfh, "lstat"); + if ($use_system == 1) { verify_stat($cmdfh, $outfh, "lstat", $is_alpha, @stats); - + } # Now do statvfs functions $cmdstr = '$buf2 = ALLOC ( $size2 = CALL sizeof statvfs )'."\n"; @@ -207,10 +217,6 @@ $testdir =~ s/\/\w+.pl$//; my $i=0; - # Stupid hack. statvfs on Cplant is unhappy :-( - # Rather than do the honest thing and just continue to report its unhappiness, - # don't test for its happiness - if ( $is_alpha == 0) { foreach my $stat1 (@vfsstats1) { if ($stat1 ne $vfsstats2[$i++]) { my $str = sprintf("vfsstats field %d are not equal (%s != %s)\n", @@ -218,7 +224,6 @@ $testdir =~ s/\/\w+.pl$//; helper::print_and_exit($cmdfh, $outfh, 1, $str); } } - } helper::print_and_exit($cmdfh, $outfh, 0, "stat test successful\n"); } @@ -228,16 +233,16 @@ $testdir =~ s/\/\w+.pl$//; my $currarg = 0; my $is_alpha = 0; -if (@ARGV < 1) { +if (@ARGV < 2) { usage; -} elsif (@ARGV > 1) { +} elsif (@ARGV > 2) { if ($ARGV[$currarg++] eq "-alpha") { $is_alpha = 1; } } - +my $use_system= $ARGV[$currarg++]; my $file = $ARGV[$currarg]; -process_cmd($file, $is_alpha); +process_cmd($file, $use_system, $is_alpha); Index: test_symlink.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_symlink.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -b -B -p -r1.2 -r1.3 --- test_symlink.pl 28 Oct 2003 22:01:22 -0000 1.2 +++ test_symlink.pl 30 Oct 2003 15:22:19 -0000 1.3 @@ -172,7 +172,9 @@ sub process_cmd # Now remove the symbolic link and make sure everything stays the same # Remove the link (this assumes the link is not in incore) - system("rm -f $dest"); + $cmdstr = "CALL unlink $dest\n"; + helper::send_cmd($cmdfh, $outfh, "unlink", $cmdstr); + helper::verify_cmd($cmdfh, $outfh, "unlink"); # Attempt to open the symbolic link. This should return an error $cmdstr = 'CALL open '."$dest O_RDONLY\n"; @@ -196,6 +198,7 @@ sub process_cmd # Open src $cmdstr = '$src2 = CALL open '."$src O_RDONLY\n"; helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); + helper::verify_cmd($cmdfh, $outfh, "open $src(2)"); $cmdstr = 'CALL read $src2 $destbuf '."$readb\n"; helper::send_cmd($cmdfh, $outfh, "read $src(2)", $cmdstr); |