summaryrefslogtreecommitdiffstats
path: root/tools/code_coverage
diff options
context:
space:
mode:
authorjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 04:46:23 +0000
committerjrg@chromium.org <jrg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-18 04:46:23 +0000
commit862194135cffb729a7938cde3ec042e29bc50ffc (patch)
treecd3579682e2fd6a5e17c31643565f43df5c3dcbe /tools/code_coverage
parentd0b8e5f9bff9553c75bf78bdebeff855db03ebc9 (diff)
downloadchromium_src-862194135cffb729a7938cde3ec042e29bc50ffc.zip
chromium_src-862194135cffb729a7938cde3ec042e29bc50ffc.tar.gz
chromium_src-862194135cffb729a7938cde3ec042e29bc50ffc.tar.bz2
Split coverage into build and run phases in preparation for splitting
it into 2 distinct buildbot phases. Add changes to reduce size or increase speed of coverage builds. Add 'bundle files' mechanism to process_coverage.py to make the above split easier. Add unit test for said mechanism. TEST=build coverage on 10.6 and watch it work. Review URL: http://codereview.chromium.org/2121003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47496 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/code_coverage')
-rwxr-xr-xtools/code_coverage/coverage_posix.py31
-rwxr-xr-xtools/code_coverage/coverage_posix_unittest.py58
2 files changed, 87 insertions, 2 deletions
diff --git a/tools/code_coverage/coverage_posix.py b/tools/code_coverage/coverage_posix.py
index 340199d..b018ae4 100755
--- a/tools/code_coverage/coverage_posix.py
+++ b/tools/code_coverage/coverage_posix.py
@@ -48,6 +48,11 @@ Linux:
--timeout=SECS: if a subprocess doesn't have output within SECS,
assume it's a hang. Kill it and give up.
+--bundles=BUNDLEFILE: a file containing a python list of coverage
+ bundles to be eval'd. E.g.
+ ['../base/base.gyp:base_unittests']
+ This is used as part of the coverage bot.
+
Strings after all options are considered tests to run. Test names
have all text before a ':' stripped to help with gyp compatibility.
For example, ../base/base.gyp:base_unittests is interpreted as a test
@@ -235,9 +240,28 @@ class Coverage(object):
if self.options.all_unittests:
self.tests += glob.glob(os.path.join(self.directory, '*_unittests'))
+ # Tests can come in as args or as a file of bundles.
+ all_testnames = self.args[:] # Copy since we might modify
+ tests_from_bundles = None
+ if self.options.bundles:
+ try:
+ tests_from_bundles = eval(open(self.options.bundles).read())
+ except IOError:
+ logging.fatal('IO error in bundle file ' +
+ self.options.bundles + ' (doesn\'t exist?)')
+ except NameError, SyntaxError:
+ logging.fatal('Parse or syntax error in bundle file ' +
+ self.options.bundles)
+ if hasattr(tests_from_bundles, '__iter__'):
+ all_testnames += tests_from_bundles
+ else:
+ logging.fatal('Fatal error with bundle file; could not get list from' +
+ self.options.bundles)
+ sys.exit(1)
+
# If told explicit tests, run those (after stripping the name as
# appropriate)
- for testname in self.args:
+ for testname in all_testnames:
if ':' in testname:
self.tests += [os.path.join(self.directory, testname.split(':')[1])]
else:
@@ -582,6 +606,11 @@ def CoverageOptionParser():
default=9.9 * 60.0,
help='Timeout before bailing if a subprocess has no output.'
' Default is a hair under 10min (Buildbot is 10min.)')
+ parser.add_option('-B',
+ '--bundles',
+ dest='bundles',
+ default=None,
+ help='Filename of bundles for coverage.')
return parser
diff --git a/tools/code_coverage/coverage_posix_unittest.py b/tools/code_coverage/coverage_posix_unittest.py
index e7ae155..9eee129 100755
--- a/tools/code_coverage/coverage_posix_unittest.py
+++ b/tools/code_coverage/coverage_posix_unittest.py
@@ -3,16 +3,52 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Unit tests for coverage_posix.py."""
+"""Unit tests for coverage_posix.py.
+
+Run a single test with a command such as:
+ ./coverage_posix_unittest.py CoveragePosixTest.testFindTestsAsArgs
+
+Waring that running a single test like that may interfere with the arg
+parsing tests, since coverage_posix.py uses optparse.OptionParser()
+which references globals.
+"""
import coverage_posix as coverage
+import os
import sys
+import tempfile
import unittest
class CoveragePosixTest(unittest.TestCase):
+
def setUp(self):
self.parseArgs()
+ self.sample_test_names = ['zippy_tests', '../base/base.gyp:base_unittests']
+
+ def confirmSampleTestsArePresent(self, tests):
+ """Confirm the tests in self.sample_test_names are in some form in 'tests'.
+
+ The Coverage object can munge them (e.g. add .exe to the end as needed.
+ Helper function for arg parsing, bundle file tests.
+
+ Args:
+ tests: the parsed tests from a Coverage object.
+ """
+ for simple_test_name in ('zippy_tests', 'base_unittests'):
+ found = False
+ for item in tests:
+ if simple_test_name in item:
+ found = True
+ break
+ self.assertTrue(found)
+ for not_test_name in ('kablammo', 'not_a_unittest'):
+ found = False
+ for item in tests:
+ if not_test_name in item:
+ found = True
+ break
+ self.assertFalse(found)
def parseArgs(self):
"""Setup and process arg parsing."""
@@ -67,6 +103,26 @@ class CoveragePosixTest(unittest.TestCase):
c.Run,
[sys.executable, '-u', '-c', slowscript])
+ def testFindTestsAsArgs(self):
+ """Test finding of tests passed as args."""
+ self.args += '--'
+ self.args += self.sample_test_names
+ c = coverage.Coverage('.', self.options, self.args)
+ c.FindTests()
+ self.confirmSampleTestsArePresent(c.tests)
+
+ def testFindTestsFromBundleFile(self):
+ """Test finding of tests from a bundlefile."""
+ (fd, filename) = tempfile.mkstemp()
+ f = os.fdopen(fd, 'w')
+ f.write(str(self.sample_test_names))
+ f.close()
+ self.options.bundles = filename
+ c = coverage.Coverage('.', self.options, self.args)
+ c.FindTests()
+ self.confirmSampleTestsArePresent(c.tests)
+ os.unlink(filename)
+
if __name__ == '__main__':
unittest.main()