Whamcloud - gitweb
import libsysio for b_newsysio
[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 == "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   # Will use this directory...
77   system("mkdir -p $cwd/tmp_dir");
78
79   # Create a couple of files and subdirectories for use in the tests
80   system("mkdir -p $cwd/tmp_dir/test1");
81   system("mkdir -p $cwd/tmp_dir/test2");
82
83   system("cp $testdir/helper.pm $cwd/tmp_dir/test1");
84 } else {
85     $res = `perl $testdir/setup.pl $alpha_arg $cwd`;
86     chop($res);
87     if ($res ne "setup successful") {
88                         print "Test setup failed with $res, bailing out\n";
89                         exit 1;
90     }
91 }
92
93
94 if (($alpha_arg eq "") || ($is_broke == 0)) {
95     # Test getdirentries
96     $res = `perl $testdir/test_list.pl $alpha_arg $cwd/tmp_dir`;
97     chop($res);
98     if ($res ne "list test successful") {
99                         print "Basic getdirentries test failed with message: $res\n";
100                         $failures++;
101     } else {
102                         print "test_list finished successfully\n";
103                         $success++;
104     }
105 }
106
107 # Test path
108 my $path1 = abs_path($testdir);
109 my @resarr = `perl $testdir/test_path.pl $alpha_arg $path1 $cwd $cwd/tmp_dir`;
110 $res = $path1.": d\n";
111 if ($resarr[0] ne $res) {
112     print "path test returned $resarr[0] instead of $res\n";
113     $failures++;
114 } else {
115         $res = $cwd.": d\n";
116         if ($resarr[1] ne $res) {
117                 print "path test returned $resarr[1] instead of $res\n";
118                 $failures++;
119         } else {
120                 $res = $cwd."/tmp_dir: d\n";
121                 if ($resarr[2] ne $res) {
122             print "path test returned $resarr[2] instead of $res\n";
123             $failures++;
124                 } else {
125             print "test_path finished successfully\n";
126             $success++;
127                 }
128         }
129 }
130
131 # Test getcwd
132 $res = `perl $testdir/test_getcwd.pl $alpha_arg $cwd/tmp_dir/test1`;
133 chop($res);
134 if ($res ne "getcwd test successful") {
135     print "getcwd test failed with message: $res\n";
136     $failures++;
137 } else {
138     $success++;
139     print "test_getcwd finished successfully\n";
140 }
141
142 # Test copy
143 $res = `perl $testdir/test_copy.pl $alpha_arg $cwd/tmp_dir/test1/helper.pm $cwd/tmp_dir/helper.pm`;
144 chop($res);
145 if ($res ne "copy test successful") {
146   print "copy test failed with message: $res\n";
147   $failures++;
148 } else {
149   $success++;
150   print "test_copy finished successfully\n";
151 }
152
153 # Test stats
154 $res = `perl $testdir/test_stats.pl $alpha_arg $use_system $cwd/tmp_dir/test1/helper.pm`;
155 chop($res);
156 if ($res ne "stat test successful") {
157   print "stat test failed with message: $res\n";
158   $failures++;
159 } else {
160   $success++;
161   print "test_stats finished successfully\n";
162 }
163
164 # Test stdfd
165 $res = `echo "foobar" | perl $testdir/test_copy.pl $alpha_arg -o /dev/stdin /dev/stdout`;
166 chop($res);
167 if ($res ne "copy test successful") {
168   print "stdfd test failed with message: $res\n";
169   $failures++;
170 } else {
171   $success++;
172   print "test_stdfd finished successfully\n";
173 }
174
175 # Test symlink
176 $res = `perl $testdir/test_symlink.pl $alpha_arg $cwd/tmp_dir/test1/helper.pm $cwd/tmp_dir/helper.foo`;
177 chop($res);
178 if ($res ne "Symlink test successful") {
179   print "symlink test failed with message: $res\n";
180   $failures++;
181 } else {
182   $success++;
183   print "test_symlink finished successfully\n";
184 }
185
186 # Test r/w calls
187 $res = `perl $testdir/test_rw.pl $alpha_arg $cwd/tmp_dir/tmp.foo`;
188 chop($res);
189 if ($res ne "rw test successful") {
190   print "rw test failed with message: $res\n";
191   $failures++;
192 } else {
193   $success++;
194   print "rw test finished successfully\n";
195 }
196
197 # Test strided I/O
198 $res = `perl $testdir/test_strided.pl $alpha_arg $cwd/tmp_dir/tmp2.foo`;
199 chop($res);
200 if ($res ne "strided IO test successful") {
201   print "strided IO test failed with message: $res\n";
202   $failures++;
203 } else {
204   $success++;
205   print "strided IO test finished successfully\n";
206 }
207
208 print "$failures tests failed and $success tests succeeded\n";
209
210 # cleanup -- only if no failures
211 if ($failures == 0) {
212         if ($use_system == 1) {
213     system(`rm -rf $cwd/tmp_dir`);
214         } else {
215     $res = `perl $testdir/cleanup.pl $alpha_arg $cwd`;
216     chop($res);
217     if ($res ne "cleanup successful") {
218                         print "Test cleanup failed with $res, bailing out\n";
219                         exit 1;
220     }   
221         }
222 }
223 exit $failures;