From patchwork Fri Jan 22 13:20:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 8090071 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 402E09F6FA for ; Fri, 22 Jan 2016 13:23:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8114120457 for ; Fri, 22 Jan 2016 13:23:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ADFEC203AA for ; Fri, 22 Jan 2016 13:23:47 +0000 (UTC) Received: from localhost ([::1]:53708 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMbgp-0004W4-2g for patchwork-qemu-devel@patchwork.kernel.org; Fri, 22 Jan 2016 08:23:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMbeQ-0000Yk-Ge for qemu-devel@nongnu.org; Fri, 22 Jan 2016 08:21:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aMbeO-0002Pi-Qh for qemu-devel@nongnu.org; Fri, 22 Jan 2016 08:21:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39161) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aMbeO-0002PY-Ij for qemu-devel@nongnu.org; Fri, 22 Jan 2016 08:21:16 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 3EE963CA14B for ; Fri, 22 Jan 2016 13:21:16 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.34.112.60]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0MDL5gI021584; Fri, 22 Jan 2016 08:21:13 -0500 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Fri, 22 Jan 2016 14:20:57 +0100 Message-Id: <1453468862-118912-5-git-send-email-imammedo@redhat.com> In-Reply-To: <1453468862-118912-1-git-send-email-imammedo@redhat.com> References: <1453468862-118912-1-git-send-email-imammedo@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: ehabkost@redhat.com, mst@redhat.com, ghammer@redhat.com, lersek@redhat.com, lcapitulino@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH v18 4/9] tests: add a unit test for the vmgenid device. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP * test that guest can read GUID provided on CLI from buffer accessing it at HPA which is available via 'vmgid-addr' property when device is inintialized. * test setting GUID at runtime and check that it's updated at expected HPA. Signed-off-by: Gal Hammer Signed-off-by: Igor Mammedov --- tests/Makefile | 2 ++ tests/vmgenid-test.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/vmgenid-test.c diff --git a/tests/Makefile b/tests/Makefile index b7352f1..8cccf6e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -206,6 +206,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-y += tests/q35-test$(EXESUF) +check-qtest-i386-y += tests/vmgenid-test$(EXESUF) gcov-files-i386-y += hw/pci-host/q35.c check-qtest-i386-$(CONFIG_VHOST_NET_TEST_i386) += tests/vhost-user-test$(EXESUF) ifeq ($(CONFIG_VHOST_NET_TEST_i386),) @@ -565,6 +566,7 @@ tests/test-write-threshold$(EXESUF): tests/test-write-threshold.o $(test-block-o tests/test-netfilter$(EXESUF): tests/test-netfilter.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/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..9388180 --- /dev/null +++ b/tests/vmgenid-test.c @@ -0,0 +1,93 @@ +/* + * QTest testcase for VM Generation ID + * + * Copyright (c) 2016 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 +#include +#include +#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_GUID "324e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87" + +static void vmgenid_check_guid(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); + } + g_assert(addr); + + /* 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_guid(expected); +} + +static void vmgenid_set_guid_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': 'guid', 'value': '" + "124e6eaf-d1d1-4bf6-bf41-b9bb6c91fb87' } }"); + g_assert(qdict_haskey(response, "return")); + QDECREF(response); + + vmgenid_check_guid(expected); +} + +int main(int argc, char **argv) +{ + int ret; + + g_test_init(&argc, &argv, NULL); + + qtest_start("-machine accel=tcg -device vmgenid,id=testvgid," + "guid=" VGID_GUID); + qtest_add_func("/vmgenid/vmgenid", vmgenid_test); + qtest_add_func("/vmgenid/vmgenid/set-guid", vmgenid_set_guid_test); + ret = g_test_run(); + + qtest_end(); + + return ret; +}