4 # rw test: Write a buffer out using all the different writes, read it back
5 # and make sure it matches
13 use lib "$FindBin::Bin";
18 print "Usage: ./test_rw.pl [-alpha] <file>: Write to/read from file\n";
24 my ($cmdfh, $outfh, $cmdstr, $exp_val, $eq_op) = @_;
27 my $res = helper::verify_cmd($cmdfh, $outfh, $cmdstr);
31 if ($res != $exp_val) {
32 print STDOUT "Error! $cmdstr returned $res insted of $exp_val\n";
37 if ($res > $exp_val) {
40 } elsif ($eq_op eq "<") {
41 if ($res < $exp_val) {
44 } elsif ($eq_op eq "==") {
45 if ($res == $exp_val) {
49 if ($print_err == 1) {
50 helper::print_and_exit($cmdfh, $outfh, 1, "Error! $cmdstr returned $res\n");
57 my ($cmdfh, $outfh, $id, $rwcmd, $exp_size) = @_;
59 my $cmdstr = "CALL iowait $id\n";
60 helper::send_cmd($cmdfh, $outfh, "iowait", $cmdstr);
62 my $descstr = "iowait:$rwcmd";
63 verify_result($cmdfh, $outfh, $descstr, $exp_size, "!=");
68 my ($cmdfh, $outfh, $callnum) = @_;
70 my $VECLEN = $NUMVECS * 1024;
72 my $varname = "iovbuf$callnum";
75 my $cmdstr = '$iovsize = CALL sizeof iovec'."\n";
76 helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr);
77 my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof iovec");
79 $size = $size * $NUMVECS;
81 # Allocate iovec buffer
82 $cmdstr = '$'."$varname = ALLOC $size\n";
83 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
86 # Now initilize all of them
88 for (my $i=0; $i < $NUMVECS; $i++) {
89 $cmdstr = 'CALL init_iovec $buf '."$off $VECLEN $i ". '$'."$varname\n";
90 helper::send_cmd($cmdfh, $outfh, "init_iovec", $cmdstr);
91 helper::verify_cmd($cmdfh, $outfh, "init_iovec");
101 my ($cmdfh, $outfh, $callnum, $startoff) = @_;
102 my $VECLEN = 4 * 8 * 1024;
104 my $varname = "xtvbuf$callnum";
107 my $cmdstr = '$xtvsize = CALL sizeof xtvec'."\n";
108 helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr);
109 my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec");
113 # Allocate iovec buffer
114 $cmdstr = '$'."$varname = ALLOC $size\n";
115 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
118 # Now initilize all of them
120 for (my $i=0; $i < 2; $i++) {
121 $cmdstr = "CALL init_xtvec $off $VECLEN $i ". '$'."$varname\n";
122 helper::send_cmd($cmdfh, $outfh, "init_xtvec", $cmdstr);
123 helper::verify_cmd($cmdfh, $outfh, "init_xtvec");
133 my ($cmdfh, $outfh, $bufsize, $readcmd) = @_;
139 for ($i =0; $i < 64; $i++) {
140 $cmdstr = 'CALL checkbuf $buf'. " 1024 $digit $offset\n";
141 helper::send_cmd($cmdfh, $outfh, "checkbuf", $cmdstr);
142 my $res = helper::verify_cmd($cmdfh, $outfh, "checkbuf");
146 print STDOUT "Checkbuf returned $res\n";
147 helper::print_and_exit($cmdfh, $outfh, 1, "$readcmd did not return all $digit 's\n");
157 # Now fill the buffer with 0s
158 $cmdstr = '$buf = CALL setbuf 0 '."$bufsize ".'$buf'." 0\n";
159 helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr);
165 my ($cmdfh, $outfh) = @_;
171 # Fill up the buffer with alternating digits
174 for ($i=0; $i < 64 ; $i++) {
175 my $cmdstr = "CALL setbuf $digit 1024 ".'$buf'." $offset\n";
176 helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr);
187 my ($cmdfh, $outfh, $bufsize) = @_;
192 fill_buf($cmdfh, $outfh);
194 # write 64K bytes at pos 0
195 my $cmdstr = 'CALL write $fd $buf '."$bufsize\n";
196 helper::send_cmd($cmdfh, $outfh, "write", $cmdstr);
197 verify_result($cmdfh, $outfh, "write", $bufsize, "!=");
200 fill_buf($cmdfh, $outfh);
202 # iwrite 64K bytes at pos 64K
203 $cmdstr = '$id1 = CALL iwrite $fd $buf '."$bufsize\n";
204 helper::send_cmd($cmdfh, $outfh, "iwrite", $cmdstr);
205 verify_result($cmdfh, $outfh, "iwrite", $IOID_FAIL, "==");
206 do_iowait($cmdfh, $outfh, '$id1', "iwrite", $bufsize);
210 my $iovname = set_iovecs($cmdfh, $outfh, $iovcnt);
213 fill_buf($cmdfh, $outfh);
215 # writev 64K bytes using 8 iovecs at pos 128K
216 $cmdstr = 'CALL writev $fd $'."$iovname $NUMVECS\n";
217 helper::send_cmd($cmdfh, $outfh, "writev", $cmdstr);
218 verify_result($cmdfh, $outfh, "writev", $bufsize, "!=");
221 fill_buf($cmdfh, $outfh);
223 # iwritev 64K bytes using 8 iovecs at pos 192K
224 $cmdstr = '$id2 = CALL iwritev $fd $'."$iovname $NUMVECS\n";
225 helper::send_cmd($cmdfh, $outfh, "iwritev", $cmdstr);
226 verify_result($cmdfh, $outfh, "iwritev", $IOID_FAIL, "==");
227 do_iowait($cmdfh, $outfh, '$id2', "iwritev", $bufsize);
230 fill_buf($cmdfh, $outfh);
232 # pwrite 64K bytes starting at pos 256K
233 my $offset = 256 * 1024;
234 $cmdstr = 'CALL pwrite $fd $buf '."$bufsize $offset\n";
235 helper::send_cmd($cmdfh, $outfh, "pwrite", $cmdstr);
236 verify_result($cmdfh, $outfh, "pwrite", $bufsize, "!=");
239 fill_buf($cmdfh, $outfh);
241 # ipwrite 64K bytes starting at pos 320K
242 $offset = 320 * 1024;
243 $cmdstr = '$id3 = CALL ipwrite $fd $buf '."$bufsize $offset\n";
244 helper::send_cmd($cmdfh, $outfh, "ipwrite", $cmdstr);
245 verify_result($cmdfh, $outfh, "ipwrite", $IOID_FAIL, "==");
246 do_iowait($cmdfh, $outfh, '$id3', "ipwrite", $bufsize);
251 fill_buf($cmdfh, $outfh);
253 # pwritev using 8 8K buffers at offset 384
254 $offset = 384 * 1024;
255 $cmdstr = 'CALL pwritev $fd $'."$iovname $NUMVECS $offset\n";
256 helper::send_cmd($cmdfh, $outfh, "pwritev", $cmdstr);
257 verify_result($cmdfh, $outfh, "pwritev", $bufsize, "!=");
260 fill_buf($cmdfh, $outfh);
262 # ipwritev using 8 8k buffers at offset 448
263 $offset = 448 * 1024;
264 $cmdstr = '$id4 = CALL ipwritev $fd $'."$iovname $NUMVECS $offset\n";
265 helper::send_cmd($cmdfh, $outfh, "ipwritev", $cmdstr);
266 verify_result($cmdfh, $outfh, "ipwritev", $IOID_FAIL, "==");
267 do_iowait($cmdfh, $outfh, '$id4', "ipwritev", $bufsize);
269 # Set up the xtvecs. Starting offset is 512K
271 my $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 512 * 1024);
276 fill_buf($cmdfh, $outfh);
278 # Call writex using 8 8k buffers at offset 512
279 $cmdstr = 'CALL writex $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n";
280 helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr);
281 verify_result($cmdfh, $outfh, "writex", $bufsize, "!=");
283 # Call iwritex using 8 8k buffers starting at offset 576
284 # Re-setup xtvs since I am lazy. This is leaking memory like
287 $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 576 * 1024);
292 fill_buf($cmdfh, $outfh);
294 $cmdstr = '$id5 = CALL iwritex $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n";
295 helper::send_cmd($cmdfh, $outfh, "iwritex", $cmdstr);
296 verify_result($cmdfh, $outfh, "iwritex", $IOID_FAIL, "==");
297 do_iowait($cmdfh, $outfh, '$id5', "iwritex", $bufsize);
301 # Lseek back to pos 0
302 $cmdstr = 'CALL lseek $fd 0 SEEK_SET'."\n";
303 helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr);
304 helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec");
306 # fill the buffer with 0's
307 $cmdstr = '$buf = CALL setbuf 0 '."$bufsize ".'$buf'." 0\n";
308 helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr);
310 # read 64K bytes from pos 0
311 $cmdstr = 'CALL read $fd $buf '."$bufsize\n";
312 helper::send_cmd($cmdfh, $outfh, "read", $cmdstr);
313 verify_result($cmdfh, $outfh, "read", $bufsize, "!=");
315 # Check the buffer to make sure it matches
316 check_buf($cmdfh, $outfh, $bufsize, "read");
318 # iread 64K bytes at pos 64K
319 $cmdstr = '$id6 = CALL iread $fd $buf '."$bufsize\n";
320 helper::send_cmd($cmdfh, $outfh, "iread", $cmdstr);
321 verify_result($cmdfh, $outfh, "iread", $IOID_FAIL, "==");
322 do_iowait($cmdfh, $outfh, '$id6', "iread", $bufsize);
323 check_buf($cmdfh, $outfh, $bufsize, "iread");
327 # readv 64K bytes using 8 iovecs at pos 128K
328 $cmdstr = 'CALL readv $fd $'."$iovname $NUMVECS\n";
329 helper::send_cmd($cmdfh, $outfh, "readv", $cmdstr);
330 verify_result($cmdfh, $outfh, "readv", $bufsize, "!=");
331 check_buf($cmdfh, $outfh, $bufsize, "readv");
333 # ireadv 64K bytes using 8 iovecs at pos 192K
334 $cmdstr = '$id7 = CALL ireadv $fd $'."$iovname $NUMVECS\n";
335 helper::send_cmd($cmdfh, $outfh, "ireadv", $cmdstr);
336 verify_result($cmdfh, $outfh, "ireadv", $IOID_FAIL, "==");
337 do_iowait($cmdfh, $outfh, '$id7', "ireadv", $bufsize);
338 check_buf($cmdfh, $outfh, $bufsize, "ireadv");
340 # pread64K bytes starting at pos 256K
341 $offset = 256 * 1024;
342 $cmdstr = 'CALL pread $fd $buf '."$bufsize $offset\n";
343 helper::send_cmd($cmdfh, $outfh, "pread", $cmdstr);
344 verify_result($cmdfh, $outfh, "pread", $bufsize, "!=");
345 check_buf($cmdfh, $outfh, $bufsize, "pread");
347 # ipread 64K bytes starting at pos 320K
348 $offset = 320 * 1024;
349 $cmdstr = '$id8 = CALL ipread $fd $buf '."$bufsize $offset\n";
350 helper::send_cmd($cmdfh, $outfh, "ipread", $cmdstr);
351 verify_result($cmdfh, $outfh, "ipread", $IOID_FAIL, "==");
352 do_iowait($cmdfh, $outfh, '$id8', "ipread", $bufsize);
353 check_buf($cmdfh, $outfh, $bufsize, "ipread");
358 # preadv using 8 8K buffers at offset 384
359 $offset = 384 * 1024;
360 $cmdstr = 'CALL preadv $fd $'."$iovname $NUMVECS $offset\n";
361 helper::send_cmd($cmdfh, $outfh, "preadv", $cmdstr);
362 verify_result($cmdfh, $outfh, "preadv", $bufsize, "!=");
363 check_buf($cmdfh, $outfh, $bufsize, "preadv");
365 # ipreadv using 8 8k buffers at offset 448
366 $offset = 448 * 1024;
367 $cmdstr = '$id9 = CALL ipreadv $fd $'."$iovname $NUMVECS $offset\n";
368 helper::send_cmd($cmdfh, $outfh, "ipreadv", $cmdstr);
369 verify_result($cmdfh, $outfh, "ipreadv", $IOID_FAIL, "==");
370 do_iowait($cmdfh, $outfh, '$id9', "ipreadv", $bufsize);
371 check_buf($cmdfh, $outfh, $bufsize, "ipreadv");
373 # Set up the xtvecs. Starting offset is 512K
375 $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 512 * 1024);
379 # Call readx using 8 8k buffers at offset 512
380 $cmdstr = 'CALL readx $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n";
381 helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr);
382 verify_result($cmdfh, $outfh, "readx", $bufsize, "!=");
383 check_buf($cmdfh, $outfh, $bufsize, "readx");
385 # Call ireadx using 8 8k buffers starting at offset 576
386 # Re-setup xtvs since I am lazy. This is leaking memory like
389 $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 576 * 1024);
393 $cmdstr = '$id10 = CALL ireadx $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n";
394 helper::send_cmd($cmdfh, $outfh, "ireadx", $cmdstr);
395 verify_result($cmdfh, $outfh, "ireadx", $IOID_FAIL, "==");
396 do_iowait($cmdfh, $outfh, '$id10', "ireadx", $bufsize);
397 check_buf($cmdfh, $outfh, $bufsize, "ireadx");
403 my ($exp_digit, @arr) = @_;
407 if ($exp_digit == 0) {
409 } elsif ($exp_digit < 7) {
410 $exp_char = "00".$exp_digit;
411 } elsif ($exp_digit == 7) {
413 } elsif ($exp_digit == 8) {
415 } elsif ($exp_digit == 9) {
418 print STDERR "Invalid expected digit $exp_digit\n";
422 foreach my $str (@arr) {
423 if ($str ne $exp_char) {
424 print STDERR "At pos $pos got digit $str instead of $exp_char\n";
433 # Perform an od on the output and verify that the output makes
437 my ($cmdfh, $outfh, $file) = @_;
440 # Do an od in order to verify the contents of the file
441 system("od -c $file > tmp.out.$$");
442 open(ODFILE, "<tmp.out.$$") ||
443 helper::print_and_exit($cmdfh, $outfh, 1, "Unable to open tmp.out.$$\n");
449 my ($lineno, @nums) = split($_);
450 if (check_array($exp_digit, @nums) != 0) {
451 helper::print_and_exit($cmdfh, $outfh, 1, "At line $lineno, got unexpected result\n");
453 if ($exp_digit < 9) {
462 system("rm -f tmp.out.$$");
467 my ($file, $is_alpha) = @_;
469 # Get tests directory
470 my $testdir = $FindBin::Bin;
474 if ($is_alpha == 0) {
475 open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
477 open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np");
482 if ($@ =~ /^open2/) {
483 warn "open2 failed: $!\n$@\n";
490 my $outfh = \*OUTFILE;
491 my $cmdfh = \*CMDFILE;
493 if ($is_alpha == 0) {
494 helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
498 my $cmdstr = '$fd = CALL open '."$file O_RDWR|O_CREAT 0777\n";
499 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
500 helper::verify_cmd($cmdfh, $outfh, $cmdstr);
504 $cmdstr = '$buf = ALLOC '."$bufsize\n";
505 helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr);
508 do_rwcalls($cmdfh, $outfh, $bufsize);
511 $cmdstr = 'CALL close $fd'."\n";
512 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
515 od_verify($cmdfh, $outfh, $file);
517 system("rm -f $file");
518 helper::print_and_exit($cmdfh, $outfh, 0, "rw test successful\n");
526 } elsif (@ARGV > 1 ) {
527 if ($ARGV[$currarg++] eq "-alpha") {
532 my $file = $ARGV[$currarg];
534 process_cmd($file, $is_alpha);