[Libsysio-commit] strided-io: libsysio/tests test_rw.pl help.c sysio_stubs.c test_driver.c test_driv
Brought to you by:
lward
|
From: Sonja T. <so...@us...> - 2004-01-30 19:57:22
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19342/tests Modified Files: Tag: strided-io help.c sysio_stubs.c test_driver.c test_driver.h test_stats.pl Added Files: Tag: strided-io test_rw.pl Log Message: Fixed bug in lockop_all that sent in the wrong command to fcntl. Added more calls to the test driver Added a rw test to the test suite. This calls all of the write/read combos: write, iwrite, writev, iwritev, pwrite, ipwrite, ipwritev, writex, iwritex. Ensures that what they wrote out and what they read back matches. Removed for now the statvfs test. --- NEW FILE --- #!/usr/bin/perl -w # # rw test: Write a buffer out using all the different writes, read it back # and make sure it matches # # use IPC::Open2; use strict; use FindBin; use lib "$FindBin::Bin"; use helper; sub usage { print "Usage: ./test_rw.pl [-alpha] <file>: Write to/read from file\n"; exit(-1); } sub verify_result { my ($cmdfh, $outfh, $cmdstr, $exp_val, $eq_op) = @_; my $print_err = 0; my $res = helper::verify_cmd($cmdfh, $outfh, $cmdstr); $res = oct($res); if ($eq_op eq "!=") { if ($res != $exp_val) { print STDOUT "Error! $cmdstr returned $res insted of $exp_val\n"; exit 1; } } else { if ($eq_op eq ">") { if ($res > $exp_val) { $print_err = 1; } } elsif ($eq_op eq "<") { if ($res < $exp_val) { $print_err = 1; } } elsif ($eq_op eq "==") { if ($res == $exp_val) { $print_err = 1; } } if ($print_err == 1) { helper::print_and_exit($cmdfh, $outfh, 1, "Error! $cmdstr returned $res\n"); } } } sub do_iowait { my ($cmdfh, $outfh, $id, $rwcmd, $exp_size) = @_; my $cmdstr = "CALL iowait $id\n"; helper::send_cmd($cmdfh, $outfh, "iowait", $cmdstr); my $descstr = "iowait:$rwcmd"; verify_result($cmdfh, $outfh, $descstr, $exp_size, "!="); } sub set_iovecs { my ($cmdfh, $outfh, $callnum) = @_; my $NUMVECS = 8; my $VECLEN = $NUMVECS * 1024; my $varname = "iovbuf$callnum"; # Get size of iovecs my $cmdstr = '$iovsize = CALL sizeof iovec'."\n"; helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr); my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof iovec"); $size = oct($size); $size = $size * $NUMVECS; # Allocate iovec buffer $cmdstr = '$'."$varname = ALLOC $size\n"; helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); # Now initilize all of them my $off = 0; for (my $i=0; $i < $NUMVECS; $i++) { $cmdstr = 'CALL init_iovec $buf '."$off $VECLEN $i ". '$'."$varname\n"; helper::send_cmd($cmdfh, $outfh, "init_iovec", $cmdstr); helper::verify_cmd($cmdfh, $outfh, "init_iovec"); $off += $VECLEN; } return $varname; } sub set_xtvecs { my ($cmdfh, $outfh, $callnum, $startoff) = @_; my $VECLEN = 4 * 8 * 1024; my $varname = "xtvbuf$callnum"; # Get size of iovecs my $cmdstr = '$xtvsize = CALL sizeof xtvec'."\n"; helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr); my $size = helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec"); $size = oct($size); $size = $size * 2; # Allocate iovec buffer $cmdstr = '$'."$varname = ALLOC $size\n"; helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); # Now initilize all of them my $off = $startoff; for (my $i=0; $i < 2; $i++) { $cmdstr = "CALL init_xtvec $off $VECLEN $i ". '$'."$varname\n"; helper::send_cmd($cmdfh, $outfh, "init_xtvec", $cmdstr); helper::verify_cmd($cmdfh, $outfh, "init_xtvec"); $off += $VECLEN; } return $varname; } sub check_buf { my ($cmdfh, $outfh, $bufsize, $readcmd) = @_; my $cmdstr = 'CALL checkbuf $buf '. "1 $bufsize\n"; helper::send_cmd($cmdfh, $outfh, "checkbuf", $cmdstr); my $res = helper::verify_cmd($cmdfh, $outfh, "checkbuf"); $res = oct($res); if ($res != 0) { print STDOUT "Checkbuf returned $res\n"; helper::print_and_exit($cmdfh, $outfh, 1, "$readcmd did not return all 1's\n"); } # Now fill the buffer with 0s $cmdstr = '$buf = CALL setbuf 1 '."$bufsize ".'$buf'."\n"; helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); } sub do_rwcalls { my ($cmdfh, $outfh, $bufsize) = @_; my $IOID_FAIL = 0; my $NUMVECS = 8; # write 64K bytes at pos 0 my $cmdstr = 'CALL write $fd $buf '."$bufsize\n"; helper::send_cmd($cmdfh, $outfh, "write", $cmdstr); verify_result($cmdfh, $outfh, "write", $bufsize, "!="); # iwrite 64K bytes at pos 64K $cmdstr = '$id1 = CALL iwrite $fd $buf '."$bufsize\n"; helper::send_cmd($cmdfh, $outfh, "iwrite", $cmdstr); verify_result($cmdfh, $outfh, "iwrite", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id1', "iwrite", $bufsize); # Set up the iovecs my $iovcnt = 0; my $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); # writev 64K bytes using 8 iovecs at pos 128K $cmdstr = 'CALL writev $fd $'."$iovname $NUMVECS\n"; helper::send_cmd($cmdfh, $outfh, "writev", $cmdstr); verify_result($cmdfh, $outfh, "writev", $bufsize, "!="); # iwritev 64K bytes using 8 iovecs at pos 192K $cmdstr = '$id2 = CALL iwritev $fd $'."$iovname $NUMVECS\n"; helper::send_cmd($cmdfh, $outfh, "iwritev", $cmdstr); verify_result($cmdfh, $outfh, "iwritev", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id2', "iwritev", $bufsize); # pwrite 64K bytes starting at pos 256K my $offset = 256 * 1024; $cmdstr = 'CALL pwrite $fd $buf '."$bufsize $offset\n"; helper::send_cmd($cmdfh, $outfh, "pwrite", $cmdstr); verify_result($cmdfh, $outfh, "pwrite", $bufsize, "!="); # ipwrite 64K bytes starting at pos 320K $offset = 320 * 1024; $cmdstr = '$id3 = CALL ipwrite $fd $buf '."$bufsize $offset\n"; helper::send_cmd($cmdfh, $outfh, "ipwrite", $cmdstr); verify_result($cmdfh, $outfh, "ipwrite", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id3', "ipwrite", $bufsize); # Set up the buffers again since iwritev kindly blew them away # for us... $iovcnt++; $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); # pwritev using 8 8K buffers at offset 384 $offset = 384 * 1024; $cmdstr = 'CALL pwritev $fd $'."$iovname $NUMVECS $offset\n"; helper::send_cmd($cmdfh, $outfh, "pwritev", $cmdstr); verify_result($cmdfh, $outfh, "pwritev", $bufsize, "!="); # ipwritev using 8 8k buffers at offset 448 $offset = 448 * 1024; $cmdstr = '$id4 = CALL ipwritev $fd $'."$iovname $NUMVECS $offset\n"; helper::send_cmd($cmdfh, $outfh, "ipwritev", $cmdstr); verify_result($cmdfh, $outfh, "ipwritev", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id4', "ipwritev", $bufsize); # Set up the xtvecs. Starting offset is 512K my $xtvcnt = 0; my $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 512 * 1024); # Have to re-setup the iovecs (again..) $iovcnt++; $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); # Call writex using 8 8k buffers at offset 512 $cmdstr = 'CALL writex $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; helper::send_cmd($cmdfh, $outfh, "writex", $cmdstr); verify_result($cmdfh, $outfh, "writex", $bufsize, "!="); # Call iwritex using 8 8k buffers starting at offset 576 # Re-setup xtvs since I am lazy. This is leaking memory like # a seive... $xtvcnt++; $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 576 * 1024); # And we also need to set up the iovs again $iovcnt++; $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); $cmdstr = '$id5 = CALL iwritex $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; helper::send_cmd($cmdfh, $outfh, "iwritex", $cmdstr); verify_result($cmdfh, $outfh, "iwritex", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id5', "iwritex", $bufsize); # Now do the reads # Lseek back to pos 0 $cmdstr = 'CALL lseek $fd 0 SEEK_SET'."\n"; helper::send_cmd($cmdfh, $outfh, "sizeof", $cmdstr); helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec"); # fill the buffer with 0's $cmdstr = '$buf = CALL setbuf 0 '."$bufsize ".'$buf'."\n"; helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); # read 64K bytes from pos 0 $cmdstr = 'CALL read $fd $buf '."$bufsize\n"; helper::send_cmd($cmdfh, $outfh, "read", $cmdstr); verify_result($cmdfh, $outfh, "read", $bufsize, "!="); # Check the buffer to make sure it matches check_buf($cmdfh, $outfh, $bufsize, "read"); # iread 64K bytes at pos 64K $cmdstr = '$id6 = CALL iread $fd $buf '."$bufsize\n"; helper::send_cmd($cmdfh, $outfh, "iread", $cmdstr); verify_result($cmdfh, $outfh, "iread", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id6', "iread", $bufsize); check_buf($cmdfh, $outfh, $bufsize, "iread"); # Set up the iovecs $iovcnt++; $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); # readv 64K bytes using 8 iovecs at pos 128K $cmdstr = 'CALL readv $fd $'."$iovname $NUMVECS\n"; helper::send_cmd($cmdfh, $outfh, "readv", $cmdstr); verify_result($cmdfh, $outfh, "readv", $bufsize, "!="); check_buf($cmdfh, $outfh, $bufsize, "readv"); # ireadv 64K bytes using 8 iovecs at pos 192K $cmdstr = '$id7 = CALL ireadv $fd $'."$iovname $NUMVECS\n"; helper::send_cmd($cmdfh, $outfh, "ireadv", $cmdstr); verify_result($cmdfh, $outfh, "ireadv", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id7', "ireadv", $bufsize); check_buf($cmdfh, $outfh, $bufsize, "ireadv"); # pread64K bytes starting at pos 256K $offset = 256 * 1024; $cmdstr = 'CALL pread $fd $buf '."$bufsize $offset\n"; helper::send_cmd($cmdfh, $outfh, "pread", $cmdstr); verify_result($cmdfh, $outfh, "pread", $bufsize, "!="); check_buf($cmdfh, $outfh, $bufsize, "pread"); # ipread 64K bytes starting at pos 320K $offset = 320 * 1024; $cmdstr = '$id8 = CALL ipread $fd $buf '."$bufsize $offset\n"; helper::send_cmd($cmdfh, $outfh, "ipread", $cmdstr); verify_result($cmdfh, $outfh, "ipread", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id8', "ipread", $bufsize); check_buf($cmdfh, $outfh, $bufsize, "ipread"); # Set up the buffers again since iwritev kindly blew them away # for us... $iovcnt++; $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); # preadv using 8 8K buffers at offset 384 $offset = 384 * 1024; $cmdstr = 'CALL preadv $fd $'."$iovname $NUMVECS $offset\n"; helper::send_cmd($cmdfh, $outfh, "preadv", $cmdstr); verify_result($cmdfh, $outfh, "preadv", $bufsize, "!="); check_buf($cmdfh, $outfh, $bufsize, "preadv"); # ipreadv using 8 8k buffers at offset 448 $offset = 448 * 1024; $cmdstr = '$id9 = CALL ipreadv $fd $'."$iovname $NUMVECS $offset\n"; helper::send_cmd($cmdfh, $outfh, "ipreadv", $cmdstr); verify_result($cmdfh, $outfh, "ipreadv", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id9', "ipreadv", $bufsize); check_buf($cmdfh, $outfh, $bufsize, "ipreadv"); # Set up the xtvecs. Starting offset is 512K $xtvcnt++; $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 512 * 1024); # Have to re-setup the iovecs (again..) $iovcnt++; $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); # Call readx using 8 8k buffers at offset 512 $cmdstr = 'CALL readx $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; helper::send_cmd($cmdfh, $outfh, "readx", $cmdstr); verify_result($cmdfh, $outfh, "readx", $bufsize, "!="); check_buf($cmdfh, $outfh, $bufsize, "readx"); # Call ireadx using 8 8k buffers starting at offset 576 # Re-setup xtvs since I am lazy. This is leaking memory like # a seive... $xtvcnt++; $xtvname = set_xtvecs($cmdfh, $outfh, $xtvcnt, 576 * 1024); # And we also need to set up the iovs again $iovcnt++; $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); $cmdstr = '$id10 = CALL ireadx $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; helper::send_cmd($cmdfh, $outfh, "ireadx", $cmdstr); verify_result($cmdfh, $outfh, "ireadx", $IOID_FAIL, "=="); do_iowait($cmdfh, $outfh, '$id10', "ireadx", $bufsize); check_buf($cmdfh, $outfh, $bufsize, "ireadx"); } sub process_cmd { my ($file, $is_alpha) = @_; # Get tests directory my $testdir = $FindBin::Bin; my $bufsize = 65536; eval { if ($is_alpha == 0) { open2(\*OUTFILE, \*CMDFILE, "$testdir/test_driver --np"); } else { open2(\*OUTFILE, \*CMDFILE, "yod -quiet -sz 1 $testdir/test_driver --np"); } }; if ($@) { if ($@ =~ /^open2/) { warn "open2 failed: $!\n$@\n"; return; } die; } my $outfh = \*OUTFILE; my $cmdfh = \*CMDFILE; if ($is_alpha == 0) { helper::send_cmd($cmdfh, $outfh, "init", "CALL init\n"); } # Open file my $cmdstr = '$fd = CALL open '."$file O_RDWR|O_CREAT 0777\n"; helper::send_cmd($cmdfh, $outfh, "open", $cmdstr); # Allocate buffer $cmdstr = '$buf = ALLOC '."$bufsize\n"; helper::send_cmd($cmdfh, $outfh, "ALLOC", $cmdstr); # Fill it with 1's $cmdstr = '$buf = CALL setbuf 1 '."$bufsize ".'$buf'."\n"; helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); do_rwcalls($cmdfh, $outfh, $bufsize); # Do an od and make sure that only 1's are in the file # This is what it should return: my $cmpstr = "0000000 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001 001\n"; $cmpstr .= "*\n"; $cmpstr .= "2400000"; my $res = `od -c $file`; chop($res); if ($cmpstr ne $res) { helper::print_and_exit($cmdfh, $outfh, 1, "od results indicate a ch other than 1\n"); } # Clean up $cmdstr = 'CALL close $fd'."\n"; helper::send_cmd($cmdfh, $outfh, "close", $cmdstr); system("rm -f $file"); helper::print_and_exit($cmdfh, $outfh, 0, "rw test successful\n"); } my $currarg = 0; my $is_alpha = 0; if (@ARGV < 1) { usage; } elsif (@ARGV > 1 ) { if ($ARGV[$currarg++] eq "-alpha") { $is_alpha = 1; } } my $file = $ARGV[$currarg]; process_cmd($file, $is_alpha); exit 0; Index: help.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/help.c,v retrieving revision 1.2 retrieving revision 1.2.12.1 diff -u -w -b -B -p -r1.2 -r1.2.12.1 --- help.c 14 Aug 2003 21:16:33 -0000 1.2 +++ help.c 30 Jan 2004 19:55:33 -0000 1.2.12.1 @@ -46,6 +46,12 @@ void usage_setdebug() fprintf(outfp, "setdebug [level]: Set debugging level to level\n"); } +void usage_setbuf() +{ + fprintf(outfp, "setbuf val size buf: fill size bytes of buf with byte val\n"); +} + + void usage_clear() { fprintf(outfp, "clear buf: zero out the buffer\n"); @@ -492,6 +498,53 @@ void usage_umount() fprintf(outfp, "umount [path] : Umount file at path. Returns 0 on success and -1 on failure\n"); } +void usage_init_iovec() +{ + fprintf(outfp, "init_iovec buf offset len num iov_buf: Init iovector. iov_uf points to an array of\n"); + fprintf(outfp, " iovecs, num is the number of the iovec, \n"); + fprintf(outfp, " buf is the buffer to be used, offset \n"); + fprintf(outfp, " specifies how far into the buffer the iovec\n"); + fprintf(outfp, " should point and len is the iov length\n"); +} + +void usage_init_xtvec() +{ + fprintf(outfp, "init_xtvec offset len num buf: Init xtvector. Buf points to an array of\n"); + fprintf(outfp, " xtvecs, num is the number of the xtvec, offset\n"); + fprintf(outfp, " is xtv_off and len is the iov lenghth\n"); + fprintf(outfp, " the iov length\n"); +} + +void usage_writex() +{ + fprintf(outfp, "writex fd iovs iov_cnt xtvs xtvcnt: Write iov_cnt iovecs out to file using\n"); + fprintf(outfp, " xtvcnt xtvecs\n"); +} + +void usage_iwritex() +{ + fprintf(outfp, "iwritex fd iovs iov_cnt xtvs xtvcnt: Write iov_cnt iovecs out to file using\n"); + fprintf(outfp, " xtvcnt xtvecs\n"); +} + +void usage_readx() +{ + fprintf(outfp, "readx fd iovs iov_cnt xtvs xtvcnt: Read iov_cnt iovecs out from file using\n"); + fprintf(outfp, " xtvcnt xtvecs\n"); +} + +void usage_ireadx() +{ + fprintf(outfp, "ireadx fd iovs iov_cnt xtvs xtvcnt: Read iov_cnt iovecs out from file using\n"); + fprintf(outfp, " xtvcnt xtvecs\n"); +} + + +void usage_checkbuf() +{ + fprintf(outfp, "checkbuf buf size val: Checks to see if val is in first size bytes of buf\n"); +} + void usage_exit() { } Index: sysio_stubs.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/sysio_stubs.c,v retrieving revision 1.6.6.1 retrieving revision 1.6.6.2 diff -u -w -b -B -p -r1.6.6.1 -r1.6.6.2 --- sysio_stubs.c 26 Jan 2004 16:27:48 -0000 1.6.6.1 +++ sysio_stubs.c 30 Jan 2004 19:55:33 -0000 1.6.6.2 @@ -13,6 +13,7 @@ #include "test_driver.h" #include "sysio.h" +#include "xtio.h" /* * ################################################ @@ -423,6 +424,43 @@ int get_endian(int argc, char **argv) return SUCCESS; } +int do_setbuf(int argc, char **argv) +{ + int val, size, index; + void *buf; + + if (argc != 3) { + DBG(2, fprintf(outfp, "Need val, size, and buffer for setbuf\n")); + return INVALID_ARGS; + } + val = get_obj(argv[0]); + if (val < 0) { + DBG(2, fprintf(outfp, "Unable to understand val of %s\n", + argv[0])); + return INVALID_VAR; + } + + size = get_obj(argv[1]); + if( size <=0 ) { + DBG(2, fprintf(outfp, "Size of %s is invalid\n", argv[1])); + return INVALID_VAR; + } + + index = get_obj(argv[2]); + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find buffer assocated with %s\n", + argv[2])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + memset(buf, val, size); + + return SUCCESS; +} + + int get_sizeof(int argc, char **argv) { char *type; @@ -450,6 +488,8 @@ int get_sizeof(int argc, char **argv) size = sizeof(struct statvfs); else if (!strcmp(type, "iovec")) size = sizeof(struct iovec); + else if (!strcmp(type, "xtvec")) + size = sizeof(struct xtvec); else return INVALID_ARGS; @@ -2229,3 +2269,416 @@ int test_do_umount(int argc, char **argv return SUCCESS; } +int test_do_init_iovec(int argc, char **argv) +{ + int iov_index, buf_index; + int offset, len, pos; + struct iovec *iov_ptr; + char *base_ptr; + + if (argc != 5) { + DBG(2, fprintf(outfp, "Need buffer, offset, len, array pos, and iov pointer\n")); + return INVALID_ARGS; + } + + if ((buf_index = get_obj(argv[0])) < 0) { + DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[0])); + return INVALID_VAR; + } + base_ptr = buflist[buf_index]->buf; + + if ((offset = get_obj(argv[1])) < 0) { + DBG(2, fprintf(outfp, "Cannot understand offset of %s\n", argv[1])); + return INVALID_VAR; + } + + if ((len = get_obj(argv[2])) < 0) { + DBG(2, fprintf(outfp, "Cannot understand len of %s\n", argv[2])); + return INVALID_VAR; + } + + if ((pos = get_obj(argv[3])) < 0) { + DBG(2, fprintf(outfp, "Cannot understand array pos of %s\n", argv[3])); + return INVALID_VAR; + } + + if ((iov_index = get_obj(argv[4])) < 0) { + DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[4])); + return INVALID_VAR; + } + iov_ptr = (struct iovec *)(buflist[iov_index]->buf); + + iov_ptr[pos].iov_len = len; + iov_ptr[pos].iov_base = (void *)(base_ptr + (char)offset); + + DBG(3, fprintf(outfp, "iov_ptr.len is %d and base is %p\n", + iov_ptr[pos].iov_len, iov_ptr[pos].iov_base)); + + my_errno = errno; + last_type = PTR; + + return SUCCESS; +} + + +int test_do_init_xtvec(int argc, char **argv) +{ + int xtv_index; + int offset, len, pos; + struct xtvec *xtv_ptr; + + if (argc != 4) { + DBG(2, fprintf(outfp, "Need offset, len, array pos, and xtv pointer\n")); + return INVALID_ARGS; + } + + if ((offset = get_obj(argv[0])) < 0) { + DBG(2, fprintf(outfp, "Cannot understand offset of %s\n", argv[0])); + return INVALID_VAR; + } + + if ((len = get_obj(argv[1])) < 0) { + DBG(2, fprintf(outfp, "Cannot understand len of %s\n", argv[1])); + return INVALID_VAR; + } + + if ((pos = get_obj(argv[2])) < 0) { + DBG(2, fprintf(outfp, "Cannot understand array pos of %s\n", argv[2])); + return INVALID_VAR; + } + + if ((xtv_index = get_obj(argv[3])) < 0) { + DBG(2, fprintf(outfp, "Unable to find object %s\n", argv[3])); + return INVALID_VAR; + } + xtv_ptr = (struct xtvec *)(buflist[xtv_index]->buf); + + xtv_ptr[pos].xtv_len = len; + xtv_ptr[pos].xtv_off = offset; + + DBG(3, fprintf(outfp, "xtv_ptr.len is %d and offset is %d\n", + xtv_ptr[pos].xtv_len, (int)xtv_ptr[pos].xtv_off)); + + my_errno = errno; + last_type = PTR; + + return SUCCESS; +} + +int test_do_writex(int argc, char **argv) +{ + int fd, iov_count, xtv_count,index; + char *buf; + struct iovec *iov; + struct xtvec *xtv; + + if (argc != 5) { + DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to writex\n", argc)); + return INVALID_ARGS; + } + + fd = get_obj(argv[0]); + + if (fd < 0) { + DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); + return INVALID_ARGS; + } + + index = get_obj(argv[1]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + iov = (struct iovec *)buf; + iov_count = get_obj(argv[2]); + + if (iov_count < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); + return INVALID_ARGS; + } + + index = get_obj(argv[3]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + xtv = (struct xtvec *)buf; + xtv_count = get_obj(argv[4]); + + if (xtv_count < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4])); + return INVALID_ARGS; + } + + DBG(3, fprintf(outfp, "writex(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n", + fd, iov, iov_count, xtv, xtv_count)); + + last_ret_val = writex(fd, iov, iov_count, xtv, xtv_count); + if (last_ret_val < 0) + my_perror("writex"); + my_errno = errno; + last_type = SINT; + + return SUCCESS; +} + + +int test_do_iwritex(int argc, char **argv) +{ + int fd, iov_count, xtv_count,index; + char *buf; + struct iovec *iov; + struct xtvec *xtv; + + if (argc != 5) { + DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to iwritex\n", argc)); + return INVALID_ARGS; + } + + fd = get_obj(argv[0]); + + if (fd < 0) { + DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); + return INVALID_ARGS; + } + + index = get_obj(argv[1]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + iov = (struct iovec *)buf; + iov_count = get_obj(argv[2]); + + if (iov_count < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); + return INVALID_ARGS; + } + + index = get_obj(argv[3]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + xtv = (struct xtvec *)buf; + xtv_count = get_obj(argv[4]); + + if (xtv_count < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4])); + return INVALID_ARGS; + } + + DBG(3, fprintf(outfp, "iwritex(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n", + fd, iov, iov_count, xtv, xtv_count)); + + last_ret_val = (int) iwritex(fd, iov, iov_count, xtv, xtv_count); + if (last_ret_val < 0) + my_perror("iwritex"); + my_errno = errno; + last_type = SINT; + + return SUCCESS; +} + + +int test_do_readx(int argc, char **argv) +{ + int fd, iov_count, xtv_count,index; + char *buf; + struct iovec *iov; + struct xtvec *xtv; + + if (argc != 5) { + DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to readx\n", argc)); + return INVALID_ARGS; + } + + fd = get_obj(argv[0]); + + if (fd < 0) { + DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); + return INVALID_ARGS; + } + + index = get_obj(argv[1]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + iov = (struct iovec *)buf; + iov_count = get_obj(argv[2]); + + if (iov_count < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); + return INVALID_ARGS; + } + + index = get_obj(argv[3]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + xtv = (struct xtvec *)buf; + xtv_count = get_obj(argv[4]); + + if (xtv_count < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4])); + return INVALID_ARGS; + } + + DBG(3, fprintf(outfp, "readx(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n", + fd, iov, iov_count, xtv, xtv_count)); + + last_ret_val = readx(fd, iov, iov_count, xtv, xtv_count); + if (last_ret_val < 0) + my_perror("readx"); + my_errno = errno; + last_type = SINT; + + return SUCCESS; +} + + +int test_do_ireadx(int argc, char **argv) +{ + int fd, iov_count, xtv_count,index; + char *buf; + struct iovec *iov; + struct xtvec *xtv; + + if (argc != 5) { + DBG(2, fprintf(outfp, "Invalid number of arguments (%d) to ireadx\n", argc)); + return INVALID_ARGS; + } + + fd = get_obj(argv[0]); + + if (fd < 0) { + DBG(2, fprintf(outfp, "Unable to find file described by %s\n", argv[0])); + return INVALID_ARGS; + } + + index = get_obj(argv[1]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find buffer described by %s\n", argv[1])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + iov = (struct iovec *)buf; + iov_count = get_obj(argv[2]); + + if (iov_count < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); + return INVALID_ARGS; + } + + index = get_obj(argv[3]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find xtvs described by %s\n", argv[3])); + return INVALID_VAR; + } + + buf = buflist[index]->buf; + + xtv = (struct xtvec *)buf; + xtv_count = get_obj(argv[4]); + + if (xtv_count < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[4])); + return INVALID_ARGS; + } + + DBG(3, fprintf(outfp, "ireadx(fd: %d, iov: %p iov_cnt: %d, xtv: %p, xtv_cnt: %d\n", + fd, iov, iov_count, xtv, xtv_count)); + + last_ret_val = (int) ireadx(fd, iov, iov_count, xtv, xtv_count); + if (last_ret_val < 0) + my_perror("ireadx"); + my_errno = errno; + last_type = SINT; + + return SUCCESS; +} + + +int do_checkbuf(int argc, char **argv) +{ + int size, val, index, i; + int *ref_buf, *buf; + + if (argc != 3) { + DBG(2, fprintf(outfp, "Need buffer and val for checkbuf\n")); + return INVALID_ARGS; + } + + index = get_obj(argv[0]); + + if (index < 0) { + DBG(2, fprintf(outfp, "Unable to find buf described by %s\n", argv[0])); + return INVALID_VAR; + } + + buf = (int *)buflist[index]->buf; + + val = get_obj(argv[1]); + + if (val < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[1])); + return INVALID_ARGS; + } + + size = get_obj(argv[2]); + + if (size < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); + return INVALID_ARGS; + } + + ref_buf = (int *)malloc(size); + memset((void *)ref_buf, val, size); + + last_ret_val =0; + for (i=0; i < size/sizeof(int); i++) { + if (buf[i] != ref_buf[i]) { + DBG(2, fprintf(stderr, "At pos %d I found a 0x%08x instead of 0x%08x\n", + i, buf[i], ref_buf[i])); + fprintf(stderr, "At pos %d I found a 0x%08x instead of 0x%08x\n", + i, buf[i], ref_buf[i]); + last_ret_val = 1; + break; + } + } + + my_errno = errno; + last_type = SINT; + + return SUCCESS; +} Index: test_driver.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_driver.c,v retrieving revision 1.4.6.1 retrieving revision 1.4.6.2 diff -u -w -b -B -p -r1.4.6.1 -r1.4.6.2 --- test_driver.c 26 Jan 2004 16:27:48 -0000 1.4.6.1 +++ test_driver.c 30 Jan 2004 19:55:33 -0000 1.4.6.2 @@ -40,6 +40,7 @@ struct queue_t { struct cmd_t cmd_list[] = { {"alloc", get_buffer, usage_get_buffer}, {"chdir", test_do_chdir, usage_chdir}, + {"checkbuf", do_checkbuf, usage_checkbuf}, {"chmod", test_do_chmod, usage_chmod}, {"chown", test_do_chown, usage_chown}, {"clear", test_do_clear, usage_clear}, @@ -62,6 +63,8 @@ struct cmd_t cmd_list[] = { {"getcwd", test_do_getcwd, usage_getcwd}, {"getdirentries", test_do_getdirentries, usage_getdirentries}, {"init", test_do_init, usage_init}, + {"init_iovec", test_do_init_iovec, usage_init_iovec}, + {"init_xtvec", test_do_init_xtvec, usage_init_xtvec}, {"ioctl", test_do_ioctl, usage_ioctl}, {"iodone", test_do_iodone, usage_iodone}, {"iowait", test_do_iowait, usage_iowait}, @@ -71,8 +74,10 @@ struct cmd_t cmd_list[] = { {"ipwritev", test_do_ipwritev, usage_ipwritev}, {"iread", test_do_iread, usage_iread}, {"ireadv", test_do_ireadv, usage_ireadv}, + {"ireadx", test_do_ireadx, usage_ireadx}, {"iwrite", test_do_iwrite, usage_iwrite}, {"iwritev", test_do_iwritev, usage_iwritev}, + {"iwritex", test_do_iwritex, usage_iwritex}, {"list", test_do_list, usage_list}, {"lseek", test_do_lseek, usage_lseek}, {"lstat", test_do_lstat, usage_lstat}, @@ -89,7 +94,9 @@ struct cmd_t cmd_list[] = { {"quit", test_do_exit, usage_exit}, {"read", test_do_read, usage_read}, {"readv", test_do_readv, usage_readv}, + {"readx", test_do_readx, usage_readx}, {"rmdir", test_do_rmdir, usage_rmdir}, + {"setbuf", do_setbuf, usage_setbuf}, {"sizeof", get_sizeof, usage_sizeof}, /* {"setoutput", test_do_setoutput, usage_setoutput}, */ {"stat", test_do_stat, usage_stat}, @@ -101,6 +108,7 @@ struct cmd_t cmd_list[] = { {"unlink", test_do_unlink, usage_unlink}, {"write", test_do_write, usage_write}, {"writev", test_do_writev, usage_writev}, + {"writex", test_do_writex, usage_writex}, {NULL, NULL, NULL} }; @@ -415,7 +423,6 @@ int execute_cmd(char *cmd, char **args, if (!strcmp(cmd, "help")) { if (arg_count > 0) { - while(cmd_list[i].cmd != NULL) { if (!strcmp(cmd_list[i].cmd, args[0])) { (cmd_list[i].usage)(); @@ -430,8 +437,9 @@ int execute_cmd(char *cmd, char **args, return -1; } while(cmd_list[i].cmd != NULL) { - if (!strcmp(cmd_list[i].cmd, cmd)) + if (!strcmp(cmd_list[i].cmd, cmd)) { return (cmd_list[i].func)(arg_count, args); + } i++; } DBG(2, fprintf(outfp, "Command %s was invalid\n", cmd)); @@ -729,11 +737,6 @@ char *getline(char *prompt) if ((do_prompt) && (infp == stdin)) printf(prompt); - /* - fprintf(stderr, "getline: errno %x\n", errno); - fseek(infp, 0, SEEK_CUR); - fprintf(stderr, "getline: errno %x\n", errno); - */ do { /* If we get an end of file, just wait */ if (feof(infp)) { @@ -817,6 +820,124 @@ void init_map() } } +int getquotedlen(char *str) +{ + int i; + + if (str[0] != '"' && str[0] != '\'') + return -1; + + for (i=1; str[i] != '\0' && str[i] != '"' && str[i] != '\''; i++); + + return i; +} + +int perform_op(int num1, int num2, char op) +{ + switch(op) { + + case '+': + return num1 + num2; + break; + + case '*': + return num1 * num2; + break; + + case '/': + return num1 / num2; + break; + + case '-': + return num1 - num2; + break; + + case '%': + return num1%num2; + break; + + default: + return num1; + } + return 0; +} + +int get_constant_val(char **str_ptr, int type) +{ + struct buf_t *buf; + char *buf_ptr; + char *str = *str_ptr; + char ch; + int i, j, num1, num2, size; + + printf("Getting constant val from %s\n", str); + switch(type) { + case 1: + size = getquotedlen(str); + buf = (struct buf_t *)malloc(sizeof(struct buf_t)); + buf->buf = alloc_buff32(size, 8); + buf->len = size; + buf_ptr = buf->buf; + buflist[next] = buf; + j=0; + for (i=1; i < size; i++) { + buf_ptr[j] = str[i]; + j++; + } + buf_ptr[j] = '\0'; + + DBG(3, fprintf(outfp, "Your buffer (%p) (%p) is at index %d\n", + buf, buf->buf, next)); + next++; + + last_type = PTR; + last_ret_val = next-1; + return last_ret_val; + break; + + case 2: + if (str[0] == '$') { + num1 = get_obj(str); + } else { + num1 = atoi(str); + } + str = str_ptr[1]; + ch = str_ptr[1][0]; + if ((ch == '+') || (ch == '/') || (ch == '*') || + (ch == '-') || (ch == '%')) { + if (str_ptr[2][0] == '$') + num2 = get_obj(str_ptr[2]); + else + num2 = atoi(str_ptr[2]); + num1 = perform_op(num1, num2, ch); + } + + last_type = UINT; + last_ret_val = num1; + + break; + + default: + DBG(2, fprintf(outfp, "Can't understand type of %d\n", type)); + return INVALID_ARGS; + } + + return last_ret_val; +} + +int is_constant(char *str) +{ + if ((str[0] == '"') || (str[0] == '\'')) + return 1; + + + if ( (str[0] == '$') || + ( ((int)str[0] > 47) && ((int)str[0] < 57) ) ) + return 2; + + return 0; +} + int main(int argc, char *argv[]) { int count, err, i, orig_count; @@ -902,11 +1023,18 @@ int main(int argc, char *argv[]) count--; } i++; + if ((err=is_constant(cmd[i])) != 0) { + store_result((char *)(&cmd[0][1]), get_constant_val(&cmd[i], err)); + tree = NULL; + err = 0; + } else { + tree = build_tree(&cmd[i], &count, 0); if (tree != NULL) { err = run_cmd(tree); store_result((char *)(&cmd[0][1]), last_ret_val); } + } } else { tree = build_tree(cmd, &count, 0); Index: test_driver.h =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_driver.h,v retrieving revision 1.3 retrieving revision 1.3.6.1 diff -u -w -b -B -p -r1.3 -r1.3.6.1 --- test_driver.h 10 Oct 2003 18:50:31 -0000 1.3 +++ test_driver.h 30 Jan 2004 19:55:33 -0000 1.3.6.1 @@ -145,10 +145,12 @@ extern int test_do_list(int argc, char * extern int test_do_init(int argc, char **args); extern int get_endian(int argc, char **args); extern int get_sizeof(int argc, char **args); +extern int do_setbuf(int argc, char **argv); extern int test_do_exit(int argc, char **args); extern int get_buffer(int argc, char **args); extern int free_buffer(int argc, char **args); extern int test_do_chdir(int argc, char **args); +extern int do_checkbuf(int argc, char **argv); extern int test_do_chmod(int argc, char **args); extern int test_do_chown(int argc, char **args); extern int test_do_open(int argc, char **args); @@ -161,6 +163,8 @@ extern int test_do_fstat(int argc, char extern int test_do_fsync(int argc, char **argv); extern int test_do_ftruncate(int argc, char **argv); extern int test_do_getcwd(int argc, char **argv); +extern int test_do_init_iovec(int argc, char **argv); +extern int test_do_init_xtvec(int argc, char **argv); extern int test_do_lseek(int argc, char **argv); extern int test_do_lstat(int argc, char **argv); extern int test_do_getdirentries(int argc, char **argv); @@ -183,8 +187,10 @@ extern int test_do_ipread(int argc, char extern int test_do_preadv(int argc, char **argv); extern int test_do_pread(int argc, char **argv); extern int test_do_ireadv(int argc, char **argv); +extern int test_do_ireadx(int argc, char **argv); extern int test_do_iread(int argc, char **argv); extern int test_do_readv(int argc, char **argv); +extern int test_do_readx(int argc, char **argv); extern int test_do_read(int argc, char **argv); extern int test_do_ipwritev(int argc, char **argv); extern int test_do_ipwrite(int argc, char **argv); @@ -192,7 +198,9 @@ extern int test_do_pwritev(int argc, cha extern int test_do_pwrite(int argc, char **argv); extern int test_do_iwritev(int argc, char **argv); extern int test_do_iwrite(int argc, char **argv); +extern int test_do_iwritex(int argc, char **argv); extern int test_do_writev(int argc, char **argv); +extern int test_do_writex(int argc, char **argv); extern int test_do_write(int argc, char **argv); extern int test_do_mknod(int argc, char **argv); extern int test_do_umount(int argc, char **argv); @@ -246,12 +254,16 @@ extern void usage_fstat(); extern void usage_fsync(); extern void usage_ftruncate(); extern void usage_getcwd(); +extern void usage_init_iovec(); +extern void usage_init_xtvec(); extern void usage_lseek(); extern void usage_lstat(); extern void usage_getdirentries(); extern void usage_mkdir(); +extern void usage_checkbuf(); extern void usage_cmpbufs(); extern void usage_creat(); +extern void usage_setbuf(); extern void usage_stat(); extern void usage_statvfs(); extern void usage_fstatvfs(); @@ -270,7 +282,9 @@ extern void usage_preadv(); extern void usage_pread(); extern void usage_ireadv(); extern void usage_iread(); +extern void usage_ireadx(); extern void usage_readv(); +extern void usage_readx(); extern void usage_read(); extern void usage_ipwritev(); extern void usage_ipwrite(); @@ -278,8 +292,10 @@ extern void usage_pwritev(); extern void usage_pwrite(); extern void usage_iwritev(); extern void usage_iwrite(); +extern void usage_iwritex(); extern void usage_writev(); extern void usage_write(); +extern void usage_writex(); extern void usage_mknod(); extern void usage_umount(); extern void usage_exit(); Index: test_stats.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_stats.pl,v retrieving revision 1.5.6.1 retrieving revision 1.5.6.2 diff -u -w -b -B -p -r1.5.6.1 -r1.5.6.2 --- test_stats.pl 26 Jan 2004 16:27:48 -0000 1.5.6.1 +++ test_stats.pl 30 Jan 2004 19:55:33 -0000 1.5.6.2 @@ -172,6 +172,7 @@ sub process_cmd verify_stat($cmdfh, $outfh, "lstat", $is_alpha, @stats); } + if (0) { # Now do statvfs functions $cmdstr = '$buf2 = ALLOC ( $size2 = CALL sizeof statvfs )'."\n"; helper::send_cmd($cmdfh, $outfh, "alloc", $cmdstr); @@ -223,6 +224,7 @@ sub process_cmd helper::print_and_exit($cmdfh, $outfh, 1, $str); } } + } helper::print_and_exit($cmdfh, $outfh, 0, "stat test successful\n"); } |