From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
Eduardo Habkost <ehabkost@redhat.com>,
Igor Mammedov <imammedo@redhat.com>
Subject: [PATCH v6 19/19] qtest/hyperv: Introduce a simple hyper-v test
Date: Thu, 22 Apr 2021 18:11:30 +0200 [thread overview]
Message-ID: <20210422161130.652779-20-vkuznets@redhat.com> (raw)
In-Reply-To: <20210422161130.652779-1-vkuznets@redhat.com>
For the beginning, just test 'hv-passthrough' and a couple of custom
Hyper-V enlightenments configurations through QMP. Later, it would
be great to complement this by checking CPUID values from within the
guest.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
MAINTAINERS | 1 +
tests/qtest/hyperv-test.c | 225 ++++++++++++++++++++++++++++++++++++++
tests/qtest/meson.build | 3 +-
3 files changed, 228 insertions(+), 1 deletion(-)
create mode 100644 tests/qtest/hyperv-test.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 36055f14c594..86d731e86f4a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1552,6 +1552,7 @@ F: hw/isa/apm.c
F: include/hw/isa/apm.h
F: tests/unit/test-x86-cpuid.c
F: tests/qtest/test-x86-cpuid-compat.c
+F: tests/qtest/hyperv-test.c
PC Chipset
M: Michael S. Tsirkin <mst@redhat.com>
diff --git a/tests/qtest/hyperv-test.c b/tests/qtest/hyperv-test.c
new file mode 100644
index 000000000000..0be689548e18
--- /dev/null
+++ b/tests/qtest/hyperv-test.c
@@ -0,0 +1,225 @@
+/*
+ * Hyper-V emulation CPU feature test cases
+ *
+ * Copyright (c) 2021 Red Hat Inc.
+ * Authors:
+ * Vitaly Kuznetsov <vkuznets@redhat.com>
+ *
+ * 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 <linux/kvm.h>
+#include <sys/ioctl.h>
+
+#include "qemu/osdep.h"
+#include "qemu/bitops.h"
+#include "libqos/libqtest.h"
+#include "qapi/qmp/qdict.h"
+#include "qapi/qmp/qjson.h"
+
+#define MACHINE_KVM "-machine pc-q35-5.2 -accel kvm "
+#define QUERY_HEAD "{ 'execute': 'query-cpu-model-expansion', " \
+ " 'arguments': { 'type': 'full', "
+#define QUERY_TAIL "}}"
+
+static bool kvm_enabled(QTestState *qts)
+{
+ QDict *resp, *qdict;
+ bool enabled;
+
+ resp = qtest_qmp(qts, "{ 'execute': 'query-kvm' }");
+ g_assert(qdict_haskey(resp, "return"));
+ qdict = qdict_get_qdict(resp, "return");
+ g_assert(qdict_haskey(qdict, "enabled"));
+ enabled = qdict_get_bool(qdict, "enabled");
+ qobject_unref(resp);
+
+ return enabled;
+}
+
+static bool kvm_has_sys_hyperv_cpuid(void)
+{
+ int fd = open("/dev/kvm", O_RDWR);
+ int ret;
+
+ g_assert(fd > 0);
+
+ ret = ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_SYS_HYPERV_CPUID);
+
+ close(fd);
+
+ return ret > 0;
+}
+
+static QDict *do_query_no_props(QTestState *qts, const char *cpu_type)
+{
+ return qtest_qmp(qts, QUERY_HEAD "'model': { 'name': %s }"
+ QUERY_TAIL, cpu_type);
+}
+
+static bool resp_has_props(QDict *resp)
+{
+ QDict *qdict;
+
+ g_assert(resp);
+
+ if (!qdict_haskey(resp, "return")) {
+ return false;
+ }
+ qdict = qdict_get_qdict(resp, "return");
+
+ if (!qdict_haskey(qdict, "model")) {
+ return false;
+ }
+ qdict = qdict_get_qdict(qdict, "model");
+
+ return qdict_haskey(qdict, "props");
+}
+
+static QDict *resp_get_props(QDict *resp)
+{
+ QDict *qdict;
+
+ g_assert(resp);
+ g_assert(resp_has_props(resp));
+
+ qdict = qdict_get_qdict(resp, "return");
+ qdict = qdict_get_qdict(qdict, "model");
+ qdict = qdict_get_qdict(qdict, "props");
+
+ return qdict;
+}
+
+static bool resp_get_feature(QDict *resp, const char *feature)
+{
+ QDict *props;
+
+ g_assert(resp);
+ g_assert(resp_has_props(resp));
+ props = resp_get_props(resp);
+ g_assert(qdict_get(props, feature));
+ return qdict_get_bool(props, feature);
+}
+
+#define assert_has_feature(qts, cpu_type, feature) \
+({ \
+ QDict *_resp = do_query_no_props(qts, cpu_type); \
+ g_assert(_resp); \
+ g_assert(resp_has_props(_resp)); \
+ g_assert(qdict_get(resp_get_props(_resp), feature)); \
+ qobject_unref(_resp); \
+})
+
+#define resp_assert_feature(resp, feature, expected_value) \
+({ \
+ QDict *_props; \
+ \
+ g_assert(_resp); \
+ g_assert(resp_has_props(_resp)); \
+ _props = resp_get_props(_resp); \
+ g_assert(qdict_get(_props, feature)); \
+ g_assert(qdict_get_bool(_props, feature) == (expected_value)); \
+})
+
+#define assert_feature(qts, cpu_type, feature, expected_value) \
+({ \
+ QDict *_resp; \
+ \
+ _resp = do_query_no_props(qts, cpu_type); \
+ g_assert(_resp); \
+ resp_assert_feature(_resp, feature, expected_value); \
+ qobject_unref(_resp); \
+})
+
+#define assert_has_feature_enabled(qts, cpu_type, feature) \
+ assert_feature(qts, cpu_type, feature, true)
+
+#define assert_has_feature_disabled(qts, cpu_type, feature) \
+ assert_feature(qts, cpu_type, feature, false)
+
+static void test_assert_hyperv_all_but_evmcs(QTestState *qts)
+{
+ assert_has_feature_enabled(qts, "host", "hv-relaxed");
+ assert_has_feature_enabled(qts, "host", "hv-vapic");
+ assert_has_feature_enabled(qts, "host", "hv-vpindex");
+ assert_has_feature_enabled(qts, "host", "hv-runtime");
+ assert_has_feature_enabled(qts, "host", "hv-crash");
+ assert_has_feature_enabled(qts, "host", "hv-time");
+ assert_has_feature_enabled(qts, "host", "hv-synic");
+ assert_has_feature_enabled(qts, "host", "hv-stimer");
+ assert_has_feature_enabled(qts, "host", "hv-tlbflush");
+ assert_has_feature_enabled(qts, "host", "hv-ipi");
+ assert_has_feature_enabled(qts, "host", "hv-reset");
+ assert_has_feature_enabled(qts, "host", "hv-frequencies");
+ assert_has_feature_enabled(qts, "host", "hv-reenlightenment");
+ assert_has_feature_enabled(qts, "host", "hv-stimer-direct");
+}
+
+static void test_query_cpu_hv_all_but_evmcs(const void *data)
+{
+ QTestState *qts;
+
+ qts = qtest_init(MACHINE_KVM "-cpu host,hv-relaxed,hv-vapic,hv-vpindex,"
+ "hv-runtime,hv-crash,hv-time,hv-synic,hv-stimer,"
+ "hv-tlbflush,hv-ipi,hv-reset,hv-frequencies,"
+ "hv-reenlightenment,hv-stimer-direct");
+
+ test_assert_hyperv_all_but_evmcs(qts);
+
+ qtest_quit(qts);
+}
+
+static void test_query_cpu_hv_custom(const void *data)
+{
+ QTestState *qts;
+
+ qts = qtest_init(MACHINE_KVM "-cpu host,hv-vpindex");
+
+ assert_has_feature_enabled(qts, "host", "hv-vpindex");
+ assert_has_feature_disabled(qts, "host", "hv-synic");
+
+ qtest_quit(qts);
+}
+
+static void test_query_cpu_hv_passthrough(const void *data)
+{
+ QTestState *qts;
+ QDict *resp;
+
+ qts = qtest_init(MACHINE_KVM "-cpu host,hv-passthrough");
+ if (!kvm_enabled(qts)) {
+ qtest_quit(qts);
+ return;
+ }
+
+ test_assert_hyperv_all_but_evmcs(qts);
+
+ resp = do_query_no_props(qts, "host");
+ if (resp_get_feature(resp, "vmx")) {
+ assert_has_feature_enabled(qts, "host", "hv-evmcs");
+ } else {
+ assert_has_feature_disabled(qts, "host", "hv-evmcs");
+ }
+
+ qtest_quit(qts);
+}
+
+int main(int argc, char **argv)
+{
+ const char *arch = qtest_get_arch();
+
+ g_test_init(&argc, &argv, NULL);
+
+ if (!strcmp(arch, "i386") || !strcmp(arch, "x86_64")) {
+ qtest_add_data_func("/hyperv/hv-all-but-evmcs",
+ NULL, test_query_cpu_hv_all_but_evmcs);
+ qtest_add_data_func("/hyperv/hv-custom",
+ NULL, test_query_cpu_hv_custom);
+ if (kvm_has_sys_hyperv_cpuid()) {
+ qtest_add_data_func("/hyperv/hv-passthrough",
+ NULL, test_query_cpu_hv_passthrough);
+ }
+ }
+
+ return g_test_run();
+}
diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build
index 0c7673892179..03da00f82ba9 100644
--- a/tests/qtest/meson.build
+++ b/tests/qtest/meson.build
@@ -83,7 +83,8 @@ qtests_i386 = \
'vmgenid-test',
'migration-test',
'test-x86-cpuid-compat',
- 'numa-test']
+ 'numa-test',
+ 'hyperv-test']
dbus_daemon = find_program('dbus-daemon', required: false)
if dbus_daemon.found() and config_host.has_key('GDBUS_CODEGEN')
--
2.30.2
next prev parent reply other threads:[~2021-04-22 16:32 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-22 16:11 [PATCH v6 00/19] i386: KVM: expand Hyper-V features early Vitaly Kuznetsov
2021-04-22 16:11 ` [PATCH v6 01/19] i386: keep hyperv_vendor string up-to-date Vitaly Kuznetsov
2021-04-30 23:07 ` Eduardo Habkost
2021-06-02 11:41 ` Vitaly Kuznetsov
2021-04-22 16:11 ` [PATCH v6 02/19] i386: invert hyperv_spinlock_attempts setting logic with hv_passthrough Vitaly Kuznetsov
2021-04-30 23:09 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 03/19] i386: always fill Hyper-V CPUID feature leaves from X86CPU data Vitaly Kuznetsov
2021-04-30 23:15 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 04/19] i386: stop using env->features[] for filling Hyper-V CPUIDs Vitaly Kuznetsov
2021-05-01 0:34 ` Eduardo Habkost
2021-05-20 19:49 ` Eduardo Habkost
2021-05-21 7:54 ` Vitaly Kuznetsov
2021-04-22 16:11 ` [PATCH v6 05/19] i386: introduce hyperv_feature_supported() Vitaly Kuznetsov
2021-05-20 19:53 ` Eduardo Habkost
2021-05-21 7:57 ` Vitaly Kuznetsov
2021-04-22 16:11 ` [PATCH v6 06/19] i386: introduce hv_cpuid_get_host() Vitaly Kuznetsov
2021-05-20 20:01 ` Eduardo Habkost
2021-05-21 7:57 ` Vitaly Kuznetsov
2021-04-22 16:11 ` [PATCH v6 07/19] i386: drop FEAT_HYPERV feature leaves Vitaly Kuznetsov
2021-05-20 20:13 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 08/19] i386: introduce hv_cpuid_cache Vitaly Kuznetsov
2021-05-20 20:16 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 09/19] i386: split hyperv_handle_properties() into hyperv_expand_features()/hyperv_fill_cpuids() Vitaly Kuznetsov
2021-05-20 21:34 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 10/19] i386: move eVMCS enablement to hyperv_init_vcpu() Vitaly Kuznetsov
2021-05-21 21:20 ` Eduardo Habkost
2021-05-24 12:00 ` Vitaly Kuznetsov
2021-05-26 16:35 ` Eduardo Habkost
2021-05-27 7:27 ` Vitaly Kuznetsov
2021-05-27 19:16 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 11/19] i386: switch hyperv_expand_features() to using error_setg() Vitaly Kuznetsov
2021-05-21 21:37 ` Eduardo Habkost
2021-05-24 12:05 ` Vitaly Kuznetsov
2021-04-22 16:11 ` [PATCH v6 12/19] i386: adjust the expected KVM_GET_SUPPORTED_HV_CPUID array size Vitaly Kuznetsov
2021-05-21 21:37 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 13/19] i386: prefer system KVM_GET_SUPPORTED_HV_CPUID ioctl over vCPU's one Vitaly Kuznetsov
2021-05-21 21:42 ` Eduardo Habkost
2021-05-24 12:08 ` Vitaly Kuznetsov
2021-05-26 16:46 ` Eduardo Habkost
2021-05-26 16:56 ` Daniel P. Berrangé
2021-04-22 16:11 ` [PATCH v6 14/19] i386: use global kvm_state in hyperv_enabled() check Vitaly Kuznetsov
2021-05-21 21:42 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 15/19] i386: expand Hyper-V features during CPU feature expansion time Vitaly Kuznetsov
2021-05-21 21:45 ` Eduardo Habkost
2021-05-24 12:13 ` Vitaly Kuznetsov
2021-05-26 16:57 ` Eduardo Habkost
2021-05-27 7:29 ` Vitaly Kuznetsov
2021-04-22 16:11 ` [PATCH v6 16/19] i386: kill off hv_cpuid_check_and_set() Vitaly Kuznetsov
2021-05-21 21:56 ` Eduardo Habkost
2021-05-24 12:13 ` Vitaly Kuznetsov
2021-04-22 16:11 ` [PATCH v6 17/19] i386: HV_HYPERCALL_AVAILABLE privilege bit is always needed Vitaly Kuznetsov
2021-05-21 22:06 ` Eduardo Habkost
2021-05-24 12:22 ` Vitaly Kuznetsov
2021-05-26 17:05 ` Eduardo Habkost
2021-05-27 7:37 ` Vitaly Kuznetsov
2021-05-27 19:34 ` Eduardo Habkost
2021-04-22 16:11 ` [PATCH v6 18/19] i386: Hyper-V SynIC requires POST_MESSAGES/SIGNAL_EVENTS priviliges Vitaly Kuznetsov
2021-04-22 16:11 ` Vitaly Kuznetsov [this message]
2021-05-26 20:20 ` [PATCH v6 00/19] i386: KVM: expand Hyper-V features early Eduardo Habkost
2021-05-27 7:39 ` Vitaly Kuznetsov
2021-05-27 19:35 ` Eduardo Habkost
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=20210422161130.652779-20-vkuznets@redhat.com \
--to=vkuznets@redhat.com \
--cc=ehabkost@redhat.com \
--cc=imammedo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@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).