4 # strided IO test: Perform a series of different reads/writes
5 # using readx and writex with different buffer
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";
33 system("killall test_driver");
38 if ($res > $exp_val) {
41 } elsif ($eq_op eq "<") {
42 if ($res < $exp_val) {
45 } elsif ($eq_op eq "==") {
46 if ($res == $exp_val) {
50 if ($print_err == 1) {
51 print STDOUT "Error! $cmdstr returned $res\n";
57 # Initilize the iovec number $vecnum
58 # in the iovec buffer $vecname with buffer
59 # pos $buf and using len $veclen
62 my ($cmdfh, $outfh, $vecname, $vecnum, $buf, $veclen) = @_;
64 my $cmdstr = 'CALL init_iovec $'.$buf." 0 $veclen ";
65 $cmdstr .= "$vecnum ".'$'."$vecname\n";
67 helper::send_cmd($cmdfh, $outfh, "init_iovec", $cmdstr);
68 helper::verify_cmd($cmdfh, $outfh, "init_iovec");
74 my ($cmdfh, $outfh) = @_;
77 my $cmdstr = '$xtvsize = CALL sizeof xtvec'."\n";
78 helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr);
79 my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec");
83 # Allocate iovec buffer
84 $cmdstr = '$xtvbuf'." = ALLOC $size\n";
85 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
88 # Now initilize xtvbuf
89 $cmdstr = "CALL init_xtvec 0 100 0 ". '$xtvbuf'."\n";
90 helper::send_cmd($cmdfh, $outfh, "init_xtvec", $cmdstr);
91 helper::verify_cmd($cmdfh, $outfh, "init_xtvec");
93 $cmdstr = "CALL init_xtvec 1000 100 1 ". '$xtvbuf'."\n";
94 helper::send_cmd($cmdfh, $outfh, "init_xtvec", $cmdstr);
95 helper::verify_cmd($cmdfh, $outfh, "init_xtvec");
101 my ($cmdfh, $outfh, $bufsize, $bufname,
102 $readcmd, $digit, $offset) = @_;
104 my $cmdstr = 'CALL checkbuf $'. "$bufname $bufsize $digit $offset\n";
105 helper::send_cmd($cmdfh, $outfh, "checkbuf", $cmdstr);
106 my $res = helper::verify_cmd($cmdfh, $outfh, "checkbuf");
110 print STDOUT "$readcmd did not return all $digit 's\n";
114 # Fill given buffer with $digit up to $size
115 # starting at $offset
118 my ($cmdfh, $outfh, $buf, $digit, $size, $off) = @_;
120 my $cmdstr = "CALL setbuf $digit $size ".'$'."$buf $off\n";
121 helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr);
126 my ($cmdfh, $outfh, $numbufs, $num) = @_;
129 my $cmdstr = '$iovsize = CALL sizeof iovec'."\n";
130 helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr);
131 my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof iovec");
133 $size = $size * $numbufs;
135 # Allocate iovec buffer
136 $cmdstr = '$iovbuf'."$num = ALLOC $size\n";
137 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
139 my $retstr = "iovbuf".$num;
146 my ($cmdfh, $outfh, $fh) = @_;
148 # Allocate and initilize xtvecs
149 setup_xtvecs($cmdfh, $outfh);
151 # Allocate 2 different iovecs, one for cases
152 # (a) and (d) and one for cases (b) and (c)
153 my $iovbuf1 = alloc_iovbuf($cmdfh, $outfh, 3, 0);
154 my $iovbuf2 = alloc_iovbuf($cmdfh, $outfh, 1, 1);
156 # Allocate four buffers, each 200 bytes long
157 my $cmdstr = '$buf1 '. "= ALLOC 200\n";
158 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
159 $cmdstr = '$buf2 '. "= ALLOC 200\n";
160 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
161 $cmdstr = '$buf3 '. "= ALLOC 200\n";
162 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
163 $cmdstr = '$buf4 '. "= ALLOC 200\n";
164 helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr);
167 # xtvec[] = { { 0, 100 }, {1000, 100} }
168 # iovec[] = { { buf1, 50}, {buf2, 50}, {buf3, 100}
170 # Fill each of the 3 buffers of. They will be filled
178 fill_buf($cmdfh, $outfh, "buf1", 1, 50, 0);
179 fill_buf($cmdfh, $outfh, "buf1", 2, 150, 50);
180 fill_buf($cmdfh, $outfh, "buf2", 3, 50, 0);
181 fill_buf($cmdfh, $outfh, "buf2", 4, 150, 50);
182 fill_buf($cmdfh, $outfh, "buf3", 5, 100, 0);
183 fill_buf($cmdfh, $outfh, "buf3", 6, 100, 100);
186 set_iovec($cmdfh, $outfh, $iovbuf1, 0, "buf1", 50);
187 set_iovec($cmdfh, $outfh, $iovbuf1, 1, "buf2", 50);
188 set_iovec($cmdfh, $outfh, $iovbuf1, 2, "buf3", 100);
191 $cmdstr = 'CALL writex $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n";
192 helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr);
193 verify_result($cmdfh, $outfh, "writex (case a)", 200, "!=");
195 # Clear out the buffers
196 fill_buf($cmdfh, $outfh, "buf1", 0, 200, 0);
197 fill_buf($cmdfh, $outfh, "buf2", 0, 200, 0);
198 fill_buf($cmdfh, $outfh, "buf3", 0, 200, 0);
201 $cmdstr = 'CALL readx $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n";
202 helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr);
203 verify_result($cmdfh, $outfh, "readx (case a)", 200, "!=");
205 # Make sure we got what we expected...
206 check_buf($cmdfh, $outfh, 50, "buf1", "readx (case a)", 1, 0);
207 check_buf($cmdfh, $outfh, 50, "buf2", "readx (case a)", 3, 0);
208 check_buf($cmdfh, $outfh, 100, "buf3", "readx (case a)", 5, 0);
211 # xtvec[] = { { 0, 100 }, {1000, 100} }
212 # iovec[] = { { buf4, 200} }
215 # Fill buf4 with 7's...
216 fill_buf($cmdfh, $outfh, "buf4", 7, 200, 0);
219 set_iovec($cmdfh, $outfh, $iovbuf2, 0, "buf4", 200);
222 $cmdstr = 'CALL writex $'."$fh ".'$'."$iovbuf2 1 ".'$xtvbuf '."2\n";
223 helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr);
224 verify_result($cmdfh, $outfh, "writex (case b)", 200, "!=");
226 # Clear out the buffer
227 fill_buf($cmdfh, $outfh, "buf4", 0, 200, 0);
230 $cmdstr = 'CALL readx $'."$fh $iovbuf2 1 ".'$xtvbuf '."2\n";
231 helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr);
232 verify_result($cmdfh, $outfh, "readx (case b)", 200, "!=");
234 # Make sure we got what we expected...
235 check_buf($cmdfh, $outfh, 200, "buf4", "readx (case b)", 7, 0);
239 # xtvec[] = { { 0, 100 }, {1000, 100} }
240 # iovec[] = { { buf4, 40} }
242 # Fill buf4 with 8's...
243 fill_buf($cmdfh, $outfh, "buf4", 8, 200, 0);
246 set_iovec($cmdfh, $outfh, $iovbuf2, 0, "buf4", 40);
249 $cmdstr = 'CALL writex $'."$fh $iovbuf2 1 ".'$xtvbuf '."2\n";
250 helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr);
251 verify_result($cmdfh, $outfh, "writex (case c)", 40, "!=");
253 # Clear out the buffer
254 fill_buf($cmdfh, $outfh, "buf4", 0, 200, 0);
257 $cmdstr = 'CALL readx $'."$fh $iovbuf2 1 ".'$xtvbuf '."2\n";
258 helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr);
259 verify_result($cmdfh, $outfh, "readx (case c)", 40, "!=");
261 # Make sure we got what we expected...
262 check_buf($cmdfh, $outfh, 40, "buf4", "readx (case c)", 8, 0);
266 # xtvec[] = { { 0, 100 }, {1000, 100} }
267 # iovec[] = { { buf1, 40}, {buf2, 150}, {buf3, 200} }
269 # Fill each of the 3 buffers of. They will be filled
277 fill_buf($cmdfh, $outfh, "buf1", 1, 40, 0);
278 fill_buf($cmdfh, $outfh, "buf1", 2, 160, 40);
279 fill_buf($cmdfh, $outfh, "buf2", 3, 150, 0);
280 fill_buf($cmdfh, $outfh, "buf2", 4, 50, 150);
281 fill_buf($cmdfh, $outfh, "buf3", 5, 10, 0);
282 fill_buf($cmdfh, $outfh, "buf3", 6, 190, 10);
285 set_iovec($cmdfh, $outfh, $iovbuf1, 0, "buf1", 40);
286 set_iovec($cmdfh, $outfh, $iovbuf1, 1, "buf2", 150);
287 set_iovec($cmdfh, $outfh, $iovbuf1, 2, "buf3", 200);
290 $cmdstr = 'CALL writex $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n";
291 helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr);
292 verify_result($cmdfh, $outfh, "writex (case d)", 200, "!=");
294 # Clear out the buffers
295 fill_buf($cmdfh, $outfh, "buf1", 0, 200, 0);
296 fill_buf($cmdfh, $outfh, "buf2", 0, 200, 0);
297 fill_buf($cmdfh, $outfh, "buf3", 0, 200, 0);
300 $cmdstr = 'CALL readx $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n";
301 helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr);
302 verify_result($cmdfh, $outfh, "readx (case d)", 200, "!=");
304 # Make sure we got what we expected...
305 check_buf($cmdfh, $outfh, 40, "buf1", "readx (case d)", 1, 0);
306 check_buf($cmdfh, $outfh, 150, "buf2", "readx (case d)", 3, 0);
307 check_buf($cmdfh, $outfh, 10, "buf3", "readx (case d)", 5, 0);
310 # xtvec[] = { { 0, 100 }, {1000, 100} }
311 # iovec[] = { { buf1, 30}, {buf2, 30}, {buf3, 30} }
313 # Fill each of the 3 buffers as follows:
320 fill_buf($cmdfh, $outfh, "buf1", 1, 30, 0);
321 fill_buf($cmdfh, $outfh, "buf1", 2, 170, 30);
322 fill_buf($cmdfh, $outfh, "buf2", 3, 30, 0);
323 fill_buf($cmdfh, $outfh, "buf2", 4, 170, 30);
324 fill_buf($cmdfh, $outfh, "buf3", 5, 30, 0);
325 fill_buf($cmdfh, $outfh, "buf3", 6, 170, 30);
328 set_iovec($cmdfh, $outfh, $iovbuf1, 0, "buf1", 30);
329 set_iovec($cmdfh, $outfh, $iovbuf1, 1, "buf2", 30);
330 set_iovec($cmdfh, $outfh, $iovbuf1, 2, "buf3", 30);
333 $cmdstr = 'CALL writex $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n";
334 helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr);
335 verify_result($cmdfh, $outfh, "writex (case e)", 90, "!=");
337 # Clear out the buffers
338 fill_buf($cmdfh, $outfh, "buf1", 0, 200, 0);
339 fill_buf($cmdfh, $outfh, "buf2", 0, 200, 0);
340 fill_buf($cmdfh, $outfh, "buf3", 0, 200, 0);
343 $cmdstr = 'CALL readx $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n";
344 helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr);
345 verify_result($cmdfh, $outfh, "readx (case e)", 90, "!=");
347 # Make sure we got what we expected...
348 check_buf($cmdfh, $outfh, 30, "buf1", "readx (case e)", 1, 0);
349 check_buf($cmdfh, $outfh, 30, "buf2", "readx (case e)", 3, 0);
350 check_buf($cmdfh, $outfh, 30, "buf3", "readx (case e)", 5, 0);
353 # xtvec[] = { { 0, 100 }, {1000, 100} }
354 # iovec[] = { { buf1, 30}, {buf2, 90}, {buf3, 200} }
356 # Fill each of the 3 buffers as follows:
363 fill_buf($cmdfh, $outfh, "buf1", 1, 30, 0);
364 fill_buf($cmdfh, $outfh, "buf1", 2, 170, 30);
365 fill_buf($cmdfh, $outfh, "buf2", 3, 70, 0);
366 fill_buf($cmdfh, $outfh, "buf2", 4, 90, 70);
367 fill_buf($cmdfh, $outfh, "buf2", 5, 110, 90);
368 fill_buf($cmdfh, $outfh, "buf3", 6, 200, 0);
371 set_iovec($cmdfh, $outfh, $iovbuf1, 0, "buf1", 30);
372 set_iovec($cmdfh, $outfh, $iovbuf1, 1, "buf2", 90);
373 set_iovec($cmdfh, $outfh, $iovbuf1, 2, "buf3", 200);
376 $cmdstr = 'CALL writex $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n";
377 helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr);
378 verify_result($cmdfh, $outfh, "writex (case f)", 200, "!=");
380 # Clear out the buffers
381 fill_buf($cmdfh, $outfh, "buf1", 0, 200, 0);
382 fill_buf($cmdfh, $outfh, "buf2", 0, 200, 0);
383 fill_buf($cmdfh, $outfh, "buf3", 0, 200, 0);
386 $cmdstr = 'CALL readx $'."$fh $iovbuf1 3 ".'$xtvbuf '."2\n";
387 helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr);
388 verify_result($cmdfh, $outfh, "readx (case f)", 200, "!=");
390 # Make sure we got what we expected...
391 check_buf($cmdfh, $outfh, 30, "buf1", "readx (case f)", 1, 0);
392 check_buf($cmdfh, $outfh, 70, "buf2", "readx (case f)", 3, 0);
393 check_buf($cmdfh, $outfh, 20, "buf2", "readx (case f)", 4, 70);
394 check_buf($cmdfh, $outfh, 70, "buf3", "readx (case f)", 6, 0);
401 my ($file, $is_alpha) = @_;
403 # Get tests directory
404 my $testdir = $FindBin::Bin;
407 if ($is_alpha == 0) {
408 open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np");
410 open2(\*OUTFILE, \*CMDFILE,
411 "yod -quiet -sz 1 $testdir/test_driver --np");
416 if ($@ =~ /^open2/) {
417 warn "open2 failed: $!\n$@\n";
424 my $outfh = \*OUTFILE;
425 my $cmdfh = \*CMDFILE;
427 if ($is_alpha == 0) {
428 helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n");
432 my $cmdstr = '$fd = CALL open '."$file O_RDWR|O_CREAT|O_TRUNC S_IRWXU\n";
433 helper::send_cmd($cmdfh, $outfh, "open", $cmdstr);
434 helper::verify_cmd($cmdfh, $outfh, $cmdstr);
437 do_rwcalls($cmdfh, $outfh, "fd");
440 $cmdstr = 'CALL close $fd'."\n";
441 helper::send_cmd($cmdfh, $outfh, "close", $cmdstr);
443 # system("rm -f $file");
444 helper::print_and_exit($cmdfh, $outfh, 0, "strided IO test successful\n");
452 } elsif (@ARGV > 1 ) {
453 if ($ARGV[$currarg++] eq "-alpha") {
458 my $file = $ARGV[$currarg];
460 process_cmd($file, $is_alpha);