[foozzie] Refactoring - move source hashing to main script

BUG=chromium:673246
NOTRY=true

Review-Url: https://codereview.chromium.org/2635923002
Cr-Commit-Position: refs/heads/master@{#42386}
This commit is contained in:
machenbach 2017-01-16 11:53:35 -08:00 committed by Commit bot
parent a7e67924d1
commit 310a899773
3 changed files with 29 additions and 25 deletions

View File

@ -8,6 +8,7 @@ V8 correctness fuzzer launcher script.
"""
import argparse
import hashlib
import itertools
import json
import os
@ -84,6 +85,13 @@ FAILURE_TEMPLATE = FAILURE_HEADER_TEMPLATE + """#
FUZZ_TEST_RE = re.compile(r'.*fuzz(-\d+\.js)')
SOURCE_RE = re.compile(r'print\("v8-foozzie source: (.*)"\);')
# The number of hex digits used from the hash of the original source file path.
# Keep the number small to avoid duplicate explosion.
ORIGINAL_SOURCE_HASH_LENGTH = 3
# Placeholder string if no original source file could be determined.
ORIGINAL_SOURCE_DEFAULT = 'none'
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
@ -235,8 +243,15 @@ def main():
if fail_bailout(second_config_output, suppress.ignore_by_output2):
return RETURN_FAIL
difference, source, source_key = suppress.diff(
difference, source = suppress.diff(
first_config_output.stdout, second_config_output.stdout)
if source:
source_key = hashlib.sha1(source).hexdigest()[:ORIGINAL_SOURCE_HASH_LENGTH]
else:
source = ORIGINAL_SOURCE_DEFAULT
source_key = ORIGINAL_SOURCE_DEFAULT
if difference:
# The first three entries will be parsed by clusterfuzz. Format changes
# will require changes on the clusterfuzz side.

View File

@ -21,12 +21,12 @@ class UnitTest(unittest.TestCase):
'x64', 'fullcode', 'x64', 'default')
one = ''
two = ''
diff = None, 'none', 'none'
diff = None, None
self.assertEquals(diff, suppress.diff(one, two))
one = 'a \n b\nc();'
two = 'a \n b\nc();'
diff = None, 'none', 'none'
diff = None, None
self.assertEquals(diff, suppress.diff(one, two))
# Ignore line before caret, caret position, stack trace char numbers
@ -49,7 +49,7 @@ stack line :2: foo
Validation of asm.js module failed: baz
undefined
"""
diff = None, 'none', 'none'
diff = None, None
self.assertEquals(diff, suppress.diff(one, two))
one = """
@ -59,7 +59,7 @@ Extra line
two = """
Still equal
"""
diff = '- Extra line', 'none', 'none'
diff = '- Extra line', None
self.assertEquals(diff, suppress.diff(one, two))
one = """
@ -69,7 +69,7 @@ Still equal
Still equal
Extra line
"""
diff = '+ Extra line', 'none', 'none'
diff = '+ Extra line', None
self.assertEquals(diff, suppress.diff(one, two))
one = """
@ -81,7 +81,7 @@ undefined
otherfile.js: TypeError: undefined is not a constructor
"""
diff = """- somefile.js: TypeError: undefined is not a constructor
+ otherfile.js: TypeError: undefined is not a constructor""", 'none', 'none'
+ otherfile.js: TypeError: undefined is not a constructor""", None
self.assertEquals(diff, suppress.diff(one, two))

View File

@ -24,7 +24,6 @@ Alternatively, think about adding a behavior change to v8_suppressions.js
to silence a particular class of problems.
"""
import hashlib
import itertools
import re
@ -140,12 +139,7 @@ IGNORE_LINES = [
ALLOWED_LINE_DIFFS = [re.compile(exp) for exp in ALLOWED_LINE_DIFFS]
IGNORE_LINES = [re.compile(exp) for exp in IGNORE_LINES]
# The number of hex digits used from the hash of the original source file path.
# Keep the number small to avoid duplicate explosion.
SOURCE_HASH_LENGTH = 3
ORIGINAL_SOURCE_PREFIX = 'v8-foozzie source: '
ORIGINAL_SOURCE_DEFAULT = 'none'
def line_pairs(lines):
return itertools.izip_longest(
@ -183,15 +177,13 @@ def ignore_by_regexp(line1, line2, allowed):
def diff_output(output1, output2, allowed, ignore1, ignore2):
"""Returns a tuple (difference, source, source_key).
"""Returns a tuple (difference, source).
The difference is None if there's no difference, otherwise a string
with a readable diff.
The source is the last source output within the test case. It is the string
'none' if no such output existed.
The source_key is a short hash of source or 'none'.
The source is the last source output within the test case, or None if no
such output existed.
"""
def useful_line(ignore):
def fun(line):
@ -203,8 +195,7 @@ def diff_output(output1, output2, allowed, ignore1, ignore2):
# This keeps track where we are in the original source file of the fuzz
# test case.
source = ORIGINAL_SOURCE_DEFAULT
source_key = ORIGINAL_SOURCE_DEFAULT
source = None
for ((line1, lookahead1), (line2, lookahead2)) in itertools.izip_longest(
line_pairs(lines1), line_pairs(lines2), fillvalue=(None, None)):
@ -214,9 +205,9 @@ def diff_output(output1, output2, allowed, ignore1, ignore2):
# One iterator ends earlier.
if line1 is None:
return '+ %s' % short_line_output(line2), source, source_key
return '+ %s' % short_line_output(line2), source
if line2 is None:
return '- %s' % short_line_output(line1), source, source_key
return '- %s' % short_line_output(line1), source
# If lines are equal, no further checks are necessary.
if line1 == line2:
@ -225,7 +216,6 @@ def diff_output(output1, output2, allowed, ignore1, ignore2):
# are equal.
if line1.startswith(ORIGINAL_SOURCE_PREFIX):
source = line1[len(ORIGINAL_SOURCE_PREFIX):]
source_key = hashlib.sha1(source).hexdigest()[:SOURCE_HASH_LENGTH]
continue
# Look ahead. If next line is a caret, ignore this line.
@ -240,11 +230,10 @@ def diff_output(output1, output2, allowed, ignore1, ignore2):
return (
'- %s\n+ %s' % (short_line_output(line1), short_line_output(line2)),
source,
source_key,
)
# No difference found.
return None, source, source_key
return None, source
def get_suppression(arch1, config1, arch2, config2):