# Path: src/funfuzz/util/create_collector.py
# def make_collector():
# def printCrashInfo(crashInfo):  # pylint: disable=invalid-name,missing-docstring
# def printMatchingSignature(match):  # pylint: disable=invalid-name,missing-docstring
# def submit_collector(collector, crash_info, testcase, quality, meta_data=None):
# 
# Path: src/funfuzz/util/lithium_helpers.py
# (HAPPY, LITH_NO_REPRO, LITH_FINISHED, LITH_RETESTED_STILL_INTERESTING, LITH_BUSTED) = range(5)
# def pinpoint(itest, logPrefix, jsEngine, engineFlags, infilename,  # pylint: disable=invalid-name,missing-param-doc
#              bisectRepo, build_options_str, targetTime, suspiciousLevel):
# def run_lithium(lithArgs, logPrefix, targetTime):  # pylint: disable=invalid-name,missing-param-doc,missing-return-doc
# def readLithiumResult(lithlogfn):  # pylint: disable=invalid-name,missing-docstring,missing-return-doc
# def reduction_strat(logPrefix, infilename, lithArgs, targetTime, lev):  # pylint: disable=invalid-name
#     def lith_reduce(strategy):
# 
# Path: src/funfuzz/util/os_ops.py
# NO_DUMP_MSG = r"""
# WARNING: Minidumps are not being generated, so all crashes will be uninteresting.
# WARNING: Make sure the following key value exists in this key:
# WARNING: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps
# WARNING: Name: DumpType  Type: REG_DWORD
# WARNING: http://msdn.microsoft.com/en-us/library/windows/desktop/bb787181%28v=vs.85%29.aspx
# """
# def make_cdb_cmd(prog_full_path, crashed_pid):
# def make_gdb_cmd(prog_full_path, crashed_pid):
# def disable_corefile():
# def get_core_limit():
# def make_dbg_cmd(prog_full_path, crashed_pid):
# def grab_crash_log(prog_full_path, crashed_pid, log_prefix, want_stack):
# def grab_mac_crash_log(crash_pid, log_prefix, use_log_files):
# def is_win_dumping_to_default():  # pylint: disable=too-complex
# def make_wtmp_dir(base_dir):


import argparse
import io
import json
import logging
import os
import platform
import subprocess
import sys
import time
import zipfile
from pathlib import Path
from textwrap import dedent
from . import compare_jit
from . import js_interesting
from . import link_fuzzer
from . import shell_flags
from . import with_binaryen
from ..util import create_collector
from ..util import file_manipulation
from ..util import file_system_helpers
from ..util import lithium_helpers
from ..util import os_ops
    if res.lev >= js_interesting.JS_OVERALL_MISMATCH:
        showtail(out_log)
        showtail(err_log)

        # splice jsfunfuzz.js with `grep "/*FRC-" wN-out`
        [before, after] = file_manipulation.fuzzSplice(fuzzjs)

        with io.open(str(out_log), "r", encoding="utf-8", errors="replace") as f:
            newfileLines = before + [  # pylint: disable=invalid-name
                l.replace("/*FRC-", "/*") for l in file_manipulation.linesStartingWith(f, "/*FRC-")] + after
        orig_log = (log_prefix.parent / f"{log_prefix.stem}-orig").with_suffix(".js")
        with io.open(str(orig_log), "w", encoding="utf-8", errors="replace") as f:
            f.writelines(newfileLines)
        with io.open(str(reduced_log), "w", encoding="utf-8", errors="replace") as f:
            f.writelines(newfileLines)

        if not ccoverage:
            # Run Lithium and autobisectjs (make a reduced testcase and find a regression window)
            interestingpy = "funfuzz.js.js_interesting"
            itest = [interestingpy]
            if options.valgrind:
                itest.append("--valgrind")
            itest.append(f"--minlevel={res.lev}")
            itest.append(f"--timeout={options.timeout}")
            itest.append(options.knownPath)
            (lith_result, _lith_details, autobisect_log) = lithium_helpers.pinpoint(
                itest, log_prefix, options.jsEngine, options.engineFlags, reduced_log, options.repo,
                options.build_options_str, target_time, res.lev)

            # Upload with final output

