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 <ehabk...@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