Home | History | Annotate | Download | only in bin
      1 # Copyright (c) 2010 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, os
      6 
      7 from autotest_lib.client.bin import test
      8 from autotest_lib.client.common_lib import utils
      9 
     10 class unit_test(test.test):
     11     """
     12     Unit test should simply subclass this test which handles everything.
     13     """
     14     version = 1
     15     preserve_srcdir = True
     16 
     17 
     18     def setup(self):
     19       os.chdir(self.srcdir)
     20       utils.make('clean')
     21       utils.make('all')
     22       
     23       self.job.setup_dep(['gtest'])
     24 
     25     def run_once(self):
     26         dep ='gtest'
     27         dep_dir = os.path.join(self.autodir, 'deps', dep)
     28         self.job.install_pkg(dep, 'dep', dep_dir)
     29       
     30         # Run the unit test, gather the results and place the gcda files for
     31         # code coverage in the results directory.
     32         
     33         os.chdir(self.srcdir)
     34         result = utils.run('LD_LIBRARY_PATH=' + dep_dir + 
     35                            ' GCOV_PREFIX=' + self.resultsdir +
     36                            ' GCOV_PREFIX_STRIP=9999 ./unit_test > ' +
     37                            self.resultsdir + '/unit_test_result.txt')
     38         logging.debug(result.stderr)
     39         logging.info('result: ' + self.resultsdir + '/unit_test_result.txt')
     40         
     41     def cleanup(self):
     42         # This is a hack - we should only need to copy back the .gcda file but
     43         # we don't know how to access the source on the server. So copy 
     44         # everything back.
     45         
     46         os.chdir(self.srcdir)
     47         utils.run('cp * ' + self.resultsdir)
     48