gitlab.arm.com will be in the maintainance mode on Wednesday June 29th 01:00 - 10:00 (UTC+1). Repositories is read only during the maintainance.

gitlab.arm.com will be in the maintainance mode on Wednesday June 29th 01:00 - 10:00 (UTC+1). Repositories is read only during the maintainance.

You are on a read-only GitLab instance.
Commit 7d36db35 authored by Avi Kivity's avatar Avi Kivity
Browse files

Initial commit from qemu-kvm.git kvm/test/


Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parents
.gdbinit
*.a
*.d
*.o
*.flat
.pc
patches
.stgit-*
cscope.*
Copyright (C) 2006 Qumranet.
The files in this directory and its subdirectories are licensed under the
GNU LGPL, version 2.
include config.mak
DESTDIR := $(PREFIX)/share/qemu/tests
.PHONY: arch_clean clean
#make sure env CFLAGS variable is not used
CFLAGS =
libgcc := $(shell $(CC) --print-libgcc-file-name)
libcflat := lib/libcflat.a
cflatobjs := \
lib/panic.o \
lib/printf.o \
lib/string.o
#include architecure specific make rules
include config-$(ARCH).mak
# cc-option
# Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
CFLAGS += -O1
CFLAGS += $(autodepend-flags) -g -fomit-frame-pointer -Wall
CFLAGS += $(call cc-option, -fno-stack-protector, "")
CFLAGS += $(call cc-option, -fno-stack-protector-all, "")
CFLAGS += -I../include
CFLAGS += -I ../libkvm
LDFLAGS += $(CFLAGS) -L ../libkvm
CXXFLAGS = $(autodepend-flags)
autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
LDFLAGS += -pthread -lrt
kvmtrace_objs= kvmtrace.o
kvmctl: $(kvmctl_objs)
$(CC) $(LDFLAGS) $^ -o $@
kvmtrace: $(kvmtrace_objs)
$(CC) $(LDFLAGS) $^ -o $@
$(libcflat): $(cflatobjs)
$(AR) rcs $@ $^
%.o: %.S
$(CC) $(CFLAGS) -c -nostdlib -o $@ $<
-include .*.d
install:
mkdir -p $(DESTDIR)
install $(tests_and_config) $(DESTDIR)
clean: arch_clean
$(RM) kvmctl kvmtrace *.o *.a .*.d $(libcflat) $(cflatobjs)
This directory contains sources for a kvm test suite.
Tests for x86 architecture are run as kernel images for qemu that supports multiboot format.
Tests uses an infrastructure called from the bios code. The infrastructure initialize the system/cpu's,
switch to long-mode and calls the 'main' function of the individual test.
Tests uses a qemu's virtual test device, named testdev, for services like printing, exiting, query memory size etc.
See file testdev.txt for more details.
To create the tests' images just type 'make' in this directory.
Tests' images created in ./test/<ARCH>/*.flat
An example of a test invocation:
qemu-system-x86_64 -device testdev,chardev=testlog -chardev file,id=testlog,path=msr.out -kernel ./test/x86/msr.flat
This invocation runs the msr test case. The test output is in file msr.out.
Directory structure:
.: Makefile and config files for the tests
./test/lib: general services for the tests
./test/lib/<ARCH>: architecture dependent services for the tests
./test/<ARCH>: the sources of the tests and the created objects/images
TEST_DIR=x86
cstart.o = $(TEST_DIR)/cstart.o
bits = 32
ldarch = elf32-i386
CFLAGS += -D__i386__
CFLAGS += -I $(KERNELDIR)/include
tests = $(TEST_DIR)/taskswitch.flat
include config-x86-common.mak
$(TEST_DIR)/taskswitch.flat: $(cstart.o) $(TEST_DIR)/taskswitch.o
bits = 64
CFLAGS += -m64
CFLAGS += -D__ia64__
CFLAGS += -I../include/ia64
all:
# for some reason binutils hates tlbsx unless we say we're 405 :(
CFLAGS += -Wa,-m405 -I lib/powerpc/44x
cflatobjs += \
lib/powerpc/44x/map.o \
lib/powerpc/44x/tlbwe.o \
lib/powerpc/44x/timebase.o
simpletests += \
powerpc/44x/tlbsx.bin \
powerpc/44x/tlbwe_16KB.bin \
powerpc/44x/tlbwe_hole.bin \
powerpc/44x/tlbwe.bin
CFLAGS += -I../include/powerpc
CFLAGS += -Wa,-mregnames -I lib
CFLAGS += -ffreestanding
cstart := powerpc/cstart.o
cflatobjs += \
lib/powerpc/io.o
$(libcflat): LDFLAGS += -nostdlib
# these tests do not use libcflat
simpletests := \
powerpc/spin.bin \
powerpc/io.bin \
powerpc/sprg.bin
# theses tests use cstart.o, libcflat, and libgcc
tests := \
powerpc/exit.bin \
powerpc/helloworld.bin
include config-powerpc-$(PROCESSOR).mak
all: kvmtrace kvmctl $(libcflat) $(simpletests) $(tests)
$(simpletests): %.bin: %.o
$(CC) -nostdlib $^ -Wl,-T,flat.lds -o $@
$(tests): %.bin: $(cstart) %.o $(libcflat)
$(CC) -nostdlib $^ $(libgcc) -Wl,-T,flat.lds -o $@
kvmctl_objs = main-ppc.o iotable.o ../libkvm/libkvm.a
arch_clean:
$(RM) $(simpletests) $(tests) $(cstart)
$(RM) $(patsubst %.bin, %.elf, $(simpletests) $(tests))
$(RM) $(patsubst %.bin, %.o, $(simpletests) $(tests))
#This is a make file with common rules for both x86 & x86-64
CFLAGS += -I../include/x86
all: test_cases
cflatobjs += \
lib/x86/io.o \
lib/x86/smp.o
cflatobjs += lib/x86/fwcfg.o
cflatobjs += lib/x86/apic.o
$(libcflat): LDFLAGS += -nostdlib
$(libcflat): CFLAGS += -ffreestanding -I lib
CFLAGS += -m$(bits)
libgcc := $(shell $(CC) -m$(bits) --print-libgcc-file-name)
FLATLIBS = lib/libcflat.a $(libgcc)
%.flat: %.o $(FLATLIBS) flat.lds
$(CC) $(CFLAGS) -nostdlib -o $@ -Wl,-T,flat.lds $(filter %.o, $^) $(FLATLIBS)
tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
$(TEST_DIR)/smptest.flat $(TEST_DIR)/port80.flat \
$(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \
$(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat
tests_and_config = $(TEST_DIR)/*.flat $(TEST_DIR)/unittests.cfg
test_cases: $(tests-common) $(tests)
$(TEST_DIR)/%.o: CFLAGS += -std=gnu99 -ffreestanding -I lib -I lib/x86
$(TEST_DIR)/access.flat: $(cstart.o) $(TEST_DIR)/access.o $(TEST_DIR)/print.o
$(TEST_DIR)/hypercall.flat: $(cstart.o) $(TEST_DIR)/hypercall.o
$(TEST_DIR)/sieve.flat: $(cstart.o) $(TEST_DIR)/sieve.o \
$(TEST_DIR)/vm.o
$(TEST_DIR)/vmexit.flat: $(cstart.o) $(TEST_DIR)/vmexit.o
$(TEST_DIR)/smptest.flat: $(cstart.o) $(TEST_DIR)/smptest.o
$(TEST_DIR)/emulator.flat: $(cstart.o) $(TEST_DIR)/emulator.o \
$(TEST_DIR)/vm.o $(TEST_DIR)/print.o
$(TEST_DIR)/port80.flat: $(cstart.o) $(TEST_DIR)/port80.o
$(TEST_DIR)/tsc.flat: $(cstart.o) $(TEST_DIR)/tsc.o
$(TEST_DIR)/apic.flat: $(cstart.o) $(TEST_DIR)/apic.o $(TEST_DIR)/vm.o \
$(TEST_DIR)/print.o
$(TEST_DIR)/realmode.flat: $(TEST_DIR)/realmode.o
$(CC) -m32 -nostdlib -o $@ -Wl,-T,$(TEST_DIR)/realmode.lds $^
$(TEST_DIR)/realmode.o: bits = 32
$(TEST_DIR)/msr.flat: $(cstart.o) $(TEST_DIR)/msr.o
$(TEST_DIR)/idt_test.flat: $(cstart.o) $(TEST_DIR)/idt.o $(TEST_DIR)/idt_test.o
$(TEST_DIR)/xsave.flat: $(cstart.o) $(TEST_DIR)/idt.o $(TEST_DIR)/xsave.o
$(TEST_DIR)/rmap_chain.flat: $(cstart.o) $(TEST_DIR)/rmap_chain.o \
$(TEST_DIR)/print.o $(TEST_DIR)/vm.o
$(TEST_DIR)/svm.flat: $(cstart.o) $(TEST_DIR)/vm.o
arch_clean:
$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat \
$(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
-include $(TEST_DIR)/.*.d lib/.*.d lib/x86/.*.d
TEST_DIR=x86
cstart.o = $(TEST_DIR)/cstart64.o
bits = 64
ldarch = elf64-x86-64
CFLAGS += -D__x86_64__
tests = $(TEST_DIR)/access.flat $(TEST_DIR)/apic.flat \
$(TEST_DIR)/emulator.flat $(TEST_DIR)/idt_test.flat \
$(TEST_DIR)/xsave.flat $(TEST_DIR)/rmap_chain.flat
tests += $(TEST_DIR)/svm.flat
include config-x86-common.mak
PREFIX=/usr/local
KERNELDIR=/home/avi/kvm/linux-2.6
ARCH=x86_64
PROCESSOR=x86_64
CC=gcc
LD=ld
OBJCOPY=objcopy
AR=ar
#!/bin/bash
prefix=/usr/local
kerneldir=/lib/modules/$(uname -r)/build
cc=gcc
ld=ld
objcopy=objcopy
ar=ar
arch=`uname -m | sed -e s/i.86/i386/`
processor="$arch"
cross_prefix=
usage() {
cat <<-EOF
Usage: $0 [options]
Options include:
--arch=ARCH architecture to compile for ($arch)
--cross-prefix=PREFIX cross compiler prefix
--cc=CC c compiler to use ($cc)
--ld=LD ld linker to use ($ld)
--prefix=PREFIX where to install things ($prefix)
--kerneldir=DIR kernel build directory for kvm.h ($kerneldir)
EOF
exit 1
}
while [[ "$1" = -* ]]; do
opt="$1"; shift
arg=
if [[ "$opt" = *=* ]]; then
arg="${opt#*=}"
opt="${opt%%=*}"
fi
case "$opt" in
--prefix)
prefix="$arg"
;;
--kerneldir)
kerneldir="$arg"
;;
--arch)
arch="$arg"
;;
--processor)
processor="$arg"
;;
--cross-prefix)
cross_prefix="$arg"
;;
--cc)
cc="$arg"
;;
--ld)
ld="$arg"
;;
--help)
usage
;;
*)
usage
;;
esac
done
cat <<EOF > config.mak
PREFIX=$prefix
KERNELDIR=$(readlink -f $kerneldir)
ARCH=$arch
PROCESSOR=$processor
CC=$cross_prefix$cc
LD=$cross_prefix$ld
OBJCOPY=$cross_prefix$objcopy
AR=$cross_prefix$ar
EOF
SECTIONS
{
. = 4M + SIZEOF_HEADERS;
stext = .;
.text : { *(.init) *(.text) *(.text.*) }
. = ALIGN(4K);
.data : {
*(.data)
exception_table_start = .;
*(.data.ex)
exception_table_end = .;
}
. = ALIGN(16);
.rodata : { *(.rodata) }
. = ALIGN(16);
.bss : { *(.bss) }
. = ALIGN(4K);
edata = .;
}
0x00000000 %(ts)d (+%(relts)12d) unknown (0x%(event)016x) vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ 0x%(1)08x 0x%(2)08x 0x%(3)08x 0x%(4)08x 0x%(5)08x ]
0x00010001 %(ts)d (+%(relts)12d) VMENTRY vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x
0x00010002 %(ts)d (+%(relts)12d) VMEXIT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ exitcode = 0x%(1)08x, rip = 0x%(3)08x %(2)08x ]
0x00020001 %(ts)d (+%(relts)12d) PAGE_FAULT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ errorcode = 0x%(1)08x, virt = 0x%(3)08x %(2)08x ]
0x00020002 %(ts)d (+%(relts)12d) INJ_VIRQ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ vector = 0x%(1)02x ]
0x00020003 %(ts)d (+%(relts)12d) REDELIVER_EVT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ vector = 0x%(1)02x ]
0x00020004 %(ts)d (+%(relts)12d) PEND_INTR vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ vector = 0x%(1)02x ]
0x00020005 %(ts)d (+%(relts)12d) IO_READ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ port = 0x%(1)04x, size = %(2)d ]
0x00020006 %(ts)d (+%(relts)12d) IO_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ port = 0x%(1)04x, size = %(2)d ]
0x00020007 %(ts)d (+%(relts)12d) CR_READ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ CR# = %(1)d, value = 0x%(3)08x %(2)08x ]
0x00020008 %(ts)d (+%(relts)12d) CR_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ CR# = %(1)d, value = 0x%(3)08x %(2)08x ]
0x00020009 %(ts)d (+%(relts)12d) DR_READ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ DR# = %(1)d, value = 0x%(2)08x ]
0x0002000A %(ts)d (+%(relts)12d) DR_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ DR# = %(1)d, value = 0x%(2)08x ]
0x0002000B %(ts)d (+%(relts)12d) MSR_READ vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ MSR# = 0x%(1)08x, data = 0x%(3)08x %(2)08x ]
0x0002000C %(ts)d (+%(relts)12d) MSR_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ MSR# = 0x%(1)08x, data = 0x%(3)08x %(2)08x ]
0x0002000D %(ts)d (+%(relts)12d) CPUID vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ func = 0x%(1)08x, eax = 0x%(2)08x, ebx = 0x%(3)08x, ecx = 0x%(4)08x edx = 0x%(5)08x]
0x0002000E %(ts)d (+%(relts)12d) INTR vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ vector = 0x%(1)02x ]
0x0002000F %(ts)d (+%(relts)12d) NMI vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x
0x00020010 %(ts)d (+%(relts)12d) VMMCALL vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ func = 0x%(1)08x ]
0x00020011 %(ts)d (+%(relts)12d) HLT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x
0x00020012 %(ts)d (+%(relts)12d) CLTS vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x
0x00020013 %(ts)d (+%(relts)12d) LMSW vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ value = 0x%(1)08x ]
0x00020014 %(ts)d (+%(relts)12d) APIC_ACCESS vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ offset = 0x%(1)08x ]
0x00020015 %(ts)d (+%(relts)12d) TDP_FAULT vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ errorcode = 0x%(1)08x, virt = 0x%(3)08x %(2)08x ]
# ppc: tlb traces
0x00020016 GTLB_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ index = 0x%(1)08x, tid = 0x%(2)08x, word1=0x%(3)08x, word2=0x%(4)08x, word3=0x%(5)08x ]
0x00020017 STLB_WRITE vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ index = 0x%(1)08x, tid = 0x%(2)08x, word1=0x%(3)08x, word2=0x%(4)08x, word3=0x%(5)08x ]
0x00020018 STLB_INVAL vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ index = 0x%(1)08x, tid = 0x%(2)08x, word1=0x%(3)08x, word2=0x%(4)08x, word3=0x%(5)08x ]
# ppc: instruction emulation - this type is handled more complex in kvmtrace_format, but listed to show the eventid and transported data
#0x00020019 %(ts)d (+%(relts)12d) PPC_INSTR vcpu = 0x%(vcpu)08x pid = 0x%(pid)08x [ instr = 0x%(1)08x, pc = 0x%(2)08x, emul = 0x%(3)08x, nsec = %(4)08d ]
/*
* Kernel-based Virtual Machine test driver
*
* This test driver provides a simple way of testing kvm, without a full
* device model.
*
* Copyright (C) 2006 Qumranet
*
* Authors:
*
* Avi Kivity <avi@qumranet.com>
* Yaniv Kamay <yaniv@qumranet.com>
*
* This work is licensed under the GNU LGPL license, version 2.
*/
#include <stdlib.h>
#include <stdint.h>
#include <errno.h>
#include "iotable.h"
struct io_table_entry *io_table_lookup(struct io_table *io_table, uint64_t addr)
{
int i;
for (i = 0; i < io_table->nr_entries; i++) {
if (io_table->entries[i].start <= addr &&
addr < io_table->entries[i].end)
return &io_table->entries[i];
}
return NULL;
}
int io_table_register(struct io_table *io_table, uint64_t start, uint64_t size,
io_table_handler_t *handler, void *opaque)
{
struct io_table_entry *entry;
if (io_table->nr_entries == MAX_IO_TABLE)
return -ENOSPC;
entry = &io_table->entries[io_table->nr_entries];
io_table->nr_entries++;
entry->start = start;
entry->end = start + size;
entry->handler = handler;
entry->opaque = opaque;
return 0;
}
/*
* Kernel-based Virtual Machine test driver
*
* This test driver provides a simple way of testing kvm, without a full
* device model.
*
* Copyright (C) 2006 Qumranet
*
* Authors:
*
* Avi Kivity <avi@qumranet.com>
* Yaniv Kamay <yaniv@qumranet.com>
*
* This work is licensed under the GNU LGPL license, version 2.
*/
#include <stdint.h>
#define MAX_IO_TABLE 50
typedef int (io_table_handler_t)(void *, int, int, uint64_t, uint64_t *);
struct io_table_entry
{
uint64_t start;
uint64_t end;
io_table_handler_t *handler;
void *opaque;
};
struct io_table
{
int nr_entries;
struct io_table_entry entries[MAX_IO_TABLE];
};
struct io_table_entry *io_table_lookup(struct io_table *io_table,
uint64_t addr);
int io_table_register(struct io_table *io_table, uint64_t start, uint64_t size,
io_table_handler_t *handler, void *opaque);
File added
/*
* kvm tracing application
*
* This tool is used for collecting trace buffer data
* for kvm trace.
*
* Based on blktrace 0.99.3
*
* Copyright (C) 2005 Jens Axboe <axboe@suse.de>
* Copyright (C) 2006 Jens Axboe <axboe@kernel.dk>
* Copyright (C) 2008 Eric Liu <eric.e.liu@intel.com>
*
* This work is licensed under the GNU LGPL license, version 2.
*/
#define _GNU_SOURCE
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/statfs.h>
#include <sys/poll.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <getopt.h>
#include <errno.h>
#include <sched.h>
#ifndef __user
#define __user
#endif
#include <linux/kvm.h>
static char kvmtrace_version[] = "0.1";
/*
* You may want to increase this even more, if you are logging at a high
* rate and see skipped/missed events
*/
#define BUF_SIZE (512 * 1024)
#define BUF_NR (8)
#define OFILE_BUF (128 * 1024)
#define DEBUGFS_TYPE 0x64626720
#define max(a, b) ((a) > (b) ? (a) : (b))
#define S_OPTS "r:o:w:?Vb:n:D:"
static struct option l_opts[] = {
{
.name = "relay",
.has_arg = required_argument,
.flag = NULL,
.val = 'r'
},
{
.name = "output",
.has_arg = required_argument,
.flag = NULL,
.val = 'o'
},
{
.name = "stopwatch",
.has_arg = required_argument,
.flag = NULL,
.val = 'w'
},
{
.name = "version",
.has_arg = no_argument,
.flag = NULL,
.val = 'V'
},
{
.name = "buffer-size",
.has_arg = required_argument,
.flag = NULL,
.val = 'b'
},
{
.name = "num-sub-buffers",
.has_arg = required_argument,
.flag = NULL,
.val = 'n'
},
{
.name = "output-dir",
.has_arg = required_argument,
.flag = NULL,
.val = 'D'
},
{
.name = NULL,
}
};
struct thread_information {
int cpu;
pthread_t thread;
int fd;
char fn[MAXPATHLEN + 64];
FILE *ofile;
char *ofile_buffer;
int (*get_subbuf)(struct thread_information *, unsigned int);
int (*read_data)(struct thread_information *, void *, unsigned int);
unsigned long long data_read;
struct kvm_trace_information *trace_info;
int exited;
/*
* mmap controlled output files
*/
unsigned long long fs_size;
unsigned long long fs_max_size