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