-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dump_guest_core:qemu dump new cases development
1.Use gdb check core dump file 2.Use crash check vmcore file Signed-off-by: Leidong Wang <leidwang@redhat.com>
- Loading branch information
Showing
2 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
- 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" | ||
vmcore_file = "/tmp/vmcore" | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
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 ppc64-le\" >> %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, 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 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 += 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.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") | ||
vmcore_file = params.get("vmcore_file") | ||
|
||
process.run(pre_command, shell=True) | ||
process.run(pre_command1, shell=True) | ||
|
||
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() |