Index: tools/run-valgrind.py |
=================================================================== |
--- tools/run-valgrind.py (revision 0) |
+++ tools/run-valgrind.py (revision 0) |
@@ -0,0 +1,51 @@ |
+#!/usr/bin/python |
Christian Plesner Hansen
2009/03/11 15:12:54
Copyright?
|
+ |
+# 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.") |
Christian Plesner Hansen
2009/03/11 15:12:54
Any reason not to use r"(?:definitely|indirectly|p
|
+LEAK_OKAY = re.compile(r"lost: 0 bytes in 0 blocks.") |
+leaks = [] |
+for line in errors: |
Christian Plesner Hansen
2009/03/11 15:12:54
Simpler might be to use re.findall.
|
+ 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 |
+ * |