Whamcloud - gitweb
import libsysio for b_newsysio
[fs/lustre-release.git] / libsysio / tests / setup.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: ./setup.pl <cwd> : Setup initial system directories for test\n";
13     exit(-1);
14 }
15
16 sub do_makedir
17 {
18     my ($cmdfh, $outfh, $cwd, $lastdir) = @_;
19     my $cmd = "CALL mkdir $cwd/$lastdir 0777\n";
20
21     # Now create newdir
22     helper::send_cmd($cmdfh, $outfh, "mkdir", $cmd);  
23
24     # Verify the directory was made correctly
25     helper::verify_cmd($cmdfh, $outfh, "mkdir");      
26  }
27
28
29 my $currarg = 0;
30 my $is_alpha = 0;
31 my $alpha_arg = "";
32 if (@ARGV == 0) {
33     usage();
34 }
35 if ((@ARGV > 1) && ($ARGV[$currarg++] eq "-alpha")){
36     $is_alpha = 1;
37     $alpha_arg = $ARGV[$currarg-1];
38
39
40 my $cwd = $ARGV[$currarg];
41
42 # Get tests directory
43 my $testdir = $FindBin::Bin;
44   
45 eval {
46     if ($is_alpha == 0) {
47         open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
48     } else {
49         open2(\*OUTFILE, \*CMDFILE, 
50               "yod -batch -quiet -sz 1 $testdir/test_driver --np");
51     }
52 };
53
54 if ($@) {
55     if ($@ =~ /^open2/) {
56         warn "open2 failed: $!\n$@\n";
57         return;
58     }
59     die;
60 }
61
62 my $outfh = \*OUTFILE;
63 my $cmdfh = \*CMDFILE;
64
65 if ($is_alpha == 0) {
66     helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
67 }
68
69
70 # Create tmp_dir
71 do_makedir($cmdfh, $outfh, $cwd, "tmp_dir");
72 do_makedir($cmdfh, $outfh, $cwd, "tmp_dir/test1");
73 do_makedir($cmdfh, $outfh, $cwd, "tmp_dir/test2");
74
75 # Copy helper.pm
76 print STDERR "Copying $testdir/helper.pm to $cwd/tmp_dir/test1/helper.pm\n";
77 my $res = `perl $testdir/test_copy.pl $alpha_arg $testdir/helper.pm $cwd/tmp_dir/test1/helper.pm`;
78 chop($res);
79
80 if ($res ne "copy test successful") {
81   print STDERR "setup (copy test) failed with message: $res\n";
82   print $cmdfh "exit\n";
83   close $outfh;
84
85   # Give test_driver time to finish
86   sleep 0.000001;
87
88   print STDOUT "Copying of helper.pm failed\n";
89   exit 1;
90
91
92  print $cmdfh "exit\n";
93 close $outfh;
94
95 # Give test_driver time to finish
96 sleep 0.000001;
97
98 print STDOUT "setup successful\n";
99
100 exit 0;
101
102
103
104