Skip to content

Commit 7685fb9

Browse files
committed
block_check_memory_leak:add overflow test
Support overflow checking Signed-off-by: qingwangrh <[email protected]>
1 parent a4408fc commit 7685fb9

File tree

2 files changed

+132
-45
lines changed

2 files changed

+132
-45
lines changed

qemu/tests/block_check_memory_leak.py

Lines changed: 92 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import time
66

77
from avocado.utils import process
8-
from virttest import arch, error_context
8+
from virttest import arch, error_context, env_process
99
from virttest import data_dir as virttest_data_dir
1010
from virttest.utils_misc import get_linux_drive_path
1111

@@ -27,12 +27,17 @@ def run(test, params, env):
2727
:param env: Dictionary with test environment.
2828
"""
2929

30-
def _execute_io_in_guest():
30+
def _execute_io_in_guest(serial=None):
3131
devs = ""
32-
for serial in data_images:
32+
if serial:
3333
drive = get_linux_drive_path(session, serial)
3434
if drive:
3535
devs += drive.replace("/dev/", "") + " "
36+
else:
37+
for serial in data_images:
38+
drive = get_linux_drive_path(session, serial)
39+
if drive:
40+
devs += drive.replace("/dev/", "") + " "
3641

3742
guest_io_cmd = params["guest_io_cmd"] % devs
3843
host_script = params["host_script"]
@@ -43,40 +48,95 @@ def _execute_io_in_guest():
4348
logger.info("Execute io:%s", guest_io_cmd)
4449
session.sendline("$SHELL " + guest_io_cmd)
4550

51+
def _get_scsi_debug_disk():
52+
output = process.system_output("lsscsi -giss|grep scsi_debug",
53+
shell=True,
54+
ignore_status=True).decode().strip()
55+
test.log.info("Host cmd output '%s'", output)
56+
disk_info = []
57+
if len(output) < 10:
58+
test.log.warning("Can not find scsi_debug disk")
59+
return
60+
61+
output = output.split("\n")
62+
for disk in output:
63+
info = disk.split()
64+
disk_dic = {"path": info[5], "wwn": info[6], "sg": info[7],
65+
"size": info[8], "all": disk}
66+
disk_info.append(disk_dic)
67+
68+
test.log.info(disk_info)
69+
return disk_info
70+
4671
if arch.ARCH in ("ppc64", "ppc64le"):
47-
output = process.system_output("lscfg --list firmware -v", shell=True).decode()
48-
ver = float(re.findall(r"\d\.\d", output)[0])
72+
out = process.system_output("lscfg --list firmware -v",
73+
shell=True).decode()
74+
ver = float(re.findall(r"\d\.\d", out)[0])
4975
if ver >= 6.3:
5076
# bz2235228,cancel test due to known product bug.
5177
test.cancel(
5278
"Skip test for xive kvm interrupt guest due to"
5379
" known host crash issue."
5480
)
81+
5582
logger = test.log
56-
data_images = params["data_images"].split()
57-
error_context.context("Get the main VM", logger.info)
58-
vm = env.get_vm(params["main_vm"])
59-
vm.verify_alive()
60-
61-
timeout = params.get_numeric("login_timeout", 360)
62-
session = vm.wait_for_login(timeout=timeout)
63-
time.sleep(60)
64-
logger.info("Start to IO in guest")
65-
_execute_io_in_guest()
66-
logger.info("Wait ...")
67-
time.sleep(params.get_numeric("io_timeout", 300))
68-
69-
logger.info("Try to cancel IO.")
70-
session = vm.wait_for_login(timeout=timeout)
71-
session.cmd(params["guest_cancel_io_cmd"], timeout=timeout)
72-
logger.info("Ready to destroy vm")
73-
vm.destroy()
74-
logger.info("Ready to check vm...")
75-
cp_cmd = "cp %s %s" % (params["valgrind_log"], test.logdir)
76-
process.system_output(cp_cmd, shell=True)
77-
check_cmd = params["check_cmd"]
78-
out = process.system_output(check_cmd, shell=True).decode()
79-
leak_threshold = params.get_numeric("leak_threshold")
80-
logger.info("Find leak:%s,threshold: %d", out, leak_threshold)
81-
if len(out) and int(out) > leak_threshold:
82-
test.fail("Find memory leak %s,Please check valgrind.log" % out)
83+
84+
vm = None
85+
disk_wwn = None
86+
if params.get("get_scsi_device") == "yes":
87+
scsi_debug_devs = _get_scsi_debug_disk()
88+
if scsi_debug_devs:
89+
dev = scsi_debug_devs[0]
90+
disk_wwn = dev["wwn"]
91+
if params["drive_format_stg1"] == "scsi-generic":
92+
params["image_name_stg1"] = dev["sg"]
93+
else:
94+
params["image_name_stg1"] = dev["path"]
95+
else:
96+
test.fail("Can not find scsi_debug devices")
97+
try:
98+
if params.get("not_preprocess", "no") == "yes":
99+
logger.debug("Ready boot VM : %s", params["images"])
100+
env_process.process(
101+
test, params, env, env_process.preprocess_image,
102+
env_process.preprocess_vm
103+
)
104+
105+
data_images = params["data_images"].split()
106+
error_context.context("Get the main VM", logger.info)
107+
vm = env.get_vm(params["main_vm"])
108+
vm.verify_alive()
109+
110+
timeout = params.get_numeric("login_timeout", 360)
111+
session = vm.wait_for_login(timeout=timeout)
112+
time.sleep(params.get_numeric("vm_boot_timeout", 60))
113+
logger.info("Start to IO in guest")
114+
_execute_io_in_guest(disk_wwn)
115+
logger.info("Wait ...")
116+
time.sleep(params.get_numeric("io_timeout", 300))
117+
118+
logger.info("Try to cancel IO.")
119+
session = vm.wait_for_login(timeout=timeout)
120+
session.cmd(params["guest_cancel_io_cmd"], timeout=timeout)
121+
logger.info("Ready to destroy vm")
122+
vm.destroy()
123+
logger.info("Ready to check vm...")
124+
cp_cmd = "cp %s %s" % (params["valgrind_log"], test.logdir)
125+
process.system_output(cp_cmd, shell=True)
126+
if params.get("leak_check", "yes") == "yes":
127+
check_cmd = params["leak_check_cmd"]
128+
out = process.system_output(check_cmd, shell=True).decode()
129+
leak_threshold = params.get_numeric("leak_threshold")
130+
logger.info("Find leak:%s,threshold: %d", out, leak_threshold)
131+
if len(out) and int(out) > leak_threshold:
132+
test.fail("Find memory leak %s,Please check valgrind.log" % out)
133+
134+
if params.get("overflow_check", "yes") == "yes":
135+
check_cmd = params["overflow_check_cmd"]
136+
out = process.system_output(check_cmd, shell=True,
137+
ignore_status=True).decode()
138+
if out and len(out):
139+
test.fail("Find overflow %s,Please check valgrind.log" % out)
140+
finally:
141+
if vm and vm.is_alive():
142+
vm.destroy(gracefully=False)

qemu/tests/cfg/block_check_memory_leak.cfg

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
type = block_check_memory_leak
44
kill_timeout = 300
55
vm_create_timeout = 360
6-
io_timeout = 600
6+
vm_boot_timeout = 60
7+
io_timeout = 180
78
login_timeout = 1600
89
valgrind_log = /tmp/valgrind.log
9-
pre_command = "if ! which valgrind;then yum install -y valgrind; fi;which valgrind"
10-
qemu_command_prefix = "valgrind --trace-children=yes --track-origins=yes --leak-check=full "
10+
pre_command = "if ! which valgrind;then yum install -y valgrind; fi;which valgrind;"
11+
qemu_command_prefix = "valgrind -s --trace-children=yes --track-origins=yes --leak-check=full "
1112
qemu_command_prefix += " --show-leak-kinds=definite --log-file=${valgrind_log} "
1213
qemu_sandbox =
1314
mem_devs =
@@ -36,20 +37,46 @@
3637
image_format_stg3 = raw
3738
drive_format_stg4 = virtio
3839
image_format_stg4 = qcow2
39-
force_create_image_stg1 = yes
40-
force_create_image_stg2 = yes
41-
force_create_image_stg3 = yes
42-
force_create_image_stg4 = yes
43-
blk_extra_params_stg1 = "serial=${image_stg1}"
44-
blk_extra_params_stg2 = "serial=${image_stg2}"
45-
blk_extra_params_stg3 = "serial=${image_stg3}"
46-
blk_extra_params_stg4 = "serial=${image_stg4}"
4740
guest_dir = /home
4841
name_script = guest_fio_on_disks.sh
4942
host_script = block_device/${name_script}
50-
guest_io_cmd = "${guest_dir}/${name_script} -n 10 -s 10g -d '%s'"
43+
leak_check = yes
44+
overflow_check = yes
5145
guest_cancel_io_cmd = "cat /tmp/mpid|xargs kill -SIGINT;pgrep fio|xargs kill -9;sleep 2"
52-
check_cmd = "cat ${valgrind_log}|grep -a "definitely lost:"|tail -n 1|awk '{print $4}'|tr -d ','"
46+
leak_check_cmd = "cat ${valgrind_log}|grep -a "definitely lost:"|tail -n 1|awk '{print $4}'|tr -d ','"
5347
leak_threshold = 0
48+
overflow_check_cmd = "cat ${valgrind_log}|grep -E 'Invalid (write|read)'"
5449
arm64-pci, arm64-mmio:
5550
leak_threshold = 1000
51+
variants:
52+
- with_normal:
53+
guest_operation = boot_test
54+
blk_extra_params_stg1 = "serial=${image_stg1}"
55+
blk_extra_params_stg2 = "serial=${image_stg2}"
56+
blk_extra_params_stg3 = "serial=${image_stg3}"
57+
blk_extra_params_stg4 = "serial=${image_stg4}"
58+
force_create_image_stg1 = yes
59+
force_create_image_stg2 = yes
60+
force_create_image_stg3 = yes
61+
force_create_image_stg4 = yes
62+
guest_io_cmd = "${guest_dir}/${name_script} -n 10 -s 10g -d '%s'"
63+
- with_pass_through:
64+
not_preprocess = yes
65+
get_scsi_device = yes
66+
data_images = "${image_stg1}"
67+
images = "image1 ${data_images}"
68+
image_format_stg1 = raw
69+
image_raw_device_stg1 = yes
70+
image_name_stg1 = TBD
71+
vm_boot_timeout = 30
72+
io_timeout = 60
73+
guest_io_cmd = "${guest_dir}/${name_script} -n 10 -s 500M -d '%s'"
74+
disk_size = 576
75+
pre_command += "modprobe -r scsi_debug; modprobe scsi_debug dev_size_mb=${disk_size};"
76+
post_command += "modprobe -r scsi_debug;"
77+
variants:
78+
- with_block:
79+
drive_format_stg1 = scsi-block
80+
- with_generic:
81+
drive_format_stg1 = scsi-generic
82+
drive_cache_stg1 = writethrough

0 commit comments

Comments
 (0)