Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 Add tox env for fuzz testcase run #263

Merged
merged 3 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ name: fuzzing
# to guard against code introducing crashes in the Markdown parsing,
# which should in principle always run against any text input.
# See: https://google.github.io/oss-fuzz/getting-started/continuous-integration/#how-it-works
# Note, to reproduce a crash locally, copy to `testcase` file` and run: `tox -e fuzz`

on:
pull_request:
paths-ignore: ['docs/**', 'tests/**']

jobs:
Fuzzing:
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run_apidoc(app):
this_folder = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
api_folder = os.path.join(this_folder, "api")
module_path = os.path.normpath(os.path.join(this_folder, "../"))
ignore_paths = ["../profiler.py", "../conftest.py", "../tests", "../benchmarking"]
ignore_paths = ["../scripts", "../conftest.py", "../tests", "../benchmarking"]
ignore_paths = [
os.path.normpath(os.path.join(this_folder, p)) for p in ignore_paths
]
Expand Down
42 changes: 42 additions & 0 deletions scripts/build_fuzzers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Build fuzzers idempotently in a given folder."""
import argparse
from pathlib import Path
import subprocess


def main():
"""Build fuzzers idempotently in a given folder."""
parser = argparse.ArgumentParser()
parser.add_argument("folder")
args = parser.parse_args()
folder = Path(args.folder)
if not folder.exists():
print(f"Cloning google/oss-fuzz into: {folder}")
folder.mkdir(parents=True)
subprocess.check_call(
[
"git",
"clone",
"--single-branch",
"https://github.com/google/oss-fuzz",
str(folder),
]
)
else:
print(f"Using google/oss-fuzz in: {folder}")
if not (folder / "build").exists():
print(f"Building fuzzers in: {folder / 'build'}")
subprocess.check_call(
[
"python",
str(folder / "infra" / "helper.py"),
"build_fuzzers",
"markdown-it-py",
]
)
else:
print(f"Using existing fuzzers in: {folder / 'build'}")


if __name__ == "__main__":
main()
File renamed without changes.
9 changes: 8 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ allowlist_externals =
dot
commands =
mkdir -p "{toxworkdir}/prof"
python -m cProfile -o "{toxworkdir}/prof/output.pstats" profiler.py
python -m cProfile -o "{toxworkdir}/prof/output.pstats" scripts/profiler.py
gprof2dot -f pstats -o "{toxworkdir}/prof/output.dot" "{toxworkdir}/prof/output.pstats"
dot -Tsvg -o "{toxworkdir}/prof/output.svg" "{toxworkdir}/prof/output.dot"
python -c 'import pathlib; print("profiler svg output under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "prof" / "output.svg"))'

[testenv:fuzz]
description = run fuzzer on testcase file
; See: https://google.github.io/oss-fuzz/
deps = atheris
commands_pre = python scripts/build_fuzzers.py {envdir}/oss-fuzz
commands = python {envdir}/oss-fuzz/infra/helper.py reproduce markdown-it-py fuzz_markdown {posargs:testcase}

[flake8]
max-line-length = 100
extend-ignore = E203