Whamcloud - gitweb
new upstream libsysio snapshot (20041101)
[fs/lustre-release.git] / libsysio / tests / test_all.pl
1 #!/usr/bin/perl -w
2
3 #
4 # VERY basic functionality test for sysio.  To run, just type ./test_all.pl
5 # Absolutely no guarantees for running on alpha/cplant 
6 #
7
8 use strict;
9 use FindBin;
10
11 use Cwd 'abs_path';         
12
13 my $alpha_arg = "";
14 my $use_system = 1;
15 my $is_broke = 1; # Don't test certain areas known to not work on Cplant
16 my $arg_count = @ARGV;
17 foreach my $arg (@ARGV) {
18     if ($arg eq "-alpha") {
19                         $alpha_arg = "-alpha";
20     } elsif ($arg eq "-nosystem") {
21                         $use_system = 0;
22     }
23 }
24 my $alpha_env = $ENV{"IS_ALPHA"};
25 # Check the environment vars
26 if (defined($alpha_env) && ($alpha_env eq "yes")) {
27     $alpha_arg = "-alpha";
28 }
29
30 my $failures = 0;
31 my $success = 0;
32 # Get cwd..
33 my $cwd = $ENV{PWD};
34
35 # Get tests directory
36 my $testdir = $FindBin::Bin;
37
38 my $namespace_env = "SYSIO_NAMESPACE";
39 my $home = $ENV{"HOME"};
40 my $auto_mount = $ENV{"SYSIO_AUTOMOUNT"};
41 my $root_flags = "0";
42 my $extras = "";
43 if ((defined($auto_mount)) && ($auto_mount eq "xyes")) {
44         $root_flags = "2";
45
46         #
47         # Add a /auto directory for automounted file systems. We
48         # craft one automount that mounts /usr/home from the native
49         # file system. Further automounts in the sub-mounts are not enabled.
50         #
51         $extras=" \
52                 {mnt,   dev=\"incore:0755+0+0\",dir=\"/mnt\",fl=2} \
53                 {creat, ft=dir,nm=\"/mnt/home\",pm=0755,ow=0,gr=0} \
54                 {creat, ft=file,nm=\"/mnt/home/.mount\",pm=0600, \
55                         str=\"native:/usr/home\"}";
56 }
57 $ENV{$namespace_env} = "\
58         {mnt,   dev=\"native:/\",dir=/,fl=$root_flags} \
59         {mnt,   dev=\"incore:0755+0+0\",dir=\"/dev\"} \
60         {creat, ft=chr,nm=\"/dev/stdin\",pm=0400,mm=0+0} \
61         {creat, ft=chr,nm=\"/dev/stdout\",pm=0200,mm=0+1} \
62         {creat, ft=chr,nm=\"/dev/stderr\",pm=0200,mm=0+2} \
63         {creat, ft=dir,nm=\"/dev/fd\",pm=0755,ow=0,gr=0} \
64         {creat, ft=chr,nm=\"/dev/fd/0\",pm=0400,mm=0+0} \
65         {open,  nm=\"/dev/fd/0\",fd=0,m=0} \
66         {creat, ft=chr,nm=\"/dev/fd/1\",pm=0200,mm=0+1} \
67         {open,  nm=\"/dev/fd/1\",fd=1,m=1} \
68         {creat, ft=chr,nm=\"/dev/fd/2\",pm=0200,mm=0+2} \
69         {open,  nm=\"/dev/fd/2\",fd=2,m=1} \
70         {cd,    dir=\"$home\"} \
71         $extras ";
72
73 my $res;
74
75 if ($use_system == 1) {
76         # Test for tmp_dir.  If it exists, fail 
77         # The tmp_dir should be removed after a successful
78         # test run, but is kept if anything fails
79         if (-e "$cwd/tmp_dir") {
80                 print STDERR "ERROR! tmp_dir already exists.\n";
81                 print STDERR "Need to remove tmp_dir for test to run properly\n";
82                 exit 1;
83         } 
84
85   # Will use this directory...
86   system("mkdir -p $cwd/tmp_dir");
87
88   # Create a couple of files and subdirectories for use in the tests
89   system("mkdir -p $cwd/tmp_dir/test1");
90   system("mkdir -p $cwd/tmp_dir/test2");
91
92   system("cp $testdir/helper.pm $cwd/tmp_dir/test1");
93 } else {
94     $res = `perl $testdir/setup.pl $alpha_arg $cwd`;
95     chop($res);
96     if ($res ne "setup successful") {
97                         print "Test setup failed with $res, bailing out\n";
98                         exit 1;
99     }
100 }
101
102
103 if (($alpha_arg eq "") || ($is_broke == 0)) {
104     # Test getdirentries
105     $res = `perl $testdir/test_list.pl $alpha_arg $cwd/tmp_dir`;
106     chop($res);
107     if ($res ne "list test successful") {
108                         print "Basic getdirentries test failed with message: $res\n";
109                         $failures++;
110     } else {
111                         print "test_list finished successfully\n";
112                         $success++;
113     }
114 }
115
116 # Test path
117 my $path1 = abs_path($testdir);
118 my @resarr = `perl $testdir/test_path.pl $alpha_arg $path1 $cwd $cwd/tmp_dir`;
119 $res = $path1.": d\n";
120 if ($resarr[0] ne $res) {
121     print "path test returned $resarr[0] instead of $res\n";
122     $failures++;
123 } else {
124         $res = $cwd.": d\n";
125         if ($resarr[1] ne $res) {
126                 print "path test returned $resarr[1] instead of $res\n";
127                 $failures++;
128         } else {
129                 $res = $cwd."/tmp_dir: d\n";
130                 if ($resarr[2] ne $res) {
131             print "path test returned $resarr[2] instead of $res\n";
132             $failures++;
133                 } else {
134             print "test_path finished successfully\n";
135             $success++;
136                 }
137         }
138 }
139
140 # Test getcwd
141 $res = `perl $testdir/test_getcwd.pl $alpha_arg $cwd/tmp_dir/test1`;
142 chop($res);
143 if ($res ne "getcwd test successful") {
144     print "getcwd test failed with message: $res\n";
145     $failures++;
146 } else {
147     $success++;
148     print "test_getcwd finished successfully\n";
149 }
150
151 # Test copy
152 $res = `perl $testdir/test_copy.pl $alpha_arg $cwd/tmp_dir/test1/helper.pm $cwd/tmp_dir/helper.pm`;
153 chop($res);
154 if ($res ne "copy test successful") {
155   print "copy test failed with message: $res\n";
156   $failures++;
157 } else {
158   $success++;
159   print "test_copy finished successfully\n";
160 }
161
162 # Test stats
163 $res = `perl $testdir/test_stats.pl $alpha_arg $use_system $cwd/tmp_dir/test1/helper.pm`;
164 chop($res);
165 if ($res ne "stat test successful") {
166   print "stat test failed with message: $res\n";
167   $failures++;
168 } else {
169   $success++;
170   print "test_stats finished successfully\n";
171 }
172
173 # Test stdfd
174 $res = `echo "foobar" | perl $testdir/test_copy.pl $alpha_arg -o /dev/stdin /dev/stdout`;
175 chop($res);
176 if ($res ne "copy test successful") {
177   print "stdfd test failed with message: $res\n";
178   $failures++;
179 } else {
180   $success++;
181   print "test_stdfd finished successfully\n";
182 }
183
184 # Test symlink
185 $res = `perl $testdir/test_symlink.pl $alpha_arg $cwd/tmp_dir/test1/helper.pm $cwd/tmp_dir/helper.foo`;
186 chop($res);
187 if ($res ne "Symlink test successful") {
188   print "symlink test failed with message: $res\n";
189   $failures++;
190 } else {
191   $success++;
192   print "test_symlink finished successfully\n";
193 }
194
195 # Test r/w calls
196 $res = `perl $testdir/test_rw.pl $alpha_arg $cwd/tmp_dir/tmp.foo`;
197 chop($res);
198 if ($res ne "rw test successful") {
199   print "rw test failed with message: $res\n";
200   $failures++;
201 } else {
202   $success++;
203   print "rw test finished successfully\n";
204 }
205
206 # Test strided I/O
207 $res = `perl $testdir/test_strided.pl $alpha_arg $cwd/tmp_dir/tmp2.foo`;
208 chop($res);
209 if ($res ne "strided IO test successful") {
210   print "strided IO test failed with message: $res\n";
211   $failures++;
212 } else {
213   $success++;
214   print "strided IO test finished successfully\n";
215 }
216
217 print "$failures tests failed and $success tests succeeded\n";
218
219 # cleanup -- only if no failures
220 if ($failures == 0) {
221         if ($use_system == 1) {
222     system(`rm -rf $cwd/tmp_dir`);
223         } else {
224     $res = `perl $testdir/cleanup.pl $alpha_arg $cwd`;
225     chop($res);
226     if ($res ne "cleanup successful") {
227                         print "Test cleanup failed with $res, bailing out\n";
228                         exit 1;
229     }   
230         }
231 }
232 exit $failures;