# Path: src/funfuzz/util/create_collector.py
# def make_collector():
# def printCrashInfo(crashInfo):  # pylint: disable=invalid-name,missing-docstring
# def printMatchingSignature(match):  # pylint: disable=invalid-name,missing-docstring
# def submit_collector(collector, crash_info, testcase, quality, meta_data=None):
# 
# Path: src/funfuzz/util/lithium_helpers.py
# (HAPPY, LITH_NO_REPRO, LITH_FINISHED, LITH_RETESTED_STILL_INTERESTING, LITH_BUSTED) = range(5)
# def pinpoint(itest, logPrefix, jsEngine, engineFlags, infilename,  # pylint: disable=invalid-name,missing-param-doc
#              bisectRepo, build_options_str, targetTime, suspiciousLevel):
# def run_lithium(lithArgs, logPrefix, targetTime):  # pylint: disable=invalid-name,missing-param-doc,missing-return-doc
# def readLithiumResult(lithlogfn):  # pylint: disable=invalid-name,missing-docstring,missing-return-doc
# def reduction_strat(logPrefix, infilename, lithArgs, targetTime, lev):  # pylint: disable=invalid-name
#     def lith_reduce(strategy):
# 
# Path: src/funfuzz/util/os_ops.py
# NO_DUMP_MSG = r"""
# WARNING: Minidumps are not being generated, so all crashes will be uninteresting.
# WARNING: Make sure the following key value exists in this key:
# WARNING: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Windows Error Reporting\LocalDumps
# WARNING: Name: DumpType  Type: REG_DWORD
# WARNING: http://msdn.microsoft.com/en-us/library/windows/desktop/bb787181%28v=vs.85%29.aspx
# """
# def make_cdb_cmd(prog_full_path, crashed_pid):
# def make_gdb_cmd(prog_full_path, crashed_pid):
# def disable_corefile():
# def get_core_limit():
# def make_dbg_cmd(prog_full_path, crashed_pid):
# def grab_crash_log(prog_full_path, crashed_pid, log_prefix, want_stack):
# def grab_mac_crash_log(crash_pid, log_prefix, use_log_files):
# def is_win_dumping_to_default():  # pylint: disable=too-complex
# def make_wtmp_dir(base_dir):


# Path: src/funfuzz/js/loop.py
import argparse
import io
import json
import logging
import os
import platform
import subprocess
import sys
import time
import zipfile
from pathlib import Path
from textwrap import dedent
from . import compare_jit
from . import js_interesting
from . import link_fuzzer
from . import shell_flags
from . import with_binaryen
from ..util import create_collector
from ..util import file_manipulation
from ..util import file_system_helpers
from ..util import lithium_helpers
from ..util import os_ops

    if res.lev >= js_interesting.JS_OVERALL_MISMATCH:
        showtail(out_log)
        showtail(err_log)

        # splice jsfunfuzz.js with `grep "/*FRC-" wN-out`
        [before, after] = file_manipulation.fuzzSplice(fuzzjs)

        with io.open(str(out_log), "r", encoding="utf-8", errors="replace") as f:
            newfileLines = before + [  # pylint: disable=invalid-name
                l.replace("/*FRC-", "/*") for l in file_manipulation.linesStartingWith(f, "/*FRC-")] + after
        orig_log = (log_prefix.parent / f"{log_prefix.stem}-orig").with_suffix(".js")
        with io.open(str(orig_log), "w", encoding="utf-8", errors="replace") as f:
            f.writelines(newfileLines)
        with io.open(str(reduced_log), "w", encoding="utf-8", errors="replace") as f:
            f.writelines(newfileLines)

        if not ccoverage:
            # Run Lithium and autobisectjs (make a reduced testcase and find a regression window)
            interestingpy = "funfuzz.js.js_interesting"
            itest = [interestingpy]
            if options.valgrind:
                itest.append("--valgrind")
            itest.append(f"--minlevel={res.lev}")
            itest.append(f"--timeout={options.timeout}")
            itest.append(options.knownPath)
            (lith_result, _lith_details, autobisect_log) = lithium_helpers.pinpoint(
                itest, log_prefix, options.jsEngine, options.engineFlags, reduced_log, options.repo,
                options.build_options_str, target_time, res.lev)

            # Upload with final output

            if lith_result == lithium_helpers.LITH_FINISHED: