OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 the V8 project authors. All rights reserved. | 2 # Copyright 2014 the V8 project authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import os | 6 import os |
7 import re | 7 import re |
8 import shutil | 8 import shutil |
9 import sys | 9 import sys |
10 | 10 |
11 # TODO(jkummerow): Support DATA_VIEW_{G,S}ETTER in runtime.cc | 11 # TODO(jkummerow): Support DATA_VIEW_{G,S}ETTER in runtime.cc |
12 | 12 |
13 FILENAME = "src/runtime.cc" | 13 FILENAME = "src/runtime.cc" |
14 HEADERFILENAME = "src/runtime.h" | 14 HEADERFILENAME = "src/runtime.h" |
15 FUNCTION = re.compile("^RUNTIME_FUNCTION\(Runtime_(\w+)") | 15 FUNCTION = re.compile("^RUNTIME_FUNCTION\(Runtime_(\w+)") |
16 ARGSLENGTH = re.compile(".*ASSERT\(.*args\.length\(\) == (\d+)\);") | 16 ARGSLENGTH = re.compile(".*ASSERT\(.*args\.length\(\) == (\d+)\);") |
17 FUNCTIONEND = "}\n" | 17 FUNCTIONEND = "}\n" |
18 | 18 |
19 WORKSPACE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")) | 19 WORKSPACE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "..")) |
20 BASEPATH = os.path.join(WORKSPACE, "test", "mjsunit", "runtime-gen") | 20 BASEPATH = os.path.join(WORKSPACE, "test", "mjsunit", "runtime-gen") |
21 THIS_SCRIPT = os.path.relpath(sys.argv[0]) | 21 THIS_SCRIPT = os.path.relpath(sys.argv[0]) |
22 | 22 |
23 # Counts of functions in each detection state. These are used to assert | 23 # Counts of functions in each detection state. These are used to assert |
24 # that the parser doesn't bit-rot. Change the values as needed when you add, | 24 # that the parser doesn't bit-rot. Change the values as needed when you add, |
25 # remove or change runtime functions, but make sure we don't lose our ability | 25 # remove or change runtime functions, but make sure we don't lose our ability |
26 # to parse them! | 26 # to parse them! |
27 EXPECTED_FUNCTION_COUNT = 339 | 27 EXPECTED_FUNCTION_COUNT = 339 |
28 EXPECTED_FUZZABLE_COUNT = 316 | 28 EXPECTED_FUZZABLE_COUNT = 306 |
29 EXPECTED_CCTEST_COUNT = 6 | 29 EXPECTED_CCTEST_COUNT = 6 |
30 EXPECTED_UNKNOWN_COUNT = 5 | 30 EXPECTED_UNKNOWN_COUNT = 5 |
31 | 31 |
32 | 32 |
33 # Don't call these at all. | 33 # Don't call these at all. |
34 BLACKLISTED = [ | 34 BLACKLISTED = [ |
35 "Abort", # Kills the process. | 35 "Abort", # Kills the process. |
36 "AbortJS", # Kills the process. | 36 "AbortJS", # Kills the process. |
37 "CompileForOnStackReplacement", # Riddled with ASSERTs. | 37 "CompileForOnStackReplacement", # Riddled with ASSERTs. |
38 "IS_VAR", # Not implemented in the runtime. | 38 "IS_VAR", # Not implemented in the runtime. |
39 "ListNatives", # Not available in Release mode. | 39 "ListNatives", # Not available in Release mode. |
40 "SetAllocationTimeout", # Too slow for fuzzing. | 40 "SetAllocationTimeout", # Too slow for fuzzing. |
41 "SystemBreak", # Kills (int3) the process. | 41 "SystemBreak", # Kills (int3) the process. |
42 | 42 |
43 # These are weird. They violate some invariants when called after | 43 # These are weird. They violate some invariants when called after |
44 # bootstrapping. | 44 # bootstrapping. |
45 "DisableAccessChecks", | 45 "DisableAccessChecks", |
46 "EnableAccessChecks", | 46 "EnableAccessChecks", |
47 | 47 |
48 # Seems to be incompatible with --stress-runs. | 48 # The current LiveEdit implementation relies on and messes with internals |
| 49 # in ways that makes it fundamentally unfuzzable :-( |
| 50 "DebugGetLoadedScripts", |
| 51 "DebugSetScriptSource", |
| 52 "LiveEditFindSharedFunctionInfosForScript", |
| 53 "LiveEditFunctionSourceUpdated", |
| 54 "LiveEditGatherCompileInfo", |
| 55 "LiveEditPatchFunctionPositions", |
| 56 "LiveEditReplaceFunctionCode", |
| 57 "LiveEditReplaceRefToNestedFunction", |
49 "LiveEditReplaceScript", | 58 "LiveEditReplaceScript", |
| 59 "LiveEditRestartFrame", |
| 60 "SetScriptBreakPoint", |
50 | 61 |
51 # TODO(jkummerow): Fix these and un-blacklist them! | 62 # TODO(jkummerow): Fix these and un-blacklist them! |
52 "CreateDateTimeFormat", | 63 "CreateDateTimeFormat", |
53 "CreateNumberFormat", | 64 "CreateNumberFormat", |
54 ] | 65 ] |
55 | 66 |
56 | 67 |
57 # These will always throw. | 68 # These will always throw. |
58 THROWS = [ | 69 THROWS = [ |
59 "CheckExecutionState", # Needs to hit a break point. | 70 "CheckExecutionState", # Needs to hit a break point. |
60 "CheckIsBootstrapping", # Needs to be bootstrapping. | 71 "CheckIsBootstrapping", # Needs to be bootstrapping. |
61 "DebugEvaluate", # Needs to hit a break point. | 72 "DebugEvaluate", # Needs to hit a break point. |
62 "DebugEvaluateGlobal", # Needs to hit a break point. | 73 "DebugEvaluateGlobal", # Needs to hit a break point. |
63 "DebugIndexedInterceptorElementValue", # Needs an indexed interceptor. | 74 "DebugIndexedInterceptorElementValue", # Needs an indexed interceptor. |
64 "DebugNamedInterceptorPropertyValue", # Needs a named interceptor. | 75 "DebugNamedInterceptorPropertyValue", # Needs a named interceptor. |
65 "DebugSetScriptSource", # Checks compilation state of script. | 76 "DebugSetScriptSource", # Checks compilation state of script. |
66 "GetAllScopesDetails", # Needs to hit a break point. | 77 "GetAllScopesDetails", # Needs to hit a break point. |
67 "GetFrameCount", # Needs to hit a break point. | 78 "GetFrameCount", # Needs to hit a break point. |
68 "GetFrameDetails", # Needs to hit a break point. | 79 "GetFrameDetails", # Needs to hit a break point. |
69 "GetRootNaN", # Needs to be bootstrapping. | 80 "GetRootNaN", # Needs to be bootstrapping. |
70 "GetScopeCount", # Needs to hit a break point. | 81 "GetScopeCount", # Needs to hit a break point. |
71 "GetScopeDetails", # Needs to hit a break point. | 82 "GetScopeDetails", # Needs to hit a break point. |
72 "GetStepInPositions", # Needs to hit a break point. | 83 "GetStepInPositions", # Needs to hit a break point. |
73 "GetTemplateField", # Needs a {Function,Object}TemplateInfo. | 84 "GetTemplateField", # Needs a {Function,Object}TemplateInfo. |
74 "GetThreadCount", # Needs to hit a break point. | 85 "GetThreadCount", # Needs to hit a break point. |
75 "GetThreadDetails", # Needs to hit a break point. | 86 "GetThreadDetails", # Needs to hit a break point. |
76 "IsAccessAllowedForObserver", # Needs access-check-required object. | 87 "IsAccessAllowedForObserver", # Needs access-check-required object. |
77 "LiveEditFunctionSourceUpdated", # Needs a SharedFunctionInfo. | |
78 "LiveEditPatchFunctionPositions", # Needs a SharedFunctionInfo. | |
79 "LiveEditReplaceFunctionCode", # Needs a SharedFunctionInfo. | |
80 "LiveEditReplaceRefToNestedFunction", # Needs a SharedFunctionInfo. | |
81 "LiveEditRestartFrame", # Needs to hit a break point. | |
82 "UnblockConcurrentRecompilation" # Needs --block-concurrent-recompilation. | 88 "UnblockConcurrentRecompilation" # Needs --block-concurrent-recompilation. |
83 ] | 89 ] |
84 | 90 |
85 | 91 |
86 # Definitions used in CUSTOM_KNOWN_GOOD_INPUT below. | 92 # Definitions used in CUSTOM_KNOWN_GOOD_INPUT below. |
87 _BREAK_ITERATOR = ( | 93 _BREAK_ITERATOR = ( |
88 "%GetImplFromInitializedIntlObject(new Intl.v8BreakIterator())") | 94 "%GetImplFromInitializedIntlObject(new Intl.v8BreakIterator())") |
89 _COLLATOR = "%GetImplFromInitializedIntlObject(new Intl.Collator('en-US'))" | 95 _COLLATOR = "%GetImplFromInitializedIntlObject(new Intl.Collator('en-US'))" |
90 _DATETIME_FORMAT = ( | 96 _DATETIME_FORMAT = ( |
91 "%GetImplFromInitializedIntlObject(new Intl.DateTimeFormat('en-US'))") | 97 "%GetImplFromInitializedIntlObject(new Intl.DateTimeFormat('en-US'))") |
92 _NUMBER_FORMAT = ( | 98 _NUMBER_FORMAT = ( |
93 "%GetImplFromInitializedIntlObject(new Intl.NumberFormat('en-US'))") | 99 "%GetImplFromInitializedIntlObject(new Intl.NumberFormat('en-US'))") |
94 _SCRIPT = "%DebugGetLoadedScripts()[1]" | |
95 | 100 |
96 | 101 |
97 # Custom definitions for function input that does not throw. | 102 # Custom definitions for function input that does not throw. |
98 # Format: "FunctionName": ["arg0", "arg1", ..., argslength]. | 103 # Format: "FunctionName": ["arg0", "arg1", ..., argslength]. |
99 # None means "fall back to autodetected value". | 104 # None means "fall back to autodetected value". |
100 CUSTOM_KNOWN_GOOD_INPUT = { | 105 CUSTOM_KNOWN_GOOD_INPUT = { |
101 "Apply": ["function() {}", None, None, None, None, None], | 106 "Apply": ["function() {}", None, None, None, None, None], |
102 "ArrayBufferSliceImpl": [None, None, 0, None], | 107 "ArrayBufferSliceImpl": [None, None, 0, None], |
103 "ArrayConcat": ["[1, 'a']", None], | 108 "ArrayConcat": ["[1, 'a']", None], |
104 "BreakIteratorAdoptText": [_BREAK_ITERATOR, None, None], | 109 "BreakIteratorAdoptText": [_BREAK_ITERATOR, None, None], |
105 "BreakIteratorBreakType": [_BREAK_ITERATOR, None], | 110 "BreakIteratorBreakType": [_BREAK_ITERATOR, None], |
106 "BreakIteratorCurrent": [_BREAK_ITERATOR, None], | 111 "BreakIteratorCurrent": [_BREAK_ITERATOR, None], |
107 "BreakIteratorFirst": [_BREAK_ITERATOR, None], | 112 "BreakIteratorFirst": [_BREAK_ITERATOR, None], |
108 "BreakIteratorNext": [_BREAK_ITERATOR, None], | 113 "BreakIteratorNext": [_BREAK_ITERATOR, None], |
109 "CompileString": [None, "false", None], | 114 "CompileString": [None, "false", None], |
110 "CreateBreakIterator": ["'en-US'", "{type: 'string'}", None, None], | 115 "CreateBreakIterator": ["'en-US'", "{type: 'string'}", None, None], |
111 "CreateJSFunctionProxy": [None, "function() {}", None, None, None], | 116 "CreateJSFunctionProxy": [None, "function() {}", None, None, None], |
112 "CreatePrivateSymbol": ["\"foo\"", None], | 117 "CreatePrivateSymbol": ["\"foo\"", None], |
113 "CreateSymbol": ["\"foo\"", None], | 118 "CreateSymbol": ["\"foo\"", None], |
114 "DateParseString": [None, "new Array(8)", None], | 119 "DateParseString": [None, "new Array(8)", None], |
115 "DebugSetScriptSource": [_SCRIPT, None, None], | |
116 "DefineOrRedefineAccessorProperty": [None, None, "function() {}", | 120 "DefineOrRedefineAccessorProperty": [None, None, "function() {}", |
117 "function() {}", 2, None], | 121 "function() {}", 2, None], |
118 "GetBreakLocations": [None, 0, None], | 122 "GetBreakLocations": [None, 0, None], |
119 "GetDefaultReceiver": ["function() {}", None], | 123 "GetDefaultReceiver": ["function() {}", None], |
120 "GetImplFromInitializedIntlObject": ["new Intl.NumberFormat('en-US')", None], | 124 "GetImplFromInitializedIntlObject": ["new Intl.NumberFormat('en-US')", None], |
121 "InternalCompare": [_COLLATOR, None, None, None], | 125 "InternalCompare": [_COLLATOR, None, None, None], |
122 "InternalDateFormat": [_DATETIME_FORMAT, None, None], | 126 "InternalDateFormat": [_DATETIME_FORMAT, None, None], |
123 "InternalDateParse": [_DATETIME_FORMAT, None, None], | 127 "InternalDateParse": [_DATETIME_FORMAT, None, None], |
124 "InternalNumberFormat": [_NUMBER_FORMAT, None, None], | 128 "InternalNumberFormat": [_NUMBER_FORMAT, None, None], |
125 "InternalNumberParse": [_NUMBER_FORMAT, None, None], | 129 "InternalNumberParse": [_NUMBER_FORMAT, None, None], |
126 "IsSloppyModeFunction": ["function() {}", None], | 130 "IsSloppyModeFunction": ["function() {}", None], |
127 "LiveEditFindSharedFunctionInfosForScript": [_SCRIPT, None], | |
128 "LiveEditGatherCompileInfo": [_SCRIPT, None, None], | |
129 "LoadMutableDouble": ["{foo: 1.2}", None, None], | 131 "LoadMutableDouble": ["{foo: 1.2}", None, None], |
130 "NewObjectFromBound": ["(function() {}).bind({})", None], | 132 "NewObjectFromBound": ["(function() {}).bind({})", None], |
131 "NumberToRadixString": [None, "2", None], | 133 "NumberToRadixString": [None, "2", None], |
132 "ParseJson": ["\"{}\"", 1], | 134 "ParseJson": ["\"{}\"", 1], |
133 "RegExpExecMultiple": [None, None, "['a']", "['a']", None], | 135 "RegExpExecMultiple": [None, None, "['a']", "['a']", None], |
134 "SetAccessorProperty": [None, None, "undefined", "undefined", None, None, | 136 "SetAccessorProperty": [None, None, "undefined", "undefined", None, None, |
135 None], | 137 None], |
136 "SetCreateIterator": [None, "2", None], | 138 "SetCreateIterator": [None, "2", None], |
137 "SetDebugEventListener": ["undefined", None, None], | 139 "SetDebugEventListener": ["undefined", None, None], |
138 "SetFunctionBreakPoint": [None, 200, None, None], | 140 "SetFunctionBreakPoint": [None, 200, None, None], |
139 "SetScriptBreakPoint": [_SCRIPT, None, 0, None, None], | |
140 "StringBuilderConcat": ["[1, 2, 3]", 3, None, None], | 141 "StringBuilderConcat": ["[1, 2, 3]", 3, None, None], |
141 "StringBuilderJoin": ["['a', 'b']", 4, None, None], | 142 "StringBuilderJoin": ["['a', 'b']", 4, None, None], |
142 "StringMatch": [None, None, "['a', 'b']", None], | 143 "StringMatch": [None, None, "['a', 'b']", None], |
143 "StringNormalize": [None, 2, None], | 144 "StringNormalize": [None, 2, None], |
144 "StringReplaceGlobalRegExpWithString": [None, None, None, "['a']", None], | 145 "StringReplaceGlobalRegExpWithString": [None, None, None, "['a']", None], |
145 "TypedArrayInitialize": [None, 6, "new ArrayBuffer(8)", None, 4, None], | 146 "TypedArrayInitialize": [None, 6, "new ArrayBuffer(8)", None, 4, None], |
146 "TypedArrayInitializeFromArrayLike": [None, 6, None, None, None], | 147 "TypedArrayInitializeFromArrayLike": [None, 6, None, None, None], |
147 "TypedArraySetFastCases": [None, None, "0", None], | 148 "TypedArraySetFastCases": [None, None, "0", None], |
148 } | 149 } |
149 | 150 |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 print("Missing testcase for %s, please run '%s generate'" % | 491 print("Missing testcase for %s, please run '%s generate'" % |
491 (f.name, THIS_SCRIPT)) | 492 (f.name, THIS_SCRIPT)) |
492 error = True | 493 error = True |
493 files = filter(lambda filename: not filename.startswith("."), | 494 files = filter(lambda filename: not filename.startswith("."), |
494 os.listdir(BASEPATH)) | 495 os.listdir(BASEPATH)) |
495 if (len(files) != len(functions)): | 496 if (len(files) != len(functions)): |
496 unexpected_files = set(files) - set([f.Filename() for f in functions]) | 497 unexpected_files = set(files) - set([f.Filename() for f in functions]) |
497 for f in unexpected_files: | 498 for f in unexpected_files: |
498 print("Unexpected testcase: %s" % os.path.join(BASEPATH, f)) | 499 print("Unexpected testcase: %s" % os.path.join(BASEPATH, f)) |
499 error = True | 500 error = True |
| 501 print("Run '%s generate' to automatically clean these up." |
| 502 % THIS_SCRIPT) |
500 CheckTestcasesExisting(js_fuzzable_functions) | 503 CheckTestcasesExisting(js_fuzzable_functions) |
501 | 504 |
502 if error: | 505 if error: |
503 sys.exit(1) | 506 sys.exit(1) |
504 print("Generated runtime tests: all good.") | 507 print("Generated runtime tests: all good.") |
505 sys.exit(0) | 508 sys.exit(0) |
506 | 509 |
507 if action == "generate": | 510 if action == "generate": |
508 GenerateTestcases(js_fuzzable_functions) | 511 GenerateTestcases(js_fuzzable_functions) |
509 sys.exit(0) | 512 sys.exit(0) |
OLD | NEW |