Home | History | Annotate | Download | only in kernel_LTP
      1 # Copyright (c) 2013 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 os
      6 from autotest_lib.client.bin import utils, test
      7 from autotest_lib.client.common_lib import error
      8 
      9 import parse_ltp_out
     10 
     11 
     12 class kernel_LTP(test.test):
     13     """Base class ltp test runner."""
     14     _DEP = 'kernel_ltp_dep'
     15     version = 1
     16 
     17     # Note: to run specific test(s), runltp supports the following options:
     18     #       -f CMDFILES (separate with ',')
     19     #       -s PATTERN
     20     #       -S SKIPFILE (ChromeOS uses ./site_excluded)
     21     #
     22     #       CMDFILES are lists of tests grouped by area. If no CMDFILES
     23     #       are supplied, runltp has a default set of CMDFILES listed
     24     #       in '$LTPROOT/scenario_groups/default' it uses. The CMDFILES are
     25     #       individual files under '$LTPROOT/runtest' such as commands, dio
     26     #       and fsx. Finally, the test cases listed in a CMDFILE are individual
     27     #       tests which reside under '$LTPROOT/testcases'.
     28     #
     29     #       Then, an abridged look at the parts of the LTP dir structure
     30     #       used here would be:
     31     #       $LTPROOT
     32     #               /scenario_groups/default - default list of CMDFILES
     33     #               /runtest/...             - CMDFILES group test cases
     34     #               /testcases/...           - test cases
     35     #
     36     #       The PATTERN argument is used to refine the tests that will run
     37     #       within an individual CMDFILE by supplying a regex match for
     38     #       individual test case names.
     39     #
     40     #       The SKIPFILE lists individual test cases to be excluded. These
     41     #       tests are not appropriate for a project.  ChromeOS uses the
     42     #       default SKIPFILE=site_excluded.
     43     #
     44     # e.g. -for all tests in math cmdfile:
     45     #           job.run_test('ltp', '-f math')
     46     #      -for just the float_bessel test in the math cmdfile:
     47     #           job.run_test('ltp', '-f math -s float_bessel')
     48     #      -for the math and memory management cmdfiles:
     49     #           job.run_test('ltp', '-f math,mm')
     50     def run_once(self, args='', script='runltp', select_tests=None):
     51         """A test wrapper for running tests/scripts under $LTPROOT.
     52 
     53         For ChromeOS $LTPROOT is the repo under src/third_party/ltp.
     54 
     55         @param args: arguments to be passed to 'script' (usually runltp).
     56         @param script: LTP script to run.
     57         @param select_tests: comma-separated list of names of tests
     58                              (executable files under ltp/testcases/bin) to run.
     59                              Used for running and debugging during development.
     60         """
     61         # In case the user wants to run a test script other than runltp
     62         # though runltp is the common case.
     63         if script == 'runltp':
     64             failcmdfile = os.path.join(self.debugdir, 'failcmdfile')
     65             outfile = os.path.join(self.resultsdir, 'ltp.out')
     66             args2 = ['-l %s' % os.path.join(self.resultsdir, 'ltp.log'),
     67                      '-C %s' % failcmdfile,
     68                      '-d %s' % self.tmpdir,
     69                      '-o %s' % outfile,
     70                      '-S %s' % os.path.join(self.bindir, 'site_excluded')]
     71             args = '%s -p %s' % (args, ' '.join(args2))
     72 
     73         # Uses the LTP binaries build into client/deps/kernel_ltp_dep.
     74         dep = self._DEP
     75         dep_dir = os.path.join(self.autodir, 'deps', dep)
     76         self.job.install_pkg(dep, 'dep', dep_dir)
     77 
     78         # Setup a fake runtest/testcase file if only running one test.
     79         if select_tests:
     80             # Selected files must exist under testcases/bin.
     81             testcase_bin_dir = os.path.join(dep_dir, 'testcases', 'bin')
     82             select_tests = select_tests.split(',')
     83             for select_test in select_tests:
     84                 test_bin_file = os.path.join(testcase_bin_dir, select_test)
     85                 if not os.path.isfile(test_bin_file):
     86                     raise error.TestFail('%s not found.' % test_bin_file)
     87             with open(os.path.join(dep_dir, 'runtest', 'cros_suite'), 'w') as f:
     88                 for select_test in select_tests:
     89                     f.write('%s %s\n' % (select_test, select_test))
     90             args += ' -f cros_suite'
     91 
     92         cmd = '%s %s' % (os.path.join(dep_dir, script), args)
     93         result = utils.run(cmd, ignore_status=True)
     94 
     95         if script == 'runltp':
     96             parse_ltp_out.summarize(outfile)
     97 
     98         # look for any failed test command.
     99         try:
    100             f = open(failcmdfile)
    101         except IOError:
    102             raise error.TestFail('Expected to find failcmdfile but did not.')
    103         failed_cmd = f.read().strip()
    104         f.close()
    105         if failed_cmd:
    106             raise error.TestFail(failed_cmd)
    107