4 # symlink test: Verify that symbolic links work
11 use lib "$FindBin::Bin";
16 print "Usage: ./test_symlink.pl [-alpha] <src> <dest>: Create a symlink from src to dest\n";
22 my ($cmdfh, $outfh, $exit_num, $exit_str) = @_;
24 print STDOUT "$exit_str";
27 my $cmdstr = 'FREE $srcbuf'."\n";
33 if ($res ne "0000 ") {
34 print STDOUT "ERROR! Failed to free srcbuf (code $res)\n";
37 $cmdstr = 'FREE $destbuf'."\n";
43 if ($res ne "0000 ") {
44 print STDOUT "ERROR! Failed to free destbuf (code $res)\n";
47 print $cmdfh "exit\n";
50 # Give test_driver time to finish
58 my ($src, $dest, $is_alpha) = @_;
61 my $testdir = $FindBin::Bin;
65 open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
67 open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np");
73 warn "open2 failed: $!\n$@\n";
80 my $outfh = \*OUTFILE;
81 my $cmdfh = \*CMDFILE;
84 helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
87 # Get the filesize of src
91 if ( $size > 1024) { # Arbitrary limit
97 # Create the symbolic link from src to dest
98 my $cmdstr = "CALL symlink $src $dest\n";
99 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
101 helper::verify_cmd($cmdfh, $outfh, "symlink");
104 $cmdstr = '$src = CALL open '."$src O_RDONLY\n";
105 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
108 $cmdstr = '$dest = CALL open '."$dest O_RDONLY\n";
109 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
111 my $res = helper::verify_cmd($cmdfh, $outfh, "open $dest");
113 # Allocate buffer for src
114 $cmdstr = '$srcbuf = ALLOC '."$bufsize\n";
115 helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr);
117 # Allocate buffer for dest
118 $cmdstr = '$destbuf = ALLOC '."$bufsize\n";
119 helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr);
122 # Read size bytes from src and dest, then compare them and verify they
124 $cmdstr = 'CALL read $src $srcbuf '."$bufsize\n";
125 helper::send_cmd($cmdfh, $outfh, "read $src", $cmdstr);
127 $res = helper::verify_cmd($cmdfh, $outfh, "read $src");
128 my $readb = oct($res);
130 # Now read $readb from dest
131 $cmdstr = 'CALL read $dest $destbuf '."$readb\n";
132 helper::send_cmd($cmdfh, $outfh, "read $dest", $cmdstr);
134 $res = helper::verify_cmd($cmdfh, $outfh, "read $dest");
137 if ($readb != oct($res)) {
138 $errstr = "ERROR! Read $readb bytes from src but only $res bytes from dest\n";
139 clean_exit($cmdfh, $outfh, 1, $errstr);
142 # Compare the two buffers
143 $cmdstr = 'CALL cmpstr $srcbuf $destbuf'."\n";
144 helper::send_cmd($cmdfh, $outfh, "cmpstr", $cmdstr);
146 # Verify that it returned an error
147 $cmdstr = 'PRINT $$';
149 helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
154 $res = helper::verify_cmd($cmdfh, $outfh, "cmpstr");
157 $errstr = "ERROR! Buffers from $src and $dest do not match\n";
158 clean_exit($cmdfh, $outfh, 1, $errstr);
162 $cmdstr = 'CALL close $src'."\n";
163 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
164 $cmdstr = 'CALL close $dest'."\n";
165 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
168 $cmdstr = 'CALL clear $destbuf'."\n";
169 helper::send_cmd($cmdfh, $outfh, "CLEAR", $cmdstr);
171 # Now remove the symbolic link and make sure everything stays the same
173 # Remove the link (this assumes the link is not in incore)
174 $cmdstr = "CALL unlink $dest\n";
175 helper::send_cmd($cmdfh, $outfh, "unlink", $cmdstr);
176 helper::verify_cmd($cmdfh, $outfh, "unlink");
178 # Attempt to open the symbolic link. This should return an error
179 $cmdstr = 'CALL open '."$dest O_RDONLY\n";
180 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
182 # Verify that it returned an error
183 $cmdstr = 'PRINT $$';
185 helper::send_cmd($cmdfh, $outfh, "PRINT", $cmdstr);
190 if ($res ne "0xffffffff") {
191 $errstr = "ERROR! Open on $dest succeeded (should have failed)\n";
192 clean_exit($cmdfh, $outfh, 1, $errstr);
195 # Now read from the src again and make sure it matches the original
198 $cmdstr = '$src2 = CALL open '."$src O_RDONLY\n";
199 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
200 helper::verify_cmd($cmdfh, $outfh, "open $src(2)");
202 $cmdstr = 'CALL read $src2 $destbuf '."$readb\n";
203 helper::send_cmd($cmdfh, $outfh, "read $src(2)", $cmdstr);
205 $res = helper::verify_cmd($cmdfh, $outfh, "read $src(2)");
207 if ($readb != oct($res)) {
208 $errstr = "ERROR! Read $readb bytes from src originally but now only $res bytes\n";
209 clean_exit($cmdfh, $outfh, 1, $errstr);
212 # Compare the two buffers
213 $cmdstr = 'CALL cmpstr $srcbuf $destbuf'."\n";
214 helper::send_cmd($cmdfh, $outfh, "cmpstr", $cmdstr);
215 $res = helper::verify_cmd($cmdfh, $outfh, "cmpstr");
218 $errstr = "ERROR! Original buffers from $src and new buf do not match\n";
219 clean_exit($cmdfh, $outfh, 1, $errstr);
223 $cmdstr = 'CALL close $src2'."\n";
224 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
226 clean_exit($cmdfh, $outfh, 0, "Symlink test successful\n");
235 } elsif (@ARGV > 2 ) {
236 if ($ARGV[$currarg++] eq "-alpha") {
241 my $src = $ARGV[$currarg++];
242 my $dest = $ARGV[$currarg];
244 process_cmd($src, $dest, $is_alpha);