4 # stats test: Verifies that the set of stat calls (stat, fstat, fstatvfs, and
5 # statvfs) return the same items and that the calls return the
6 # same items as Perl's stat call (which would use a native library
15 use lib "$FindBin::Bin";
20 print "Usage ./test_stats.pl file : Verifies that the set of stat calls (stat, \n";
21 print " : fstat, fstatvfs, statvfs) return the same set\n";
22 print " : of stats for file and that the calls return \n";
23 print " : the same items as Perl's stat call (which \n";
24 print " : would use a native library and not libsysio)\n";
28 # Compares the output of Perl's stat function with the output
29 # from libsysio's stat
33 my ( $cmdfh, $outfh, $is_alpha, $bits, @stats) = @_;
36 my ($iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev,
37 $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime, @pstats) =
41 ($iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev,
42 $iosize, $ioatime, $iomtime, $ioctime, $ioblks, $ioblksize, @pstats) =
46 ($iodev, $ioino, $ionlink, $iomode, $iouid, $iogid, $iordev,
47 $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime,@pstats) =
50 my ($pdev, $pino, $pmode, $pnlink, $puid, $pgid, $prdev,
51 $psize, $patime, $pmtime, $pctime, $pblksize, $pblks) = @pstats;
53 # helper::cmp_nums($cmdfh, $outfh, $iodev, $pdev, "device numbers");
54 helper::cmp_nums($cmdfh, $outfh, $ioino, $pino, "inode numbers");
55 helper::cmp_nums($cmdfh, $outfh, $iomode, $pmode, "file modes");
56 helper::cmp_nums($cmdfh, $outfh, $ionlink, $pnlink, "number of links");
57 helper::cmp_nums($cmdfh, $outfh, $iouid, $puid, "user ids");
58 helper::cmp_nums($cmdfh, $outfh, $iogid, $pgid, "group ids");
59 helper::cmp_nums($cmdfh, $outfh, $iordev, $prdev, "device ids");
60 helper::cmp_nums($cmdfh, $outfh, $iosize, $psize, "file sizes");
61 helper::cmp_nums($cmdfh, $outfh, $ioatime, $patime, "access times");
62 helper::cmp_nums($cmdfh, $outfh, $iomtime, $pmtime, "modification times");
63 helper::cmp_nums($cmdfh, $outfh, $ioctime, $pctime, "inode change times");
64 helper::cmp_nums($cmdfh, $outfh, $ioblksize, $pblksize, "block sizes");
65 helper::cmp_nums($cmdfh, $outfh, $ioblks, $pblks, "blocks allocated");
69 # Prints out the stat buffer and verifies that it matches
73 my ($cmdfh, $outfh, $cmd, $is_alpha, $bits, @stats) = @_;
77 # Print out the stat buffer
79 $cmdstr = 'PRINT $buf 0 16 LONG 16 16 INT 32 8 LONG 40 4 INT 48 40 LONG'."\n";
80 } elsif ($bits == 32) {
81 $cmdstr = 'PRINT $buf 0 8 LONG 12 24 INT 44 8 LONG 48 8 INT 56 24 LONG'."\n";
83 $cmdstr = 'PRINT $buf 0 24 LONG 24 16 INT 48 32 LONG 88 8 LONG 104 8 LONG'."\n";
86 helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
91 my @iostats = split(' ', $res);
92 foreach my $iostat (@iostats) {
93 $iostats[$i] = oct($iostat);
97 cmp_stats($cmdfh, $outfh, $is_alpha, $bits, @iostats, @stats);
103 my ($file, $use_system, $is_alpha) = @_;
105 # Get tests directory
106 my $testdir = $FindBin::Bin;
109 if ($is_alpha == 0) {
110 open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
112 open2(\*OUTFILE, \*CMDFILE,
113 "yod -batch -quiet -sz 1 $testdir/test_driver --np");
118 if ($@ =~ /^open2/) {
119 warn "open2 failed: $!\n$@\n";
126 my $outfh = \*OUTFILE;
127 my $cmdfh = \*CMDFILE;
129 if ($is_alpha == 0) {
130 helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
134 if ($use_system == 1) {
136 @stats = stat($file);
139 # Allocate the buffer
140 my $cmdstr = '$buf = ALLOC ( $size = CALL sizeof stat )'."\n";
141 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
144 # Issue the stat command
145 $cmdstr = 'CALL stat '."$file ".'$buf'."\n";
146 helper::send_cmd($cmdfh, $outfh, "stat", $cmdstr);
147 helper::verify_cmd($cmdfh, $outfh, "stat");
149 # Attempt to determine type
150 $cmdstr = 'PRINT $size'."\n";
151 helper::send_cmd($cmdfh, $outfh, "print", $cmdstr);
152 my $statsize = <$outfh>;
154 $statsize = oct($statsize);
156 if ($statsize == 144) {
160 if ($use_system == 1) {
161 # Now print the buffer out and verify that it matches
163 verify_stat($cmdfh, $outfh, "stat", $is_alpha, $bits, @stats);
167 $cmdstr = '$fd = CALL open '."$file O_RDONLY\n";
168 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
169 helper::verify_cmd($cmdfh, $outfh, "open");
172 # Now issue an fstat call
173 $cmdstr = 'CALL fstat $fd $buf'."\n";
174 helper::send_cmd($cmdfh, $outfh, "fstat", $cmdstr);
175 helper::verify_cmd($cmdfh, $outfh, "fstat");
177 if ($use_system == 1) {
178 verify_stat($cmdfh, $outfh, "fstat", $is_alpha, $bits, @stats);
182 if ($use_system == 1) {
183 @stats = lstat($file);
186 $cmdstr = 'CALL lstat '."$file ".'$buf'."\n";
187 helper::send_cmd($cmdfh, $outfh, "lstat", $cmdstr);
188 helper::verify_cmd($cmdfh, $outfh, "lstat");
190 if ($use_system == 1) {
191 verify_stat($cmdfh, $outfh, "lstat", $is_alpha, $bits, @stats);
195 # Now do statvfs functions
196 $cmdstr = '$buf2 = ALLOC ( $size2 = CALL sizeof statvfs )'."\n";
197 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
199 # Clear out the buffer
200 $cmdstr = 'CALL clear $buf2'."\n";
201 helper::send_cmd($cmdfh, $outfh, "CLEAR", $cmdstr);
203 $cmdstr = 'CALL statvfs '."$file ".'$buf2'."\n";
204 helper::send_cmd($cmdfh, $outfh, "statvfs", $cmdstr);
205 helper::verify_cmd($cmdfh, $outfh, "statvfs");
207 # Print out the statvfs buffer
208 $cmdstr = 'PRINT $buf2 0 16 LONG 16 32 INT 48 16 LONG'."\n";
209 helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
213 my @vfsstats1 = split(' ', $res);
215 # Clear out the buffer
216 $cmdstr = 'CALL clear $buf2'."\n";
217 helper::send_cmd($cmdfh, $outfh, "CLEAR", $cmdstr);
220 $cmdstr = 'CALL fstatvfs $fd $buf2'."\n";
221 helper::send_cmd($cmdfh, $outfh, "fstatvfs", $cmdstr);
222 helper::verify_cmd($cmdfh, $outfh, "fstatvfs");
224 # Print out the statvfs buffer
225 $cmdstr = 'PRINT $buf2 0 16 LONG 16 32 INT 48 16 LONG'."\n";
226 helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
230 my @vfsstats2 = split(' ', $res);
232 # Verify the two vfsstats arrays match
233 if (@vfsstats1 != @vfsstats2) {
234 helper::print_and_exit($cmdfh, $outfh, 1, "Two vfsstat arrays unequal lengths\n");
239 foreach my $stat1 (@vfsstats1) {
240 if ($stat1 ne $vfsstats2[$i++]) {
241 my $str = sprintf("vfsstats field %d are not equal (%s != %s)\n",
242 $i-1, $stat1, $vfsstats2[$i-1]);
243 helper::print_and_exit($cmdfh, $outfh, 1, $str);
248 helper::print_and_exit($cmdfh, $outfh, 0, "stat test successful\n");
258 } elsif (@ARGV > 2) {
259 if ($ARGV[$currarg++] eq "-alpha") {
264 my $use_system= $ARGV[$currarg++];
265 my $file = $ARGV[$currarg];
267 process_cmd($file, $use_system, $is_alpha);