funfuzz icon indicating copy to clipboard operation
funfuzz copied to clipboard

Remove globals and other cleanup

Open nth10sd opened this issue 7 years ago • 3 comments

Here's a bunch of cleanups.

  • #125 gets fixed here, removing all globals
  • 2 ride-alongs
    • detect_malloc_errors gets removed with its functions simplified and inlined
    • knownPath (from the days of multiple-year-lasting branches) is also removed

nth10sd avatar Apr 11 '18 00:04 nth10sd

Codecov Report

Merging #169 into master will increase coverage by 0.15%. The diff coverage is 17.39%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #169      +/-   ##
==========================================
+ Coverage   44.17%   44.32%   +0.15%     
==========================================
  Files          31       30       -1     
  Lines        2685     2653      -32     
==========================================
- Hits         1186     1176      -10     
+ Misses       1499     1477      -22
Impacted Files Coverage Δ
src/funfuzz/util/__init__.py 100% <ø> (ø) :arrow_up:
src/funfuzz/bot.py 23.35% <ø> (+0.16%) :arrow_up:
src/funfuzz/js/loop.py 18.11% <0%> (+0.38%) :arrow_up:
src/funfuzz/js/compare_jit.py 15.72% <25%> (-0.65%) :arrow_down:
src/funfuzz/js/js_interesting.py 22.22% <33.33%> (-0.23%) :arrow_down:
src/funfuzz/util/file_manipulation.py 15.9% <9.09%> (-2.28%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 35b5e09...e8bc84d. Read the comment docs.

codecov-io avatar Apr 11 '18 05:04 codecov-io

Sample command:

python -u -m lithium funfuzz.js.compare_jit --flags="--fuzzing-safe --test-wasm-await-tier2 --no-wasm-ion --no-asmjs --no-avx --no-sse4 --no-ion --nursery-strings=on --no-array-proto-values --ion-offthread-compile=off --no-threads --baseline-eager" ./js testcase.js
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/winworklin/.local/lib/python2.7/site-packages/lithium/__main__.py", line 13, in <module>
    main()
  File "/home/winworklin/.local/lib/python2.7/site-packages/lithium/reducer.py", line 1414, in main
    exit(Lithium().main())
  File "/home/winworklin/.local/lib/python2.7/site-packages/lithium/reducer.py", line 1193, in main
    return self.run()
  File "/home/winworklin/.local/lib/python2.7/site-packages/lithium/reducer.py", line 1209, in run
    result = self.strategy.main(self.testcase, self.interesting, self.testcaseTempFilename)
  File "/home/winworklin/.local/lib/python2.7/site-packages/lithium/reducer.py", line 329, in main
    if not interesting(testcase, writeIt=False):
  File "/home/winworklin/.local/lib/python2.7/site-packages/lithium/reducer.py", line 1366, in interesting
    inter = self.conditionScript.interesting(self.conditionArgs, tempPrefix)
  File "/home/winworklin/.local/lib/python2.7/site-packages/funfuzz/js/compare_jit.py", line 259, in interesting
    opts.jsengine, opts.flags, opts.infilename, tempPrefix, opts, False, False)[0]
AttributeError: 'list' object has no attribute 'jsengine'

This PR still seems to throw when run with Lithium... :-/

Of course, turns out _args is used by Lithium. What will be a good way of solving this?

nth10sd avatar Apr 13 '18 03:04 nth10sd

This is what we did in grizzly's interesting script:

class Interesting(object):

    def __init__(self, interestingness_script=False):
        if interestingness_script:
            global init, interesting, cleanup  # pylint: disable=global-variable-undefined,invalid-name
            init = self.init
            interesting = self.interesting
            cleanup = self.cleanup

        self.args = None
        ...

    def init(self, args):
        self.args = self.parse_ffp_options(args)
        ...

    def interesting(self, _args, temp_prefix):
        ...

    def cleanup(self, _):
        ...

Interesting(True)

So the interestingness_script argument is used to create an instance of the class that handles the global init, interesting, and cleanup "functions" when lithium is called from the command-line, but the class is also usable with lithium.Lithium(). You do still have globals, but they're hidden...

jschwartzentruber avatar Apr 20 '18 20:04 jschwartzentruber