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 16, 2020
1 parent 82f653b commit f6dafd2
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
21 changes: 21 additions & 0 deletions qemu/tests/cfg/dump_guest_core.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- 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"
gdb_command = "gdb /var/core.%s --command=${gdb_command_file}"
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
extra_params += " -machine dump-guest-core=${dump_guest_core}"
- off:
dump_guest_core = off
extra_params += " -machine dump-guest-core=${dump_guest_core}"
104 changes: 104 additions & 0 deletions qemu/tests/dump_guest_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import logging
import os

from avocado.utils import process

from virttest import env_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 = params['vm_arch_name']
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)
crash_cmd = "crash -i %s /usr/lib/debug/lib/modules/%s/vmlinux %s"
crash_cmd %= (crash_script, host_kernel_version, vmcore_file)
status, output = process.getstatusoutput(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"]
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"]
vmcore_file = params["vmcore_file"]
env_process.process(test, params, env,
env_process.preprocess_image,
env_process.preprocess_vm)
vm = env.get_vm(params["main_vm"])
session = vm.wait_for_login()
host_kernel_version = process.getoutput("uname -r").strip()
check_env()

qemu_id = vm.get_pid()
gdb_command %= qemu_id
core_file = '/var/core.' + str(qemu_id)
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':
check_vmcore_file()

0 comments on commit f6dafd2

Please sign in to comment.