From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lucas Meneghel Rodrigues Subject: Re: [Autotest] [PATCH] KVM test: Add a subtest iofuzz Date: Thu, 6 May 2010 20:18:54 -0300 Message-ID: References: <20100407115509.14877.87055.stgit@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: autotest@test.kernel.org, kvm@vger.kernel.org To: Jason Wang Return-path: Received: from mail-wy0-f174.google.com ([74.125.82.174]:49215 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751228Ab0EFXS4 convert rfc822-to-8bit (ORCPT ); Thu, 6 May 2010 19:18:56 -0400 Received: by wyg36 with SMTP id 36so420152wyg.19 for ; Thu, 06 May 2010 16:18:54 -0700 (PDT) In-Reply-To: <20100407115509.14877.87055.stgit@localhost.localdomain> Sender: kvm-owner@vger.kernel.org List-ID: On Wed, Apr 7, 2010 at 8:55 AM, Jason Wang wrote: > The design of iofuzz is simple: it just generate random I/O port > activity inside the virtual machine. The correctness of the device > emulation may be verified through this test. > > As the instrcutions are randomly generated, guest may enter the wrong > state. The test solve this issue by detect the hang and restart the > virtual machine. > > The test duration could also be adjusted through the "fuzz_count". An= d > the parameter "skip_devices" is used to specified the devices which > should not be used to do the fuzzing. > > For current version, every activity were logged and the commnad was > sent through a seesion between host and guest. Through this method ma= y > slow down the whole test but it works well. The enumeration was done > through /proc/ioports and the scenario of avtivity is not aggressive. > > Suggestions are welcomed. Hi Jason, nice test! I have made some little changes, re-submitted and will commit. Thanks! > Signed-off-by: Jason Wang > --- > =A0client/tests/kvm/tests/iofuzz.py =A0 =A0 =A0 | =A0 97 ++++++++++++= ++++++++++++++++++++ > =A0client/tests/kvm/tests_base.cfg.sample | =A0 =A02 + > =A02 files changed, 99 insertions(+), 0 deletions(-) > =A0create mode 100644 client/tests/kvm/tests/iofuzz.py > > diff --git a/client/tests/kvm/tests/iofuzz.py b/client/tests/kvm/test= s/iofuzz.py > new file mode 100644 > index 0000000..c2f22af > --- /dev/null > +++ b/client/tests/kvm/tests/iofuzz.py > @@ -0,0 +1,97 @@ > +import logging, time, re, random > +from autotest_lib.client.common_lib import error > +import kvm_subprocess, kvm_test_utils, kvm_utils > + > + > +def run_iofuzz(test, params, env): > + =A0 =A0""" > + =A0 =A0KVM iofuzz test: > + =A0 =A01) Log into a guest > + > + =A0 =A0@param test: kvm test object > + =A0 =A0@param params: Dictionary with the test parameters > + =A0 =A0@param env: Dictionary with test environment. > + =A0 =A0""" > + =A0 =A0vm =3D kvm_test_utils.get_living_vm(env, params.get("main_vm= ")) > + =A0 =A0session =3D kvm_test_utils.wait_for_login(vm, 0, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 float(params.get("boot_timeout", 240)), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 0, 2) > + > + =A0 =A0def outb(session, port, data): > + =A0 =A0 =A0 =A0logging.debug("outb(0x%x,0x%x)" % (port, data)) > + =A0 =A0 =A0 =A0outb_cmd =3D "echo -e '\\%s' | dd of=3D/dev/port see= k=3D%d bs=3D1 count=3D1" % \ > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (oct(data), port) > + =A0 =A0 =A0 =A0s, o =3D session.get_command_status_output(outb_cmd) > + =A0 =A0 =A0 =A0if s !=3D 0: > + =A0 =A0 =A0 =A0 =A0 =A0logging.debug("None zero value returned") > + > + =A0 =A0def inb(session, port): > + =A0 =A0 =A0 =A0logging.debug("inb(0x%x)" % port) > + =A0 =A0 =A0 =A0inb_cmd =3D "dd if=3D/dev/port seek=3D%d of=3D/dev/n= ull bs=3D1 count=3D1" % port > + =A0 =A0 =A0 =A0s, o =3D session.get_command_status_output(inb_cmd) > + =A0 =A0 =A0 =A0if s !=3D 0: > + =A0 =A0 =A0 =A0 =A0 =A0logging.debug("None zero value returned") > + > + =A0 =A0def fuzz(session, inst_list): > + =A0 =A0 =A0 =A0for (op, operand) in inst_list: > + =A0 =A0 =A0 =A0 =A0 =A0if op =3D=3D "read": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0inb(session, operand[0]) > + =A0 =A0 =A0 =A0 =A0 =A0elif op =3D=3D"write": > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0outb(session, operand[0], operand[1]= ) > + =A0 =A0 =A0 =A0 =A0 =A0else: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0raise error.TestError("Unknown comma= nd %s" % op) > + > + =A0 =A0 =A0 =A0 =A0 =A0if not session.is_responsive(): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Session is not respon= sive") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if vm.process.is_alive(): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("VM is alive, = try to re-login") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0try: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0session =3D kvm_test= _utils.wait_for_login(vm, 0, 10, 0, 2) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0except: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.debug("Could= not re-login, reboot the guest") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0session =3D kvm_test= _utils.reboot(vm, session, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0method =3D "system_reset") > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0raise error.TestFail("VM hav= e quit abnormally") > + =A0 =A0try: > + =A0 =A0 =A0 =A0ports =3D {} > + =A0 =A0 =A0 =A0ran =3D random.SystemRandom() > + > + =A0 =A0 =A0 =A0logging.info("Enumerate the device through /proc/iop= orts") > + =A0 =A0 =A0 =A0ioports =3D session.get_command_output("cat /proc/io= ports") > + =A0 =A0 =A0 =A0logging.debug(ioports) > + =A0 =A0 =A0 =A0devices =3D re.findall("(\w+)-(\w+)\ : (.*)", ioport= s) > + > + =A0 =A0 =A0 =A0skip_devices =3D params.get("skip_devices","") > + =A0 =A0 =A0 =A0fuzz_count =3D int(params.get("fuzz_count", 10)) > + > + =A0 =A0 =A0 =A0for (beg, end, name) in devices: > + =A0 =A0 =A0 =A0 =A0 =A0ports[(int(beg, base=3D16), int(end, base=3D= 16))] =3D name.strip() > + > + =A0 =A0 =A0 =A0for (beg, end) in ports.keys(): > + > + =A0 =A0 =A0 =A0 =A0 =A0name =3D ports[(beg, end)] > + =A0 =A0 =A0 =A0 =A0 =A0if name in skip_devices: > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0logging.info("Skipping %s" % name) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0continue > + > + =A0 =A0 =A0 =A0 =A0 =A0logging.info("Fuzzing %s at 0x%x-0x%x" % (na= me, beg, end)) > + =A0 =A0 =A0 =A0 =A0 =A0inst =3D [] > + > + =A0 =A0 =A0 =A0 =A0 =A0# Read all ports > + =A0 =A0 =A0 =A0 =A0 =A0for port in range(beg, end+1): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0inst.append(("read", [port])) > + > + =A0 =A0 =A0 =A0 =A0 =A0# Outb with zero > + =A0 =A0 =A0 =A0 =A0 =A0for port in range(beg, end+1): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0inst.append(("write", [port, 0])) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pass > + > + =A0 =A0 =A0 =A0 =A0 =A0# Random fuzzing > + =A0 =A0 =A0 =A0 =A0 =A0for seq in range(fuzz_count * (end-beg+1)): > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0inst.append(("write", [ran.randint(b= eg, end), ran.randint(0,255)])) > + > + =A0 =A0 =A0 =A0 =A0 =A0fuzz(session, inst) > + > + =A0 =A0finally: > + =A0 =A0 =A0 =A0session.close() > diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kv= m/tests_base.cfg.sample > index d162cf8..01080bb 100644 > --- a/client/tests/kvm/tests_base.cfg.sample > +++ b/client/tests/kvm/tests_base.cfg.sample > @@ -294,6 +294,8 @@ variants: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ksm_mode =3D "serial" > =A0 =A0 =A0 =A0 =A0 =A0 - ksm_parallel: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ksm_mode =3D "parallel" > + =A0 =A0- iofuzz: > + =A0 =A0 =A0 =A0type =3D iofuzz > > =A0 =A0 # system_powerdown, system_reset and shutdown *must* be the l= ast ones > =A0 =A0 # defined (in this order), since the effect of such tests can= leave > > _______________________________________________ > Autotest mailing list > Autotest@test.kernel.org > http://test.kernel.org/cgi-bin/mailman/listinfo/autotest > --=20 Lucas