1# Copyright 2016 the V8 project authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import os 6import subprocess 7import sys 8import unittest 9 10import v8_foozzie 11import v8_suppressions 12 13BASE_DIR = os.path.dirname(os.path.abspath(__file__)) 14FOOZZIE = os.path.join(BASE_DIR, 'v8_foozzie.py') 15TEST_DATA = os.path.join(BASE_DIR, 'testdata') 16 17class UnitTest(unittest.TestCase): 18 def testDiff(self): 19 # TODO(machenbach): Mock out suppression configuration. 20 suppress = v8_suppressions.get_suppression( 21 'x64', 'fullcode', 'x64', 'default') 22 one = '' 23 two = '' 24 diff = None, None 25 self.assertEquals(diff, suppress.diff(one, two)) 26 27 one = 'a \n b\nc();' 28 two = 'a \n b\nc();' 29 diff = None, None 30 self.assertEquals(diff, suppress.diff(one, two)) 31 32 # Ignore line before caret, caret position, stack trace char numbers 33 # error message and validator output. 34 one = """ 35undefined 36weird stuff 37 ^ 38Validation of asm.js module failed: foo bar 39somefile.js: TypeError: undefined is not a function 40stack line :15: foo 41 undefined 42""" 43 two = """ 44undefined 45other weird stuff 46 ^ 47somefile.js: TypeError: baz is not a function 48stack line :2: foo 49Validation of asm.js module failed: baz 50 undefined 51""" 52 diff = None, None 53 self.assertEquals(diff, suppress.diff(one, two)) 54 55 one = """ 56Still equal 57Extra line 58""" 59 two = """ 60Still equal 61""" 62 diff = '- Extra line', None 63 self.assertEquals(diff, suppress.diff(one, two)) 64 65 one = """ 66Still equal 67""" 68 two = """ 69Still equal 70Extra line 71""" 72 diff = '+ Extra line', None 73 self.assertEquals(diff, suppress.diff(one, two)) 74 75 one = """ 76undefined 77somefile.js: TypeError: undefined is not a constructor 78""" 79 two = """ 80undefined 81otherfile.js: TypeError: undefined is not a constructor 82""" 83 diff = """- somefile.js: TypeError: undefined is not a constructor 84+ otherfile.js: TypeError: undefined is not a constructor""", None 85 self.assertEquals(diff, suppress.diff(one, two)) 86 87 88def cut_verbose_output(stdout): 89 return '\n'.join(stdout.split('\n')[2:]) 90 91 92def run_foozzie(first_d8, second_d8): 93 return subprocess.check_output([ 94 sys.executable, FOOZZIE, 95 '--random-seed', '12345', 96 '--first-d8', os.path.join(TEST_DATA, first_d8), 97 '--second-d8', os.path.join(TEST_DATA, second_d8), 98 '--first-config', 'ignition', 99 '--second-config', 'ignition_staging', 100 os.path.join(TEST_DATA, 'fuzz-123.js'), 101 ]) 102 103 104class SystemTest(unittest.TestCase): 105 def testSyntaxErrorDiffPass(self): 106 stdout = run_foozzie('test_d8_1.py', 'test_d8_2.py') 107 self.assertEquals('# V8 correctness - pass\n', cut_verbose_output(stdout)) 108 109 def testDifferentOutputFail(self): 110 with open(os.path.join(TEST_DATA, 'failure_output.txt')) as f: 111 expected_output = f.read() 112 with self.assertRaises(subprocess.CalledProcessError) as ctx: 113 run_foozzie('test_d8_1.py', 'test_d8_3.py') 114 e = ctx.exception 115 self.assertEquals(v8_foozzie.RETURN_FAIL, e.returncode) 116 self.assertEquals(expected_output, cut_verbose_output(e.output)) 117