4 # copy test: Copy a file from src to dest and verify that the new file
5 # : is the same as the old
12 use lib "$FindBin::Bin";
17 print "Usage: ./test_copy.pl [-alpha] <src> <dest>: Copy a file from src to dest\n";
23 my ($src, $dest, $overwrite, $is_alpha) = @_;
26 my $testdir = $FindBin::Bin;
30 open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
32 open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np");
38 warn "open2 failed: $!\n$@\n";
45 my $outfh = \*OUTFILE;
46 my $cmdfh = \*CMDFILE;
51 helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
54 # Get the filesize of src
58 # If reading from stdin, just read one line
60 if ($src eq "/dev/stdin") {
62 $size = length($line);
65 if ( $size > 1024) { # Arbitrary limit
73 if ($src ne "/dev/stdin") {
74 $cmdstr = '$src = CALL open '."$src O_RDONLY\n";
75 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
76 helper::verify_cmd($cmdfh, $outfh, "open $src");
78 if ($dest ne "/dev/stdout") {
80 my $flags = "O_WRONLY|O_CREAT";
81 if ($overwrite == 0) {
84 $cmdstr = '$dest = CALL open '."$dest $flags 0777\n";
85 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
86 my $destfile = helper::verify_cmd($cmdfh, $outfh, "open $dest");
90 $cmdstr = '$buf = ALLOC '."$bufsize\n";
91 helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr);
93 # Read size bytes from src and write them out to dest
99 if ($src eq "/dev/stdin") {
100 # Send "delay" option to read which will give us time to
101 # put something in stdin (since we can't send an eof)
102 my $cmdstr = "CALL read ".'0 $buf '."$bytes delay\n";
103 print $cmdfh $cmdstr;
104 # Give time to process command
107 # Send line from stdin
111 # Make sure read was OK
114 if ($res ne "0000 ") {
115 helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Read failed with code $res\n");
118 # See how many bytes we got...
119 $readb = helper::verify_cmd($cmdfh, $outfh, "read");
120 $readb = oct($readb);
121 if ($readb != $bytes) {
122 helper::print_and_exit($cmdfh, $outfh, 0, "Short read\n");
125 if ($dest eq "/dev/stdout") {
126 $cmdstr = "CALL write ".'1 $buf '."$readb\n";
128 $cmdstr = "CALL write ".'$dest $buf '."$readb\n";
130 print $cmdfh $cmdstr;
132 # Suck up the stdout...
141 helper::print_and_exit($cmdfh, $outfh, 1, "ERROR! Write failed with code $res\n");
144 $cmdstr = 'CALL read $src $buf '."$bufsize\n";
145 helper::send_cmd($cmdfh, $outfh, "read", $cmdstr);
147 $res = helper::verify_cmd($cmdfh, $outfh, "read");
150 # Now write $readb back out to dest
151 $cmdstr = 'CALL write $dest $buf '."$readb\n";
152 helper::send_cmd($cmdfh, $outfh, "write", $cmdstr);
155 $res = helper::verify_cmd($cmdfh, $outfh, "write");
157 if ($readb != oct($res)) {
158 print STDOUT "ERROR! Read $readb bytes but got back $res bytes\n";
166 if ($src ne "/dev/stdin") {
167 $cmdstr = 'CALL close $src'."\n";
168 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
170 if ($dest ne "/dev/stdout") {
171 $cmdstr = 'CALL close $dest'."\n";
172 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
174 if ($src ne "/dev/stdin") {
175 my $cmd = "cmp $src $dest " . '2>&1';
176 my $cmpstr = qx($cmd);
177 my $exitval = $? >> 8;
180 print STDOUT "ERROR! File $src differs from $dest\n";
181 print STDOUT "Comparison returned $cmpstr";
183 print STDOUT "ERROR! File comparison failed with msg $cmpstr";
188 helper::print_and_exit($cmdfh, $outfh, 0, "copy test successful\n");
202 for ($i=0; $i < $len; $i++ ) {
203 if ($ARGV[$i] eq "-alpha") {
206 if ($ARGV[$i] eq "-o") {
211 my $src = $ARGV[$i++];
212 my $dest = $ARGV[$i];
215 process_cmd($src, $dest, $overwrite, $is_alpha);