diff mbox

[V15,5/5] tests: add a unit test for the vmgenid device.

Message ID 1430133591-6197-6-git-send-email-ghammer@redhat.com
State New
Headers show

Commit Message

Gal Hammer April 27, 2015, 11:19 a.m. UTC
Signed-off-by: Gal Hammer <ghammer@redhat.com>
---
 tests/Makefile       |  2 ++
 tests/vmgenid-test.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100644 tests/vmgenid-test.c

Comments

Eric Blake April 27, 2015, 3:01 p.m. UTC | #1
On 04/27/2015 05:19 AM, Gal Hammer wrote:
> Signed-off-by: Gal Hammer <ghammer@redhat.com>

Subject line: Most commits do NOT end in a trailing '.'. It's less
obvious if there is a preference for starting commits with a capital
after the subject, but that seems to be the current prevailing trend.
So I might have done:

tests: Add a unit test for vmgenid device

or even:

vmgenid: Add a unit test

(the latter approach would mean grouping all of the series under a
single topic of vmgenid, instead of your approach of a different topic
per patch according to which part was being modified in support of
adding vmgenid. Either approach is fine by me)
Michael S. Tsirkin April 27, 2015, 4:17 p.m. UTC | #2
On Mon, Apr 27, 2015 at 09:01:36AM -0600, Eric Blake wrote:
> On 04/27/2015 05:19 AM, Gal Hammer wrote:
> > Signed-off-by: Gal Hammer <ghammer@redhat.com>
> 
> Subject line: Most commits do NOT end in a trailing '.'. It's less
> obvious if there is a preference for starting commits with a capital
> after the subject, but that seems to be the current prevailing trend.

I personally prefer all-lower-case subjects.
In particular upper case after : is just weird.

> So I might have done:
> 
> tests: Add a unit test for vmgenid device
> 
> or even:
> 
> vmgenid: Add a unit test
> 
> (the latter approach would mean grouping all of the series under a
> single topic of vmgenid, instead of your approach of a different topic
> per patch according to which part was being modified in support of
> adding vmgenid. Either approach is fine by me)
> 
> -- 
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
diff mbox

Patch

diff --git a/tests/Makefile b/tests/Makefile
index 55aa745..6e4905c 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -175,6 +175,7 @@  check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF)
 gcov-files-i386-y += hw/usb/hcd-xhci.c
 check-qtest-i386-y += tests/pc-cpu-test$(EXESUF)
 check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF)
+check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
 check-qtest-x86_64-y = $(check-qtest-i386-y)
 gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
 gcov-files-x86_64-y = $(subst i386-softmmu/,x86_64-softmmu/,$(gcov-files-i386-y))
@@ -369,6 +370,7 @@  tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
 tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a
 tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(block-obj-y) libqemuutil.a libqemustub.a
+tests/vmgenid-test$(EXESUF): tests/vmgenid-test.o
 
 ifeq ($(CONFIG_POSIX),y)
 LIBS += -lutil
diff --git a/tests/vmgenid-test.c b/tests/vmgenid-test.c
new file mode 100644
index 0000000..abb7974
--- /dev/null
+++ b/tests/vmgenid-test.c
@@ -0,0 +1,44 @@ 
+/*
+ * QTest testcase for VM Generation ID
+ *
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include <string.h>
+#include "libqtest.h"
+
+static void vmgenid_test(void)
+{
+    static const uint8_t expected[16] = {
+        0x32, 0x4e, 0x6e, 0xaf, 0xd1, 0xd1, 0x4b, 0xf6,
+        0xbf, 0x41, 0xb9, 0xbb, 0x6c, 0x91, 0xfb, 0x87
+    };
+    uint8_t guid[16];
+    uint32_t i;
+
+    /* Skip the ACPI ADDR method and read the GUID directly from memory. */
+    for (i = 0; i < 16; i++) {
+        guid[i] = readb(0xfedf0000 + i);
+    }
+
+    g_assert_cmpuint(sizeof(guid), ==, sizeof(expected));
+    g_assert(memcmp(guid, expected, sizeof(guid)) == 0);
+}
+
+int main(int argc, char **argv)
+{
+    int ret;
+
+    g_test_init(&argc, &argv, NULL);
+    qtest_add_func("/vmgenid/vmgenid", vmgenid_test);
+
+    qtest_start("-global vmgenid.uuid=324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87");
+    ret = g_test_run();
+
+    qtest_end();
+
+    return ret;
+}