From patchwork Wed Apr 7 11:55:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 91013 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o37Boj5N009536 for ; Wed, 7 Apr 2010 11:50:45 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757731Ab0DGLun (ORCPT ); Wed, 7 Apr 2010 07:50:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48865 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757695Ab0DGLum (ORCPT ); Wed, 7 Apr 2010 07:50:42 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o37Boesc013091 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 7 Apr 2010 07:50:40 -0400 Received: from localhost.localdomain ([10.66.91.25]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o37BocLm014765; Wed, 7 Apr 2010 07:50:39 -0400 Subject: [PATCH] KVM test: Add a subtest iofuzz To: autotest@test.kernel.org, lmr@redhat.com, kvm@vger.kernel.org From: Jason Wang Date: Wed, 07 Apr 2010 19:55:09 +0800 Message-ID: <20100407115509.14877.87055.stgit@localhost.localdomain> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 07 Apr 2010 11:51:02 +0000 (UTC) diff --git a/client/tests/kvm/tests/iofuzz.py b/client/tests/kvm/tests/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): + """ + KVM iofuzz test: + 1) Log into a guest + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + vm = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + session = kvm_test_utils.wait_for_login(vm, 0, + float(params.get("boot_timeout", 240)), + 0, 2) + + def outb(session, port, data): + logging.debug("outb(0x%x,0x%x)" % (port, data)) + outb_cmd = "echo -e '\\%s' | dd of=/dev/port seek=%d bs=1 count=1" % \ + (oct(data), port) + s, o = session.get_command_status_output(outb_cmd) + if s != 0: + logging.debug("None zero value returned") + + def inb(session, port): + logging.debug("inb(0x%x)" % port) + inb_cmd = "dd if=/dev/port seek=%d of=/dev/null bs=1 count=1" % port + s, o = session.get_command_status_output(inb_cmd) + if s != 0: + logging.debug("None zero value returned") + + def fuzz(session, inst_list): + for (op, operand) in inst_list: + if op == "read": + inb(session, operand[0]) + elif op =="write": + outb(session, operand[0], operand[1]) + else: + raise error.TestError("Unknown command %s" % op) + + if not session.is_responsive(): + logging.debug("Session is not responsive") + if vm.process.is_alive(): + logging.debug("VM is alive, try to re-login") + try: + session = kvm_test_utils.wait_for_login(vm, 0, 10, 0, 2) + except: + logging.debug("Could not re-login, reboot the guest") + session = kvm_test_utils.reboot(vm, session, + method = "system_reset") + else: + raise error.TestFail("VM have quit abnormally") + try: + ports = {} + ran = random.SystemRandom() + + logging.info("Enumerate the device through /proc/ioports") + ioports = session.get_command_output("cat /proc/ioports") + logging.debug(ioports) + devices = re.findall("(\w+)-(\w+)\ : (.*)", ioports) + + skip_devices = params.get("skip_devices","") + fuzz_count = int(params.get("fuzz_count", 10)) + + for (beg, end, name) in devices: + ports[(int(beg, base=16), int(end, base=16))] = name.strip() + + for (beg, end) in ports.keys(): + + name = ports[(beg, end)] + if name in skip_devices: + logging.info("Skipping %s" % name) + continue + + logging.info("Fuzzing %s at 0x%x-0x%x" % (name, beg, end)) + inst = [] + + # Read all ports + for port in range(beg, end+1): + inst.append(("read", [port])) + + # Outb with zero + for port in range(beg, end+1): + inst.append(("write", [port, 0])) + pass + + # Random fuzzing + for seq in range(fuzz_count * (end-beg+1)): + inst.append(("write", [ran.randint(beg, end), ran.randint(0,255)])) + + fuzz(session, inst) + + finally: + session.close() diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/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: ksm_mode = "serial" - ksm_parallel: ksm_mode = "parallel" + - iofuzz: + type = iofuzz # system_powerdown, system_reset and shutdown *must* be the last ones # defined (in this order), since the effect of such tests can leave