提交 82d85aac 编写于 作者: Y Yiqiao Pu

Merge pull request #20 from humanux/iofuzz

test.iofuzz: some modifications of iofuzz
- iofuzz: install setup image_copy unattended_install.cdrom
virt_test_type = qemu libvirt
backup_image_before_testing = yes
backup_image_on_check_error = yes
restore_image = yes
restore_image_on_check_error = yes
only Linux
type = iofuzz
......@@ -2,7 +2,8 @@ import logging
import re
import random
from autotest.client.shared import error
from virttest import aexpect
from virttest import aexpect, qemu_vm, virt_vm
from virttest import data_dir, storage, qemu_storage
def run(test, params, env):
......@@ -23,6 +24,16 @@ def run(test, params, env):
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
def qemu_img_check():
"""
Check guest disk image, and backup image when error occured
"""
params["backup_image_on_check_error"] = 'yes'
base_dir = data_dir.get_data_dir()
image_name = storage.get_image_filename(params, base_dir)
image = qemu_storage.QemuImg(params, base_dir, image_name)
image.check_image(params, base_dir)
def outb(session, port, data):
"""
Write data to a given port.
......@@ -37,8 +48,8 @@ def run(test, params, env):
(oct(data), port))
try:
session.cmd(outb_cmd)
except aexpect.ShellError, e:
logging.debug(e)
except aexpect.ShellError, err:
logging.debug(err)
def inb(session, port):
"""
......@@ -51,8 +62,8 @@ def run(test, params, env):
inb_cmd = "dd if=/dev/port seek=%d of=/dev/null bs=1 count=1" % port
try:
session.cmd(inb_cmd)
except aexpect.ShellError, e:
logging.debug(e)
except aexpect.ShellError, err:
logging.debug(err)
def fuzz(session, inst_list):
"""
......@@ -66,26 +77,36 @@ def run(test, params, env):
:raise error.TestFail: If the VM process dies in the middle of the
fuzzing procedure.
"""
for (op, operand) in inst_list:
if op == "read":
for (wr_op, operand) in inst_list:
if wr_op == "read":
inb(session, operand[0])
elif op == "write":
elif wr_op == "write":
outb(session, operand[0], operand[1])
else:
raise error.TestError("Unknown command %s" % op)
raise error.TestError("Unknown command %s" % wr_op)
if not session.is_responsive():
logging.debug("Session is not responsive")
try:
vm.verify_alive()
except qemu_vm.QemuSegFaultError, err:
raise error.TestFail("Qemu crash, error info: %s" % err)
except virt_vm.VMDeadKernelCrashError, err:
raise error.TestFail("Guest kernel crash, info: %s" % err)
else:
logging.warn("Guest is not alive during test")
if vm.process.is_alive():
logging.debug("VM is alive, try to re-login")
try:
session = vm.wait_for_login(timeout=10)
except Exception:
logging.debug("Could not re-login, reboot the guest")
qemu_img_check()
session = vm.reboot(method="system_reset")
else:
raise error.TestFail("VM has quit abnormally during "
"%s: %s" % (op, operand))
"%s: %s" % (wr_op, operand))
login_timeout = float(params.get("login_timeout", 240))
vm = env.get_vm(params["main_vm"])
......@@ -94,12 +115,12 @@ def run(test, params, env):
try:
ports = {}
r = random.SystemRandom()
o_random = random.SystemRandom()
logging.info("Enumerate guest devices through /proc/ioports")
ioports = session.cmd_output("cat /proc/ioports")
logging.debug(ioports)
devices = re.findall("(\w+)-(\w+)\ : (.*)", ioports)
devices = re.findall(r"(\w+)-(\w+)\ : (.*)", ioports)
skip_devices = params.get("skip_devices", "")
fuzz_count = int(params.get("fuzz_count", 10))
......@@ -126,10 +147,10 @@ def run(test, params, env):
# Write random values to random ports of the range
for _ in range(fuzz_count * (end - beg + 1)):
inst.append(("write",
[r.randint(beg, end), r.randint(0, 255)]))
inst.append(("write",[o_random.randint(beg, end),
o_random.randint(0, 255)]))
fuzz(session, inst)
vm.verify_alive()
finally:
session.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册