# 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):


import io
import os
import subprocess
import sys
import tempfile
import FTB.Signatures.CrashInfo as Crash_Info
from optparse import OptionParser  # pylint: disable=deprecated-module
from pathlib import Path
from random import random
from shlex import quote
from FTB.ProgramConfiguration import ProgramConfiguration
from . import js_interesting
from . import shell_flags
from ..util import create_collector
from ..util import file_system_helpers
from ..util import lithium_helpers
            pass
        elif "Bailed out of parallel operation" in line:
            # This error message will only appear when threads and JITs are enabled.
            pass
        else:
            lines.append(line)
    return lines


def compare_jit(jsEngine,  # pylint: disable=invalid-name,missing-param-doc,missing-type-doc,too-many-arguments
                flags, infilename, logPrefix, repo, build_options_str, targetTime, options, ccoverage):
    """For use in loop.py

    Returns:
        bool: True if any kind of bug is found, otherwise False
    """
    # pylint: disable=too-many-locals
    # If Lithium uses this as an interestingness test, logPrefix is likely not a Path object, so make it one.
    logPrefix = Path(logPrefix)
    initialdir_name = logPrefix.parent / f"{logPrefix.stem}-initial"
    is_quick_mode = random() < 0.5
    # pylint: disable=invalid-name
    cl = compareLevel(jsEngine, flags, infilename, initialdir_name, options, False, is_quick_mode)
    lev = cl[0]

    if not (ccoverage or lev == js_interesting.JS_FINE):
        itest = [__name__, f'--flags={" ".join(flags)}',
                 f"--minlevel={lev}", f"--timeout={options.timeout}", options.knownPath]
        (lithResult, _lithDetails, autoBisectLog) = lithium_helpers.pinpoint(  # pylint: disable=invalid-name
            itest, logPrefix, jsEngine, [], infilename, repo, build_options_str, targetTime, lev)

# 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/js/compare_jit.py
import io
import os
import subprocess
import sys
import tempfile
import FTB.Signatures.CrashInfo as Crash_Info
from optparse import OptionParser  # pylint: disable=deprecated-module
from pathlib import Path
from random import random
from shlex import quote
from FTB.ProgramConfiguration import ProgramConfiguration
from . import js_interesting
from . import shell_flags
from ..util import create_collector
from ..util import file_system_helpers
from ..util import lithium_helpers

            pass
        elif "Bailed out of parallel operation" in line:
            # This error message will only appear when threads and JITs are enabled.
            pass
        else:
            lines.append(line)
    return lines


def compare_jit(jsEngine,  # pylint: disable=invalid-name,missing-param-doc,missing-type-doc,too-many-arguments
                flags, infilename, logPrefix, repo, build_options_str, targetTime, options, ccoverage):
    """For use in loop.py

    Returns:
        bool: True if any kind of bug is found, otherwise False
    """
    # pylint: disable=too-many-locals
    # If Lithium uses this as an interestingness test, logPrefix is likely not a Path object, so make it one.
    logPrefix = Path(logPrefix)
    initialdir_name = logPrefix.parent / f"{logPrefix.stem}-initial"
    is_quick_mode = random() < 0.5
    # pylint: disable=invalid-name
    cl = compareLevel(jsEngine, flags, infilename, initialdir_name, options, False, is_quick_mode)
    lev = cl[0]

    if not (ccoverage or lev == js_interesting.JS_FINE):
        itest = [__name__, f'--flags={" ".join(flags)}',
                 f"--minlevel={lev}", f"--timeout={options.timeout}", options.knownPath]
        (lithResult, _lithDetails, autoBisectLog) = lithium_helpers.pinpoint(  # pylint: disable=invalid-name
            itest, logPrefix, jsEngine, [], infilename, repo, build_options_str, targetTime, lev)

        if lithResult == lithium_helpers.LITH_FINISHED: