qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code
@ 2014-09-25 20:18 Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 01/10] tests: Add missing include to test-bitops.c Eduardo Habkost
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

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.

Eduardo Habkost (10):
  tests: Add missing include to test-bitops.c
  bitops.h: Don't include qemu-common.h
  bitmap.h: Don't include qemu-common.h
  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

 include/qemu/bitmap.h  |   5 +-
 include/qemu/bitops.h  |   4 +-
 target-i386/cpu.c      |  12 ++--
 tests/.gitignore       |   1 +
 tests/Makefile         |  48 ++++++++++---
 tests/aio-stub.c       |  20 ++++++
 tests/block-stub.c     |  11 +++
 tests/coroutine-stub.c |  13 ++++
 tests/monitor-stub.c   |  34 +++++++++
 tests/test-bitops.c    |   1 +
 tests/test-vmstate.c   |  11 ---
 tests/test-x86-cpu.c   |  97 ++++++++++++++++++++++++++
 tests/timer-stub.c     |  65 +++++++++++++++++
 tests/vl-stub.c        |  45 ++++++++++++
 tests/x86-stub.c       | 186 +++++++++++++++++++++++++++++++++++++++++++++++++
 15 files changed, 525 insertions(+), 28 deletions(-)
 create mode 100644 tests/aio-stub.c
 create mode 100644 tests/block-stub.c
 create mode 100644 tests/coroutine-stub.c
 create mode 100644 tests/monitor-stub.c
 create mode 100644 tests/test-x86-cpu.c
 create mode 100644 tests/timer-stub.c
 create mode 100644 tests/vl-stub.c
 create mode 100644 tests/x86-stub.c

-- 
1.9.3

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Qemu-devel] [RFC 01/10] tests: Add missing include to test-bitops.c
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 02/10] bitops.h: Don't include qemu-common.h Eduardo Habkost
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

The test code needs osdep.h for the ARRAY_SIZE macro.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/test-bitops.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tests/test-bitops.c b/tests/test-bitops.c
index 8238eb5..47b5d3e 100644
--- a/tests/test-bitops.c
+++ b/tests/test-bitops.c
@@ -8,6 +8,7 @@
 
 #include <glib.h>
 #include <stdint.h>
+#include "qemu/osdep.h"
 #include "qemu/bitops.h"
 
 typedef struct {
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [RFC 02/10] bitops.h: Don't include qemu-common.h
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 01/10] tests: Add missing include to test-bitops.c Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 03/10] bitmap.h: " Eduardo Habkost
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

This removes the following circular dependency:

bitops.h -> qemu-common.h -> target-i386/cpu.h -> target-i386/cpu-qom.h ->
qom/cpu.h -> qdev-core.h -> bitmap.h -> bitops.h.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/qemu/bitops.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h
index 7e2d5c9..181bd46 100644
--- a/include/qemu/bitops.h
+++ b/include/qemu/bitops.h
@@ -12,7 +12,9 @@
 #ifndef BITOPS_H
 #define BITOPS_H
 
-#include "qemu-common.h"
+#include <stdint.h>
+#include <assert.h>
+
 #include "host-utils.h"
 
 #define BITS_PER_BYTE           CHAR_BIT
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [RFC 03/10] bitmap.h: Don't include qemu-common.h
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 01/10] tests: Add missing include to test-bitops.c Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 02/10] bitops.h: Don't include qemu-common.h Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 04/10] tests: Move fake yield_until_fd_readable() to coroutine-stub.c Eduardo Habkost
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

This will avoid unexpected circular header dependencies in the future.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 include/qemu/bitmap.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/qemu/bitmap.h b/include/qemu/bitmap.h
index 1babd5d..8c50d70 100644
--- a/include/qemu/bitmap.h
+++ b/include/qemu/bitmap.h
@@ -12,7 +12,10 @@
 #ifndef BITMAP_H
 #define BITMAP_H
 
