From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: ghammer@redhat.com, mst@redhat.com
Subject: [Qemu-devel] [PATCH V14 3/3] tests: add a unit test for the vmgenid device.
Date: Tue, 3 Mar 2015 17:18:15 +0100 [thread overview]
Message-ID: <1425399495-13664-4-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1425399495-13664-1-git-send-email-imammedo@redhat.com>
* test that guest can read UUID provided on CLI from buffer
accessing it at HPA which is available via 'vmgid-addr'
property when device is inintialized.
* test setting UUID at runtime and check that it's updated
at expected HPA.
Signed-off-by: Gal Hammer <ghammer@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v3:
* fix comment style to /*... */
v2:
* fix: make sure that test actually runs
* use property to get UUID buffer HPA
* add setting UUID via QMP at runtime test case
---
tests/Makefile | 2 ++
tests/vmgenid-test.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 94 insertions(+)
create mode 100644 tests/vmgenid-test.c
diff --git a/tests/Makefile b/tests/Makefile
index d5df168..ccd0eb5 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -171,6 +171,7 @@ gcov-files-i386-y += hw/usb/dev-hid.c
gcov-files-i386-y += hw/usb/dev-storage.c
check-qtest-i386-y += tests/usb-hcd-xhci-test$(EXESUF)
gcov-files-i386-y += hw/usb/hcd-xhci.c
+check-qtest-i386-y += tests/vmgenid-test$(EXESUF)
check-qtest-i386-$(CONFIG_LINUX) += tests/vhost-user-test$(EXESUF)
check-qtest-x86_64-y = $(check-qtest-i386-y)
gcov-files-i386-y += i386-softmmu/hw/timer/mc146818rtc.c
@@ -363,6 +364,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..628e1ec
--- /dev/null
+++ b/tests/vmgenid-test.c
@@ -0,0 +1,92 @@
+/*
+ * QTest testcase for VM Generation ID
+ *
+ * Copyright (c) 2015 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 <glib.h>
+#include <string.h>
+#include <unistd.h>
+#include "libqtest.h"
+
+/* Wait at most 1 minute */
+#define TEST_DELAY (1 * G_USEC_PER_SEC / 10)
+#define TEST_CYCLES MAX((60 * G_USEC_PER_SEC / TEST_DELAY), 1)
+
+#define VGID_UUID "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87"
+
+static void vmgenid_check_uuid(const uint8_t *expected)
+{
+ uint8_t guid[16];
+ int i;
+ uint32_t addr = 0;
+ QDict *response;
+
+ for (i = 0; i < TEST_CYCLES; ++i) {
+ response = qmp("{ 'execute': 'qom-get', 'arguments': { "
+ "'path': '/machine/peripheral/testvgid', "
+ "'property': 'vmgid-addr' } }");
+ if (qdict_haskey(response, "return")) {
+ addr = qdict_get_int(response, "return");
+ }
+ QDECREF(response);
+ if (addr) {
+ break;
+ }
+ g_usleep(TEST_DELAY);
+ }
+
+ /* Skip the ACPI ADDR method and read the GUID directly from memory */
+ for (i = 0; i < 16; i++) {
+ guid[i] = readb(addr + i);
+ }
+
+ g_assert(memcmp(guid, expected, sizeof(guid)) == 0);
+}
+
+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
+ };
+ vmgenid_check_uuid(expected);
+}
+
+static void vmgenid_set_uuid_test(void)
+{
+ QDict *response;
+ static const uint8_t expected[16] = {
+ 0x12, 0x4e, 0x6e, 0xaf, 0xd1, 0xd1, 0x4b, 0xf6,
+ 0xbf, 0x41, 0xb9, 0xbb, 0x6c, 0x91, 0xfb, 0x87
+ };
+
+ response = qmp("{ 'execute': 'qom-set', 'arguments': { "
+ "'path': '/machine/peripheral/testvgid', "
+ "'property': 'uuid', 'value': '"
+ "124e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87' } }");
+ g_assert(qdict_haskey(response, "return"));
+ QDECREF(response);
+
+ vmgenid_check_uuid(expected);
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+
+ g_test_init(&argc, &argv, NULL);
+
+ qtest_start("-machine accel=tcg -device vmgenid,id=testvgid,"
+ "uuid=" VGID_UUID);
+ qtest_add_func("/vmgenid/vmgenid", vmgenid_test);
+ qtest_add_func("/vmgenid/vmgenid/set-uuid", vmgenid_set_uuid_test);
+ ret = g_test_run();
+
+ qtest_end();
+
+ return ret;
+}
--
2.1.0
next prev parent reply other threads:[~2015-03-03 17:16 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-03 16:18 [Qemu-devel] [PATCH V14 0/3] Virtual Machine Generation ID Igor Mammedov
2015-03-03 16:18 ` [Qemu-devel] [PATCH V14 1/3] docs: vm generation id device's description Igor Mammedov
2015-03-04 19:57 ` Eric Blake
2015-03-03 16:18 ` [Qemu-devel] [PATCH V14 2/3] pc: add a Virtual Machine Generation ID device Igor Mammedov
2015-03-03 17:35 ` Michael S. Tsirkin
2015-03-03 20:33 ` Igor Mammedov
2015-03-04 12:11 ` Michael S. Tsirkin
2015-03-04 13:12 ` Igor Mammedov
2015-03-04 13:49 ` Michael S. Tsirkin
2015-03-04 14:03 ` Andreas Färber
2015-03-04 15:14 ` Igor Mammedov
2015-03-04 15:31 ` Michael S. Tsirkin
2015-03-04 16:33 ` Igor Mammedov
2015-03-04 19:12 ` Michael S. Tsirkin
2015-03-05 14:22 ` Igor Mammedov
2015-03-11 5:35 ` David Gibson
2015-03-19 9:50 ` Michael S. Tsirkin
2015-03-19 11:31 ` Gal Hammer
2015-03-20 4:58 ` David Gibson
2015-03-03 16:18 ` Igor Mammedov [this message]
2015-04-15 10:38 ` [Qemu-devel] [PATCH V14 0/3] Virtual Machine Generation ID Michael S. Tsirkin
2015-04-15 13:59 ` Igor Mammedov
2015-04-19 7:52 ` Michael S. Tsirkin
2015-04-19 13:38 ` Yan Vugenfirer
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=1425399495-13664-4-git-send-email-imammedo@redhat.com \
--to=imammedo@redhat.com \
--cc=ghammer@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).