@@ -61,38 +61,40 @@ def ignore_some_stderr(err_inp):
6161 return lines
6262
6363
64- def compare_jit (jsEngine , # pylint: disable=invalid-name,missing-param-doc,missing-type-doc,too-many-arguments
64+ def compare_jit (js_engine , # pylint: disable=invalid-name,missing-param-doc,missing-type-doc,too-many-arguments
6565 flags , infilename , logPrefix , repo , build_options_str , targetTime , options ):
6666 """For use in loop.py
6767
6868 Returns:
6969 bool: True if any kind of bug is found, otherwise False
7070 """
7171 # pylint: disable=too-many-locals
72+ js_engine = Path (js_engine )
73+ infilename = Path (infilename )
7274 # If Lithium uses this as an interestingness test, logPrefix is likely not a Path object, so make it one.
7375 logPrefix = Path (logPrefix )
7476 initialdir_name = (logPrefix .parent / (logPrefix .stem + "-initial" ))
75- # pylint: disable=invalid-name
76- cl = compareLevel ( jsEngine , flags , infilename , initialdir_name , options , False , True )
77+ cl = compareLevel ( js_engine , # pylint: disable=invalid-name
78+ flags , infilename , initialdir_name , options , False , True )
7779 lev = cl [0 ]
7880
7981 if lev != js_interesting .JS_FINE :
8082 itest = [__name__ , "--flags=" + " " .join (flags ),
81- "--minlevel=" + str (lev ), "--timeout=" + str (options .timeout ), options . knownPath ]
83+ "--minlevel=" + str (lev ), "--timeout=" + str (options .timeout )]
8284 (lithResult , _lithDetails , autoBisectLog ) = lithium_helpers .pinpoint ( # pylint: disable=invalid-name
83- itest , logPrefix , jsEngine , [], infilename , repo , build_options_str , targetTime , lev )
85+ itest , logPrefix , js_engine , [], infilename , repo , build_options_str , targetTime , lev )
8486 if lithResult == lithium_helpers .LITH_FINISHED :
85- print ("Retesting %s after running Lithium:" % infilename )
87+ print ("Retesting %s after running Lithium:" % str ( infilename ) )
8688 finaldir_name = (logPrefix .parent / (logPrefix .stem + "-final" ))
87- retest_cl = compareLevel (jsEngine , flags , infilename , finaldir_name , options , True , False )
89+ retest_cl = compareLevel (js_engine , flags , infilename , finaldir_name , options , True , False )
8890 if retest_cl [0 ] != js_interesting .JS_FINE :
89- cl = retest_cl
91+ cl = retest_cl # pylint: disable=invalid-name
9092 quality = 0
9193 else :
9294 quality = 6
9395 else :
9496 quality = 10
95- print ("compare_jit: Uploading %s with quality %s" % (infilename , quality ))
97+ print ("compare_jit: Uploading %s with quality %s" % (str ( infilename ) , quality ))
9698
9799 metadata = {}
98100 if autoBisectLog :
@@ -103,17 +105,19 @@ def compare_jit(jsEngine, # pylint: disable=invalid-name,missing-param-doc,miss
103105 return False
104106
105107
106- def compareLevel (jsEngine , flags , infilename , logPrefix , options , showDetailedDiffs , quickMode ):
107- # pylint: disable=invalid-name,missing-docstring,missing-return-doc,missing-return-type-doc,too-complex
108- # pylint: disable=too-many-branches,too-many-arguments,too-many-locals
108+ def compareLevel (js_engine , # pylint: disable=invalid-name,missing-docstring,missing-return-doc,missing-return-type-doc
109+ flags , infilename , logPrefix , options , showDetailedDiffs , quickMode ):
110+ # pylint: disable=too-complex,too- many-branches,too-many-arguments,too-many-locals
109111
110112 # options dict must be one we can pass to js_interesting.ShellResult
111- # we also use it directly for knownPath, timeout, and collector
113+ # we also use it directly for timeout, and collector
112114 # Return: (lev, crashInfo) or (js_interesting.JS_FINE, None)
113115
114- assert isinstance (infilename , Path )
116+ js_engine = Path (js_engine )
117+ infilename = Path (infilename )
118+ logPrefix = Path (logPrefix )
115119
116- combos = shell_flags .basic_flag_sets (jsEngine )
120+ combos = shell_flags .basic_flag_sets (str ( js_engine ) )
117121
118122 if quickMode :
119123 # Only used during initial fuzzing. Allowed to have false negatives.
@@ -122,7 +126,7 @@ def compareLevel(jsEngine, flags, infilename, logPrefix, options, showDetailedDi
122126 if flags :
123127 combos .insert (0 , flags )
124128
125- commands = [[jsEngine ] + combo + [str (infilename )] for combo in combos ]
129+ commands = [[str ( js_engine ) ] + combo + [str (infilename )] for combo in combos ]
126130
127131 for i , command in enumerate (commands ):
128132 prefix = (logPrefix .parent / ("%s-r%s" % (logPrefix .stem , str (i ))))
@@ -192,8 +196,7 @@ def optionDisabledAsmOnOneSide(): # pylint: disable=invalid-name,missing-docstr
192196 rerunCommand = " " .join (quote (str (x )) for x in ["python -m funfuzz.js.compare_jit" ,
193197 "--flags=" + " " .join (flags ),
194198 "--timeout=" + str (options .timeout ),
195- str (options .knownPath ),
196- str (jsEngine ),
199+ str (js_engine ),
197200 str (infilename .name )])
198201 (summary , issues ) = summarizeMismatch (mismatchErr , mismatchOut , prefix0 , prefix )
199202 summary = (" " + " " .join (quote (str (x )) for x in commands [0 ]) + "\n " +
@@ -209,7 +212,7 @@ def optionDisabledAsmOnOneSide(): # pylint: disable=invalid-name,missing-docstr
209212 print (summary )
210213 print ()
211214 # Create a crashInfo object with empty stdout, and stderr showing diffs
212- pc = ProgramConfiguration .fromBinary (str (jsEngine )) # pylint: disable=invalid-name
215+ pc = ProgramConfiguration .fromBinary (str (js_engine )) # pylint: disable=invalid-name
213216 pc .addProgramArguments (flags )
214217 crashInfo = CrashInfo .CrashInfo .fromRawCrashData ([], summary , pc ) # pylint: disable=invalid-name
215218 return (js_interesting .JS_OVERALL_MISMATCH , crashInfo )
@@ -281,11 +284,10 @@ def parseOptions(args): # pylint: disable=invalid-name
281284 default = "" ,
282285 help = "space-separated list of one set of flags" )
283286 options , args = parser .parse_args (args )
284- if len (args ) != 3 :
285- raise Exception ("Wrong number of positional arguments. Need 3 (knownPath, jsengine, infilename)." )
286- options .knownPath = Path (args [0 ]).expanduser ().resolve ()
287- options .jsengine = Path (args [1 ]).expanduser ().resolve ()
288- options .infilename = Path (args [2 ]).expanduser ().resolve ()
287+ if len (args ) != 2 :
288+ raise Exception ("Wrong number of positional arguments. Need 2 (jsengine, infilename)." )
289+ options .jsengine = Path (args [0 ]).expanduser ().resolve ()
290+ options .infilename = Path (args [1 ]).expanduser ().resolve ()
289291 options .flags = options .flagsSpaceSep .split (" " ) if options .flagsSpaceSep else []
290292 if not options .jsengine .is_file ():
291293 raise OSError ("js shell does not exist: %s" % options .jsengine )
@@ -298,24 +300,37 @@ def parseOptions(args): # pylint: disable=invalid-name
298300 return options
299301
300302
301- # For use by Lithium and autobisectjs. (autobisectjs calls init multiple times because it changes the js engine name)
302- def init (args ):
303- global gOptions # pylint: disable=invalid-name,global-statement
304- gOptions = parseOptions (args )
303+ class Interesting (object ):
304+
305+ def __init__ (self , interestingness_script = False ):
306+ if interestingness_script :
307+ global init , interesting # pylint: disable=global-variable-undefined
308+ init = self .init
309+ interesting = self .interesting
310+
311+ self .args = None
312+ self .real_level = None
313+
314+ # For use by Lithium and autobisectjs.
315+ # (autobisectjs calls init multiple times because it changes the js engine name)
316+ def init (self , args ):
317+ self .args = parseOptions (args )
318+
319+ def interesting (self , _args , cwd_prefix ): # pylint: disable=missing-docstring,missing-return-doc
320+ # pylint: disable=missing-return-type-doc
321+ self .real_level = compareLevel (
322+ Path (self .args .jsengine ), self .args .flags , Path (self .args .infilename ),
323+ Path (cwd_prefix ), self .args , False , False )[0 ]
324+ return self .real_level >= self .args .minimumInterestingLevel
305325
306326
307- # FIXME: _args is unused here, we should check if it can be removed? # pylint: disable=fixme
308- def interesting (_args , cwd_prefix ):
309- cwd_prefix = Path (cwd_prefix ) # Lithium uses this function and cwd_prefix from Lithium is not a Path
310- actualLevel = compareLevel ( # pylint: disable=invalid-name
311- gOptions .jsengine , gOptions .flags , gOptions .infilename , cwd_prefix , gOptions , False , False )[0 ]
312- return actualLevel >= gOptions .minimumInterestingLevel
327+ Interesting (interestingness_script = True )
313328
314329
315330def main ():
316331 options = parseOptions (sys .argv [1 :])
317332 print (compareLevel (
318- options .jsengine , options .flags , options .infilename , # pylint: disable=no-member
333+ Path ( options .jsengine ) , options .flags , Path ( options .infilename ) , # pylint: disable=no-member
319334 Path (tempfile .mkdtemp ("compare_jitmain" )), options , True , False )[0 ])
320335
321336
0 commit comments