All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeff Cody <jcody@redhat.com>
To: Fam Zheng <famz@redhat.com>
Cc: qemu-devel@nongnu.org, kwolf@redhat.com, qemu-block@nongnu.org,
	sw@weilnetz.de, mdroth@linux.vnet.ibm.com, armbru@redhat.com,
	pbonzini@redhat.com, mreitz@redhat.com, eblake@redhat.com,
	rth@twiddle.net
Subject: Re: [Qemu-devel] [PATCH v8 11/12] tests: Add uuid tests
Date: Sun, 18 Sep 2016 23:44:18 -0400	[thread overview]
Message-ID: <20160919034418.GK32304@localhost.localdomain> (raw)
In-Reply-To: <1474172732-31994-12-git-send-email-famz@redhat.com>

On Sun, Sep 18, 2016 at 12:25:31PM +0800, Fam Zheng wrote:
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  tests/Makefile.include |   2 +
>  tests/test-uuid.c      | 177 +++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 179 insertions(+)
>  create mode 100644 tests/test-uuid.c
> 
> diff --git a/tests/Makefile.include b/tests/Makefile.include
> index 2f11064..15e7f8f 100644
> --- a/tests/Makefile.include
> +++ b/tests/Makefile.include
> @@ -115,6 +115,7 @@ check-unit-y += tests/test-logging$(EXESUF)
>  check-unit-$(CONFIG_REPLICATION) += tests/test-replication$(EXESUF)
>  check-unit-y += tests/test-bufferiszero$(EXESUF)
>  gcov-files-check-bufferiszero-y = util/bufferiszero.c
> +check-unit-y += tests/test-uuid$(EXESUF)
>  
>  check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
>  
> @@ -658,6 +659,7 @@ tests/test-filter-mirror$(EXESUF): tests/test-filter-mirror.o $(qtest-obj-y)
>  tests/test-filter-redirector$(EXESUF): tests/test-filter-redirector.o $(qtest-obj-y)
>  tests/ivshmem-test$(EXESUF): tests/ivshmem-test.o contrib/ivshmem-server/ivshmem-server.o $(libqos-pc-obj-y)
>  tests/vhost-user-bridge$(EXESUF): tests/vhost-user-bridge.o
> +tests/test-uuid$(EXESUF): tests/test-uuid.o $(test-util-obj-y)
>  
>  tests/migration/stress$(EXESUF): tests/migration/stress.o
>  	$(call quiet-command, $(LINKPROG) -static -O3 $(PTHREAD_LIB) -o $@ $< ,"  LINK  $(TARGET_DIR)$@")
> diff --git a/tests/test-uuid.c b/tests/test-uuid.c
> new file mode 100644
> index 0000000..77dcdc4
> --- /dev/null
> +++ b/tests/test-uuid.c
> @@ -0,0 +1,177 @@
> +/*
> + * QEMU UUID Library
> + *
> + * Copyright (c) 2016 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, see <http://www.gnu.org/licenses/>.
> + *
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/uuid.h"
> +
> +struct {
> +    const char *uuidstr;
> +    QemuUUID uuid;
> +    bool uuidstr_is_valid;
> +    bool check_unparse;
> +} uuid_test_data[] = {
> +    {    /* Normal */
> +        "586ece27-7f09-41e0-9e74-e901317e9d42",
> +        { { {
> +             0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0,
> +             0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42,
> +        } } },
> +        true, true,
> +    }, { /* NULL */
> +        "00000000-0000-0000-0000-000000000000",
> +        { },
> +        true, true,
> +    }, { /* Upper case */
> +        "0CC6C752-3961-4028-A286-C05CC616D396",
> +        { { {
> +             0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
> +             0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
> +        } } },
> +        true, false,
> +    }, { /* Mixed case */
> +        "0CC6C752-3961-4028-a286-c05cc616D396",
> +        { { {
> +             0x0c, 0xc6, 0xc7, 0x52, 0x39, 0x61, 0x40, 0x28,
> +             0xa2, 0x86, 0xc0, 0x5c, 0xc6, 0x16, 0xd3, 0x96,
> +        } } },
> +        true, false,
> +    }, { /* Empty */
> +        ""
> +    }, { /* Too short */
> +        "abc",
> +    }, { /* Non-hex */
> +        "abcdefgh-0000-0000-0000-000000000000",
> +    }, { /* No '-' */
> +        "0cc6c75239614028a286c05cc616d396",
> +    }, { /* '-' in wrong position */
> +        "0cc6c-7523961-4028-a286-c05cc616d396",
> +    }, { /* Double '-' */
> +        "0cc6c752--3961-4028-a286-c05cc616d396",
> +    }, { /* Too long */
> +        "0000000000000000000000000000000000000000000000",
> +    }, { /* Invalid char in the beginning */
> +        ")cc6c752-3961-4028-a286-c05cc616d396",
> +    }, { /* Invalid char in the beginning, in extra */
> +        ")0cc6c752-3961-4028-a286-c05cc616d396",
> +    }, { /* Invalid char in the middle */
> +        "0cc6c752-39*1-4028-a286-c05cc616d396",
> +    }, { /* Invalid char in the middle, in extra */
> +        "0cc6c752-39*61-4028-a286-c05cc616d396",
> +    }, { /* Invalid char in the end */
> +        "0cc6c752-3961-4028-a286-c05cc616d39&",
> +    }, { /* Invalid char in the end, in extra */
> +        "0cc6c752-3961-4028-a286-c05cc616d396&",
> +    }, { /* Short end and trailing space */
> +        "0cc6c752-3961-4028-a286-c05cc616d39 ",
> +    }, { /* Leading space and short end */
> +        " 0cc6c752-3961-4028-a286-c05cc616d39",
> +    },
> +};
> +
> +static inline bool uuid_is_valid(QemuUUID *uuid)
> +{
> +    return qemu_uuid_is_null(uuid) ||
> +            ((uuid->data[6] & 0xf0) == 0x40 && (uuid->data[8] & 0xc0) == 0x80);
> +}
> +
> +static void test_uuid_generate(void)
> +{
> +    QemuUUID uuid;
> +    int i;
> +
> +    for (i = 0; i < 100; ++i) {
> +        qemu_uuid_generate(&uuid);
> +        g_assert(uuid_is_valid(&uuid));
> +    }
> +}
> +
> +static void test_uuid_is_null(void)
> +{
> +    QemuUUID uuid_null = { };
> +    QemuUUID uuid_not_null = { { {
> +        0x58, 0x6e, 0xce, 0x27, 0x7f, 0x09, 0x41, 0xe0,
> +        0x9e, 0x74, 0xe9, 0x01, 0x31, 0x7e, 0x9d, 0x42
> +    } } };
> +    QemuUUID uuid_not_null_2 = { { { 1 } } };
> +
> +    g_assert(qemu_uuid_is_null(&uuid_null));
> +    g_assert_false(qemu_uuid_is_null(&uuid_not_null));
> +    g_assert_false(qemu_uuid_is_null(&uuid_not_null_2));
> +}
> +
> +static void test_uuid_parse(void)
> +{
> +    int i, r;
> +
> +    for (i = 0; i < ARRAY_SIZE(uuid_test_data); i++) {
> +        QemuUUID uuid;
> +        bool is_valid = uuid_test_data[i].uuidstr_is_valid;
> +
> +        r = qemu_uuid_parse(uuid_test_data[i].uuidstr, &uuid);
> +        g_assert_cmpint(!r, ==, is_valid);
> +        if (is_valid) {
> +            g_assert_cmpint(is_valid, ==, uuid_is_valid(&uuid));
> +            g_assert_cmpmem(&uuid_test_data[i].uuid, sizeof(uuid),
> +                            &uuid, sizeof(uuid));
> +        }
> +    }
> +}
> +
> +static void test_uuid_unparse(void)
> +{
> +    int i;
> +
> +    for (i = 0; i < ARRAY_SIZE(uuid_test_data); i++) {
> +        char out[37];
> +
> +        if (!uuid_test_data[i].check_unparse) {
> +            continue;
> +        }
> +        qemu_uuid_unparse(&uuid_test_data[i].uuid, out);
> +        g_assert_cmpstr(uuid_test_data[i].uuidstr, ==, out);
> +    }
> +}
> +
> +static void test_uuid_unparse_strdup(void)
> +{
> +    int i;
> +
> +    for (i = 0; i < ARRAY_SIZE(uuid_test_data); i++) {
> +        char *out;
> +
> +        if (!uuid_test_data[i].check_unparse) {
> +            continue;
> +        }
> +        out = qemu_uuid_unparse_strdup(&uuid_test_data[i].uuid);
> +        g_assert_cmpstr(uuid_test_data[i].uuidstr, ==, out);
> +    }
> +}
> +
> +int main(int argc, char **argv)
> +{
> +    g_test_init(&argc, &argv, NULL);
> +    g_test_add_func("/uuid/generate", test_uuid_generate);
> +    g_test_add_func("/uuid/is_null", test_uuid_is_null);
> +    g_test_add_func("/uuid/parse", test_uuid_parse);
> +    g_test_add_func("/uuid/unparse", test_uuid_unparse);
> +    g_test_add_func("/uuid/unparse_strdup", test_uuid_unparse_strdup);
> +
> +    return g_test_run();
> +}
> -- 
> 2.7.4
> 
Reviewed-by: Jeff Cody <jcody@redhat.com>

  reply	other threads:[~2016-09-19  3:44 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-18  4:25 [Qemu-devel] [PATCH v8 00/12] UUID clean ups for 2.8 Fam Zheng
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 01/12] util: Add UUID API Fam Zheng
2016-09-19  3:30   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 02/12] uuid: Make null_uuid static Fam Zheng
2016-09-19  3:31   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 03/12] vhdx: Use QEMU UUID API Fam Zheng
2016-09-19  3:33   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 04/12] vdi: " Fam Zheng
2016-09-19  3:33   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 05/12] vpc: " Fam Zheng
2016-09-19  3:33   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 06/12] crypto: Switch to " Fam Zheng
2016-09-19  3:34   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 07/12] tests: No longer dependent on CONFIG_UUID Fam Zheng
2016-09-19  3:34   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 08/12] configure: Remove detection code for UUID Fam Zheng
2016-09-19  3:34   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 09/12] vl: Switch qemu_uuid to QemuUUID Fam Zheng
2016-09-19  3:34   ` Jeff Cody
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 10/12] uuid: Tighten uuid parse Fam Zheng
2016-09-19  3:44   ` Jeff Cody
2016-09-19 20:30   ` Eric Blake
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 11/12] tests: Add uuid tests Fam Zheng
2016-09-19  3:44   ` Jeff Cody [this message]
2016-09-20 15:37   ` Eric Blake
2016-09-21  3:32     ` Fam Zheng
2016-09-18  4:25 ` [Qemu-devel] [PATCH v8 12/12] Add UUID files to MAINTAINERS Fam Zheng
2016-09-19  3:44   ` Jeff Cody

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=20160919034418.GK32304@localhost.localdomain \
    --to=jcody@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=sw@weilnetz.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.