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 Oct 28, 2020
1 parent 82f653b commit 45a8534
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
19 changes: 19 additions & 0 deletions qemu/tests/cfg/dump_guest_core.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- dump_guest_core:
type = dump_guest_core
virt_test_type = qemu
start_vm = no
pre_command = "ulimit -c unlimited"
pre_command1 = "echo "/var/core.%p" > /proc/sys/kernel/core_pattern"
trigger_core_dump_command = "kill -s SIGSEGV %s"
gdb_command = "gdb /var/core.%s --command=%s"
gdb_command_file = "/home/gdb_command"
crash_script = "/home/crash.cmd"
extra_params += " -machine dump-guest-core=%s"
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
116 changes: 116 additions & 0 deletions qemu/tests/dump_guest_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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
"""
process.run("echo \"source /usr/share/qemu-kvm/dump-guest-memory.py\" > %s"
% gdb_command_file, shell=True)
process.run("echo \"set height 0\" >> %s"
% gdb_command_file, shell=True)
if params['vm_arch_name'] == 'x86_64':
process.run("echo \"dump-guest-memory /tmp/vmcore X86_64\" >> %s"
% gdb_command_file, shell=True)
if params['vm_arch_name'] == 'ppc64le':
process.run("echo \"dump-guest-memory /tmp/vmcore ppc64le\" >> %s"
% gdb_command_file, shell=True)
process.run("echo bt >> %s" % gdb_command_file, shell=True)
process.run("echo quit >> %s" % gdb_command_file, shell=True)
logging.info("gdb_command is %s" % gdb_command)
status, output = process.getstatusoutput(gdb_command)
os.remove(gdb_command_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 bt > %s" % crash_script, shell=True)
process.run("echo task 0 >> %s" % crash_script, shell=True)
process.run("echo task 1 >> %s" % crash_script, shell=True)
process.run("echo quit >> %s" % crash_script, shell=True)
crash_cmd = "crash -i %s /usr/lib/debug/lib/modules/%s/vmlinux"
crash_cmd %= (crash_script, host_kernel_version)
crash_cmd += " /tmp/vmcore"
status, output = process.getstatusoutput(crash_cmd)
os.remove(crash_script)
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-debug*"]
utils_package.package_install(packages)

trigger_core_dump_command = params.get("trigger_core_dump_command")
gdb_command = params.get("gdb_command")
gdb_command_file = params.get("gdb_command_file")
dump_guest_core = params.get("dump_guest_core")
pre_command = params.get("pre_command")
pre_command1 = params.get("pre_command1")
crash_script = params.get("crash_script")

process.run(pre_command)
process.run(pre_command1)

params["extra_params"] %= dump_guest_core
params["start_vm"] = "yes"
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, gdb_command_file)
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 45a8534

Please sign in to comment.