Commit 310a8997 authored by machenbach's avatar machenbach Committed by Commit bot

[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}
parent a7e67924
...@@ -8,6 +8,7 @@ V8 correctness fuzzer launcher script. ...@@ -8,6 +8,7 @@ V8 correctness fuzzer launcher script.
""" """
import argparse import argparse
import hashlib
import itertools import itertools
import json import json
import os import os
...@@ -84,6 +85,13 @@ FAILURE_TEMPLATE = FAILURE_HEADER_TEMPLATE + """# ...@@ -84,6 +85,13 @@ FAILURE_TEMPLATE = FAILURE_HEADER_TEMPLATE + """#
FUZZ_TEST_RE = re.compile(r'.*fuzz(-\d+\.js)') FUZZ_TEST_RE = re.compile(r'.*fuzz(-\d+\.js)')
SOURCE_RE = re.compile(r'print\("v8-foozzie source: (.*)"\);') 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(): def parse_args():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
...@@ -235,8 +243,15 @@ def main(): ...@@ -235,8 +243,15 @@ def main():
if fail_bailout(second_config_output, suppress.ignore_by_output2): if fail_bailout(second_config_output, suppress.ignore_by_output2):
return RETURN_FAIL return RETURN_FAIL
difference, source, source_key = suppress.diff( difference, source = suppress.diff(
first_config_output.stdout, second_config_output.stdout) 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: if difference:
# The first three entries will be parsed by clusterfuzz. Format changes # The first three entries will be parsed by clusterfuzz. Format changes
# will require changes on the clusterfuzz side. # will require changes on the clusterfuzz side.
......
...@@ -21,12 +21,12 @@ class UnitTest(unittest.TestCase): ...@@ -21,12 +21,12 @@ class UnitTest(unittest.TestCase):
'x64', 'fullcode', 'x64', 'default') 'x64', 'fullcode', 'x64', 'default')
one = '' one = ''
two = '' two = ''
diff = None, 'none', 'none' diff = None, None
self.assertEquals(diff, suppress.diff(one, two)) self.assertEquals(diff, suppress.diff(one, two))
one = 'a \n b\nc();' one = 'a \n b\nc();'
two = 'a \n b\nc();' two = 'a \n b\nc();'
diff = None, 'none', 'none' diff = None, None
self.assertEquals(diff, suppress.diff(one, two)) self.assertEquals(diff, suppress.diff(one, two))
# Ignore line before caret, caret position, stack trace char numbers # Ignore line before caret, caret position, stack trace char numbers
...@@ -49,7 +49,7 @@ stack line :2: foo ...@@ -49,7 +49,7 @@ stack line :2: foo
Validation of asm.js module failed: baz Validation of asm.js module failed: baz
undefined undefined
""" """
diff = None, 'none', 'none' diff = None, None
self.assertEquals(diff, suppress.diff(one, two)) self.assertEquals(diff, suppress.diff(one, two))
one = """ one = """
...@@ -59,7 +59,7 @@ Extra line ...@@ -59,7 +59,7 @@ Extra line
two = """ two = """
Still equal Still equal
""" """
diff = '- Extra line', 'none', 'none' diff = '- Extra line', None
self.assertEquals(diff, suppress.diff(one, two)) self.assertEquals(diff, suppress.diff(one, two))
one = """ one = """
...@@ -69,7 +69,7 @@ Still equal ...@@ -69,7 +69,7 @@ Still equal
Still equal Still equal
Extra line Extra line
""" """
diff = '+ Extra line', 'none', 'none' diff = '+ Extra line', None
self.assertEquals(diff, suppress.diff(one, two)) self.assertEquals(diff, suppress.diff(one, two))
one = """ one = """
...@@ -81,7 +81,7 @@ undefined ...@@ -81,7 +81,7 @@ undefined
otherfile.js: TypeError: undefined is not a constructor otherfile.js: TypeError: undefined is not a constructor
""" """
diff = """- somefile.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)) self.assertEquals(diff, suppress.diff(one, two))
......
...@@ -24,7 +24,6 @@ Alternatively, think about adding a behavior change to v8_suppressions.js ...@@ -24,7 +24,6 @@ Alternatively, think about adding a behavior change to v8_suppressions.js
to silence a particular class of problems. to silence a particular class of problems.
""" """
import hashlib
import itertools import itertools
import re import re
...@@ -140,12 +139,7 @@ IGNORE_LINES = [ ...@@ -140,12 +139,7 @@ IGNORE_LINES = [
ALLOWED_LINE_DIFFS = [re.compile(exp) for exp in ALLOWED_LINE_DIFFS] ALLOWED_LINE_DIFFS = [re.compile(exp) for exp in ALLOWED_LINE_DIFFS]
IGNORE_LINES = [re.compile(exp) for exp in IGNORE_LINES] 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_PREFIX = 'v8-foozzie source: '
ORIGINAL_SOURCE_DEFAULT = 'none'
def line_pairs(lines): def line_pairs(lines):
return itertools.izip_longest( return itertools.izip_longest(
...@@ -183,15 +177,13 @@ def ignore_by_regexp(line1, line2, allowed): ...@@ -183,15 +177,13 @@ def ignore_by_regexp(line1, line2, allowed):
def diff_output(output1, output2, allowed, ignore1, ignore2): 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 The difference is None if there's no difference, otherwise a string
with a readable diff. with a readable diff.
The source is the last source output within the test case. It is the string The source is the last source output within the test case, or None if no
'none' if no such output existed. such output existed.
The source_key is a short hash of source or 'none'.
""" """
def useful_line(ignore): def useful_line(ignore):
def fun(line): def fun(line):
...@@ -203,8 +195,7 @@ def diff_output(output1, output2, allowed, ignore1, ignore2): ...@@ -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 # This keeps track where we are in the original source file of the fuzz
# test case. # test case.
source = ORIGINAL_SOURCE_DEFAULT source = None
source_key = ORIGINAL_SOURCE_DEFAULT
for ((line1, lookahead1), (line2, lookahead2)) in itertools.izip_longest( for ((line1, lookahead1), (line2, lookahead2)) in itertools.izip_longest(
line_pairs(lines1), line_pairs(lines2), fillvalue=(None, None)): line_pairs(lines1), line_pairs(lines2), fillvalue=(None, None)):
...@@ -214,9 +205,9 @@ def diff_output(output1, output2, allowed, ignore1, ignore2): ...@@ -214,9 +205,9 @@ def diff_output(output1, output2, allowed, ignore1, ignore2):
# One iterator ends earlier. # One iterator ends earlier.
if line1 is None: if line1 is None:
return '+ %s' % short_line_output(line2), source, source_key return '+ %s' % short_line_output(line2), source
if line2 is None: 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 lines are equal, no further checks are necessary.
if line1 == line2: if line1 == line2:
...@@ -225,7 +216,6 @@ def diff_output(output1, output2, allowed, ignore1, ignore2): ...@@ -225,7 +216,6 @@ def diff_output(output1, output2, allowed, ignore1, ignore2):
# are equal. # are equal.
if line1.startswith(ORIGINAL_SOURCE_PREFIX): if line1.startswith(ORIGINAL_SOURCE_PREFIX):
source = line1[len(ORIGINAL_SOURCE_PREFIX):] source = line1[len(ORIGINAL_SOURCE_PREFIX):]
source_key = hashlib.sha1(source).hexdigest()[:SOURCE_HASH_LENGTH]
continue continue
# Look ahead. If next line is a caret, ignore this line. # Look ahead. If next line is a caret, ignore this line.
...@@ -240,11 +230,10 @@ def diff_output(output1, output2, allowed, ignore1, ignore2): ...@@ -240,11 +230,10 @@ def diff_output(output1, output2, allowed, ignore1, ignore2):
return ( return (
'- %s\n+ %s' % (short_line_output(line1), short_line_output(line2)), '- %s\n+ %s' % (short_line_output(line1), short_line_output(line2)),
source, source,
source_key,
) )
# No difference found. # No difference found.
return None, source, source_key return None, source
def get_suppression(arch1, config1, arch2, config2): def get_suppression(arch1, config1, arch2, config2):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment