On 01/30/2013 04:41 AM, Orit Wasserman wrote: > Signed-off-by: Orit Wasserman <[email protected]> > --- > tests/Makefile | 3 + > tests/test-xbzrle.c | 186 > ++++++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 189 insertions(+) > create mode 100644 tests/test-xbzrle.c
> +++ b/tests/test-xbzrle.c
> @@ -0,0 +1,186 @@
> +#include <stdint.h>
No copyright notice? Please state what license this file is under.
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <strings.h>
> +#include <string.h>
> +#include <sys/time.h>
> +#include <assert.h>
> +#include "qemu-common.h"
> +#include "include/migration/migration.h"
> +
> +#define PAGE_SIZE 4096
> +
> +static void test_uleb(void)
> +{
> + uint32_t i, val;
> + uint8_t *buf = g_malloc(sizeof(uint8_t)*2);
Spaces around '*' for multiplication. Also, why bother mallocing a 2
byte array? Just make it stack-local:
uint8_t buf[2];
> + int encode_ret, decode_ret;
> +
> + for (i = 0; i <= 0x3fff; i++) {
> + encode_ret = uleb128_encode_small(buf, i);
> + decode_ret = uleb128_decode_small(buf, &val);
> + g_assert(encode_ret == decode_ret);
> + g_assert(i == val);
> + }
> +
> + /* decode invalid value */
> + buf[0] = 0x80;
> + buf[1] = 0x80;
> +
> + decode_ret = uleb128_decode_small(buf, &val);
> + g_assert(decode_ret == -1);
Is it worth testing what happens to the contents of val on error?
> +
> + g_free(buf);
If you make buf stack-local, you don't need to free it here.
> +static void test_encode_decode_overflow(void)
> +{
> + uint8_t *compressed = g_malloc0(PAGE_SIZE);
> + uint8_t *test = g_malloc0(PAGE_SIZE);
> + uint8_t *buffer = g_malloc0(PAGE_SIZE);
> + int i = 0, rc = 0;
> +
> + for (i = 0; i < PAGE_SIZE/2 - 1; i++) {
> + test[i*2] = 1;
Spaces around binary operators.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