-#include "qemu-common.h"
+#include <glib.h>
+#include <string.h>
+
+#include "qemu/osdep.h"
 #include "qemu/bitops.h"
 
 /*
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [RFC 04/10] tests: Move fake yield_until_fd_readable() to coroutine-stub.c
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
                   ` (2 preceding siblings ...)
  2014-09-25 20:18 ` [Qemu-devel] [RFC 03/10] bitmap.h: " Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 05/10] tests: Support target-specific unit tests Eduardo Habkost
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

Other test code will use the function.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 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

diff --git a/tests/Makefile b/tests/Makefile
index f5de29c..483ba61 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -258,6 +258,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
 
diff --git a/tests/coroutine-stub.c b/tests/coroutine-stub.c
new file mode 100644
index 0000000..8af58dd
--- /dev/null
+++ b/tests/coroutine-stub.c
@@ -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);
+}
diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c
index d72c64c..412634f 100644
--- a/tests/test-vmstate.c
+++ b/tests/test-vmstate.c
@@ -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)
 {
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [RFC 05/10] tests: Support target-specific unit tests
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
                   ` (3 preceding siblings ...)
  2014-09-25 20:18 ` [Qemu-devel] [RFC 04/10] tests: Move fake yield_until_fd_readable() to coroutine-stub.c Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 06/10] tests: Make test-x86-cpuid target-specific Eduardo Habkost
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

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 483ba61..95566d9 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] 13+ messages in thread

* [Qemu-devel] [RFC 06/10] tests: Make test-x86-cpuid target-specific
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
                   ` (4 preceding siblings ...)
  2014-09-25 20:18 ` [Qemu-devel] [RFC 05/10] tests: Support target-specific unit tests Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 07/10] tests: Add unit test for X86CPU code Eduardo Habkost
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

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 95566d9..f1d9907 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] 13+ messages in thread

* [Qemu-devel] [RFC 07/10] tests: Add unit test for X86CPU code
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
                   ` (5 preceding siblings ...)
  2014-09-25 20:18 ` [Qemu-devel] [RFC 06/10] tests: Make test-x86-cpuid target-specific Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 08/10] target-i386: Isolate enabled-by-default features to a separate array Eduardo Habkost
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

To allow the unit test file include target-i386/cpu.c code, lots of stub
functions were needed to fulfill dependencies.

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.

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>
---
 tests/.gitignore     |   1 +
 tests/Makefile       |  12 +++-
 tests/aio-stub.c     |  20 ++++++
 tests/block-stub.c   |  11 +++
 tests/monitor-stub.c |  34 ++++++++++
 tests/test-x86-cpu.c |  44 ++++++++++++
 tests/timer-stub.c   |  65 ++++++++++++++++++
 tests/vl-stub.c      |  45 +++++++++++++
 tests/x86-stub.c     | 186 +++++++++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 417 insertions(+), 1 deletion(-)
 create mode 100644 tests/aio-stub.c
 create mode 100644 tests/block-stub.c
 create mode 100644 tests/monitor-stub.c
 create mode 100644 tests/test-x86-cpu.c
 create mode 100644 tests/timer-stub.c
 create mode 100644 tests/vl-stub.c
 create mode 100644 tests/x86-stub.c

diff --git a/tests/.gitignore b/tests/.gitignore
index c71c110..6af66b4 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -32,5 +32,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 f1d9907..b563866 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,14 @@ 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 \
+	qemu-log.o \
+	qom/object.o qom/qom-qobject.o qom/cpu.o qom/container.o \
+	hw/core/qdev.o hw/core/qdev-properties.o hw/core/irq.o hw/core/fw-path-provider.o hw/core/hotplug.o \
+	vmstate.o qemu-file.o $(util-obj-y) \
+	x86_64-softmmu/cpus.o x86_64-softmmu/target-i386/machine.o \
+	tests/vl-stub.o tests/x86-stub.o tests/coroutine-stub.o tests/monitor-stub.o tests/aio-stub.o tests/timer-stub.o tests/block-stub.o \
+	stubs/reset.o stubs/sysbus.o stubs/vmstate.o stubs/fdset-remove-fd.o stubs/mon-printf.o stubs/qtest.o stubs/vm-stop.o
 
 ifeq ($(CONFIG_POSIX),y)
 LIBS += -lutil
diff --git a/tests/aio-stub.c b/tests/aio-stub.c
new file mode 100644
index 0000000..0b6b2d1
--- /dev/null
+++ b/tests/aio-stub.c
@@ -0,0 +1,20 @@
+#include "block/aio.h"
+#include "qemu/main-loop.h"
+
+int qemu_set_fd_handler(int fd,
+                        IOHandler *fd_read,
+                        IOHandler *fd_write,
+                        void *opaque)
+{
+    abort();
+}
+
+int qemu_set_fd_handler2(int fd,
+                         IOCanReadHandler *fd_read_poll,
+                         IOHandler *fd_read,
+                         IOHandler *fd_write,
+                         void *opaque)
+{
+    abort();
+}
+
diff --git a/tests/block-stub.c b/tests/block-stub.c
new file mode 100644
index 0000000..ef8f696
--- /dev/null
+++ b/tests/block-stub.c
@@ -0,0 +1,11 @@
+#include "block/block.h"
+
+void bdrv_drain_all(void)
+{
+    abort();
+}
+
+int bdrv_flush_all(void)
+{
+    abort();
+}
diff --git a/tests/monitor-stub.c b/tests/monitor-stub.c
new file mode 100644
index 0000000..b574b09
--- /dev/null
+++ b/tests/monitor-stub.c
@@ -0,0 +1,34 @@
+#include "monitor/monitor.h"
+
+Monitor *cur_mon;
+
+int monitor_cur_is_qmp(void)
+{
+    return 1;
+}
+
+void monitor_set_error(Monitor *mon, QError *qerror)
+{
+    abort();
+}
+
+int monitor_fdset_get_fd(int64_t fdset_id, int flags)
+{
+    abort();
+}
+
+int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd)
+{
+    abort();
+}
+
+int monitor_fdset_dup_fd_find(int dup_fd)
+{
+    abort();
+}
+
+int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
+{
+    abort();
+}
+
diff --git a/tests/test-x86-cpu.c b/tests/test-x86-cpu.c
new file mode 100644
index 0000000..9227e20
--- /dev/null
+++ b/tests/test-x86-cpu.c
@@ -0,0 +1,44 @@
+#include "cpu.c"
+
+#include <glib.h>
+
+uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,
+                                      uint32_t index, int reg)
+{
+    return 0;
+}
+
+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/timer-stub.c b/tests/timer-stub.c
new file mode 100644
index 0000000..9f7b473
--- /dev/null
+++ b/tests/timer-stub.c
@@ -0,0 +1,65 @@
+#include "qemu/timer.h"
+
+QEMUTimerListGroup main_loop_tlg;
+
+void timer_del(QEMUTimer *ts)
+{
+    abort();
+}
+
+void timer_free(QEMUTimer *ts)
+{
+    abort();
+}
+
+void timer_init(QEMUTimer *ts,
+                QEMUTimerList *timer_list, int scale,
+                QEMUTimerCB *cb, void *opaque)
+{
+    abort();
+}
+
+int64_t qemu_clock_get_ns(QEMUClockType type)
+{
+    abort();
+}
+
+bool timer_pending(QEMUTimer *ts)
+{
+    abort();
+}
+
+void timer_mod(QEMUTimer *ts, int64_t expire_time)
+{
+    abort();
+}
+
+bool qemu_clock_expired(QEMUClockType type)
+{
+    abort();
+}
+
+void qemu_clock_notify(QEMUClockType type)
+{
+    abort();
+}
+
+int64_t qemu_clock_deadline_ns_all(QEMUClockType type)
+{
+    abort();
+}
+
+bool qemu_clock_run_timers(QEMUClockType type)
+{
+    abort();
+}
+
+void qemu_clock_enable(QEMUClockType type, bool enabled)
+{
+    abort();
+}
+
+void timer_mod_anticipate(QEMUTimer *ts, int64_t expire_time)
+{
+    abort();
+}
diff --git a/tests/vl-stub.c b/tests/vl-stub.c
new file mode 100644
index 0000000..8de64e4
--- /dev/null
+++ b/tests/vl-stub.c
@@ -0,0 +1,45 @@
+#include "sysemu/sysemu.h"
+#include "sysemu/kvm.h"
+#include "hw/hw.h"
+#include "hw/hw.h"
+
+int nb_numa_nodes;
+int max_numa_nodeid;
+NodeInfo numa_info[MAX_NODES];
+int icount_align_option;
+bool xen_allowed;
+int smp_cpus = 1;
+int smp_cores = 1;
+int smp_threads = 1;
+
+
+int runstate_is_running(void)
+{
+    return 0;
+}
+
+void runstate_set(RunState new_state)
+{
+    abort();
+}
+
+void vm_state_notify(int running, RunState state)
+{
+    abort();
+}
+
+int qemu_boot_set(const char *boot_order)
+{
+    /* Not supposed to be called by test code */
+    abort();
+}
+
+bool tcg_enabled(void)
+{
+    return !kvm_allowed && !xen_allowed;
+}
+
+void qemu_system_debug_request(void)
+{
+    abort();
+}
diff --git a/tests/x86-stub.c b/tests/x86-stub.c
new file mode 100644
index 0000000..bb98e63
--- /dev/null
+++ b/tests/x86-stub.c
@@ -0,0 +1,186 @@
+/* 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"
+
+static void abort_handle_interrupt(CPUState *cpu, int mask);
+
+struct CPUTailQ cpus = QTAILQ_HEAD_INITIALIZER(cpus);
+DEFINE_TLS(CPUState *, current_cpu);
+int use_icount;
+volatile sig_atomic_t exit_request;
+CPUInterruptHandler cpu_interrupt_handler = abort_handle_interrupt;
+bool kvm_halt_in_kernel_allowed;
+
+static void abort_handle_interrupt(CPUState *cpu, int mask)
+{
+    abort();
+}
+
+void x86_cpu_do_interrupt(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();
+}
+
+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();
+}
+
+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 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_breakpoint_remove_all(CPUState *cpu, int mask)
+{
+    abort();
+}
+
+void cpu_watchpoint_remove_all(CPUState *cpu, int mask)
+{
+    abort();
+}
+
+bool target_words_bigendian(void); /* No prototype on any .h file */
+bool target_words_bigendian(void)
+{
+    return false;
+}
+
+void optimize_flags_init(void)
+{
+}
+
+void cpu_exec_init(CPUArchState *env)
+{
+}
+
+uint64_t cpu_get_apic_base(DeviceState *dev)
+{
+    abort();
+}
+
+void apic_designate_bsp(DeviceState *dev)
+{
+    abort();
+}
+
+void apic_deliver_nmi(DeviceState *dev)
+{
+    abort();
+}
+
+void gdb_set_stop_cpu(CPUState *cpu)
+{
+    abort();
+}
+
+void kvm_arch_reset_vcpu(X86CPU *cpu)
+{
+}
+
+int cpu_exec(CPUArchState *env)
+{
+    abort();
+}
+
+void tcg_cpu_address_space_init(CPUState *cpu, AddressSpace *as)
+{
+    abort();
+}
+
+CPUState *qemu_get_cpu(int index)
+{
+    abort();
+}
+
+int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr,
+                        uint8_t *buf, int len, int is_write)
+{
+    abort();
+}
+
+void cpu_physical_memory_rw(hwaddr addr, uint8_t *buf,
+                            int len, int is_write)
+{
+    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();
+}
+
+void hw_breakpoint_insert(CPUX86State *env, int index)
+{
+    abort();
+}
+
+#include "kvm-stub.c"
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [RFC 08/10] target-i386: Isolate enabled-by-default features to a separate array
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
                   ` (6 preceding siblings ...)
  2014-09-25 20:18 ` [Qemu-devel] [RFC 07/10] tests: Add unit test for X86CPU code Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 09/10] tests: test-x86-cpu: Add TCG feature bit initialization test Eduardo Habkost
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

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 90d0a05..8d1af64 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_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.
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [RFC 09/10] tests: test-x86-cpu: Add TCG feature bit initialization test
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
                   ` (7 preceding siblings ...)
  2014-09-25 20:18 ` [Qemu-devel] [RFC 08/10] target-i386: Isolate enabled-by-default features to a separate array Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-25 20:18 ` [Qemu-devel] [RFC 10/10] tests: test-x86-cpu: Add KVM " Eduardo Habkost
  2014-09-26 15:20 ` [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Paolo Bonzini
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

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 9227e20..e8e9a74 100644
--- a/tests/test-x86-cpu.c
+++ b/tests/test-x86-cpu.c
@@ -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();
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Qemu-devel] [RFC 10/10] tests: test-x86-cpu: Add KVM feature bit initialization test
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
                   ` (8 preceding siblings ...)
  2014-09-25 20:18 ` [Qemu-devel] [RFC 09/10] tests: test-x86-cpu: Add TCG feature bit initialization test Eduardo Habkost
