2014-02-06 04:17:09 +04:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
2016-02-26 05:22:43 +03:00
|
|
|
import logging
|
2014-02-06 04:17:09 +04:00
|
|
|
import re
|
|
|
|
|
2018-05-22 00:56:34 +03:00
|
|
|
|
2014-02-06 04:17:09 +04:00
|
|
|
class OutputHandler(object):
|
|
|
|
'''
|
|
|
|
A class for handling Valgrind output.
|
|
|
|
|
|
|
|
Valgrind errors look like this:
|
|
|
|
|
|
|
|
==60741== 40 (24 direct, 16 indirect) bytes in 1 blocks are definitely lost in loss record 2,746 of 5,235
|
|
|
|
==60741== at 0x4C26B43: calloc (vg_replace_malloc.c:593)
|
|
|
|
==60741== by 0x63AEF65: PR_Calloc (prmem.c:443)
|
|
|
|
==60741== by 0x69F236E: PORT_ZAlloc_Util (secport.c:117)
|
|
|
|
==60741== by 0x69F1336: SECITEM_AllocItem_Util (secitem.c:28)
|
|
|
|
==60741== by 0xA04280B: ffi_call_unix64 (in /builds/slave/m-in-l64-valgrind-000000000000/objdir/toolkit/library/libxul.so)
|
|
|
|
==60741== by 0xA042443: ffi_call (ffi64.c:485)
|
|
|
|
|
|
|
|
For each such error, this class extracts most or all of the first (error
|
|
|
|
kind) line, plus the function name in each of the first few stack entries.
|
|
|
|
With this data it constructs and prints a TEST-UNEXPECTED-FAIL message that
|
|
|
|
TBPL will highlight.
|
|
|
|
|
|
|
|
It buffers these lines from which text is extracted so that the
|
|
|
|
TEST-UNEXPECTED-FAIL message can be printed before the full error.
|
|
|
|
|
|
|
|
Parsing the Valgrind output isn't ideal, and it may break in the future if
|
|
|
|
Valgrind changes the format of the messages, or introduces new error kinds.
|
|
|
|
To protect against this, we also count how many lines containing
|
|
|
|
"<insert_a_suppression_name_here>" are seen. Thanks to the use of
|
|
|
|
--gen-suppressions=yes, exactly one of these lines is present per error. If
|
|
|
|
the count of these lines doesn't match the error count found during
|
|
|
|
parsing, then the parsing has missed one or more errors and we can fail
|
|
|
|
appropriately.
|
2018-05-22 00:58:19 +03:00
|
|
|
''' # NOQA: E501
|
2014-02-06 04:17:09 +04:00
|
|
|
|
2016-02-26 05:22:43 +03:00
|
|
|
def __init__(self, logger):
|
2014-02-06 04:17:09 +04:00
|
|
|
# The regexps in this list match all of Valgrind's errors. Note that
|
|
|
|
# Valgrind is English-only, so we don't have to worry about
|
|
|
|
# localization.
|
2016-02-26 05:22:43 +03:00
|
|
|
self.logger = logger
|
2014-02-06 04:17:09 +04:00
|
|
|
self.re_error = \
|
|
|
|
r'==\d+== (' + \
|
|
|
|
r'(Use of uninitialised value of size \d+)|' + \
|
|
|
|
r'(Conditional jump or move depends on uninitialised value\(s\))|' + \
|
|
|
|
r'(Syscall param .* contains uninitialised byte\(s\))|' + \
|
|
|
|
r'(Syscall param .* points to (unaddressable|uninitialised) byte\(s\))|' + \
|
|
|
|
r'((Unaddressable|Uninitialised) byte\(s\) found during client check request)|' + \
|
|
|
|
r'(Invalid free\(\) / delete / delete\[\] / realloc\(\))|' + \
|
|
|
|
r'(Mismatched free\(\) / delete / delete \[\])|' + \
|
|
|
|
r'(Invalid (read|write) of size \d+)|' + \
|
|
|
|
r'(Jump to the invalid address stated on the next line)|' + \
|
|
|
|
r'(Source and destination overlap in .*)|' + \
|
|
|
|
r'(.* bytes in .* blocks are .* lost)' + \
|
|
|
|
r')'
|
|
|
|
# Match identifer chars, plus ':' for namespaces, and '\?' in order to
|
|
|
|
# match "???" which Valgrind sometimes produces.
|
2014-03-11 08:45:08 +04:00
|
|
|
self.re_stack_entry = r'^==\d+==.*0x[A-Z0-9]+: ([A-Za-z0-9_:\?]+)'
|
2014-02-06 04:17:09 +04:00
|
|
|
self.re_suppression = r' *<insert_a_suppression_name_here>'
|
|
|
|
self.error_count = 0
|
|
|
|
self.suppression_count = 0
|
|
|
|
self.number_of_stack_entries_to_get = 0
|
2016-02-26 05:22:43 +03:00
|
|
|
self.curr_error = None
|
|
|
|
self.curr_location = None
|
2014-02-06 04:17:09 +04:00
|
|
|
self.buffered_lines = None
|
|
|
|
|
2016-02-26 05:22:43 +03:00
|
|
|
def log(self, line):
|
|
|
|
self.logger(logging.INFO, 'valgrind-output', {'line': line}, '{line}')
|
|
|
|
|
2014-02-06 04:17:09 +04:00
|
|
|
def __call__(self, line):
|
|
|
|
if self.number_of_stack_entries_to_get == 0:
|
|
|
|
# Look for the start of a Valgrind error.
|
|
|
|
m = re.search(self.re_error, line)
|
|
|
|
if m:
|
|
|
|
self.error_count += 1
|
|
|
|
self.number_of_stack_entries_to_get = 4
|
2016-02-26 05:22:43 +03:00
|
|
|
self.curr_error = m.group(1)
|
|
|
|
self.curr_location = ""
|
2014-02-06 04:17:09 +04:00
|
|
|
self.buffered_lines = [line]
|
|
|
|
else:
|
2016-02-26 05:22:43 +03:00
|
|
|
self.log(line)
|
2014-02-06 04:17:09 +04:00
|
|
|
|
|
|
|
else:
|
|
|
|
# We've recently found a Valgrind error, and are now extracting
|
|
|
|
# details from the first few stack entries.
|
|
|
|
self.buffered_lines.append(line)
|
|
|
|
m = re.match(self.re_stack_entry, line)
|
|
|
|
if m:
|
2016-02-26 05:22:43 +03:00
|
|
|
self.curr_location += m.group(1)
|
2014-02-06 04:17:09 +04:00
|
|
|
else:
|
2016-02-26 05:22:43 +03:00
|
|
|
self.curr_location += '?!?'
|
2014-02-06 04:17:09 +04:00
|
|
|
|
|
|
|
self.number_of_stack_entries_to_get -= 1
|
|
|
|
if self.number_of_stack_entries_to_get != 0:
|
2016-02-26 05:22:43 +03:00
|
|
|
self.curr_location += ' / '
|
2014-02-06 04:17:09 +04:00
|
|
|
else:
|
|
|
|
# We've finished getting the first few stack entries. Print the
|
|
|
|
# failure message and the buffered lines, and then reset state.
|
2016-02-26 05:22:43 +03:00
|
|
|
self.logger(logging.ERROR, 'valgrind-error-msg',
|
|
|
|
{'error': self.curr_error,
|
|
|
|
'location': self.curr_location},
|
2018-05-22 00:56:34 +03:00
|
|
|
'TEST-UNEXPECTED-FAIL | valgrind-test | {error} at {location}')
|
2014-02-06 04:17:09 +04:00
|
|
|
for b in self.buffered_lines:
|
2016-04-06 05:01:56 +03:00
|
|
|
self.log(b)
|
2016-02-26 05:22:43 +03:00
|
|
|
self.curr_error = None
|
|
|
|
self.curr_location = None
|
2014-02-06 04:17:09 +04:00
|
|
|
self.buffered_lines = None
|
|
|
|
|
|
|
|
if re.match(self.re_suppression, line):
|
|
|
|
self.suppression_count += 1
|