|
27 | 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28 | 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29 | 29 |
|
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 |
| - |
36 | 30 | from os import path
|
37 |
| -import platform |
38 |
| -import re |
39 | 31 | import subprocess
|
40 | 32 | import sys
|
41 | 33 |
|
42 |
| -V8_ROOT = path.dirname(path.dirname(path.abspath(__file__))) |
| 34 | +NODE_ROOT = path.dirname(path.dirname(path.abspath(__file__))) |
43 | 35 |
|
44 | 36 | VALGRIND_ARGUMENTS = [
|
45 | 37 | 'valgrind',
|
46 | 38 | '--error-exitcode=1',
|
47 |
| - '--leak-check=full', |
48 | 39 | '--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', |
49 | 43 | ]
|
50 | 44 |
|
51 | 45 | if len(sys.argv) < 2:
|
52 | 46 | print 'Please provide an executable to analyze.'
|
53 | 47 | sys.exit(1)
|
54 | 48 |
|
55 |
| -executable = path.join(V8_ROOT, sys.argv[1]) |
| 49 | +executable = path.join(NODE_ROOT, sys.argv[1]) |
56 | 50 | if not path.exists(executable):
|
57 | 51 | print 'Cannot find the file specified: %s' % executable
|
58 | 52 | sys.exit(1)
|
|
62 | 56 |
|
63 | 57 | # Run valgrind.
|
64 | 58 | 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() |
67 | 61 |
|
68 | 62 | # If valgrind produced an error, we report that to the user.
|
69 | 63 | if code != 0:
|
70 | 64 | sys.stderr.writelines(errors)
|
71 | 65 | 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