Home | History | Annotate | Download | only in ltp
      1 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import logging
      6 import os
      7 from autotest_lib.client.bin import utils, test
      8 from autotest_lib.client.common_lib import error
      9 
     10 import parse_ltp_out
     11 
     12 
     13 class ltp(test.test):
     14     version = 6
     15 
     16     def _import_site_config(self):
     17         site_config_path = os.path.join(os.path.dirname(__file__),
     18                                         'site_config.py')
     19         if os.path.exists(site_config_path):
     20             # for some reason __import__ with full path does not work within
     21             # autotest, although it works just fine on the same client machine
     22             # in the python interactive shell or separate testcases
     23             execfile(site_config_path)
     24             self.site_ignore_tests = locals().get('ignore_tests', [])
     25         else:
     26             self.site_ignore_tests = []
     27 
     28 
     29     def initialize(self):
     30         self._import_site_config()
     31         self.job.require_gcc()
     32 
     33 
     34     # http://sourceforge.net/projects/ltp/files/LTP%20Source/ltp-20120104/
     35     #        ltp-full-20120104.bz2
     36     def setup(self, tarball = 'ltp-full-20120104.bz2'):
     37         tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
     38         utils.extract_tarball_to_dir(tarball, self.srcdir)
     39         os.chdir(self.srcdir)
     40         ltpbin_dir = os.path.join(self.srcdir, 'bin')
     41         os.mkdir(ltpbin_dir)
     42 
     43         utils.system('patch -p1 < ../patches/getdents.patch')
     44         utils.system('patch -p1 < ../patches/cpuid.patch')
     45         utils.system('patch -p1 < ../patches/kill-ipc.patch')
     46         utils.system('patch -p1 < ../patches/genpow.patch')
     47         utils.system('patch -p1 < ../patches/sysctl.patch')
     48         utils.make('autotools')
     49         utils.configure('--prefix=%s' % ltpbin_dir)
     50         utils.make('-j %d all' % utils.count_cpus())
     51         utils.system('yes n | make SKIP_IDCHECK=1 install')
     52 
     53 
     54     # Note: to run specific test(s), runltp supports an option (-f)
     55     #       to specify a custom 'scenario group' which is a comma-separated
     56     #       list of cmdfiles and/or an option (-s) to specify a grep match
     57     #       pattern for individual test names.
     58     # e.g. -for all tests in math cmdfile:
     59     #       job.run_test('ltp', '-f math')
     60     #      -for just the float_bessel test in the math cmdfile:
     61     #       job.run_test('ltp', '-f math -s float_bessel')
     62     #      -for the math and memory management cmdfiles:
     63     #       job.run_test('ltp', '-f math,mm')
     64     # Note: the site_excluded file lists individual test tags for tests
     65     #       to exclude (see the comment at the top of site_excluded).
     66     def run_once(self, args = '', script = 'runltp', ignore_tests=[]):
     67 
     68         ignore_tests = ignore_tests + self.site_ignore_tests
     69 
     70         # In case the user wants to run another test script
     71         if script == 'runltp':
     72             logfile = os.path.join(self.resultsdir, 'ltp.log')
     73             outfile = os.path.join(self.resultsdir, 'ltp.out')
     74             failcmdfile = os.path.join(self.debugdir, 'failcmdfile')
     75             excludecmdfile = os.path.join(self.bindir, 'site_excluded')
     76             args2 = '-p -l %s -C %s -d %s -o %s -S %s' % (logfile, failcmdfile,
     77                                                           self.tmpdir, outfile,
     78                                                           excludecmdfile)
     79             args = args + ' ' + args2
     80 
     81         ltpbin_dir = os.path.join(self.srcdir, 'bin')
     82         cmd = os.path.join(ltpbin_dir, script) + ' ' + args
     83         result = utils.run(cmd, ignore_status=True)
     84 
     85         if script == 'runltp':
     86             parse_ltp_out.summarize(outfile)
     87 
     88         # look for any failed test command.
     89         try:
     90             f = open(failcmdfile)
     91         except IOError:
     92             logging.warning('Expected to find failcmdfile but did not.')
     93             return
     94         failed_cmd = f.read().strip()
     95         f.close()
     96         if failed_cmd:
     97             raise error.TestFail(failed_cmd)
     98