blob: 2536f147c984edd7da96a24802415f928ce59a6a [file] [log] [blame]
mbligh9cd69d32008-06-26 23:29:33 +00001#!/usr/bin/python2.4
2
3import os, sys
4import unittest_suite
5import common
6from autotest_lib.client.common_lib import utils
7
8root = os.path.abspath(os.path.dirname(__file__))
9
10
11def is_valid_directory(dirpath):
mbligh35b3ae12008-07-01 01:49:22 +000012 if dirpath.find('client/tests') >= 0:
13 return False
14 elif dirpath.find('client/site_tests') >= 0:
15 return False
16 elif dirpath.find('tko/migrations') >= 0:
17 return False
18 elif dirpath.find('server/tests') >= 0:
19 return False
20 elif dirpath.find('server/site_tests') >= 0:
21 return False
22 else:
23 return True
mbligh9cd69d32008-06-26 23:29:33 +000024
25
26def is_valid_filename(f):
27 # has to be a .py file
28 if not f.endswith('.py'):
29 return False
30
31 # but there are execptions
32 if f.endswith('_unittest.py'):
33 return False
34 elif f == '__init__.py':
35 return False
36 elif f == 'common.py':
37 return False
38 else:
39 return True
40
41
42def main():
43 coverage = os.path.join(root, "contrib/coverage.py")
44 unittest_suite = os.path.join(root, "unittest_suite.py")
mbligh35b3ae12008-07-01 01:49:22 +000045
mbligh9cd69d32008-06-26 23:29:33 +000046 # remove preceeding coverage data
47 cmd = "%s -e" % (coverage)
48 utils.system_output(cmd)
mbligh35b3ae12008-07-01 01:49:22 +000049
mbligh9cd69d32008-06-26 23:29:33 +000050 # run unittest_suite through coverage analysis
51 cmd = "%s -x %s" % (coverage, unittest_suite)
52 utils.system_output(cmd)
mbligh35b3ae12008-07-01 01:49:22 +000053
mbligh9cd69d32008-06-26 23:29:33 +000054 # now walk through directory grabbing lits of files
55 module_strings = []
56 for dirpath, dirnames, files in os.walk(root):
57 if is_valid_directory(dirpath):
58 for f in files:
59 if is_valid_filename(f):
60 temp = os.path.join(dirpath, f)
61 module_strings.append(temp)
mbligh35b3ae12008-07-01 01:49:22 +000062
mbligh9cd69d32008-06-26 23:29:33 +000063 # analyze files
64 cmd = "%s -r -m %s" % (coverage, " ".join(module_strings))
65 utils.system(cmd)
66
67
68if __name__ == "__main__":
69 main()