[Libsysio-commit] HEAD: libsysio/tests help.c sysio_stubs.c test_rw.pl
Brought to you by:
lward
From: Sonja T. <so...@us...> - 2004-03-01 23:05:50
|
Update of /cvsroot/libsysio/libsysio/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31370/tests Modified Files: help.c sysio_stubs.c test_rw.pl Log Message: Make test_rw.pl a little more useful by using different integers in the buffer Index: help.c =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/help.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -b -B -p -r1.3 -r1.4 --- help.c 6 Feb 2004 20:07:31 -0000 1.3 +++ help.c 1 Mar 2004 22:46:39 -0000 1.4 @@ -48,7 +48,7 @@ void usage_setdebug() void usage_setbuf() { - fprintf(outfp, "setbuf val size buf: fill size bytes of buf with byte val\n"); + fprintf(outfp, "setbuf [val] [size] [buf] [off]: fill size bytes of buf with byte val\n"); } @@ -542,7 +542,8 @@ void usage_ireadx() void usage_checkbuf() { - fprintf(outfp, "checkbuf buf size val: Checks to see if val is in first size bytes of buf\n"); + fprintf(outfp, "checkbuf [buf] [size] [val] [off]: Staring at offset off, checks to see\n"); + fprintf(outfp, " 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.10 retrieving revision 1.11 diff -u -w -b -B -p -r1.10 -r1.11 --- sysio_stubs.c 24 Feb 2004 15:46:33 -0000 1.10 +++ sysio_stubs.c 1 Mar 2004 22:46:39 -0000 1.11 @@ -425,11 +425,11 @@ int get_endian(int argc, char **argv) int do_setbuf(int argc, char **argv) { - int val, size, index; + int val, size, index, offset; void *buf; - if (argc != 3) { - DBG(2, fprintf(outfp, "Need val, size, and buffer for setbuf\n")); + if (argc != 4) { + DBG(2, fprintf(outfp, "Need val, size, buffer, and offset for setbuf\n")); return INVALID_ARGS; } val = get_obj(argv[0]); @@ -454,6 +454,15 @@ int do_setbuf(int argc, char **argv) buf = buflist[index]->buf; + offset = get_obj(argv[3]); + + if (offset < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[3])); + return INVALID_ARGS; + } + + buf = (void *)((char *)buf +offset); + memset(buf, val, size); return SUCCESS; @@ -2308,7 +2317,7 @@ int test_do_init_iovec(int argc, char ** iov_ptr = (struct iovec *)(buflist[iov_index]->buf); iov_ptr[pos].iov_len = len; - iov_ptr[pos].iov_base = (void *)(base_ptr + (char)offset); + iov_ptr[pos].iov_base = (void *)(base_ptr + 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)); @@ -2630,11 +2638,11 @@ int test_do_ireadx(int argc, char **argv int do_checkbuf(int argc, char **argv) { - int size, val, index, i; + int size, val, index, i, offset; int *ref_buf, *buf; - if (argc != 3) { - DBG(2, fprintf(outfp, "Need buffer and val for checkbuf\n")); + if (argc != 4) { + DBG(2, fprintf(outfp, "Need buffer, val, and offset for checkbuf\n")); return INVALID_ARGS; } @@ -2647,30 +2655,41 @@ int do_checkbuf(int argc, char **argv) buf = (int *)buflist[index]->buf; - val = get_obj(argv[1]); - if (val < 0) { + size = get_obj(argv[1]); + + if (size < 0) { DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[1])); return INVALID_ARGS; } - size = get_obj(argv[2]); + val = get_obj(argv[2]); - if (size < 0) { + if (val < 0) { DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[2])); return INVALID_ARGS; } + + offset = get_obj(argv[3]); + + if (offset < 0) { + DBG(2, fprintf(outfp, "Unable to understand %s\n", argv[3])); + return INVALID_ARGS; + } + + ref_buf = (int *)malloc(size); memset((void *)ref_buf, val, size); last_ret_val =0; + buf = (int *)((char *)buf + offset); for (i=0; (unsigned)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]); + fprintf(stderr, "At pos %d I found a 0x%08x instead of 0x%08x (val was %d)\n", + i, buf[i], ref_buf[i], val); last_ret_val = 1; break; } Index: test_rw.pl =================================================================== RCS file: /cvsroot/libsysio/libsysio/tests/test_rw.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -b -B -p -r1.2 -r1.3 --- test_rw.pl 6 Feb 2004 20:07:31 -0000 1.2 +++ test_rw.pl 1 Mar 2004 22:46:39 -0000 1.3 @@ -130,33 +131,74 @@ sub check_buf { my ($cmdfh, $outfh, $bufsize, $readcmd) = @_; + my $i; + my $digit = 0; + my $offset = 0; + my $cmdstr; - my $cmdstr = 'CALL checkbuf $buf '. "1 $bufsize\n"; + for ($i =0; $i < 64; $i++) { + $cmdstr = 'CALL checkbuf $buf'. " 1024 $digit $offset\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"); + helper::print_and_exit($cmdfh, $outfh, 1, "$readcmd did not return all $digit 's\n"); + } + + $offset += 1024; + $digit++; + if ($digit == 10) { + $digit = 0; + } } # Now fill the buffer with 0s - $cmdstr = '$buf = CALL setbuf 1 '."$bufsize ".'$buf'."\n"; + $cmdstr = '$buf = CALL setbuf 0 '."$bufsize ".'$buf'." 0\n"; helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); } + +sub fill_buf +{ + my ($cmdfh, $outfh) = @_; + my $i; + my $digit=0; + my $cmdstr; + my $offset = 0; + + # Fill up the buffer with alternating digits + # from 0-9 + + for ($i=0; $i < 64 ; $i++) { + my $cmdstr = "CALL setbuf $digit 1024 ".'$buf'." $offset\n"; + helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); + $offset += 1024; + $digit++; + if ($digit == 10) { + $digit = 0; + } + } +} + sub do_rwcalls { my ($cmdfh, $outfh, $bufsize) = @_; my $IOID_FAIL = 0; my $NUMVECS = 8; + # Initilize buffer + fill_buf($cmdfh, $outfh); + # 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, "!="); + # Initilize buffer + fill_buf($cmdfh, $outfh); + # iwrite 64K bytes at pos 64K $cmdstr = '$id1 = CALL iwrite $fd $buf '."$bufsize\n"; helper::send_cmd($cmdfh, $outfh, "iwrite", $cmdstr); @@ -167,23 +209,35 @@ sub do_rwcalls my $iovcnt = 0; my $iovname = set_iovecs($cmdfh, $outfh, $iovcnt); + # Initilize buffer + fill_buf($cmdfh, $outfh); + # 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, "!="); + # Initilize buffer + fill_buf($cmdfh, $outfh); + # 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); + # Initilize buffer + fill_buf($cmdfh, $outfh); + # 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, "!="); + # Initilize buffer + fill_buf($cmdfh, $outfh); + # ipwrite 64K bytes starting at pos 320K $offset = 320 * 1024; $cmdstr = '$id3 = CALL ipwrite $fd $buf '."$bufsize $offset\n"; @@ -193,12 +247,18 @@ sub do_rwcalls $iovcnt++; + # Initilize buffer + fill_buf($cmdfh, $outfh); + # 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, "!="); + # Initilize buffer + fill_buf($cmdfh, $outfh); + # ipwritev using 8 8k buffers at offset 448 $offset = 448 * 1024; $cmdstr = '$id4 = CALL ipwritev $fd $'."$iovname $NUMVECS $offset\n"; @@ -212,6 +272,9 @@ sub do_rwcalls $iovcnt++; + # Initilize buffer + fill_buf($cmdfh, $outfh); + # 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); @@ -225,6 +288,9 @@ sub do_rwcalls $iovcnt++; + # Initilize buffer + fill_buf($cmdfh, $outfh); + $cmdstr = '$id5 = CALL iwritex $fd $'."$iovname $NUMVECS ".'$'."$xtvname 2\n"; helper::send_cmd($cmdfh, $outfh, "iwritex", $cmdstr); verify_result($cmdfh, $outfh, "iwritex", $IOID_FAIL, "=="); @@ -238,7 +304,7 @@ sub do_rwcalls helper::verify_cmd($cmdfh, $outfh, "sizeof xtvec"); # fill the buffer with 0's - $cmdstr = '$buf = CALL setbuf 0 '."$bufsize ".'$buf'."\n"; + $cmdstr = '$buf = CALL setbuf 0 '."$bufsize ".'$buf'." 0\n"; helper::send_cmd($cmdfh, $outfh, "setbuf", $cmdstr); # read 64K bytes from pos 0 @@ -332,6 +398,68 @@ sub do_rwcalls } +sub check_array +{ + my ($exp_digit, @arr) = @_; + my $exp_char; + my $pos = 0; + + if ($exp_digit == 0) { + $exp_char = "\\0"; + } elsif ($exp_digit < 7) { + $exp_char = "00".$exp_digit; + } elsif ($exp_digit == 7) { + $exp_char = "\\a"; + } elsif ($exp_digit == 8) { + $exp_char = "\\b"; + } elsif ($exp_digit == 9) { + $exp_char = "\\t"; + } else { + print STDERR "Invalid expected digit $exp_digit\n"; + return(1); + } + + foreach my $str (@arr) { + if ($str ne $exp_char) { + print STDERR "At pos $pos got digit $str instead of $exp_char\n"; + return(1); + } + $pos++; + } + + return(0); +} + +# Perform an od on the output and verify that the output makes +# sense +sub od_verify +{ + my ($cmdfh, $outfh, $file) = @_; + my $exp_digit = 0; + + # Do an od in order to verify the contents of the file + system("od -c $file > tmp.out.$$"); + open(ODFILE, "<tmp.out.$$") || + helper::print_and_exit($cmdfh, $outfh, 1, "Unable to open tmp.out.$$\n"); + + while (<ODFILE>) { + if (/^\*/) { + # Do nothing... + } else { + my ($lineno, @nums) = split($_); + if (check_array($exp_digit, @nums) != 0) { + helper::print_and_exit($cmdfh, $outfh, 1, "At line $lineno, got unexpected result\n"); + } + if ($exp_digit < 9) { + $exp_digit ++; + } else { + $exp_digit = 0; + } + } + } + + close(ODFILE); +} sub process_cmd { @@ -375,30 +503,17 @@ sub process_cmd $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"); + # Verify it worked + od_verify($cmdfh, $outfh, $file); + + system("rm -f $file"); helper::print_and_exit($cmdfh, $outfh, 0, "rw test successful\n"); } |