1 import os, re, logging 2 from autotest_lib.client.bin import test, utils, os_dep 3 from autotest_lib.client.common_lib import error 4 5 6 class qemu_iotests(test.test): 7 """ 8 This autotest module runs the qemu_iotests testsuite. 9 10 @copyright: Red Hat 2009 11 @author: Yolkfull Chow (yzhou (at] redhat.com) 12 @see: http://www.kernel.org/pub/scm/linux/kernel/git/hch/qemu-iotests.git 13 """ 14 version = 2 15 def initialize(self, qemu_path=''): 16 if qemu_path: 17 # Prepending the path at the beginning of $PATH will make the 18 # version found on qemu_path be preferred over other ones. 19 os.environ['PATH'] = qemu_path + ":" + os.environ['PATH'] 20 try: 21 self.qemu_img_path = os_dep.command('qemu-img') 22 self.qemu_io_path = os_dep.command('qemu-io') 23 except ValueError, e: 24 raise error.TestNAError('Commands qemu-img or qemu-io missing') 25 self.job.require_gcc() 26 27 28 def setup(self, tarball='qemu-iotests.tar.bz2'): 29 """ 30 Uncompresses the tarball and cleans any leftover output files. 31 32 @param tarball: Relative path to the testsuite tarball. 33 """ 34 tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir) 35 utils.extract_tarball_to_dir(tarball, self.srcdir) 36 os.chdir(self.srcdir) 37 utils.make('clean') 38 39 40 def run_once(self, options='', testlist=''): 41 """ 42 Passes the appropriate parameters to the testsuite. 43 44 # Usage: $0 [options] [testlist] 45 # check options 46 # -raw test raw (default) 47 # -cow test cow 48 # -qcow test qcow 49 # -qcow2 test qcow2 50 # -vpc test vpc 51 # -vmdk test vmdk 52 # -xdiff graphical mode diff 53 # -nocache use O_DIRECT on backing file 54 # -misalign misalign memory allocations 55 # -n show me, do not run tests 56 # -T output timestamps 57 # -r randomize test order 58 # 59 # testlist options 60 # -g group[,group...] include tests from these groups 61 # -x group[,group...] exclude tests from these groups 62 # NNN include test NNN 63 # NNN-NNN include test range (eg. 012-021) 64 65 @param qemu_path: Optional qemu install path. 66 @param options: Options accepted by the testsuite. 67 @param testlist: List of tests that will be executed (by default, all 68 testcases will be executed). 69 """ 70 os.chdir(self.srcdir) 71 test_dir = os.path.join(self.srcdir, "scratch") 72 if not os.path.exists(test_dir): 73 os.mkdir(test_dir) 74 cmd = "./check" 75 if options: 76 cmd += " " + options 77 if testlist: 78 cmd += " " + testlist 79 80 try: 81 try: 82 result = utils.system(cmd) 83 except error.CmdError, e: 84 failed_cases = re.findall("Failures: (\d+)", str(e)) 85 for num in failed_cases: 86 failed_name = num + ".out.bad" 87 src = os.path.join(self.srcdir, failed_name) 88 dest = os.path.join(self.resultsdir, failed_name) 89 utils.get_file(src, dest) 90 if failed_cases: 91 e_msg = ("Qemu-iotests failed. Failed cases: %s" % 92 failed_cases) 93 else: 94 e_msg = "Qemu-iotests failed" 95 raise error.TestFail(e_msg) 96 finally: 97 src = os.path.join(self.srcdir, "check.log") 98 dest = os.path.join(self.resultsdir, "check.log") 99 utils.get_file(src, dest) 100