qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 2/5] Add XBZRLE testing


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v2 2/5] Add XBZRLE testing
Date: Wed, 30 Jan 2013 11:22:01 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

On 01/30/2013 04:41 AM, Orit Wasserman wrote:
> Signed-off-by: Orit Wasserman <address@hidden>
> ---
>  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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]