* [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h
2014-12-10 19:26 [Qemu-devel] [PATCH v3 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
@ 2014-12-10 19:26 ` Eduardo Habkost
2014-12-10 19:44 ` Peter Maydell
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 2/7] tests: Support target-specific unit tests Eduardo Habkost
` (5 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Eduardo Habkost @ 2014-12-10 19:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Igor Mammedov
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
exec.c | 1 -
hw/virtio/virtio.c | 1 -
include/exec/exec-all.h | 2 ++
3 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/exec.c b/exec.c
index 71ac104..6666ed5 100644
--- a/exec.c
+++ b/exec.c
@@ -2845,7 +2845,6 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
* A helper function for the _utterly broken_ virtio device model to find out if
* it's running on a big endian machine. Don't do this at home kids!
*/
-bool target_words_bigendian(void);
bool target_words_bigendian(void)
{
#if defined(TARGET_WORDS_BIGENDIAN)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 013979a..9df248d 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -552,7 +552,6 @@ void virtio_set_status(VirtIODevice *vdev, uint8_t val)
vdev->status = val;
}
-bool target_words_bigendian(void);
static enum virtio_device_endian virtio_default_endian(void)
{
if (target_words_bigendian()) {
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 0844885..d8ca313 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -383,4 +383,6 @@ static inline bool cpu_can_do_io(CPUState *cpu)
return cpu->can_do_io != 0;
}
+bool target_words_bigendian(void);
+
#endif
--
1.9.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h Eduardo Habkost
@ 2014-12-10 19:44 ` Peter Maydell
2014-12-12 18:20 ` Eduardo Habkost
0 siblings, 1 reply; 12+ messages in thread
From: Peter Maydell @ 2014-12-10 19:44 UTC (permalink / raw)
To: Eduardo Habkost; +Cc: Paolo Bonzini, QEMU Developers, Igor Mammedov
On 10 December 2014 at 19:26, Eduardo Habkost <ehabkost@redhat.com> wrote:
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> exec.c | 1 -
> hw/virtio/virtio.c | 1 -
> include/exec/exec-all.h | 2 ++
> 3 files changed, 2 insertions(+), 2 deletions(-)
I thought this prototype was deliberately not in a generally
included header file because it's really not something that
should be needed by most code. If we do want to move it into
a header then we definitely don't want it in exec-all.h.
thanks
-- PMM
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h
2014-12-10 19:44 ` Peter Maydell
@ 2014-12-12 18:20 ` Eduardo Habkost
2014-12-15 9:30 ` Thomas Huth
2014-12-15 10:17 ` Greg Kurz
0 siblings, 2 replies; 12+ messages in thread
From: Eduardo Habkost @ 2014-12-12 18:20 UTC (permalink / raw)
To: Peter Maydell
Cc: Paolo Bonzini, Michael S. Tsirkin, QEMU Developers, Igor Mammedov
On Wed, Dec 10, 2014 at 07:44:04PM +0000, Peter Maydell wrote:
> On 10 December 2014 at 19:26, Eduardo Habkost <ehabkost@redhat.com> wrote:
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> > exec.c | 1 -
> > hw/virtio/virtio.c | 1 -
> > include/exec/exec-all.h | 2 ++
> > 3 files changed, 2 insertions(+), 2 deletions(-)
>
> I thought this prototype was deliberately not in a generally
> included header file because it's really not something that
> should be needed by most code. If we do want to move it into
> a header then we definitely don't want it in exec-all.h.
I have no idea what would be the best place for the prototype, then.
CCing the people who introduced the function, in case they have any
suggestion.
Anyway, I don't want to make this series depend on dealing with the
virtio default-endianness mess, so in the next version I will drop this
patch and simply put the prototype inside tests/x86-stub.c.
--
Eduardo
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h
2014-12-12 18:20 ` Eduardo Habkost
@ 2014-12-15 9:30 ` Thomas Huth
2014-12-15 10:17 ` Greg Kurz
1 sibling, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2014-12-15 9:30 UTC (permalink / raw)
To: Eduardo Habkost
Cc: Peter Maydell, Igor Mammedov, Michael S. Tsirkin, QEMU Developers,
Paolo Bonzini
On Fri, 12 Dec 2014 16:20:16 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:
> On Wed, Dec 10, 2014 at 07:44:04PM +0000, Peter Maydell wrote:
> > On 10 December 2014 at 19:26, Eduardo Habkost <ehabkost@redhat.com> wrote:
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > > exec.c | 1 -
> > > hw/virtio/virtio.c | 1 -
> > > include/exec/exec-all.h | 2 ++
> > > 3 files changed, 2 insertions(+), 2 deletions(-)
> >
> > I thought this prototype was deliberately not in a generally
> > included header file because it's really not something that
> > should be needed by most code. If we do want to move it into
> > a header then we definitely don't want it in exec-all.h.
>
> I have no idea what would be the best place for the prototype, then.
Maybe include/qemu/bswap.h ?
Thomas
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h
2014-12-12 18:20 ` Eduardo Habkost
2014-12-15 9:30 ` Thomas Huth
@ 2014-12-15 10:17 ` Greg Kurz
1 sibling, 0 replies; 12+ messages in thread
From: Greg Kurz @ 2014-12-15 10:17 UTC (permalink / raw)
To: Eduardo Habkost
Cc: Peter Maydell, Igor Mammedov, Michael S. Tsirkin, QEMU Developers,
Paolo Bonzini
On Fri, 12 Dec 2014 16:20:16 -0200
Eduardo Habkost <ehabkost@redhat.com> wrote:
> On Wed, Dec 10, 2014 at 07:44:04PM +0000, Peter Maydell wrote:
> > On 10 December 2014 at 19:26, Eduardo Habkost <ehabkost@redhat.com> wrote:
> > > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > > ---
> > > exec.c | 1 -
> > > hw/virtio/virtio.c | 1 -
> > > include/exec/exec-all.h | 2 ++
> > > 3 files changed, 2 insertions(+), 2 deletions(-)
> >
> > I thought this prototype was not in a generally
> > included header file because it's really not something that
> > should be needed by most code. If we do want to move it into
> > a header then we definitely don't want it in exec-all.h.
>
> I have no idea what would be the best place for the prototype, then.
> CCing the people who introduced the function, in case they have any
> suggestion.
>
> Anyway, I don't want to make this series depend on dealing with the
> virtio default-endianness mess, so in the next version I will drop this
> patch and simply put the prototype inside tests/x86-stub.c.
>
Indeed, this function is part of the legacy virtio endianness mess. And
Peter's remark is true: the prototype was deliberately kept hidden since
no code should need it except virtio.
There are two users and this isn't likely to change (except when everyone
will have switched to virtio-1 and we drop all the legacy virtio hacks):
- virtio_default_endian() in hw/virtio/virtio.c
- cpu_common_virtio_is_big_endian() in qom/cpu.c
I don't think it is worth moving the prototype to a common header file.
Perhaps a comment saying "this is a legacy virtio hack that should
stay hidden" would be more appropriate.
--
Greg
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v3 2/7] tests: Support target-specific unit tests
2014-12-10 19:26 [Qemu-devel] [PATCH v3 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h Eduardo Habkost
@ 2014-12-10 19:26 ` Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 3/7] tests: Make test-x86-cpuid target-specific Eduardo Habkost
` (4 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Eduardo Habkost @ 2014-12-10 19:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Igor Mammedov
To 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).
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
tests/Makefile | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index 16f0e4c..85ac430 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -356,12 +356,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
@@ -393,8 +408,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))} \
@@ -417,7 +432,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 $@")
@@ -426,7 +441,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
@@ -460,7 +475,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
--
1.9.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v3 3/7] tests: Make test-x86-cpuid target-specific
2014-12-10 19:26 [Qemu-devel] [PATCH v3 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 1/7] Move target_words_bigendian() prototype to exec-all.h Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 2/7] tests: Support target-specific unit tests Eduardo Habkost
@ 2014-12-10 19:26 ` Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 4/7] tests: Add unit test for X86CPU code Eduardo Habkost
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Eduardo Habkost @ 2014-12-10 19:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Igor Mammedov
Instead of using a test-specific hack to add -I$(SRC_PATH)/target-i386, add
test-x86-cpuid to $(test-obj-x86_64-softmmu-y).
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
tests/Makefile | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tests/Makefile b/tests/Makefile
index 85ac430..f918350 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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)
@@ -223,6 +223,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
@@ -230,8 +232,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
--
1.9.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v3 4/7] tests: Add unit test for X86CPU code
2014-12-10 19:26 [Qemu-devel] [PATCH v3 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
` (2 preceding siblings ...)
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 3/7] tests: Make test-x86-cpuid target-specific Eduardo Habkost
@ 2014-12-10 19:26 ` Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 5/7] target-i386: Isolate enabled-by-default features to a separate array Eduardo Habkost
` (2 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Eduardo Habkost @ 2014-12-10 19:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Igor Mammedov
The 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.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
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 | 68 +++++++++++++++++++++
tests/vl-stub.c | 15 +++++
tests/x86-stub.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 262 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
diff --git a/tests/.gitignore b/tests/.gitignore
index e2e4957..07f903e 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -35,5 +35,6 @@ test-visitor-serialization
test-vmstate
test-x86-cpuid
test-xbzrle
+test-x86-cpu
*-test
qapi-schema/*.test.*
diff --git a/tests/Makefile b/tests/Makefile
index f918350..842cf68 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -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
@@ -223,7 +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-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
@@ -351,6 +353,17 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o $(libqos-usb-obj-y)
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
ifeq ($(CONFIG_POSIX),y)
LIBS += -lutil
diff --git a/tests/test-x86-cpu.c b/tests/test-x86-cpu.c
new file mode 100644
index 0000000..b6e4382
--- /dev/null
+++ b/tests/test-x86-cpu.c
@@ -0,0 +1,68 @@
+#include <glib.h>
+
+#include "cpu.c"
+
+
+/* stub to avoid requiring hw/intc/apic.o */
+void apic_poll_irq(DeviceState *dev)
+{
+}
+
+/* Special test modes where everything will be supported/unsupported */
+static bool all_supported;
+static bool all_unsupported;
+
+/* Fake get_supported_cpuid() which will just return as hash of
+ * function/index/reg. Use a (somewhat poor) hash function to do that.
+ */
+static uint32_t fake_cpuid(uint32_t function, uint32_t index, int reg)
+{
+ uint64_t i = (uint64_t)function * 16ULL * 4ULL + (uint64_t)index * 4 + reg;
+ return i * 2654435761ULL;
+}
+
+uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
+ uint32_t index, int reg)
+{
+ if (all_supported) {
+ return ~0;
+ } else if (all_unsupported) {
+ return 0;
+ }
+ return fake_cpuid(function, index, reg);
+}
+
+static void test_cpu_creation(void)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(builtin_x86_defs); ++i) {
+ ObjectClass *oc;
+ X86CPUClass *xcc;
+ X86CPU *cpu;
+ Error *error = NULL;
+ X86CPUDefinition *def = &builtin_x86_defs[i];
+ char features[] = "";
+
+ oc = x86_cpu_class_by_name(def->name);
+ g_assert_true(oc);
+ xcc = X86_CPU_CLASS(oc);
+ g_assert_true(xcc);
+ cpu = X86_CPU(object_new(object_class_get_name(oc)));
+ x86_cpu_parse_featurestr(CPU(cpu), features, &error);
+ g_assert(!error);
+ object_unref(OBJECT(cpu));
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ module_call_init(MODULE_INIT_QOM);
+
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/cpu/x86/creation", test_cpu_creation);
+
+ g_test_run();
+
+ return 0;
+}
diff --git a/tests/vl-stub.c b/tests/vl-stub.c
new file mode 100644
index 0000000..32085aa
--- /dev/null
+++ b/tests/vl-stub.c
@@ -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;
+}
+
diff --git a/tests/x86-stub.c b/tests/x86-stub.c
new file mode 100644
index 0000000..f8fbc65
--- /dev/null
+++ b/tests/x86-stub.c
@@ -0,0 +1,164 @@
+/* Stub functions for target-specific code (target-i386 files, cpu-exec.c,
+ * exec.c, etc.) */
+#include "target-i386/cpu.h"
+#include "target-i386/cpu-qom.h"
+#include "target-i386/kvm_i386.h"
+#include "exec/exec-all.h"
+#include "sysemu/kvm.h"
+#include "exec/gdbstub.h"
+
+struct CPUTailQ cpus = QTAILQ_HEAD_INITIALIZER(cpus);
+
+void cpu_exec_init(CPUArchState *env)
+{
+}
+
+void kvm_arch_reset_vcpu(X86CPU *cpu)
+{
+}
+
+void optimize_flags_init(void)
+{
+}
+
+void x86_cpu_do_interrupt(CPUState *cs)
+{
+ abort();
+}
+
+bool x86_cpu_exec_interrupt(CPUState *cs, int interrupt_request)
+{
+ abort();
+}
+
+void x86_cpu_exec_enter(CPUState *cs)
+{
+ abort();
+}
+
+void x86_cpu_exec_exit(CPUState *cs)
+{
+ abort();
+}
+
+void x86_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
+ int flags)
+{
+ abort();
+}
+
+int x86_cpu_gdb_read_register(CPUState *cs, uint8_t *mem_buf, int n)
+{
+ abort();
+}
+
+int x86_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
+{
+ abort();
+}
+
+int x86_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
+ int cpuid, void *opaque)
+{
+ abort();
+}
+
+int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cs,
+ void *opaque)
+{
+ abort();
+}
+
+
+int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
+ int cpuid, void *opaque)
+{
+ abort();
+}
+
+int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cs,
+ void *opaque)
+{
+ abort();
+}
+
+void x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list,
+ Error **errp)
+{
+ abort();
+}
+
+hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
+{
+ abort();
+}
+
+void hw_breakpoint_insert(CPUX86State *env, int index)
+{
+ abort();
+}
+
+void cpu_breakpoint_remove_all(CPUState *cpu, int mask)
+{
+ abort();
+}
+
+void cpu_watchpoint_remove_all(CPUState *cpu, int mask)
+{
+ abort();
+}
+
+void breakpoint_handler(CPUState *cs)
+{
+ abort();
+}
+
+void tlb_flush(CPUState *cpu, int flush_global)
+{
+ abort();
+}
+
+void cpu_x86_update_cr0(CPUX86State *env, uint32_t new_cr0)
+{
+ abort();
+}
+
+void cpu_set_fpuc(CPUX86State *env, uint16_t val)
+{
+ abort();
+}
+
+void update_fp_status(CPUX86State *env)
+{
+ abort();
+}
+
+void cpu_get_fp80(uint64_t *pmant, uint16_t *pexp, floatx80 f)
+{
+ abort();
+}
+
+floatx80 cpu_set_fp80(uint64_t mant, uint16_t upper)
+{
+ abort();
+}
+
+uint64_t cpu_get_apic_base(DeviceState *dev)
+{
+ abort();
+}
+
+void apic_designate_bsp(DeviceState *dev)
+{
+ abort();
+}
+
+bool target_words_bigendian(void)
+{
+ return false;
+}
+
+/* Include kvm-stub.c here instead of linking against kvm-stub.o because
+ * kvm-stub.o is built only if CONFIG_KVM is disabled
+ */
+#include "kvm-stub.c"
--
1.9.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v3 5/7] target-i386: Isolate enabled-by-default features to a separate array
2014-12-10 19:26 [Qemu-devel] [PATCH v3 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
` (3 preceding siblings ...)
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 4/7] tests: Add unit test for X86CPU code Eduardo Habkost
@ 2014-12-10 19:26 ` Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 6/7] tests: test-x86-cpu: Add TCG feature bit initialization test Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 7/7] tests: test-x86-cpu: Add KVM " Eduardo Habkost
6 siblings, 0 replies; 12+ messages in thread
From: Eduardo Habkost @ 2014-12-10 19:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Igor Mammedov
This will make it easier to write unit tests for the feature
initialization logic.
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
target-i386/cpu.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/target-i386/cpu.c b/target-i386/cpu.c
index e9df33e..b6b3c4f 100644
--- a/target-i386/cpu.c
+++ b/target-i386/cpu.c
@@ -464,6 +464,11 @@ static uint32_t kvm_default_unset_features[FEATURE_WORDS] = {
[FEAT_8000_0001_ECX] = CPUID_EXT3_SVM,
};
+/* 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_kvm_no_autoenable(FeatureWord w, uint32_t features)
{
kvm_default_features[w] &= ~features;
@@ -2005,15 +2010,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.
--
1.9.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v3 6/7] tests: test-x86-cpu: Add TCG feature bit initialization test
2014-12-10 19:26 [Qemu-devel] [PATCH v3 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
` (4 preceding siblings ...)
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 5/7] target-i386: Isolate enabled-by-default features to a separate array Eduardo Habkost
@ 2014-12-10 19:26 ` Eduardo Habkost
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 7/7] tests: test-x86-cpu: Add KVM " Eduardo Habkost
6 siblings, 0 replies; 12+ messages in thread
From: Eduardo Habkost @ 2014-12-10 19:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Igor Mammedov
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
tests/test-x86-cpu.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/tests/test-x86-cpu.c b/tests/test-x86-cpu.c
index b6e4382..fb3de05 100644
--- a/tests/test-x86-cpu.c
+++ b/tests/test-x86-cpu.c
@@ -54,6 +54,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);
@@ -61,6 +85,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();
--
1.9.3
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [Qemu-devel] [PATCH v3 7/7] tests: test-x86-cpu: Add KVM feature bit initialization test
2014-12-10 19:26 [Qemu-devel] [PATCH v3 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
` (5 preceding siblings ...)
2014-12-10 19:26 ` [Qemu-devel] [PATCH v3 6/7] tests: test-x86-cpu: Add TCG feature bit initialization test Eduardo Habkost
@ 2014-12-10 19:26 ` Eduardo Habkost
6 siblings, 0 replies; 12+ messages in thread
From: Eduardo Habkost @ 2014-12-10 19:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Paolo Bonzini, Igor Mammedov
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
tests/test-x86-cpu.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/tests/test-x86-cpu.c b/tests/test-x86-cpu.c
index fb3de05..20842c5 100644
--- a/tests/test-x86-cpu.c
+++ b/tests/test-x86-cpu.c
@@ -78,6 +78,94 @@ 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] |
+ kvm_default_features[w]) &
+ ~kvm_default_unset_features[w];
+ uint32_t actual = cpu->env.features[w] | cpu->filtered_features[w];
+ g_assert_cmpint(actual, ==, expected);
+ /*TODO: test this after moving feature filtering outside realizefn:
+ uint32_t expect_filtered = expected &
+ ~x86_cpu_get_supported_feature_word(w, true);
+ g_assert_cmpint(cpu->filtered_features[w], ==, expect_filtered);
+ */
+ }
+ object_unref(OBJECT(cpu));
+ }
+}
+
+static void test_host_cpu_features_kvm(void)
+{
+ FeatureWord w;
+ ObjectClass *oc;
+ X86CPU *cpu;
+ Error *error = NULL;
+ char features1[] = "migratable=off";
+ char features2[] = "migratable=off";
+ char features3[] = "migratable=off";
+
+ kvm_allowed = true;
+ oc = x86_cpu_class_by_name("host");
+
+ /* fake_cpuid() test mode: */
+ cpu = X86_CPU(object_new(object_class_get_name(oc)));
+ x86_cpu_parse_featurestr(CPU(cpu), features1, &error);
+
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ FeatureWordInfo *wi = &feature_word_info[w];
+ uint32_t expected = fake_cpuid(wi->cpuid_eax, wi->cpuid_ecx,
+ wi->cpuid_reg);
+ uint32_t actual = cpu->env.features[w];
+ g_assert_cmpint(cpu->filtered_features[w], ==, 0);
+ g_assert_cmpint(actual, ==, expected);
+ }
+ object_unref(OBJECT(cpu));
+
+ /* all-supported test mode: */
+ all_supported = true;
+ cpu = X86_CPU(object_new(object_class_get_name(oc)));
+ x86_cpu_parse_featurestr(CPU(cpu), features2, &error);
+
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ uint32_t expected = ~0;
+ uint32_t actual = cpu->env.features[w];
+ g_assert_cmpint(cpu->filtered_features[w], ==, 0);
+ g_assert_cmpint(actual, ==, expected);
+ }
+ object_unref(OBJECT(cpu));
+
+ /* all-unsupported test mode: */
+ all_supported = false;
+ all_unsupported = true;
+ cpu = X86_CPU(object_new(object_class_get_name(oc)));
+ x86_cpu_parse_featurestr(CPU(cpu), features3, &error);
+
+ for (w = 0; w < FEATURE_WORDS; w++) {
+ uint32_t expected = 0;
+ uint32_t actual = cpu->env.features[w];
+ g_assert_cmpint(cpu->filtered_features[w], ==, 0);
+ g_assert_cmpint(actual, ==, expected);
+ }
+ object_unref(OBJECT(cpu));
+ all_unsupported = false;
+}
+
int main(int argc, char *argv[])
{
module_call_init(MODULE_INIT_QOM);
@@ -86,6 +174,8 @@ 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_add_func("/cpu/x86/features/host", test_host_cpu_features_kvm);
g_test_run();
--
1.9.3
^ permalink raw reply related [flat|nested] 12+ messages in thread