From: "Daniel P. Berrange" <berrange@redhat.com>
To: Thomas Huth <thuth@redhat.com>
Cc: Roman Kagan <rkagan@virtuozzo.com>,
qemu-devel@nongnu.org, Fam Zheng <famz@redhat.com>,
"Denis V. Lunev" <den@openvz.org>
Subject: Re: [Qemu-devel] [PATCH] util: add is_equal to UUID API
Date: Mon, 27 Nov 2017 11:45:52 +0000 [thread overview]
Message-ID: <20171127114552.GI32413@redhat.com> (raw)
In-Reply-To: <64158eb0-98a0-5d06-7545-cb3a08a3c472@redhat.com>
On Fri, Nov 24, 2017 at 06:34:03PM +0100, Thomas Huth wrote:
> On 24.11.2017 15:32, Roman Kagan wrote:
> > It's going to be useful, in particular, in VMBus code massively using
> > uuids aka GUIDs.
> >
> > Signed-off-by: Roman Kagan <rkagan@virtuozzo.com>
> > ---
> > include/qemu/uuid.h | 2 ++
> > tests/test-uuid.c | 24 ++++++++++++++++++++++++
> > util/uuid.c | 7 ++++++-
> > 3 files changed, 32 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/qemu/uuid.h b/include/qemu/uuid.h
> > index afe4840296..09489ce5c5 100644
> > --- a/include/qemu/uuid.h
> > +++ b/include/qemu/uuid.h
> > @@ -48,6 +48,8 @@ void qemu_uuid_generate(QemuUUID *out);
> >
> > int qemu_uuid_is_null(const QemuUUID *uu);
> >
> > +int qemu_uuid_is_equal(const QemuUUID *lhv, const QemuUUID *rhv);
> > +
> > void qemu_uuid_unparse(const QemuUUID *uuid, char *out);
> >
> > char *qemu_uuid_unparse_strdup(const QemuUUID *uuid);
> > diff --git a/tests/test-uuid.c b/tests/test-uuid.c
> > index d3a2791fd4..c6c8148117 100644
> > --- a/tests/test-uuid.c
> > +++ b/tests/test-uuid.c
> > @@ -116,6 +116,29 @@ static void test_uuid_is_null(void)
> > g_assert_false(qemu_uuid_is_null(&uuid_not_null_2));
> > }
> >
> > +static void test_uuid_is_equal(void)
> > +{
> > + int i;
> > + QemuUUID uuid;
> > + 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_null_2 = uuid_null;
> > + QemuUUID uuid_not_null_2 = uuid_not_null;
> > +
> > + g_assert(qemu_uuid_is_equal(&uuid_null, &uuid_null_2));
> > + g_assert(qemu_uuid_is_equal(&uuid_not_null, &uuid_not_null_2));
> > + g_assert_false(qemu_uuid_is_equal(&uuid_null, &uuid_not_null));
> > +
> > + for (i = 0; i < 100; ++i) {
> > + qemu_uuid_generate(&uuid);
> > + g_assert_false(qemu_uuid_is_equal(&uuid_null, &uuid));
> > + g_assert_false(qemu_uuid_is_equal(&uuid_not_null, &uuid));
>
> Isn't there a very low chance that the last line triggers by accident?
> Or uuid_no_null guaranteed to not match the generated one? In the latter
> case, a comment with a short explanation might be helpful here...
Regardless of that question, I think this is rather overkill when we are
just validating the memcmp() works correct in qemu_uuid_is_equal. The
for() loop here is not really adding any value over what the earlier
asserts already did. In fact the for() loop is arguably testing the
qemu_uuid_generate method, so better done in a separate unit test.
IOW, I would just suggest deleting this for() loop as its adding no
value.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2017-11-27 11:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-24 14:32 [Qemu-devel] [PATCH] util: add is_equal to UUID API Roman Kagan
2017-11-24 17:34 ` Thomas Huth
2017-11-27 11:02 ` Roman Kagan
2017-11-27 11:45 ` Daniel P. Berrange [this message]
2017-11-27 12:24 ` Roman Kagan
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=20171127114552.GI32413@redhat.com \
--to=berrange@redhat.com \
--cc=den@openvz.org \
--cc=famz@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rkagan@virtuozzo.com \
--cc=thuth@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).