Home | History | Annotate | Download | only in xfstests
      1 import os, re, glob, logging
      2 from autotest_lib.client.common_lib import error
      3 from autotest_lib.client.bin import test, utils, os_dep
      4 
      5 class xfstests(test.test):
      6 
      7     version = 1
      8 
      9     PASSED_RE = re.compile(r'Passed all \d+ tests')
     10     FAILED_RE = re.compile(r'Failed \d+ of \d+ tests')
     11     NA_RE = re.compile(r'Passed all 0 tests')
     12     NA_DETAIL_RE = re.compile(r'(\d{3})\s*(\[not run\])\s*(.*)')
     13 
     14 
     15     def _get_available_tests(self):
     16         tests = glob.glob('???.out')
     17         tests_list = [t[:-4] for t in tests if os.path.exists(t[:-4])]
     18         tests_list.sort()
     19         return tests_list
     20 
     21 
     22     def _run_sub_test(self, test):
     23         os.chdir(self.srcdir)
     24         output = utils.system_output('./check %s' % test,
     25                                      ignore_status=True,
     26                                      retain_output=True)
     27         lines = output.split('\n')
     28         result_line = lines[-1]
     29 
     30         if self.NA_RE.match(result_line):
     31             detail_line = lines[-3]
     32             match = self.NA_DETAIL_RE.match(detail_line)
     33             if match is not None:
     34                 error_msg = match.groups()[2]
     35             else:
     36                 error_msg = 'Test dependency failed, test not run'
     37             raise error.TestNAError(error_msg)
     38 
     39         elif self.FAILED_RE.match(result_line):
     40             raise error.TestError('Test error, check debug logs for complete '
     41                                   'test output')
     42 
     43         elif self.PASSED_RE.match(result_line):
     44             return
     45 
     46         else:
     47             raise error.TestError('Could not assert test success or failure, '
     48                                   'assuming failure. Please check debug logs')
     49 
     50 
     51     def setup(self, tarball = 'xfstests.tar.bz2'):
     52         #
     53         # Anticipate failures due to missing devel tools, libraries, headers
     54         # and xfs commands
     55         #
     56         os_dep.command('autoconf')
     57         os_dep.command('autoheader')
     58         os_dep.command('libtool')
     59         os_dep.library('libuuid.so.1')
     60         os_dep.header('xfs/xfs.h')
     61         os_dep.header('attr/xattr.h')
     62         os_dep.header('sys/acl.h')
     63         os_dep.command('mkfs.xfs')
     64         os_dep.command('xfs_db')
     65         os_dep.command('xfs_bmap')
     66         os_dep.command('xfsdump')
     67 
     68         self.job.require_gcc()
     69 
     70         tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
     71         utils.extract_tarball_to_dir(tarball, self.srcdir)
     72         os.chdir(self.srcdir)
     73         utils.make()
     74 
     75         logging.debug("Available tests in srcdir: %s" %
     76                       ", ".join(self._get_available_tests()))
     77 
     78 
     79     def run_once(self, test_number):
     80         os.chdir(self.srcdir)
     81         if test_number == '000':
     82             logging.debug('Dummy test to setup xfstests')
     83             return
     84 
     85         if test_number not in self._get_available_tests():
     86             raise error.TestError('test file %s not found' % test_number)
     87 
     88         logging.debug("Running test: %s" % test_number)
     89         self._run_sub_test(test_number)
     90