mirror of https://github.com/nodejs/node.git
test: fix up `make valgrind-test`
* valgrind complained too much about memory leaks from the V8 heap to be useful, run it with --leak-check=no. Not ideal, needs to be revisited, preferably with a suppression file. * tools/run-valgrind.py didn't deal with tests that logged to stderr, rewrite the heuristic and make valgrind write to a socket instead of stderr. Fixes #3869.pull/24503/head
parent
de32b38992
commit
90ea68107a
|
@ -30,48 +30,36 @@
|
|||
# Simple wrapper for running valgrind and checking the output on
|
||||
# stderr for memory leaks.
|
||||
|
||||
import os
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import re
|
||||
|
||||
VALGRIND = os.environ.get('VALGRIND', 'valgrind')
|
||||
|
||||
VALGRIND_ARGUMENTS = [
|
||||
'valgrind',
|
||||
'--error-exitcode=1',
|
||||
'--leak-check=full',
|
||||
'--smc-check=all'
|
||||
VALGRIND,
|
||||
'--log-socket=127.0.0.1:15151',
|
||||
'--error-exitcode=247',
|
||||
'--leak-check=no',
|
||||
'--smc-check=all',
|
||||
]
|
||||
|
||||
# Compute the command line.
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server.bind(('127.0.0.1', 15151))
|
||||
server.listen(1)
|
||||
|
||||
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)
|
||||
errors = ''
|
||||
conn, addr = server.accept()
|
||||
while True:
|
||||
data = conn.recv(8192)
|
||||
if not data: break
|
||||
errors += data
|
||||
|
||||
# Look through the leak details and make sure that we don't
|
||||
# have any definitely, indirectly, and possibly lost bytes.
|
||||
LEAK_RE = r"(?:definitely|indirectly|possibly) 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 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)
|
||||
code = process.wait()
|
||||
if code == 247: sys.stderr.writelines(errors)
|
||||
sys.exit(code)
|
||||
|
|
Loading…
Reference in New Issue