@ 2014-09-25 20:18 ` Eduardo Habkost
  2014-09-26 15:20 ` [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Paolo Bonzini
  10 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-25 20:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Igor Mammedov, Andreas Färber, Paolo Bonzini

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 tests/test-x86-cpu.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tests/test-x86-cpu.c b/tests/test-x86-cpu.c
index e8e9a74..afd5088 100644
--- a/tests/test-x86-cpu.c
+++ b/tests/test-x86-cpu.c
@@ -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();
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code
  2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
                   ` (9 preceding siblings ...)
  2014-09-25 20:18 ` [Qemu-devel] [RFC 10/10] tests: test-x86-cpu: Add KVM " Eduardo Habkost
@ 2014-09-26 15:20 ` Paolo Bonzini
  2014-09-26 16:34   ` Eduardo Habkost
  10 siblings, 1 reply; 13+ messages in thread
From: Paolo Bonzini @ 2014-09-26 15:20 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel; +Cc: Igor Mammedov, Andreas Färber

Il 25/09/2014 22:18, Eduardo Habkost ha scritto:
> 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.

+	qemu-log.o \
+	qom/object.o qom/qom-qobject.o qom/cpu.o qom/container.o \
+	hw/core/qdev.o hw/core/qdev-properties.o hw/core/irq.o hw/core/fw-path-provider.o hw/core/hotplug.o \
+	vmstate.o qemu-file.o $(util-obj-y) \
+	x86_64-softmmu/cpus.o x86_64-softmmu/target-i386/machine.o \
+	tests/vl-stub.o tests/x86-stub.o tests/coroutine-stub.o tests/monitor-stub.o tests/aio-stub.o tests/timer-stub.o tests/block-stub.o \
+	stubs/reset.o stubs/sysbus.o stubs/vmstate.o stubs/fdset-remove-fd.o stubs/mon-printf.o stubs/qtest.o stubs/vm-stop.o

Do you really need cpus.c?  That's what brings in most dependencies,
and everything else should be included in libqemustub.a.  Also,
util-obj-y should be replaced with libqemuutil.a

In any case, most of these files are not needed by the linux-user
version of cpu.c, so I would need to know what exactly forces you
to include each of the files.

Also, would it be possible to do these tests via qtest and
qom-get/qom-set?

That said, please feel free to send patches 1-3 now, via qemu-trivial.

Thanks,

Paolo

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code
  2014-09-26 15:20 ` [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Paolo Bonzini
@ 2014-09-26 16:34   ` Eduardo Habkost
  0 siblings, 0 replies; 13+ messages in thread
From: Eduardo Habkost @ 2014-09-26 16:34 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Igor Mammedov, qemu-devel, Andreas Färber

On Fri, Sep 26, 2014 at 05:20:32PM +0200, Paolo Bonzini wrote:
> Il 25/09/2014 22:18, Eduardo Habkost ha scritto:
> > 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.
> 
> +	qemu-log.o \
> +	qom/object.o qom/qom-qobject.o qom/cpu.o qom/container.o \
> +	hw/core/qdev.o hw/core/qdev-properties.o hw/core/irq.o hw/core/fw-path-provider.o hw/core/hotplug.o \
> +	vmstate.o qemu-file.o $(util-obj-y) \
> +	x86_64-softmmu/cpus.o x86_64-softmmu/target-i386/machine.o \
> +	tests/vl-stub.o tests/x86-stub.o tests/coroutine-stub.o tests/monitor-stub.o tests/aio-stub.o tests/timer-stub.o tests/block-stub.o \
> +	stubs/reset.o stubs/sysbus.o stubs/vmstate.o stubs/fdset-remove-fd.o stubs/mon-printf.o stubs/qtest.o stubs/vm-stop.o
> 
> Do you really need cpus.c?  That's what brings in most dependencies,
> and everything else should be included in libqemustub.a.

To be honest, I don't remember why exactly I decided to pull cpus.c
instead of making stubs for it. :)

