qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Jianjun Duan <duanj@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, dmitry@daynix.com,
	peter.maydell@linaro.org, kraxel@redhat.com, mst@redhat.com,
	david@gibson.dropbear.id.au, pbonzini@redhat.com,
	veroniabahaa@gmail.com, quintela@redhat.com,
	amit.shah@redhat.com, mreitz@redhat.com, kwolf@redhat.com,
	rth@twiddle.net, aurelien@aurel32.net, leon.alrae@imgtec.com,
	blauwirbel@gmail.com, mark.cave-ayland@ilande.co.uk,
	mdroth@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [QEMU PATCH v8 3/3] tests/migration: Add test for QTAILQ migration
Date: Wed, 26 Oct 2016 17:48:40 +0100	[thread overview]
Message-ID: <20161026164839.GB6456@work-vm> (raw)
In-Reply-To: <1477428463-10569-4-git-send-email-duanj@linux.vnet.ibm.com>

* Jianjun Duan (duanj@linux.vnet.ibm.com) wrote:
> Add a test for QTAILQ migration to tests/test-vmstate.c.
> 
> Signed-off-by: Jianjun Duan <duanj@linux.vnet.ibm.com>
> ---
>  tests/test-vmstate.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 160 insertions(+)
> 
> diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
> index d8da26f..a992408 100644
> --- a/tests/test-vmstate.c
> +++ b/tests/test-vmstate.c
> @@ -475,6 +475,164 @@ static void test_load_skip(void)
>      qemu_fclose(loading);
>  }
>  
> +
> +/* test QTAILQ migration */
> +typedef struct TestQtailqElement TestQtailqElement;
> +
> +struct TestQtailqElement {
> +    bool     b;
> +    uint8_t  u8;
> +    QTAILQ_ENTRY(TestQtailqElement) next;
> +};
> +
> +typedef struct TestQtailq {
> +    int16_t  i16;
> +    QTAILQ_HEAD(TestQtailqHead, TestQtailqElement) q;
> +    int32_t  i32;
> +} TestQtailq;
> +
> +static const VMStateDescription vmstate_q_element = {
> +    .name = "test/queue-element",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_BOOL(b, TestQtailqElement),
> +        VMSTATE_UINT8(u8, TestQtailqElement),
> +        VMSTATE_END_OF_LIST()
> +    },
> +};
> +
> +static const VMStateDescription vmstate_q = {
> +    .name = "test/queue",
> +    .version_id = 1,
> +    .minimum_version_id = 1,
> +    .fields = (VMStateField[]) {
> +        VMSTATE_INT16(i16, TestQtailq),
> +        VMSTATE_QTAILQ_V(q, TestQtailq, 1, vmstate_q_element, TestQtailqElement,
> +                         next),
> +        VMSTATE_INT32(i32, TestQtailq),
> +        VMSTATE_END_OF_LIST()
> +    }
> +};
> +
> +static void test_save_q(void)
> +{
> +    TestQtailq obj_q = {
> +        .i16 = -512,
> +        .i32 = 70000,
> +    };
> +
> +    TestQtailqElement obj_qe1 = {
> +        .b = true,
> +        .u8 = 130,
> +    };
> +
> +    TestQtailqElement obj_qe2 = {
> +        .b = false,
> +        .u8 = 65,
> +    };
> +
> +    uint8_t wire_q[] = {
> +        /* i16 */                     0xfe, 0x0,
> +        /* start of element 0 of q */ 0x01,
> +        /* .b  */                     0x01,
> +        /* .u8 */                     0x82,
> +        /* start of element 1 of q */ 0x01,
> +        /* b */                       0x00,
> +        /* u8 */                      0x41,
> +        /* end of q */                0x00,
> +        /* i32 */                     0x00, 0x01, 0x11, 0x70,
> +        QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */
> +    };
> +
> +    QTAILQ_INIT(&obj_q.q);
> +    QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe1, next);
> +    QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe2, next);
> +
> +    save_vmstate(&vmstate_q, &obj_q);
> +    compare_vmstate(wire_q, sizeof(wire_q));
> +}
> +
> +static void test_load_q(void)
> +{
> +    TestQtailq obj_q = {
> +        .i16 = -512,
> +        .i32 = 70000,
> +    };
> +
> +    TestQtailqElement obj_qe1 = {
> +        .b = true,
> +        .u8 = 130,
> +    };
> +
> +    TestQtailqElement obj_qe2 = {
> +        .b = false,
> +        .u8 = 65,
> +    };
> +
> +    uint8_t wire_q[] = {
> +        /* i16 */                     0xfe, 0x0,
> +        /* start of element 0 of q */ 0x01,
> +        /* .b  */                     0x01,
> +        /* .u8 */                     0x82,
> +        /* start of element 1 of q */ 0x01,
> +        /* b */                       0x00,
> +        /* u8 */                      0x41,
> +        /* end of q */                0x00,
> +        /* i32 */                     0x00, 0x01, 0x11, 0x70,
> +    };

OK, there would probably have been a way to avoid duplicating
all that from above.
Probably even have just done it as one test - save, compare the data, load.

> +    QTAILQ_INIT(&obj_q.q);
> +    QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe1, next);
> +    QTAILQ_INSERT_TAIL(&obj_q.q, &obj_qe2, next);
> +
> +    QEMUFile *fsave = open_test_file(true);
> +
> +    qemu_put_buffer(fsave, wire_q, sizeof(wire_q));
> +    qemu_put_byte(fsave, QEMU_VM_EOF);
> +    g_assert(!qemu_file_get_error(fsave));
> +    qemu_fclose(fsave);
> +
> +    QEMUFile *fload = open_test_file(false);
> +    TestQtailq tgt;
> +
> +    QTAILQ_INIT(&tgt.q);
> +    vmstate_load_state(fload, &vmstate_q, &tgt, 1);
> +    char eof = qemu_get_byte(fload);
> +    g_assert(!qemu_file_get_error(fload));
> +    g_assert_cmpint(tgt.i16, ==, obj_q.i16);
> +    g_assert_cmpint(tgt.i32, ==, obj_q.i32);
> +    g_assert_cmpint(eof, ==, QEMU_VM_EOF);
> +
> +    TestQtailqElement *qele_from = QTAILQ_FIRST(&obj_q.q);
> +    TestQtailqElement *qlast_from = QTAILQ_LAST(&obj_q.q, TestQtailqHead);
> +    TestQtailqElement *qele_to = QTAILQ_FIRST(&tgt.q);
> +    TestQtailqElement *qlast_to = QTAILQ_LAST(&tgt.q, TestQtailqHead);
> +
> +    while (1) {
> +        g_assert_cmpint(qele_to->b, ==, qele_from->b);
> +        g_assert_cmpint(qele_to->u8, ==, qele_from->u8);
> +        if ((qele_from == qlast_from) || (qele_to == qlast_to)) {
> +            break;
> +        }
> +        qele_from = QTAILQ_NEXT(qele_from, next);
> +        qele_to = QTAILQ_NEXT(qele_to, next);
> +    }
> +
> +    g_assert_cmpint((uint64_t) qele_from, ==, (uint64_t) qlast_from);
> +    g_assert_cmpint((uint64_t) qele_to, ==, (uint64_t) qlast_to);
> +
> +    /* clean up */
> +    TestQtailqElement *qele;
> +    while (!QTAILQ_EMPTY(&tgt.q)) {
> +        qele = QTAILQ_LAST(&tgt.q, TestQtailqHead);
> +        QTAILQ_REMOVE(&tgt.q, qele, next);
> +        free(qele);
> +        qele = NULL;
> +    }
> +    qemu_fclose(fload);
> +}
> +
>  int main(int argc, char **argv)
>  {
>      temp_fd = mkstemp(temp_file);
> @@ -489,6 +647,8 @@ 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/qtailq/save/saveq", test_save_q);
> +    g_test_add_func("/vmstate/qtailq/load/loadq", test_load_q);
>      g_test_run();
>  
>      close(temp_fd);

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

> -- 
> 1.9.1
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

      reply	other threads:[~2016-10-26 16:48 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-25 20:47 [Qemu-devel] [QEMU PATCH v8 0/3] migration: migrate QTAILQ Jianjun Duan
2016-10-25 20:47 ` [Qemu-devel] [QEMU PATCH v8 1/3] migration: extend VMStateInfo Jianjun Duan
2016-10-26 12:14   ` Dr. David Alan Gilbert
2016-10-25 20:47 ` [Qemu-devel] [QEMU PATCH v8 2/3] migration: migrate QTAILQ Jianjun Duan
2016-10-26 16:29   ` Dr. David Alan Gilbert
2016-10-26 16:50     ` Jianjun Duan
2016-10-26 16:53       ` Dr. David Alan Gilbert
2016-10-26 17:04         ` Jianjun Duan
2016-10-26 17:09           ` Dr. David Alan Gilbert
2016-10-26 17:33             ` Jianjun Duan
2016-10-27 11:16               ` Halil Pasic
2016-10-27 16:49                 ` [Qemu-devel] [Qemu-ppc] " Jianjun Duan
2016-10-25 20:47 ` [Qemu-devel] [QEMU PATCH v8 3/3] tests/migration: Add test for QTAILQ migration Jianjun Duan
2016-10-26 16:48   ` Dr. David Alan Gilbert [this message]

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=20161026164839.GB6456@work-vm \
    --to=dgilbert@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=aurelien@aurel32.net \
    --cc=blauwirbel@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=dmitry@daynix.com \
    --cc=duanj@linux.vnet.ibm.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=leon.alrae@imgtec.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rth@twiddle.net \
    --cc=veroniabahaa@gmail.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).