Skip to content

Commit deabb5c

Browse files
bnoordhuisaddaleax
authored andcommitted
tools: make run-valgrind.py useful
Node.js does not clean up on exit so don't complain about memory leaks but do complain about invalid memory access. In the future we may want to add a cleanup-on-exit flag or put together a suppression list. PR-URL: #9520 Reviewed By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 887c76a commit deabb5c

File tree

1 file changed

+7
-36
lines changed

1 file changed

+7
-36
lines changed

tools/run-valgrind.py

+7-36
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,26 @@
2727
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
# Simple wrapper for running valgrind and checking the output on
31-
# stderr for memory leaks.
32-
# Uses valgrind from third_party/valgrind. Assumes the executable is passed
33-
# with a path relative to the v8 root.
34-
35-
3630
from os import path
37-
import platform
38-
import re
3931
import subprocess
4032
import sys
4133

42-
V8_ROOT = path.dirname(path.dirname(path.abspath(__file__)))
34+
NODE_ROOT = path.dirname(path.dirname(path.abspath(__file__)))
4335

4436
VALGRIND_ARGUMENTS = [
4537
'valgrind',
4638
'--error-exitcode=1',
47-
'--leak-check=full',
4839
'--smc-check=all',
40+
# Node.js does not clean up on exit so don't complain about
41+
# memory leaks but do complain about invalid memory access.
42+
'--quiet',
4943
]
5044

5145
if len(sys.argv) < 2:
5246
print 'Please provide an executable to analyze.'
5347
sys.exit(1)
5448

55-
executable = path.join(V8_ROOT, sys.argv[1])
49+
executable = path.join(NODE_ROOT, sys.argv[1])
5650
if not path.exists(executable):
5751
print 'Cannot find the file specified: %s' % executable
5852
sys.exit(1)
@@ -62,33 +56,10 @@
6256

6357
# Run valgrind.
6458
process = subprocess.Popen(command, stderr=subprocess.PIPE)
65-
code = process.wait();
66-
errors = process.stderr.readlines();
59+
code = process.wait()
60+
errors = process.stderr.readlines()
6761

6862
# If valgrind produced an error, we report that to the user.
6963
if code != 0:
7064
sys.stderr.writelines(errors)
7165
sys.exit(code)
72-
73-
# Look through the leak details and make sure that we don't
74-
# have any definitely, indirectly, and possibly lost bytes.
75-
LEAK_RE = r"(?:definitely|indirectly|possibly) lost: "
76-
LEAK_LINE_MATCHER = re.compile(LEAK_RE)
77-
LEAK_OKAY_MATCHER = re.compile(r"lost: 0 bytes in 0 blocks")
78-
leaks = []
79-
for line in errors:
80-
if LEAK_LINE_MATCHER.search(line):
81-
leaks.append(line)
82-
if not LEAK_OKAY_MATCHER.search(line):
83-
sys.stderr.writelines(errors)
84-
sys.exit(1)
85-
86-
# Make sure we found between 2 and 3 leak lines.
87-
if len(leaks) < 2 or len(leaks) > 3:
88-
sys.stderr.writelines(errors)
89-
sys.stderr.write('\n\n#### Malformed valgrind output.\n#### Exiting.\n')
90-
sys.exit(1)
91-
92-
# No leaks found.
93-
sys.stderr.writelines(errors)
94-
sys.exit(0)

0 commit comments

Comments
 (0)