Target-specific unit test support, add unit tests for target-i386/cpu.c code
v2 cover Target-specific unit test support, add unit tests for target-i386/cpu.c code
This is an attempt to write unit tests for the target-i386/cpu.c code. By now, I just implemented 3 simple test cases, to ensure X86CPU objects can be created, and to ensure the CPU features are set properly depending on the CPU model table.
This needs to be applied after:
From: Eduardo Habkost <[email protected]>
To: [email protected], [email protected]
Date: Fri, 26 Sep 2014 16:46:01 -0300
Message-Id: <[email protected]>
Subject: [Qemu-devel] [PATCH 0/3] bitops: Header dependency fixes
Changes v1 -> v2:
* Make dependency list of test binary much simpler, now that cpus.o was removed.
Eduardo Habkost (7):
tests: Move fake yield_until_fd_readable() to coroutine-stub.c
tests: Support target-specific unit tests
tests: Make test-x86-cpuid target-specific
tests: Add unit test for X86CPU code
target-i386: Isolate enabled-by-default features to a separate array
tests: test-x86-cpu: Add TCG feature bit initialization test
tests: test-x86-cpu: Add KVM feature bit initialization test
target-i386/cpu.c | 12 ++-- tests/.gitignore | 1 + tests/Makefile | 51 ++++++++++++---- tests/coroutine-stub.c | 13 ++++ tests/test-vmstate.c | 11 ---- tests/test-x86-cpu.c | 97 +++++++++++++++++++++++++++++ tests/vl-stub.c | 15 +++++ tests/x86-stub.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 337 insertions(+), 26 deletions(-) create mode 100644 tests/coroutine-stub.c create mode 100644 tests/test-x86-cpu.c create mode 100644 tests/vl-stub.c create mode 100644 tests/x86-stub.c
Signature · 1 line
1.9.3
PATCH v2 1/7 tests: Move fake yield_until_fd_readable() to coroutine-stub.c
Other test code will use the function.
--- tests/Makefile | 1 + tests/coroutine-stub.c | 13 +++++++++++++ tests/test-vmstate.c | 11 ----------- 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 tests/coroutine-stub.c
tests/Makefile +1 -0
@@ -259,6 +259,7 @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ $(test-qapi-obj-y) \ libqemuutil.a libqemustub.a tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ + tests/coroutine-stub.o \ vmstate.o qemu-file.o \ libqemuutil.a
tests/coroutine-stub.c new file +13 -0
@@ -0,0 +1,13 @@ +#include "qemu-common.h" +#include "block/coroutine.h" + +/* Fake yield_until_fd_readable() implementation so we don't have to pull the +* coroutine code as dependency. +*/ +void yield_until_fd_readable (int fd) +{ +fd_set fds; +FD_ZERO (&fds); +FD_SET (fd, &fds); +select (fd +1 , &fds,NULL ,NULL ,NULL ); +}
tests/test-vmstate.c +0 -11
@@ -32,17 +32,6 @@static char temp_file[] ="/tmp/vmst.test.XXXXXX" ;static int temp_fd; -/* Fake yield_until_fd_readable() implementation so we don't have to pull the -* coroutine code as dependency. -*/ -void yield_until_fd_readable (int fd) -{ -fd_set fds; -FD_ZERO (&fds); -FD_SET (fd, &fds); -select (fd +1 , &fds,NULL ,NULL ,NULL ); -} -/* Duplicate temp_fd and seek to the beginning of the file */ static QEMUFile *open_test_file (bool write) {
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v2 1/7] tests: Move fake yield_until_fd_readable() to coroutine-stub.c
Il 30/09/2014 20:26, Eduardo Habkost ha scritto:
Quoted 9 lines
Other test code will use the function.
Signed-off-by Eduardo Habkost <[email protected]>--- tests/Makefile | 1 + tests/coroutine-stub.c | 13 +++++++++++++ tests/test-vmstate.c | 11 ----------- 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 tests/coroutine-stub.c
Should we split qemu-file.c instead?
Paolo
Re: [Qemu-devel] [PATCH v2 1/7] tests: Move fake yield_until_fd_readable() to coroutine-stub.c
Quoted 11 lines · Paolo Bonzini
Il 30/09/2014 20:26, Eduardo Habkost ha scritto:
Quoted 9 lines
Other test code will use the function.
Signed-off-by Eduardo Habkost <[email protected]>--- tests/Makefile | 1 + tests/coroutine-stub.c | 13 +++++++++++++ tests/test-vmstate.c | 11 ----------- 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 tests/coroutine-stub.c
Quoted 1 line
Should we split
qemu-file.cinstead?
Splitting qemu-file.c won't avoid the need for a fake yield_until_fd_readable() for test-vmstate.c, but will probably help reduce cpu.c dependencies. I will give it a try.
Signature · 1 line
Eduardo
PATCH v2 2/7 tests: Support target-specific unit tests
In reply to Eduardo HabkostTo make unit tests that depend on target-specific files, use check-unit-<target>-y and test-obj-<target>-y.
Note that the qtest test cases were per-*arch* (e.g. i386, mips, ppc), not per-*target* (e.g. i386-softmmu, x86_64-linux-user), because they implicitly apply only to the -softmmu targets. Target-specific unit tests, on the other hand, may apply to any target (e.g. they may test *-softmmu and/or *-user code). To clarify this, $(TARGETS) was renamed to $(QTEST_ARCHES).
--- tests/Makefile | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-)
tests/Makefile +23 -8
@@ -357,12 +357,27 @@ ifeq ($(CONFIG_POSIX),y) LIBS += -lutil endif + +SOFTMMU_TARGETS=$(filter %-softmmu,$(TARGET_DIRS)) +SOFTMMU_ARCHES=$(patsubst %-softmmu,%, $(SOFTMMU_TARGETS)) + +# unit test rules: + +# target-specific tests/objs: + +test-obj-y += $(foreach TARGET,$(TARGET_DIRS), $(test-obj-$(TARGET)-y)) +check-unit-y += $(foreach TARGET,$(TARGET_DIRS), $(check-unit-$(TARGET)-y)) + +$(foreach TARGET,$(TARGET_DIRS),$(eval include $(TARGET)/config-target.mak) \ + $(eval $(test-obj-$(TARGET)-y): QEMU_CFLAGS += -I$(TARGET) -I$(SRC_PATH)/target-$(TARGET_BASE_ARCH) -DNEED_CPU_H)) + +$(test-obj-y): QEMU_INCLUDES += -Itests + # QTest rules -TARGETS=$(patsubst %-softmmu,%, $(filter %-softmmu,$(TARGET_DIRS))) ifeq ($(CONFIG_POSIX),y) -QTEST_TARGETS=$(foreach TARGET,$(TARGETS), $(if $(check-qtest-$(TARGET)-y), $(TARGET),)) -check-qtest-y=$(foreach TARGET,$(TARGETS), $(check-qtest-$(TARGET)-y)) +QTEST_ARCHES=$(foreach ARCH,$(SOFTMMU_ARCHES), $(if $(check-qtest-$(ARCH)-y), $(ARCH),)) +check-qtest-y=$(foreach ARCH,$(QTEST_ARCHES), $(check-qtest-$(ARCH)-y)) endif qtest-obj-y = tests/libqtest.o libqemuutil.a libqemustub.a
@@ -394,8 +409,8 @@ GCOV_OPTIONS = -n $(if $(V),-f,) # gtester tests, possibly with verbose output -.PHONY: $(patsubst %, check-qtest-%, $(QTEST_TARGETS)) -$(patsubst %, check-qtest-%, $(QTEST_TARGETS)): check-qtest-%: $(check-qtest-y) +.PHONY: $(patsubst %, check-qtest-%, $(QTEST_ARCHES)) +$(patsubst %, check-qtest-%, $(QTEST_ARCHES)): check-qtest-%: $(check-qtest-y) $(if $(CONFIG_GCOV),@rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda,) $(call quiet-command,QTEST_QEMU_BINARY=$*-softmmu/qemu-system-$* \ MALLOC_PERTURB_=$${MALLOC_PERTURB_:-$$((RANDOM % 255 + 1))} \
@@ -418,7 +433,7 @@ $(patsubst %, check-%, $(check-unit-y)): check-%: % # gtester tests with XML output -$(patsubst %, check-report-qtest-%.xml, $(QTEST_TARGETS)): check-report-qtest-%.xml: $(check-qtest-y) +$(patsubst %, check-report-qtest-%.xml, $(QTEST_ARCHES)): check-report-qtest-%.xml: $(check-qtest-y) $(call quiet-command,QTEST_QEMU_BINARY=$*-softmmu/qemu-system-$* \ gtester -q $(GTESTER_OPTIONS) -o $@ -m=$(SPEED) $(check-qtest-$*-y),"GTESTER $@")
@@ -427,7 +442,7 @@ check-report-unit.xml: $(check-unit-y) # Reports and overall runs -check-report.xml: $(patsubst %,check-report-qtest-%.xml, $(QTEST_TARGETS)) check-report-unit.xml +check-report.xml: $(patsubst %,check-report-qtest-%.xml, $(QTEST_ARCHES)) check-report-unit.xml $(call quiet-command,$(SRC_PATH)/scripts/gtester-cat $^ > $@, " GEN $@") check-report.html: check-report.xml
@@ -461,7 +476,7 @@ $(patsubst %, check-%, $(check-qapi-schema-y)): check-%.json: $(SRC_PATH)/%.json .PHONY: check-qapi-schema check-qtest check-unit check check-clean check-qapi-schema: $(patsubst %,check-%, $(check-qapi-schema-y)) -check-qtest: $(patsubst %,check-qtest-%, $(QTEST_TARGETS)) +check-qtest: $(patsubst %,check-qtest-%, $(QTEST_ARCHES)) check-unit: $(patsubst %,check-%, $(check-unit-y)) check-block: $(patsubst %,check-%, $(check-block-y)) check: check-qapi-schema check-unit check-qtest
Signature · 1 line
1.9.3
PATCH v2 3/7 tests: Make test-x86-cpuid target-specific
In reply to Eduardo HabkostInstead of using a test-specific hack to add -I$(SRC_PATH)/target-i386, add test-x86-cpuid to $(test-obj-x86_64-softmmu-y).
--- tests/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tests/Makefile +3 -3
@@ -45,7 +45,7 @@ check-unit-y += tests/test-thread-pool$(EXESUF) gcov-files-test-thread-pool-y = thread-pool.c gcov-files-test-hbitmap-y = util/hbitmap.c check-unit-y += tests/test-hbitmap$(EXESUF) -check-unit-y += tests/test-x86-cpuid$(EXESUF) +check-unit-x86_64-softmmu-y += tests/test-x86-cpuid$(EXESUF) # all code tested by test-x86-cpuid is inside topology.h gcov-files-test-x86-cpuid-y = check-unit-y += tests/test-xbzrle$(EXESUF)
@@ -224,6 +224,8 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \ tests/test-opts-visitor.o tests/test-qmp-event.o +test-obj-x86_64-softmmu-y = tests/test-x86-cpuid.o + test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \ tests/test-qapi-event.o
@@ -231,8 +233,6 @@ $(test-obj-y): QEMU_INCLUDES += -Itests QEMU_CFLAGS += -I$(SRC_PATH)/tests qom-core-obj = qom/object.o qom/qom-qobject.o qom/container.o -tests/test-x86-cpuid.o: QEMU_INCLUDES += -I$(SRC_PATH)/target-i386 - tests/check-qint$(EXESUF): tests/check-qint.o libqemuutil.a tests/check-qstring$(EXESUF): tests/check-qstring.o libqemuutil.a tests/check-qdict$(EXESUF): tests/check-qdict.o libqemuutil.a
Signature · 1 line
1.9.3
PATCH v2 4/7 tests: Add unit test for X86CPU code
In reply to Eduardo HabkostThe unit test includes target-i386/cpu.c instead of simply linking against cpu.o because the test code will use static variables/functions from cpu.c.
Reasoning for each object file included in the test binary:
* qom/cpu.o - for TYPE_CPU. Dependencies:
* qom/qom-qobject.o
* qom/qdev.o - for TYPE_DEVICE. Dependencies:
* qom/container.o
* vmstate.o. Dependencies:
* qemu-file.o
* hw/core/hotplug.o
* hw/core/irq.o
* hw/core/fw-path-provider.o
* hw/core/qdev-properties.o
* qom/object.o - for TYPE_OBJECT
* x86_64-softmmu/target-i386/machine.o - for vmstate_x86_cpu
* qemu-log.o - for the logging API, used by target-i386/cpu.c
* libqemuutil.a - for QAPI visitors, error API, and other symbols
* libqemustub.a - existing stubs, including: savevm, monitor symbols
The remaining symbols used by target-i386/cpu.c were added as stubs to either tests/vl-stub.c and tests/x86-stub.c.
Note: I couldn't add dependencies that ensure the target-specific object files are compiled on demand when building the test binary, but "make check" already requires "make" to be run first because of the qtest test cases, so I assume this is OK.
---
Changes v1 -> v2:
* Don't include cpus.o on test binary, making lots of stubs now unnecessary
--- tests/.gitignore | 1 + tests/Makefile | 15 ++++- tests/test-x86-cpu.c | 44 ++++++++++++++ tests/vl-stub.c | 15 +++++ tests/x86-stub.c | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 tests/test-x86-cpu.c create mode 100644 tests/vl-stub.c create mode 100644 tests/x86-stub.c
tests/.gitignore +1 -0
@@ -35,5 +35,6 @@ test-visitor-serialization test-vmstate test-x86-cpuid test-xbzrle +test-x86-cpu *-test qapi-schema/*.test.*
tests/Makefile +14 -1
@@ -64,6 +64,7 @@ gcov-files-check-qom-interface-y = qom/object.c check-unit-$(CONFIG_POSIX) += tests/test-vmstate$(EXESUF) check-unit-y += tests/test-qemu-opts$(EXESUF) gcov-files-test-qemu-opts-y = qom/test-qemu-opts.c +check-unit-x86_64-softmmu-y += tests/test-x86-cpu$(EXESUF) check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
@@ -224,7 +225,8 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \ tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \ tests/test-opts-visitor.o tests/test-qmp-event.o -test-obj-x86_64-softmmu-y = tests/test-x86-cpuid.o +test-obj-x86_64-softmmu-y = tests/test-x86-cpuid.o \ + tests/test-x86-cpu.o tests/x86-stub.o test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \ tests/test-qapi-event.o
@@ -352,6 +354,17 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y) 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-x86-cpu$(EXESUF): tests/test-x86-cpu.o \ + x86_64-softmmu/target-i386/machine.o \ + qom/cpu.o \ + qom/object.o qom/qom-qobject.o qom/container.o \ + hw/core/qdev.o hw/core/qdev-properties.o \ + hw/core/hotplug.o hw/core/irq.o hw/core/fw-path-provider.o \ + vmstate.o qemu-file.o \ + qemu-log.o \ + libqemuutil.a \ + libqemustub.a \ + tests/vl-stub.o tests/x86-stub.o tests/coroutine-stub.o ifeq ($(CONFIG_POSIX),y) LIBS += -lutil
tests/test-x86-cpu.c new file +44 -0
44 lines not on this page · raw message
tests/vl-stub.c new file +15 -0
@@ -0,0 +1,15 @@ +#include "sysemu/sysemu.h" +#include "sysemu/kvm.h" +#include "hw/hw.h" +#include "hw/hw.h" + +int smp_cpus =1 ; +int smp_cores =1 ; +int smp_threads =1 ; +bool xen_allowed; + +bool tcg_enabled (void ) +{ +return !kvm_allowed && !xen_allowed; +} +
tests/x86-stub.c new file +163 -0
163 lines not on this page · raw message
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH v2 4/7] tests: Add unit test for X86CPU code
Il 30/09/2014 20:26, Eduardo Habkost ha scritto:
Quoted 17 lines
Reasoning for each object file included in the test binary:
*qom/cpu.o- forTYPE_CPU. Dependencies:
*qom/qom-qobject.o
*qom/qdev.o- forTYPE_DEVICE. Dependencies:
*qom/container.o
* vmstate.o. Dependencies:
* qemu-file.o
*hw/core/hotplug.o
*hw/core/irq.o
*hw/core/fw-path-provider.o
*hw/core/qdev-properties.o
*qom/object.o- forTYPE_OBJECT
*x86_64-softmmu/target-i386/machine.o- forvmstate_x86_cpu
* qemu-log.o - for the logging API, used bytarget-i386/cpu.c
* libqemuutil.a - for QAPI visitors, error API, and other symbols
* libqemustub.a - existing stubs, including: savevm, monitor symbols
Quoted 2 lines
The remaining symbols used by
target-i386/cpu.cwere added as stubs to eithertests/vl-stub.candtests/x86-stub.c.
Nice. Luckily qemu-log.o doesn't bring in everything.
I think vl-stub.c has to be re-evaluated after your QOM accelerator patch goes in.
tests/x86-stub.c perhaps can be moved to target-i386/test-stubs.c?
Paolo
Re: [Qemu-devel] [PATCH v2 4/7] tests: Add unit test for X86CPU code
Quoted 21 lines · Paolo Bonzini
Il 30/09/2014 20:26, Eduardo Habkost ha scritto:
Quoted 17 lines
Reasoning for each object file included in the test binary:
*qom/cpu.o- forTYPE_CPU. Dependencies:
*qom/qom-qobject.o
*qom/qdev.o- forTYPE_DEVICE. Dependencies:
*qom/container.o
* vmstate.o. Dependencies:
* qemu-file.o
*hw/core/hotplug.o
*hw/core/irq.o
*hw/core/fw-path-provider.o
*hw/core/qdev-properties.o
*qom/object.o- forTYPE_OBJECT
*x86_64-softmmu/target-i386/machine.o- forvmstate_x86_cpu
* qemu-log.o - for the logging API, used bytarget-i386/cpu.c
* libqemuutil.a - for QAPI visitors, error API, and other symbols
* libqemustub.a - existing stubs, including: savevm, monitor symbolsQuoted 2 lines
The remaining symbols used by
target-i386/cpu.cwere added as stubs to eithertests/vl-stub.candtests/x86-stub.c.
Quoted 6 lines
Nice. Luckily qemu-log.o doesn't bring in everything.
I think
vl-stub.chas to be re-evaluated after your QOM accelerator patch goes in.
tests/x86-stub.cperhaps can be moved totarget-i386/test-stubs.c?
I was trying to keep all test code inside tests/. But perhaps all the target-specific test code (including test-x86-cpu.c) could be moved to target directories, and we could build/run the target-specific test cases from Makefile.target. That should simplify some of the logic I have added, and fix the build dependency problem I mentioned in the patch description.
Signature · 1 line
Eduardo
Re: [Qemu-devel] [PATCH v2 4/7] tests: Add unit test for X86CPU code
Il 01/10/2014 18:28, Eduardo Habkost ha scritto:
Quoted 7 lines
Quoted 1 line
Quoted 1 line
tests/x86-stub.cperhaps can be moved totarget-i386/test-stubs.c?I was trying to keep all test code inside tests/. But perhaps all the target-specific test code (including
test-x86-cpu.c) could be moved to target directories, and we could build/run the target-specific test cases from Makefile.target. That should simplify some of the logic I have added, and fix the build dependency problem I mentioned in the patch description.
In the end that's just bikeshedding. Sooner or later we'll have to organize tests/ in subdirectories, but it's probably early enough that we may not care yet. tests/x86-stub.c be it.
Paolo
PATCH v2 5/7 target-i386: Isolate enabled-by-default features to a separate array
In reply to Eduardo HabkostThis will make it easier to write unit tests for the feature initialization logic.
--- target-i386/cpu.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
target-i386/cpu.c +8 -4
@@ -464,6 +464,11 @@ static uint32_t kvm_default_unset_features[FEATURE_WORDS] = { [FEAT_1_ECX] = CPUID_EXT_MONITOR, }; +/* Features that are added by default to all CPU models in any accelerator: */ +FeatureWordArray default_features_all = { + [FEAT_1_ECX ] =CPUID_EXT_HYPERVISOR , +}; +void x86_cpu_compat_disable_kvm_features (FeatureWord w,uint32_t features) { kvm_default_features[w] &= ~features;
@@ -1993,15 +1998,14 @@ static void x86_cpu_load_def(X86CPU *cpu, X86CPUDefinition *def, Error **errp) }/* Special cases not set in the X86CPUDefinition structs: */ -if (kvm_enabled ()) { -FeatureWord w; -for (w =0 ; w <FEATURE_WORDS ; w++) { +for (w =0 ; w <FEATURE_WORDS ; w++) { +if (kvm_enabled ()) { env->features[w] |= kvm_default_features[w]; env->features[w] &= ~kvm_default_unset_features[w]; } + env->features[w] |= default_features_all[w]; } - env->features[FEAT_1_ECX ] |=CPUID_EXT_HYPERVISOR ;/* sysenter isn't supported in compatibility mode on AMD, * syscall isn't supported in compatibility mode on Intel.
Signature · 1 line
1.9.3
PATCH v2 6/7 tests: test-x86-cpu: Add TCG feature bit initialization test
In reply to Eduardo Habkost--- tests/test-x86-cpu.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
tests/test-x86-cpu.c +25 -0
@@ -30,6 +30,30 @@ static void test_cpu_creation(void) } } +static void test_cpu_features_tcg (void ) +{ +int i; +for (i =0 ; i <ARRAY_SIZE (builtin_x86_defs); ++i) { +FeatureWord w; +ObjectClass *oc; +X86CPU *cpu; +Error *error =NULL ; +X86CPUDefinition *def = &builtin_x86_defs[i]; +char features[] ="" ; + + oc =x86_cpu_class_by_name (def->name); + cpu =X86_CPU (object_new (object_class_get_name (oc))); +x86_cpu_parse_featurestr (CPU (cpu), features, &error); + +for (w =0 ; w <FEATURE_WORDS ; w++) { +uint32_t expected = def->features[w] | default_features_all[w]; +uint32_t actual = cpu->env.features[w] | cpu->filtered_features[w]; + g_assert_cmpint(actual, ==, expected); + } +object_unref (OBJECT (cpu)); + } +} +int main (int argc,char *argv[]) {module_call_init (MODULE_INIT_QOM );
@@ -37,6 +61,7 @@ int main(int argc, char *argv[])g_test_init (&argc, &argv,NULL );g_test_add_func ("/cpu/x86/creation" , test_cpu_creation); +g_test_add_func ("/cpu/x86/features/tcg" , test_cpu_features_tcg);g_test_run ();
Signature · 1 line
1.9.3
PATCH v2 7/7 tests: test-x86-cpu: Add KVM feature bit initialization test
In reply to Eduardo Habkost--- tests/test-x86-cpu.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
tests/test-x86-cpu.c +28 -0
@@ -54,6 +54,33 @@ static void test_cpu_features_tcg(void) } } +static void test_cpu_features_kvm (void ) +{ +int i; + kvm_allowed = true; +for (i =0 ; i <ARRAY_SIZE (builtin_x86_defs); ++i) { +FeatureWord w; +ObjectClass *oc; +X86CPU *cpu; +Error *error =NULL ; +X86CPUDefinition *def = &builtin_x86_defs[i]; +char features[] ="" ; + + oc =x86_cpu_class_by_name (def->name); + cpu =X86_CPU (object_new (object_class_get_name (oc))); +x86_cpu_parse_featurestr (CPU (cpu), features, &error); + +for (w =0 ; w <FEATURE_WORDS ; w++) { +uint32_t expected = def->features[w] | default_features_all[w]; +uint32_t actual = cpu->env.features[w] | cpu->filtered_features[w]; + expected |= kvm_default_features[w]; + expected &= ~kvm_default_unset_features[w]; + g_assert_cmpint(actual, ==, expected); + } +object_unref (OBJECT (cpu)); + } +} +int main (int argc,char *argv[]) {module_call_init (MODULE_INIT_QOM );
@@ -62,6 +89,7 @@ int main(int argc, char *argv[])g_test_add_func ("/cpu/x86/creation" , test_cpu_creation);g_test_add_func ("/cpu/x86/features/tcg" , test_cpu_features_tcg); +g_test_add_func ("/cpu/x86/features/kvm" , test_cpu_features_kvm);g_test_run ();
Signature · 1 line
1.9.3