# 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
        print("Note: When running compare_jit, the --valgrind option will be ignored", file=sys.stderr)

    return options


def showtail(filename):  # pylint: disable=missing-docstring
    # pylint: disable=fixme
    # FIXME: Get jsfunfuzz to output start & end of interesting result boundaries instead of this.
    cmd = []
    cmd.extend(["tail", "-n", "20"])
    cmd.append(str(filename))
    print(" ".join(cmd))
    print()
    subprocess.run(cmd, check=True)
    print()
    print()


def makeRegressionTestPrologue(repo):  # pylint: disable=invalid-name,missing-param-doc
    # pylint: disable=missing-return-doc,missing-return-type-doc,missing-type-doc
    """Generate a JS string to tell jsfunfuzz where to find SpiderMonkey's regression tests."""
    libdir = Path("js") / "src" / "jit-test" / "lib"
    js_src_tests_dir = Path("js") / "src" / "tests"
    non262_tests_dir = js_src_tests_dir / "non262"
    test262_tests_dir = js_src_tests_dir / "test262"
    w_pltfrm_res_dir = Path("testing") / "web-platform" / "tests" / "resources"
    return dedent(f"""
        const regressionTestsRoot = {json.dumps(str(repo) + os.sep)};
        const libdir = regressionTestsRoot + {json.dumps(str(libdir) + os.sep)}; // needed by jit-tests
        const js_src_tests_dir = regressionTestsRoot + {json.dumps(str(js_src_tests_dir) + os.sep)}; // streams tests

# 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

        print("Note: When running compare_jit, the --valgrind option will be ignored", file=sys.stderr)

    return options


def showtail(filename):  # pylint: disable=missing-docstring
    # pylint: disable=fixme
    # FIXME: Get jsfunfuzz to output start & end of interesting result boundaries instead of this.
    cmd = []
    cmd.extend(["tail", "-n", "20"])
    cmd.append(str(filename))
    print(" ".join(cmd))
    print()
    subprocess.run(cmd, check=True)
    print()
    print()


def makeRegressionTestPrologue(repo):  # pylint: disable=invalid-name,missing-param-doc
    # pylint: disable=missing-return-doc,missing-return-type-doc,missing-type-doc
    """Generate a JS string to tell jsfunfuzz where to find SpiderMonkey's regression tests."""
    libdir = Path("js") / "src" / "jit-test" / "lib"
    js_src_tests_dir = Path("js") / "src" / "tests"
    non262_tests_dir = js_src_tests_dir / "non262"
    test262_tests_dir = js_src_tests_dir / "test262"
    w_pltfrm_res_dir = Path("testing") / "web-platform" / "tests" / "resources"
    return dedent(f"""
        const regressionTestsRoot = {json.dumps(str(repo) + os.sep)};
        const libdir = regressionTestsRoot + {json.dumps(str(libdir) + os.sep)}; // needed by jit-tests
        const js_src_tests_dir = regressionTestsRoot + {json.dumps(str(js_src_tests_dir) + os.sep)}; // streams tests

        const non262_tests_dir = regressionTestsRoot + {json.dumps(str(non262_tests_dir) + os.sep)}; // non262 tests