Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qemu dump new cases development #2457

Merged
merged 1 commit into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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"
core_file = "/var/core."
pre_command += "&& echo "${core_file}%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 ${core_file}%s --command=${gdb_command_file}"
crash_cmd = "crash -i ${crash_script} /usr/lib/debug/lib/modules/%s/vmlinux ${vmcore_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:
leidwang marked this conversation as resolved.
Show resolved Hide resolved
- 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()
if host_kernel_version != guest_kernel_version:
test.cancel("Please update your host and guest kernel "
leidwang marked this conversation as resolved.
Show resolved Hide resolved
"to same version.The host kernel version is %s"
"The guest kernel version is %s"
% (host_kernel_version, guest_kernel_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")
leidwang marked this conversation as resolved.
Show resolved Hide resolved

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")
leidwang marked this conversation as resolved.
Show resolved Hide resolved

# 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"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where you define core_file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, it is because i test this on my host, then modify the code on my laptop and push it to github.I will be careful next time.
Thanks!

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 %= 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':
crash_cmd %= host_kernel_version
check_vmcore_file()