diff options
author | Michael Brown <mcb30@etherboot.org> | 2007-01-11 04:46:41 +0000 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2007-01-11 04:46:41 +0000 |
commit | c0ef730ec427e9ee20da3b1fb2500b6593783385 (patch) | |
tree | 21b8445550dc040ce832d6e7a3974c31be0bc783 /src/tests | |
parent | 83fa318b868f0eb796ab515365bc349e37dc113d (diff) | |
download | ipxe-c0ef730ec427e9ee20da3b1fb2500b6593783385.zip ipxe-c0ef730ec427e9ee20da3b1fb2500b6593783385.tar.gz ipxe-c0ef730ec427e9ee20da3b1fb2500b6593783385.tar.bz2 |
Fix bug in buffer.c, add buffer mini-unit test.
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/buffertest.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/tests/buffertest.c b/src/tests/buffertest.c new file mode 100644 index 0000000..c1cb377 --- /dev/null +++ b/src/tests/buffertest.c @@ -0,0 +1,54 @@ +#include <assert.h> +#include <gpxe/buffer.h> + + +struct buffer_test { + struct buffer buffer; + const char *source; + size_t source_len; + char *dest; + size_t dest_len; +}; + +static int test_fill_buffer ( struct buffer_test *test, + size_t start, size_t end ) { + const void *data = ( test->source + start ); + size_t len = ( end - start ); + + assert ( end <= test->source_len ); + assert ( end <= test->dest_len ); + + fill_buffer ( &test->buffer, data, start, len ); + assert ( memcmp ( ( test->dest + start ), data, len ) == 0 ); + assert ( test->buffer.free >= end ); + return 0; +} + +int test_buffer ( void ) { + char source[123]; + char dest[123]; + struct buffer_test test; + + memset ( &test, 0, sizeof ( test ) ); + test.source = source; + test.source_len = sizeof ( source ); + test.dest = dest; + test.dest_len = sizeof ( dest ); + test.buffer.addr = virt_to_phys ( dest ); + test.buffer.len = sizeof ( dest ); + + test_fill_buffer ( &test, 20, 38 ); + test_fill_buffer ( &test, 60, 61 ); + test_fill_buffer ( &test, 38, 42 ); + test_fill_buffer ( &test, 42, 60 ); + test_fill_buffer ( &test, 16, 80 ); + test_fill_buffer ( &test, 0, 16 ); + test_fill_buffer ( &test, 99, 123 ); + test_fill_buffer ( &test, 80, 99 ); + + assert ( test.buffer.fill == sizeof ( source ) ); + assert ( test.buffer.free == sizeof ( source ) ); + assert ( memcmp ( source, dest, sizeof ( source ) ) == 0 ); + + return 0; +} |