diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-12-26 00:12:08 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-12-26 00:12:08 +0000 |
commit | a7ef07b4bd3a4a3ba66336601e5a27649cb923d9 (patch) | |
tree | 7a38a26ea71a0ead464c54d0b8d58ec7330877f8 /src/or/test.c | |
parent | 1401bc54f4b8aeeea21950ad20e8d79ffc87ba0b (diff) | |
download | tor-a7ef07b4bd3a4a3ba66336601e5a27649cb923d9.tar.gz tor-a7ef07b4bd3a4a3ba66336601e5a27649cb923d9.zip |
r15693@tombo: nickm | 2007-12-25 19:11:29 -0500
Here, have some terribly clever new buffer code. It uses a mbuf-like strategy rather than a ring buffer strategy, so it should require far far less extra memory to hold any given amount of data. Also, it avoids access patterns like x=malloc(1024);x=realloc(x,1048576);x=realloc(x,1024);append_to_freelist(x) that might have been contributing to memory fragmentation. I've tested it out a little on peacetime, and it seems to work so far. If you want to benchmark it for speed, make sure to remove the #define PARANOIA; #define NOINLINE macros at the head of the module.
svn:r12983
Diffstat (limited to 'src/or/test.c')
-rw-r--r-- | src/or/test.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/or/test.c b/src/or/test.c index 029d9c4723..8a54916143 100644 --- a/src/or/test.c +++ b/src/or/test.c @@ -127,7 +127,7 @@ test_buffers(void) if (!(buf = buf_new())) test_fail(); - test_eq(buf_capacity(buf), 4096); + //test_eq(buf_capacity(buf), 4096); test_eq(buf_datalen(buf), 0); /**** @@ -169,25 +169,25 @@ test_buffers(void) /* Okay, now make sure growing can work. */ buf = buf_new_with_capacity(16); - test_eq(buf_capacity(buf), 16); + //test_eq(buf_capacity(buf), 16); write_to_buf(str+1, 255, buf); - test_eq(buf_capacity(buf), 256); + //test_eq(buf_capacity(buf), 256); fetch_from_buf(str2, 254, buf); test_memeq(str+1, str2, 254); - test_eq(buf_capacity(buf), 256); + //test_eq(buf_capacity(buf), 256); assert_buf_ok(buf); write_to_buf(str, 32, buf); - test_eq(buf_capacity(buf), 256); + //test_eq(buf_capacity(buf), 256); assert_buf_ok(buf); write_to_buf(str, 256, buf); assert_buf_ok(buf); - test_eq(buf_capacity(buf), 512); + //test_eq(buf_capacity(buf), 512); test_eq(buf_datalen(buf), 33+256); fetch_from_buf(str2, 33, buf); test_eq(*str2, str[255]); test_memeq(str2+1, str, 32); - test_eq(buf_capacity(buf), 512); + //test_eq(buf_capacity(buf), 512); test_eq(buf_datalen(buf), 256); fetch_from_buf(str2, 256, buf); test_memeq(str, str2, 256); @@ -198,7 +198,7 @@ test_buffers(void) for (j=0;j<67;++j) { write_to_buf(str,255, buf); } - test_eq(buf_capacity(buf), 33668); + //test_eq(buf_capacity(buf), 33668); test_eq(buf_datalen(buf), 17085); for (j=0; j < 40; ++j) { fetch_from_buf(str2, 255,buf); @@ -218,7 +218,7 @@ test_buffers(void) for (j=0;j<80;++j) { write_to_buf(str,255, buf); } - test_eq(buf_capacity(buf),33668); + //test_eq(buf_capacity(buf),33668); for (j=0; j < 120; ++j) { fetch_from_buf(str2, 255,buf); test_memeq(str2, str, 255); @@ -275,14 +275,14 @@ test_buffers(void) printf("%s\n", strerror(errno)); test_eq(i, 10); test_eq(eof, 0); - test_eq(buf_capacity(buf), 4096); + //test_eq(buf_capacity(buf), 4096); test_eq(buf_datalen(buf), 10); test_memeq(str, (char*)_buf_peek_raw_buffer(buf), 10); /* Test reading 0 bytes. */ i = read_to_buf(s, 0, buf, &eof); - test_eq(buf_capacity(buf), 512*1024); + //test_eq(buf_capacity(buf), 512*1024); test_eq(buf_datalen(buf), 10); test_eq(eof, 0); test_eq(i, 0); @@ -290,7 +290,7 @@ test_buffers(void) /* Now test when buffer is filled exactly. */ buf2 = buf_new_with_capacity(6); i = read_to_buf(s, 6, buf2, &eof); - test_eq(buf_capacity(buf2), 6); + //test_eq(buf_capacity(buf2), 6); test_eq(buf_datalen(buf2), 6); test_eq(eof, 0); test_eq(i, 6); @@ -300,7 +300,7 @@ test_buffers(void) /* Now test when buffer is filled with more data to read. */ buf2 = buf_new_with_capacity(32); i = read_to_buf(s, 128, buf2, &eof); - test_eq(buf_capacity(buf2), 128); + //test_eq(buf_capacity(buf2), 128); test_eq(buf_datalen(buf2), 32); test_eq(eof, 0); test_eq(i, 32); |