4 # stdfd test: Verifies that stdin, stdout, and stderr can be opened and
5 # either written to or read from (in the case of stdin)
11 use lib "$FindBin::Bin";
16 print "Usage ./test_stdfd : Verifies that stdin, stdout, and stderr can be opened and ";
17 print " : either written to or read from (in the case of stdin)";
23 my ($major, $minor) = @_;
24 my $devno = ( (($major & 0xff) << 8) | ($minor & 0xff) );
31 my ($cmdfh, $outfh, $do_print, $name) = @_;
33 my $cmd = "CALL stat $name ".'$buf'."\n";
35 helper::send_cmd($cmdfh, $outfh, "stat", $cmd);
36 helper::verify_cmd($cmdfh, $outfh, "stat $name");
38 # Print out the stat buffer
39 $cmd = 'PRINT $buf 0 8 LONG 12 24 INT 44 8 LONG 52 8 INT 64 24 LONG';
41 helper::send_cmd($cmdfh, $outfh, "PRINT", $cmd);
45 my ( $iodev, $ioino, $iomode, $ionlink, $iouid, $iogid, $iordev,
46 $iosize, $ioblksize, $ioblks, $ioatime, $iomtime, $ioctime )
49 $iomode = oct($iomode);
53 my $typechar = helper::get_type($iomode);
54 print STDOUT "$name: $typechar\n";
62 my ($cmdfh, $outfh, $name, $mode, $num) = @_;
64 helper::send_cmd($cmdfh, $outfh, "open", "CALL open $name $mode\n");
66 my $res = helper::verify_cmd($cmdfh, $outfh, "open $name");
71 helper::print_and_exit($cmdfh, $outfh, 1, "Unable to open $name\n");
79 helper::send_cmd($cmdfh, $outfh, "dup2", "CALL dup2 $res $num\n");
80 $res = helper::verify_cmd($cmdfh, $outfh, "dup2");
84 helper::print_and_exit($cmdfh, $outfh, 1, "Unable to dup $name (res was $res)\n");
91 my ($cmdfh, $outfh, $do_print, $name, $perm_num, $minor) = @_;
93 my $perm = 'S_IFCHR|'.$perm_num;
94 my $devno = mkdev(0, $minor);
96 helper::send_cmd($cmdfh, $outfh, "mknod", "CALL mknod $name $perm $devno\n");
98 helper::verify_cmd($cmdfh, $outfh, "mknod $name");
100 my $statres = statit($cmdfh, $outfh, $do_print, $name);
102 helper::print_and_exit($cmdfh, $outfh, 1, "stat on $name failed\n");
108 my ($dirname, $do_print, $is_alpha) = @_;
110 # Get tests directory
112 $testdir =~ s/\/\w+.pl$//;
115 if ($is_alpha == 1) {
116 open2(\*OUTFILE, \*CMDFILE, "yod -sz 1 -quiet -batch $testdir/test_driver --np");
118 open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
123 if ($@ =~ /^open2/) {
124 warn "open2 failed: $!\n$@\n";
131 my $outfh = \*OUTFILE;
132 my $cmdfh = \*CMDFILE;
134 if ($is_alpha == 0) {
135 helper::send_cmd($cmdfh, $outfh, "init", "CALL init incore ".'"0777+0+0"'." 0\n");
136 helper::verify_cmd($cmdfh, $outfh, "init incore");
141 my $cmd = '$buf = ALLOC ( $size = CALL sizeof stat )'."\n";
142 helper::send_cmd($cmdfh, $outfh, "alloc", $cmd);
144 if ($is_alpha == 0) {
145 # Make the test directory
146 $cmd = "CALL mkdir $dirname 0777\n";
147 helper::send_cmd($cmdfh, $outfh, "mkdir", $cmd);
148 helper::verify_cmd($cmdfh, $outfh, "mkdir");
151 # Change working dir to test dir
152 $cmd = "CALL chdir $dirname\n";
153 helper::send_cmd($cmdfh, $outfh, "chdir", $cmd);
154 helper::verify_cmd($cmdfh, $outfh, "chdir");
157 # Create the 3 special files
158 do_mknod($cmdfh, $outfh, $do_print, "stdin", "0444", 0);
159 do_mknod($cmdfh, $outfh, $do_print, "stdout", "0222", 1);
160 do_mknod($cmdfh, $outfh, $do_print, "stderr", "0222", 2);
163 do_open($cmdfh, $outfh, "stdin", "O_RDONLY", 0);
164 do_open($cmdfh, $outfh, "stdout", "O_WRONLY", 1);
165 do_open($cmdfh, $outfh, "stderr", "O_WRONLY", 2);
167 #helper::send_cmd($cmdfh, $outfh, "debug", "CALL debug 5\n");
169 # Read from stdin, write to stdout and stderr
171 # Send "delay" option to read which will give us time to
172 # put something in stdin (since we can't send an eof)
173 $cmd = "CALL read 0 ".'$buf 38'." delay\n";
175 # Give time to process command
178 # Send random junk...
179 print $cmdfh "This message is exactly 38 bytes long\n";
182 # Make sure read was OK
185 if ($res ne "0000 ") {
186 helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Command $cmd failed with code $res\n");
189 # See how many bytes we got...
190 my $bytes = helper::verify_cmd($cmdfh, $outfh, "read");
191 $bytes = oct($bytes);
193 helper::print_and_exit($cmdfh, $outfh, 0, "test_stdfd successful but read nothing\n");
197 helper::print_and_exit($cmdfh, $outfh, 0, "test_stdfd unsuccessful\n");
200 $cmd = "CALL write 1 ".'$buf '."$bytes\n";
203 # Suck up the stdout...
212 helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Command $cmd failed with code $res\n");
215 helper::verify_cmd($cmdfh, $outfh, "write stdout");
217 $cmd = "CALL write 2 ".'$buf '."$bytes\n";
218 helper::send_cmd($cmdfh, $outfh, "write stderr", $cmd);
219 helper::verify_cmd($cmdfh, $outfh, "write stderr");
221 helper::print_and_exit($cmdfh, $outfh, 0, "test_stdfd successful\n");
228 for ($i=0; $i < @ARGV; $i++) {
229 if ($ARGV[$i] eq "-alpha") {
231 } elsif ($ARGV[$i] eq "-print") {
237 my $dirname = $ARGV[$i];
239 process_cmd($dirname, $do_print, $is_alpha);