Reviewers: Christian Plesner Hansen, Description: Add support for running the tests through valgrind.
Please review this at http://codereview.chromium.org/43073 SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/ Affected files: A tools/run-valgrind.py M tools/test.py Index: tools/run-valgrind.py =================================================================== --- tools/run-valgrind.py (revision 0) +++ tools/run-valgrind.py (revision 0) @@ -0,0 +1,51 @@ +#!/usr/bin/python + +# Simple wrapper for running valgrind and checking the output on +# stderr for memory leaks. + +import subprocess +import sys +import re + +VALGRIND_ARGUMENTS = [ + 'valgrind', + '--error-exitcode=1', + '--leak-check=full', + '--smc-check=all' +] + +# Compute the command line. +command = VALGRIND_ARGUMENTS + sys.argv[1:] + +# Run valgrind. +process = subprocess.Popen(command, stderr=subprocess.PIPE) +code = process.wait(); +errors = process.stderr.readlines(); + +# If valgrind produced an error, we report that to the user. +if code != 0: + sys.stderr.writelines(errors) + sys.exit(code) + +# Look through the leak details and make sure that we don't +# have any definitely, indirectly, and possibly lost bytes. +LEAK_LINE = re.compile(r"definitely lost: \d+ bytes in \d+ blocks.|" + "indirectly lost: \d+ bytes in \d+ blocks.|" + " possibly lost: \d+ bytes in \d+ blocks.") +LEAK_OKAY = re.compile(r"lost: 0 bytes in 0 blocks.") +leaks = [] +for line in errors: + if LEAK_LINE.search(line): + leaks.append(line) + if not LEAK_OKAY.search(line): + sys.stderr.writelines(errors) + sys.exit(1) + +# Make sure we found between 2 and 3 leak lines. +if len(leaks) < 2 or len(leaks) > 3: + sys.stderr.writelines(errors) + sys.stderr.write('\n\n#### Malformed valgrind output.\n#### Exiting.\n') + sys.exit(1) + +# No leaks found. +sys.exit(0) Property changes on: tools/run-valgrind.py ___________________________________________________________________ Name: svn:executable + * Index: tools/test.py =================================================================== --- tools/test.py (revision 1490) +++ tools/test.py (working copy) @@ -1078,6 +1078,8 @@ result.add_option("--simulator", help="Run tests with architecture simulator", default='none') result.add_option("--special-command", default=None) + result.add_option("--valgrind", help="Run tests through valgrind", + default=False, action="store_true") result.add_option("--cat", help="Print the source of the tests", default=False, action="store_true") result.add_option("--warn-unused", help="Report unused rules", @@ -1214,12 +1216,18 @@ path = SplitPath(arg) paths.append(path) + # Check for --valgrind option. If enabled, we overwrite the special + # command flag with a command that uses the run-valgrind.py script. + if options.valgrind: + run_valgrind = join(workspace, "tools", "run-valgrind.py") + options.special_command = "python -u " + run_valgrind + " @" + # First build the required targets buildspace = abspath('.') context = Context(workspace, buildspace, VERBOSE, join(buildspace, 'shell'), options.timeout, - GetSpecialCommandProcessor(options.special_command), + GetSpecialCommandProcessor(options.special_command), options.suppress_dialogs) if options.j != 1: options.scons_flags += ['-j', str(options.j)] --~--~---------~--~----~------------~-------~--~----~ v8-dev mailing list [email protected] http://groups.google.com/group/v8-dev -~----------~----~----~----~------~----~------~--~---
