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