Skip to content

Commit

Permalink
dump_guest_core:qemu dump new cases development
Browse files Browse the repository at this point in the history
    1.Use gdb check core dump file
    2.Use crash check vmcore file

Signed-off-by: Leidong Wang <leidwang@redhat.com>
  • Loading branch information
leidwang committed Nov 20, 2020
1 parent 82f653b commit 0d12329
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 0 deletions.
22 changes: 22 additions & 0 deletions qemu/tests/cfg/dump_guest_core.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
- dump_guest_core:
type = dump_guest_core
virt_test_type = qemu
pre_command = "ulimit -c unlimited"
pre_command += "&& echo "/var/core.%p" > /proc/sys/kernel/core_pattern"
trigger_core_dump_command = "kill -s SIGSEGV %s"
gdb_command_file = "/home/gdb_command"
crash_script = "/home/crash.cmd"
vmcore_file = "/tmp/vmcore"
core_file = "/var/core.%s"
gdb_command = "gdb %s --command=${gdb_command_file}"
crash_cmd = "crash -i ${crash_script} /usr/lib/debug/lib/modules/%s/vmlinux %s"
dump_guest_memory_file = "/usr/share/qemu-kvm/dump-guest-memory.py"
x86_64:
extra_params += " -device vmcoreinfo"
# When 'dump-guest-core=off' is specified, guest memory is omitted from the core dump.
variants:
- on:
dump_guest_core = on
- off:
dump_guest_core = off
extra_params += " -machine dump-guest-core=${dump_guest_core}"
101 changes: 101 additions & 0 deletions qemu/tests/dump_guest_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import logging
import os

from avocado.utils import process

from virttest import utils_package
from virttest import utils_misc


def run(test, params, env):
"""
Test dump-guest-core, this case will:
1) Start VM with dump-guest-core option.
2) Check host env.
3) Trigger a core dump in host.
4) Use gdb to check core dump file.
5) If dump-guest-core=on, use crash to check vmcore file
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environmen.
"""

def check_env():
"""
Check if host kernel version is same with guest
"""
guest_kernel_version = session.cmd("uname -r").strip()
logging.info("host kernel version is %s" % host_kernel_version)
logging.info("guest kernel version is %s" % guest_kernel_version)
if host_kernel_version != guest_kernel_version:
test.cancel("Please update your host and guest kernel "
"to same version")

def check_core_file():
"""
Use gdb to check core dump file
"""
arch = 'X86_64'
arch = 'ppc64-le' if params['vm_arch_name'] == 'ppc64le' else arch
command = ('echo -e "source %s\nset height 0\ndump-guest-memory'
' %s %s\nbt\nquit" > %s' % (dump_guest_memory_file,
vmcore_file, arch,
gdb_command_file))
process.run(command, shell=True)
status, output = process.getstatusoutput(gdb_command, timeout=360)
os.remove(gdb_command_file)
os.remove(core_file)
logging.debug(output)
if status != 0:
test.fail("gdb command execute failed")
elif "<class 'gdb.MemoryError'>" in output:
if dump_guest_core == "on":
test.fail("Cannot access memory")

def check_vmcore_file():
"""
Use crash to check vmcore file
"""
process.run('echo -e "bt\ntask 0\ntask 1\nquit" > %s'
% crash_script, shell=True)
output = process.getoutput(crash_cmd, timeout=60)
os.remove(crash_script)
os.remove(vmcore_file)
logging.debug(output)
if "systemd" in output and 'swapper' in output:
logging.info("Crash command works as expected")
else:
test.fail("Vmcore corrupt")

# install crash/gdb/kernel-debuginfo in host
packages = ["crash", "gdb", "kernel-debuginfo*", "qemu-kvm-debuginfo",
"qemu-kvm-debugsource", "qemu-kvm-core-debuginfo"]
utils_package.package_install(packages)

trigger_core_dump_command = params["trigger_core_dump_command"]
core_file = params["core_file"]
dump_guest_memory_file = params["dump_guest_memory_file"]
gdb_command = params["gdb_command"]
gdb_command_file = params["gdb_command_file"]
dump_guest_core = params["dump_guest_core"]
crash_script = params["crash_script"]
crash_cmd = params["crash_cmd"]
vmcore_file = params["vmcore_file"]
host_kernel_version = process.getoutput("uname -r").strip()
vm = env.get_vm(params["main_vm"])
session = vm.wait_for_login()
check_env()

qemu_id = vm.get_pid()
core_file %= str(qemu_id)
gdb_command %= core_file
trigger_core_dump_command %= str(qemu_id)
logging.info("trigger core dump command: %s" % trigger_core_dump_command)
process.run(trigger_core_dump_command)
utils_misc.wait_for(lambda: os.path.exists(core_file), timeout=60)
check_core_file()
if dump_guest_core == 'on':
crash_cmd %= (host_kernel_version, vmcore_file)
check_vmcore_file()

0 comments on commit 0d12329

Please sign in to comment.