Whamcloud - gitweb
This commit was generated by cvs2svn to compensate for changes in r46154,
[fs/lustre-release.git] / libsysio / tests / cleanup.pl
1 #!/usr/bin/perl -w
2
3 use IPC::Open2;
4
5 use strict;
6 use FindBin;
7 use lib "$FindBin::Bin";
8 use helper;
9
10 sub usage
11 {
12     print "Usage: ./cleanup.pl <cwd> : Remove system directories used for test\n";
13     exit(-1);
14 }
15
16 sub do_remove
17 {
18     my ($cmdfh, $outfh, $type, $cwd, $lastdir) = @_;
19     my $cmd;
20     if ($type eq "dir") {
21         $cmd = "rmdir";
22     } else {
23         $cmd = "unlink";
24     }
25     my $cmdstr = "CALL $cmd $cwd/$lastdir\n";
26
27     # Now remove the file/dir
28     helper::send_cmd($cmdfh, $outfh, $cmd, $cmdstr);  
29
30     # Verify the directory was made correctly
31     helper::verify_cmd($cmdfh, $outfh, $cmd);      
32  }
33
34
35 my $currarg = 0;
36 my $is_alpha = 0;
37 my $alpha_arg = "";
38 if (@ARGV == 0) {
39     usage();
40 }
41 if ((@ARGV > 1) && ($ARGV[$currarg++] eq "-alpha")){
42     $is_alpha = 1;
43     $alpha_arg = $ARGV[$currarg-1];
44
45
46 my $cwd = $ARGV[$currarg];
47
48 # Get tests directory
49 my $testdir = $FindBin::Bin;
50   
51 eval {
52     if ($is_alpha == 0) {
53         open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
54     } else {
55         open2(\*OUTFILE, \*CMDFILE, 
56               "yod -batch -quiet -sz 1 $testdir/test_driver --np");
57     }
58 };
59
60 if ($@) {
61     if ($@ =~ /^open2/) {
62         warn "open2 failed: $!\n$@\n";
63         return;
64     }
65     die;
66 }
67
68 my $outfh = \*OUTFILE;
69 my $cmdfh = \*CMDFILE;
70
71 if ($is_alpha == 0) {
72     helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
73 }
74
75 # Remove the helper.pms
76 do_remove($cmdfh, $outfh, "file", $cwd, "tmp_dir/helper.pm");
77 do_remove($cmdfh, $outfh, "file", $cwd, "tmp_dir/test1/helper.pm");
78
79 # Remove directories
80 do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir/test1");
81 do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir/test2");
82 do_remove($cmdfh, $outfh, "dir", $cwd, "tmp_dir");
83
84 print $cmdfh "exit\n";
85 close $outfh;
86
87 # Give test_driver time to finish
88 sleep 0.000001;
89
90 print STDOUT "cleanup successful\n";
91
92 exit 0;
93
94
95
96