qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Halil Pasic <pasic@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org, Amit Shah <amit.shah@redhat.com>,
	Guenther Hutzl <hutzl@linux.vnet.ibm.com>,
	quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/4] tests/test-vmstate.c: Add vBuffer test
Date: Thu, 20 Oct 2016 12:52:06 +0100	[thread overview]
Message-ID: <20161020115206.GF2039@work-vm> (raw)
In-Reply-To: <20161018105724.26520-2-pasic@linux.vnet.ibm.com>

* Halil Pasic (pasic@linux.vnet.ibm.com) wrote:
> From: Guenther Hutzl <hutzl@linux.vnet.ibm.com>
> 
> The unit test test-vmstate.c is missing tests for some of the complex
> vmstate macros. This patch adds a new test for VMSTATE_VBUFFER
> and VMSTATE_VBUFFER_ALLOC_UINT32. The added test does not cover
> start != 0 because it's broken and unused so our intention is to
> remove start altogether.
> 
> Signed-off-by: Guenther Hutzl <hutzl@linux.vnet.ibm.com>
> Signed-off-by: Halil Pasic <pasic@linux.vnet.ibm.com>
> ---
> 
> A proof for the brokenness of start is provided in a separate patch
> so it can be easily reverted or not picked (thus we separate what is
> intended to stay, and what is intended to go away).

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  tests/test-vmstate.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 114 insertions(+)
> 
> diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
> index d8da26f..9a57aa0 100644
> --- a/tests/test-vmstate.c
> +++ b/tests/test-vmstate.c
> @@ -475,6 +475,119 @@ static void test_load_skip(void)
>      qemu_fclose(loading);
>  }
>  
> +/* vBuffer tests */
> +#define BUF_SIZE 10
> +
> +typedef struct TestVBuffer {
> +    uint8_t  u8_1;
> +    int32_t  buffer_size;
> +    uint8_t  *vBuffer_1;
> +    uint32_t buffer_alloc_size;
> +    uint8_t  *vBuffer_alloc_1;
> +    uint8_t  u8_2;
> +} TestVBuffer;
> +
> +/* buffers padded with 0xFE at the end to easier detect overflow */
> +uint8_t buf1[BUF_SIZE + 1] = { 1,  2,  3,  4,  5,  6,  7,  8,  9,  0, 0xfe};
> +uint8_t buf2[BUF_SIZE + 1] = { 1,  2,  3,  4,  5,  6,  7,  8,  9,  0, 0xfe};
> +
> +TestVBuffer obj_vbuffer = {
> +    .u8_1 = 100,
> +    .buffer_size = BUF_SIZE,
> +    .vBuffer_1 = buf1,
> +    .buffer_alloc_size = BUF_SIZE,
> +    .vBuffer_alloc_1 = buf2,
> +    .u8_2 = 200,
> +};
> +
> +static const VMStateDescription vmstate_vbuffer = {
> +    .name = "complex/vbuffer",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_UINT8(u8_1, TestVBuffer),
> +        VMSTATE_VBUFFER(vBuffer_1, TestVBuffer, 1, NULL, 0,
> +                        buffer_size),
> +        VMSTATE_VBUFFER_ALLOC_UINT32(vBuffer_alloc_1, TestVBuffer, 1, NULL, 0,
> +                        buffer_alloc_size),
> +        VMSTATE_UINT8(u8_2, TestVBuffer),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +uint8_t wire_vbuffer[] = {
> +    /* u8_1 */            0x64,
> +    /* vBuffer_1 */       0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
> +                          0x00,
> +    /* vBuffer_alloc_1 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
> +                          0x00,
> +    /* u8_2 */            0xc8,
> +    QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
> +};
> +
> +static void obj_vbuffer_copy(void *target, void *source)
> +{
> +    /* this proc copies all struct TestVBuffer entries from source to target
> +       except the vBuffer pointers which should already point to the correct
> +       locations. The buffer contents are also copied */
> +    TestVBuffer *s = (TestVBuffer *)source;
> +    TestVBuffer *t = (TestVBuffer *)target;
> +
> +    t->u8_1 = s->u8_1;
> +    t->u8_2 = s->u8_2;
> +    t->buffer_size = s->buffer_size;
> +    t->buffer_alloc_size = s->buffer_alloc_size;
> +    if (t->vBuffer_1 && s->vBuffer_1) {
> +        memcpy(t->vBuffer_1, s->vBuffer_1, BUF_SIZE);
> +    }
> +    if (t->vBuffer_alloc_1 && s->vBuffer_alloc_1) {
> +        memcpy(t->vBuffer_alloc_1, s->vBuffer_alloc_1, BUF_SIZE);
> +    }
> +}
> +
> +static void test_complex_vbuffer(void)
> +{
> +    uint8_t buffer[BUF_SIZE];
> +    uint8_t buffer_clone[BUF_SIZE];
> +    TestVBuffer obj = {
> +        .u8_1 = 0,
> +        .buffer_size = BUF_SIZE,
> +        .vBuffer_1 = buffer,
> +        .buffer_alloc_size = BUF_SIZE,
> +        .vBuffer_alloc_1 = NULL,
> +        .u8_2 = 0,
> +    };
> +    TestVBuffer obj_clone = {
> +        .u8_1 = 0,
> +        .buffer_size = BUF_SIZE,
> +        .vBuffer_1 = buffer_clone,
> +        .buffer_alloc_size = BUF_SIZE,
> +        .vBuffer_alloc_1 = NULL,
> +        .u8_2 = 0,
> +    };
> +
> +    memset(buffer, 0, BUF_SIZE);
> +    memset(buffer_clone, 0, BUF_SIZE);
> +
> +    save_vmstate(&vmstate_vbuffer, &obj_vbuffer);
> +
> +    compare_vmstate(wire_vbuffer, sizeof(wire_vbuffer));
> +
> +    SUCCESS(load_vmstate(&vmstate_vbuffer, &obj, &obj_clone,
> +                         obj_vbuffer_copy, 1, wire_vbuffer,
> +                         sizeof(wire_vbuffer)));
> +
> +#define FIELD_EQUAL(name)  g_assert_cmpint(obj.name, ==, obj_vbuffer.name)
> +#define BUFFER_EQUAL(name) SUCCESS(memcmp(obj.name, obj_vbuffer.name, BUF_SIZE))
> +
> +    FIELD_EQUAL(u8_1);
> +    BUFFER_EQUAL(vBuffer_1);
> +    BUFFER_EQUAL(vBuffer_alloc_1);
> +    FIELD_EQUAL(u8_2);
> +}
> +#undef FIELD_EQUAL
> +#undef BUFFER_EQUAL
> +
>  int main(int argc, char **argv)
>  {
>      temp_fd = mkstemp(temp_file);
> @@ -489,6 +602,7 @@ int main(int argc, char **argv)
>      g_test_add_func("/vmstate/field_exists/load/skip", test_load_skip);
>      g_test_add_func("/vmstate/field_exists/save/noskip", test_save_noskip);
>      g_test_add_func("/vmstate/field_exists/save/skip", test_save_skip);
> +    g_test_add_func("/vmstate/complex/vbuffer", test_complex_vbuffer);
>      g_test_run();
>  
>      close(temp_fd);
> -- 
> 2.8.4
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  reply	other threads:[~2016-10-20 11:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18 10:57 [Qemu-devel] [PATCH 0/4] remove unused VMSTateField.start Halil Pasic
2016-10-18 10:57 ` [Qemu-devel] [PATCH 1/4] tests/test-vmstate.c: Add vBuffer test Halil Pasic
2016-10-20 11:52   ` Dr. David Alan Gilbert [this message]
2016-10-18 10:57 ` [Qemu-devel] [PATCH 2/4] tests/test-vmstate.c: prove VMStateField.start broken Halil Pasic
2016-10-18 13:27   ` Dr. David Alan Gilbert
2016-10-18 13:43     ` Halil Pasic
2016-10-18 13:54       ` Dr. David Alan Gilbert
2016-10-18 15:33         ` Halil Pasic
2016-10-18 18:32           ` Dr. David Alan Gilbert
2016-10-19 11:04             ` Halil Pasic
2016-10-20 12:00               ` Dr. David Alan Gilbert
2016-10-20 13:05                 ` Halil Pasic
2016-10-18 10:57 ` [Qemu-devel] [PATCH 3/4] Revert "tests/test-vmstate.c: prove VMStateField.start broken" Halil Pasic
2016-10-18 10:57 ` [Qemu-devel] [PATCH 4/4] migration: drop unused VMStateField.start Halil Pasic
2016-10-20 12:00   ` Dr. David Alan Gilbert
2016-10-18 11:24 ` [Qemu-devel] [PATCH 0/4] remove unused VMSTateField.start no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161020115206.GF2039@work-vm \
    --to=dgilbert@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=hutzl@linux.vnet.ibm.com \
    --cc=pasic@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).