Skip to contentSkip to conversation

Target-specific unit test support, add unit tests for target-i386/cpu.c code

RFC Superseded Eduardo Habkost 2 participants 13 messages Sep 25, 2014 – Sep 26, 2014

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#1 lore raw

RFC 1/10 tests: Add missing include to test-bitops.c

In reply to Eduardo Habkost

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

---
 tests/test-bitops.c | 1 +
 1 file changed, 1 insertion(+)
tests/test-bitops.c +1 -0
index 8238eb5..47b5d3e 100644
@@ -8,6 +8,7 @@
 
 #include <glib.h>
 #include <stdint.h>
+#include "qemu/osdep.h"
 #include "qemu/bitops.h"
 
 typedef struct {
Signature · 1 line
1.9.3
#2 lore raw

RFC 2/10 bitops.h: Don't include qemu-common.h

In reply to Eduardo Habkost

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.

---
 include/qemu/bitops.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/qemu/bitops.h +3 -1
index 7e2d5c9..181bd46 100644
@@ -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
Signature · 1 line
1.9.3
#3 lore raw

RFC 3/10 bitmap.h: Don't include qemu-common.h

In reply to Eduardo Habkost

This will avoid unexpected circular header dependencies in the future.

---
 include/qemu/bitmap.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/qemu/bitmap.h +4 -1
index 1babd5d..8c50d70 100644
@@ -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"
 
 /*
Signature · 1 line
1.9.3
#4 lore raw

RFC 4/10 tests: Move fake yield_until_fd_readable() to coroutine-stub.c

In reply to Eduardo Habkost

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
index f5de29c..483ba61 100644
@@ -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
 
tests/coroutine-stub.c new file +13 -0
new file mode 100644
index 0000000..8af58dd
@@ -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
index d72c64c..412634f 100644
@@ -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
#5 lore raw

RFC 5/10 tests: Support target-specific unit tests

In reply to Eduardo Habkost

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

---
 tests/Makefile | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
tests/Makefile +23 -8
index 483ba61..95566d9 100644
@@ -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
Signature · 1 line
1.9.3
#7 lore raw

RFC 7/10 tests: Add unit test for X86CPU code

In reply to Eduardo Habkost

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.

---
 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
tests/.gitignore +1 -0
index c71c110..6af66b4 100644
@@ -32,5 +32,6 @@ test-visitor-serialization
 test-vmstate
 test-x86-cpuid
 test-xbzrle
+test-x86-cpu
 *-test
 qapi-schema/*.test.*
tests/Makefile +11 -1
index f1d9907..b563866 100644
@@ -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
tests/aio-stub.c new file +20 -0
new file mode 100644
index 0000000..0b6b2d1
@@ -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();
+}
+
tests/block-stub.c new file +11 -0
new file mode 100644
index 0000000..ef8f696
@@ -0,0 +1,11 @@
+#include "block/block.h"
+
+void bdrv_drain_all(void)
+{
+    abort();
+}
+
+int bdrv_flush_all(void)
+{
+    abort();
+}
tests/monitor-stub.c new file +34 -0
new file mode 100644
index 0000000..b574b09
@@ -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();
+}
+
tests/test-x86-cpu.c new file +44 -0

44 lines not on this page · raw message

tests/timer-stub.c new file +65 -0

65 lines not on this page · raw message

tests/vl-stub.c new file +45 -0

45 lines not on this page · raw message

tests/x86-stub.c new file +186 -0

186 lines not on this page · raw message

Signature · 1 line
1.9.3
#6 lore raw

RFC 6/10 tests: Make test-x86-cpuid target-specific

In reply to Eduardo Habkost

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

---
 tests/Makefile | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tests/Makefile +3 -3
index 95566d9..f1d9907 100644
@@ -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
Signature · 1 line
1.9.3
#8 lore raw

RFC 8/10 target-i386: Isolate enabled-by-default features to a separate array

In reply to Eduardo Habkost

This 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
index 90d0a05..8d1af64 100644
@@ -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
#9 lore raw

RFC 9/10 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
index 9227e20..e8e9a74 100644
@@ -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
#10 lore raw

RFC 10/10 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
index e8e9a74..afd5088 100644
@@ -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
#0 lore raw

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.

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
Signature · 1 line
1.9.3
#11 lore raw

Il 25/09/2014 22:18, Eduardo Habkost ha scritto:

Quoted 4 lines

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

#12 lore raw
Quoted 14 lines · Paolo Bonzini

Il 25/09/2014 22:18, Eduardo Habkost ha scritto:

Quoted 4 lines

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.

(quoted diff) +7 -0
+	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
Quoted 2 lines

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.

Quoted 1 line

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

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

Quoted 4 lines

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.

Quoted 3 lines

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.

Quoted 2 lines

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

OK. Thanks.

Signature · 1 line
Eduardo