qtest/hyperv: Introduce a simple hyper-v test
PATCH 1/1 qtest/hyperv: Introduce a simple hyper-v test
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.
---
- Changes since "[PATCH v8 0/9] i386: KVM: expand Hyper-V features early":
make the test SKIP correctly when KVM is not present.
--- MAINTAINERS | 1 + tests/qtest/hyperv-test.c | 228 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/hyperv-test.c
MAINTAINERS +1 -0
@@ -1576,6 +1576,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 <[email protected]>
tests/qtest/hyperv-test.c new file +228 -0
228 lines not on this page · raw message
tests/qtest/meson.build +2 -1
@@ -85,7 +85,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')
Signature · 1 line
2.31.1
Quoted 164 lines · Vitaly Kuznetsov
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 <[email protected]>---
- Changes since "[PATCH v8 0/9] i386: KVM: expand Hyper-V features early":
make the test SKIP correctly when KVM is not present.--- MAINTAINERS | 1 + tests/qtest/hyperv-test.c | 228 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/hyperv-test.cMAINTAINERS +1
-0@@ -1576,6 +1576,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 <[email protected]>tests/qtest/hyperv-test.c new file +130
-0@@ -0,0 +1,228 @@ +/* +* Hyper-V emulation CPU feature test cases +* +* Copyright (c) 2021 Red Hat Inc. +* Authors: +* Vitaly Kuznetsov <[email protected]> +* +* 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_cap (int cap) +{ +int fd =open ("/dev/kvm" ,O_RDWR ); +int ret; + +if (fd <0 ) { +return false; + } + + ret =ioctl (fd,KVM_CHECK_EXTENSION , cap); + +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); \
tests/qtest/hyperv-test.c line 140
Quoted 10 lines
tests/qtest/hyperv-test.c new file +10
-0+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)
All the code above looks like stuff we should share with other tests. Shouldn't we factor that stuff out of those test(s) into some include?
Thanks,
drew
Quoted 170 lines · Andrew Jones
Quoted 169 lines · Vitaly Kuznetsov
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 <[email protected]>---
- Changes since "[PATCH v8 0/9] i386: KVM: expand Hyper-V features early":
make the test SKIP correctly when KVM is not present.--- MAINTAINERS | 1 + tests/qtest/hyperv-test.c | 228 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/hyperv-test.cMAINTAINERS +1
-0@@ -1576,6 +1576,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 <[email protected]>tests/qtest/hyperv-test.c new file +135
-0@@ -0,0 +1,228 @@ +/* +* Hyper-V emulation CPU feature test cases +* +* Copyright (c) 2021 Red Hat Inc. +* Authors: +* Vitaly Kuznetsov <[email protected]> +* +* 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_cap (int cap) +{ +int fd =open ("/dev/kvm" ,O_RDWR ); +int ret; + +if (fd <0 ) { +return false; + } + + ret =ioctl (fd,KVM_CHECK_EXTENSION , cap); + +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); \ +}) +
Quoted 9 lines
tests/qtest/hyperv-test.c line 140
Quoted 5 lines
tests/qtest/hyperv-test.c new file +5
-0+#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)All the code above looks like stuff we should share with other tests. Shouldn't we factor that stuff out of those test(s) into some include?
Probably yes but we'll need to come up with better names for all these functions to make it clear they're CPU specific.
Signature · 1 line
Vitaly
Quoted 182 lines · Vitaly Kuznetsov
Quoted 170 lines · Andrew Jones
Quoted 169 lines · Vitaly Kuznetsov
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 <[email protected]>---
- Changes since "[PATCH v8 0/9] i386: KVM: expand Hyper-V features early":
make the test SKIP correctly when KVM is not present.--- MAINTAINERS | 1 + tests/qtest/hyperv-test.c | 228 ++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 3 files changed, 231 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/hyperv-test.cMAINTAINERS +1
-0@@ -1576,6 +1576,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 <[email protected]>tests/qtest/hyperv-test.c new file +135
-0@@ -0,0 +1,228 @@ +/* +* Hyper-V emulation CPU feature test cases +* +* Copyright (c) 2021 Red Hat Inc. +* Authors: +* Vitaly Kuznetsov <[email protected]> +* +* 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_cap (int cap) +{ +int fd =open ("/dev/kvm" ,O_RDWR ); +int ret; + +if (fd <0 ) { +return false; + } + + ret =ioctl (fd,KVM_CHECK_EXTENSION , cap); + +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); \ +}) +Quoted 9 lines
tests/qtest/hyperv-test.c line 140
Quoted 5 lines
tests/qtest/hyperv-test.c new file +5
-0+#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)All the code above looks like stuff we should share with other tests. Shouldn't we factor that stuff out of those test(s) into some include?
Quoted 3 lines
Probably yes but we'll need to come up with better names for all these functions to make it clear they're CPU specific.
Some can be given more general names, i.e. s/feature/bool/ as they're not cpu specific. The ones that take a cpu_type parameter could just get a cpu_ prefix, I guess.
Thanks,
drew