4 # getdirentries test: Tests the equivalent of a ls. Note that this is not
5 # the most robust test in the world; it simply verifies
6 # that libsysio returns all the entries in the directory
15 use lib "$FindBin::Bin";
20 print "Usage: ./test_list.pl [-p|-alpha] <dir> \n";
21 print " ./test_list.pl -m [-p|-alpha] fstype:mdir dir\n";
22 print " In the first form, will attempt to verify libsysio's\n";
23 print " getdirentries. If no dir is given, will use the \n";
24 print " current working directory\n";
25 print " In the second form, will mount the given mdir (of type fstype) in dir.\n";
26 print " It will then verify the output of libsysio's getdirentries. It will \n";
27 print " then umount the directory and verify that the umount worked\n";
28 print " The -p option will print the directory listing\n";
29 print " The -alpha option is for alpha architecture \n";
36 my ($offset, $outfh, $cmdfh, $do_print, $is_alpha) = @_;
45 my $shortoffset = $offset+$intsize;
46 my $charoffset = $shortoffset+2;
47 my $stroffset = $charoffset+1;
48 my $cmdstr = 'PRINT $buf '.
49 "$offset $intsize $intcmd $shortoffset 2 SHORT $charoffset 1 CHAR $stroffset 1 STR\n";
50 helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
54 my ($inode, $foffset, $size, $type, @names) = split(' ',$res);
59 my $name = join(' ', @names);
62 printf(STDOUT "%-35s %-14s %-14s %-6s %-4s\n", $name, $inode, $foffset, $size, $type);
70 my ($numbytes, $outfh, $cmdfh, $start, $do_print, $is_alpha) = @_;
80 while ($bytes < $numbytes) {
81 my $len = write_print($offset, $outfh, $cmdfh, $do_print, $is_alpha);
83 # write_print saw a 0 length record, indicating end of dir
102 my ($outfh, $cmdfh, $start, $mdir, $do_print, $is_alpha) = @_;
104 my $cmdstr = "CALL getdirentries ( ".'$fd = CALL open '."$mdir O_RDONLY ) ( ";
105 $cmdstr .= '$buf = ALLOC 8192 ) 8192 $basep'."\n";
106 helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr);
108 # Verify that the sysio call succeeded
109 my $res = helper::verify_cmd($cmdfh, $outfh, "getdirentries");
110 my $numbytes = oct($res);
112 while ($numbytes > 0) {
114 do_print_cmds($numbytes, $outfh, $cmdfh, $start, $do_print, $is_alpha);
116 $cmdstr = "CALL getdirentries ".'$fd $buf 8192 $basep'."\n";
117 helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr);
119 # Verify that the sysio call succeeded
120 my $res = helper::verify_cmd($cmdfh, $outfh, "getdirentries");
121 $numbytes = oct($res);
127 my ($mdir, $tdir, $do_mount, $is_alpha, $do_print) = @_;
131 # Get tests directory
132 my $testdir = $FindBin::Bin;
135 if ($is_alpha == 1) {
136 open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np");
138 open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
143 if ($@ =~ /^open2/) {
144 warn "open2 failed: $!\n$@\n";
151 my $outfh = \*OUTFILE;
152 my $cmdfh = \*CMDFILE;
154 if ($is_alpha == 0) {
155 helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
160 if ($do_mount == 1) {
161 helper::send_cmd($cmdfh, $outfh, "mount", "CALL mount $mdir $tdir\n");
162 print_dir_cmd($outfh, $cmdfh, $start, $tdir, $do_print, $is_alpha);
164 print_dir_cmd($outfh, $cmdfh, $start, $mdir, $do_print, $is_alpha);
167 # Attempt to unmount and verify the contents
168 if ($do_mount == 1) {
170 # Close the dir before we umount
171 my $cmdstr = 'CALL close $fd'."\n";
172 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
175 helper::send_cmd($cmdfh, $outfh, "umount", "CALL umount $tdir\n");
178 # Verify it is umounted
179 $cmdstr = "CALL getdirentries ( ".'$fd2 = CALL open '."$tdir O_RDONLY ) ";
180 $cmdstr .= '$buf 8192 $newp'."\n";
181 helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr);
182 my $res = helper::verify_cmd($cmdfh, $outfh, "getdirentries");
184 my $numbytes = oct($res);
185 # The only entries should be . and .., so should return 32
186 if ($numbytes != 32) {
187 helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Read in $numbytes bytes\n");
190 $cmdstr = 'CALL close $fd2'."\n";
191 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
194 my $cmdstr = 'CALL close $fd'."\n";
195 helper::send_cmd($cmdfh, $outfh, "getdirentries", $cmdstr);
198 helper::print_and_exit($cmdfh, $outfh, 0, "list test successful\n");
209 for (my $i = 0; $i < @ARGV; $i++)
211 if ($ARGV[$i] eq "-p") {
213 } elsif ($ARGV[$i] eq "-m") {
215 } elsif ($ARGV[$i] eq "-alpha") {
218 $mydir[$dircnt] = $ARGV[$i];
223 if ( ($dircnt == 0) || ($dircnt > 2) ||
224 (($do_mount==1) && ($dircnt < 2)) ||
225 (($do_mount == 0) && ($dircnt > 1)) ) {
230 if ($do_mount == 1) {
232 ($fstype, $dir) = split(/:/, $mydir[0]);
235 process_cmd($mydir[0], $mydir[1], $do_mount, $is_alpha, $do_print);