mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
55f81f2210
- Add `.style.yapf` with configuration to use Google style. - Run `yapf` on all `.py` files in this repo. - Manually fix one trailing space in a doc string. - Run `git cl format runtime` to satisfy presubmit. Change-Id: I7e6bd11e91f07926b9188362599af398551eed79 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/111600 Commit-Queue: Nate Bosch <nbosch@google.com> Reviewed-by: Alexander Thomas <athom@google.com>
66 lines
2 KiB
Python
Executable file
66 lines
2 KiB
Python
Executable file
#!/usr/bin/python
|
|
#
|
|
# Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
|
|
# for details. All rights reserved. Use of this source code is governed by a
|
|
# BSD-style license that can be found in the LICENSE file.
|
|
|
|
# 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',
|
|
'--trace-children=yes',
|
|
'--ignore-ranges=0x000-0xFFF', # Used for implicit null checks.
|
|
'--vex-iropt-level=1' # Valgrind crashes with the default level (2).
|
|
]
|
|
|
|
# Compute the command line.
|
|
command = VALGRIND_ARGUMENTS + sys.argv[1:]
|
|
|
|
# Run Valgrind.
|
|
process = subprocess.Popen(
|
|
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
code = process.wait()
|
|
output = process.stdout.readlines()
|
|
errors = process.stderr.readlines()
|
|
|
|
# Always print the output, but leave out the 3 line banner printed
|
|
# by certain versions of Valgrind.
|
|
if len(output) > 0 and output[0].startswith("** VALGRIND_ROOT="):
|
|
output = output[3:]
|
|
sys.stdout.writelines(output)
|
|
|
|
# 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 or indirectly lost bytes. We allow possibly lost
|
|
# bytes to lower the risk of false positives.
|
|
LEAK_RE = r"(?:definitely|indirectly) lost:"
|
|
LEAK_LINE_MATCHER = re.compile(LEAK_RE)
|
|
LEAK_OKAY_MATCHER = re.compile(r"lost: 0 bytes in 0 blocks")
|
|
leaks = []
|
|
for line in errors:
|
|
if LEAK_LINE_MATCHER.search(line):
|
|
leaks.append(line)
|
|
if not LEAK_OKAY_MATCHER.search(line):
|
|
sys.stderr.writelines(errors)
|
|
sys.exit(1)
|
|
|
|
# Make sure we found the right number of leak lines.
|
|
if not len(leaks) in [0, 2, 3]:
|
|
sys.stderr.writelines(errors)
|
|
sys.stderr.write('\n\n#### Malformed Valgrind output.\n#### Exiting.\n')
|
|
sys.exit(1)
|
|
|
|
# Success.
|
|
sys.exit(0)
|