• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2009 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
5import logging
6import os
7import re
8import shutil
9
10from autotest_lib.client.common_lib import utils
11from autotest_lib.server import autotest, test
12
13def gen_gcov_report(report, files):
14    results = {}
15
16    for f in files:
17        escf = re.escape(f)
18        match = re.search("File '.*%s'\nLines executed:([0-9.]+)%%" % escf,
19                          report)
20        if match:
21            # simple replace to make a valid identifier
22            key = f.replace('/', '_').replace('.', '_')
23            results[key] = float(match.group(1))
24
25    return results
26
27class unit_test_server(test.test):
28    version = 1
29
30    def run_once(self, host=None):
31        self.client = host
32
33        # Collect the gcov by running a client side test
34        client_at = autotest.Autotest(self.client)
35        client_at.run_test(self.client_test)
36
37    def postprocess(self):
38        logging.info('UnitTestServer: postprocess %s' %
39                     self.client.hostname)
40
41        # Get the result director of the client
42        results_dir = os.path.join(self.outputdir, self.client_test, 'results/')
43
44        # Execute gcov on the result
45        os.chdir(results_dir)
46        report = utils.system_output('gcov ' + ''.join(self.test_files))
47
48        # Filter report for the files of interest
49        filtered = gen_gcov_report(report, self.test_files)
50
51        # Promote the client test keyval as our own
52        src = os.path.join(self.outputdir, self.client_test, 'results/keyval')
53        dst = os.path.join(self.resultsdir, 'keyval')
54        if os.path.exists(src):
55            shutil.copy(src, dst)
56        else:
57            logging.warning('Unable to locate %s' % src)
58
59        # Append the coverage report
60        self.write_perf_keyval(filtered)
61