qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>,
	"Igor Mammedov" <imammedo@redhat.com>
Subject: [Qemu-devel] [PATCH v2 4/7] tests: Add unit test for X86CPU code
Date: Tue, 30 Sep 2014 15:26:03 -0300	[thread overview]
Message-ID: <1412101566-23669-5-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1412101566-23669-1-git-send-email-ehabkost@redhat.com>

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 |  44 ++++++++++++++
 tests/vl-stub.c      |  15 +++++
 tests/x86-stub.c     | 163 +++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 237 insertions(+), 1 deletion(-)
 create mode 100644 tests/test-x86-cpu.c
 create mode 100644 tests/vl-stub.c
 create mode 100644 tests/x86-stub.c

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 9b04a53..fd84529 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
 
@@ -224,7 +225,8 @@ test-obj-y = tests/check-qint.o tests/check-qstring.o tests/check-qdict.o \
 	tests/test-x86-cpuid.o tests/test-mul64.o tests/test-int128.o \
 	tests/test-opts-visitor.o tests/test-qmp-event.o
 
-test-obj-x86_64-softmmu-y = tests/test-x86-cpuid.o
+test-obj-x86_64-softmmu-y = tests/test-x86-cpuid.o \
+	tests/test-x86-cpu.o tests/x86-stub.o
 
 test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
 		  tests/test-qapi-event.o
@@ -352,6 +354,17 @@ tests/usb-hcd-xhci-test$(EXESUF): tests/usb-hcd-xhci-test.o
 tests/vhost-user-test$(EXESUF): tests/vhost-user-test.o qemu-char.o qemu-timer.o $(qtest-obj-y)
 tests/qemu-iotests/socket_scm_helper$(EXESUF): tests/qemu-iotests/socket_scm_helper.o
 tests/test-qemu-opts$(EXESUF): tests/test-qemu-opts.o libqemuutil.a libqemustub.a
+tests/test-x86-cpu$(EXESUF): tests/test-x86-cpu.o \
+	x86_64-softmmu/target-i386/machine.o \
+	qom/cpu.o \
+	qom/object.o qom/qom-qobject.o qom/container.o \
+	hw/core/qdev.o hw/core/qdev-properties.o \
+	hw/core/hotplug.o hw/core/irq.o hw/core/fw-path-provider.o \
+	vmstate.o qemu-file.o \
+	qemu-log.o \
+	libqemuutil.a \
+	libqemustub.a \
+	tests/vl-stub.o tests/x86-stub.o tests/coroutine-stub.o
 
 ifeq ($(CONFIG_POSIX),y)
 LIBS += -lutil
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/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..22a3c2f
--- /dev/null
+++ b/tests/x86-stub.c
@@ -0,0 +1,163 @@
+/* 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); /* No prototype on any .h file */
+bool target_words_bigendian(void)
+{
+    return false;
+}
+
+
+#include "kvm-stub.c"
-- 
1.9.3

  parent reply	other threads:[~2014-09-30 18:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-30 18:25 [Qemu-devel] [PATCH v2 0/7] Target-specific unit test support, add unit tests for target-i386/cpu.c code Eduardo Habkost
2014-09-30 18:26 ` [Qemu-devel] [PATCH v2 1/7] tests: Move fake yield_until_fd_readable() to coroutine-stub.c Eduardo Habkost
2014-09-30 22:17   ` Paolo Bonzini
2014-10-01 16:14     ` Eduardo Habkost
2014-09-30 18:26 ` [Qemu-devel] [PATCH v2 2/7] tests: Support target-specific unit tests Eduardo Habkost
2014-09-30 18:26 ` [Qemu-devel] [PATCH v2 3/7] tests: Make test-x86-cpuid target-specific Eduardo Habkost
2014-09-30 18:26 ` Eduardo Habkost [this message]
2014-09-30 22:20   ` [Qemu-devel] [PATCH v2 4/7] tests: Add unit test for X86CPU code Paolo Bonzini
2014-10-01 16:28     ` Eduardo Habkost
2014-10-01 18:18       ` Paolo Bonzini
2014-09-30 18:26 ` [Qemu-devel] [PATCH v2 5/7] target-i386: Isolate enabled-by-default features to a separate array Eduardo Habkost
2014-09-30 18:26 ` [Qemu-devel] [PATCH v2 6/7] tests: test-x86-cpu: Add TCG feature bit initialization test Eduardo Habkost
2014-09-30 18:26 ` [Qemu-devel] [PATCH v2 7/7] tests: test-x86-cpu: Add KVM " Eduardo Habkost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1412101566-23669-5-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=afaerber@suse.de \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).