I will take a look again at what happens if I don't include it.

> Also, util-obj-y should be replaced with libqemuutil.a

I will change it to use libqemuutil.a. Thanks.

> 
> In any case, most of these files are not needed by the linux-user
> version of cpu.c, so I would need to know what exactly forces you
> to include each of the files.

I want to test KVM-specific code, which isn't enabled on linux-user.

> 
> Also, would it be possible to do these tests via qtest and
> qom-get/qom-set?

Most things I want to test are not available through QMP or qtest yet.
The whole point of this test code is to give us some safety while we are
still implementing new QOM/QMP/qtest stuff.

Specifically, I want to test some behavior that depend on having missing
entries on the CPU feature name tables (e.g. the "migratable" property),
and on the return values of kvm_arch_get_supported_cpuid(), so qtest
won't work unless we add qtest/QMP code to hack
kvm_arch_get_supported_cpuid() and the CPU model/feature tables. Maybe
one day the externally-visible interfaces will become flexible and
generic enough to allow this same test code to be implemented purely
using qtest, but not today.

> 
> That said, please feel free to send patches 1-3 now, via qemu-trivial.

OK. Thanks.

-- 
Eduardo

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-09-26 16:34 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-25 20:18 [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 01/10] tests: Add missing include to test-bitops.c Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 02/10] bitops.h: Don't include qemu-common.h Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 03/10] bitmap.h: " Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 04/10] tests: Move fake yield_until_fd_readable() to coroutine-stub.c Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 05/10] tests: Support target-specific unit tests Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 06/10] tests: Make test-x86-cpuid target-specific Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 07/10] tests: Add unit test for X86CPU code Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 08/10] target-i386: Isolate enabled-by-default features to a separate array Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 09/10] tests: test-x86-cpu: Add TCG feature bit initialization test Eduardo Habkost
2014-09-25 20:18 ` [Qemu-devel] [RFC 10/10] tests: test-x86-cpu: Add KVM " Eduardo Habkost
2014-09-26 15:20 ` [Qemu-devel] [RFC 00/10] Target-specific unit test support, add unit tests for target-i386/cpu.c code Paolo Bonzini
2014-09-26 16:34   ` Eduardo Habkost

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).