Skip to content

Commit d1852a5

Browse files
authored
🔧 Add tox env for fuzz testcase run (#263)
To reproduce failing test cases reported by Google's OSS-Fuzz runs
1 parent 5059095 commit d1852a5

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

.github/workflows/fuzz.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ name: fuzzing
66
# to guard against code introducing crashes in the Markdown parsing,
77
# which should in principle always run against any text input.
88
# See: https://google.github.io/oss-fuzz/getting-started/continuous-integration/#how-it-works
9+
# Note, to reproduce a crash locally, copy to `testcase` file` and run: `tox -e fuzz`
910

1011
on:
1112
pull_request:
13+
paths-ignore: ['docs/**', 'tests/**']
1214

1315
jobs:
1416
Fuzzing:

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def run_apidoc(app):
102102
this_folder = os.path.abspath(os.path.dirname(os.path.realpath(__file__)))
103103
api_folder = os.path.join(this_folder, "api")
104104
module_path = os.path.normpath(os.path.join(this_folder, "../"))
105-
ignore_paths = ["../profiler.py", "../conftest.py", "../tests", "../benchmarking"]
105+
ignore_paths = ["../scripts", "../conftest.py", "../tests", "../benchmarking"]
106106
ignore_paths = [
107107
os.path.normpath(os.path.join(this_folder, p)) for p in ignore_paths
108108
]

scripts/build_fuzzers.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Build fuzzers idempotently in a given folder."""
2+
import argparse
3+
from pathlib import Path
4+
import subprocess
5+
6+
7+
def main():
8+
"""Build fuzzers idempotently in a given folder."""
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument("folder")
11+
args = parser.parse_args()
12+
folder = Path(args.folder)
13+
if not folder.exists():
14+
print(f"Cloning google/oss-fuzz into: {folder}")
15+
folder.mkdir(parents=True)
16+
subprocess.check_call(
17+
[
18+
"git",
19+
"clone",
20+
"--single-branch",
21+
"https://github.com/google/oss-fuzz",
22+
str(folder),
23+
]
24+
)
25+
else:
26+
print(f"Using google/oss-fuzz in: {folder}")
27+
if not (folder / "build").exists():
28+
print(f"Building fuzzers in: {folder / 'build'}")
29+
subprocess.check_call(
30+
[
31+
"python",
32+
str(folder / "infra" / "helper.py"),
33+
"build_fuzzers",
34+
"markdown-it-py",
35+
]
36+
)
37+
else:
38+
print(f"Using existing fuzzers in: {folder / 'build'}")
39+
40+
41+
if __name__ == "__main__":
42+
main()
File renamed without changes.

tox.ini

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ allowlist_externals =
5555
dot
5656
commands =
5757
mkdir -p "{toxworkdir}/prof"
58-
python -m cProfile -o "{toxworkdir}/prof/output.pstats" profiler.py
58+
python -m cProfile -o "{toxworkdir}/prof/output.pstats" scripts/profiler.py
5959
gprof2dot -f pstats -o "{toxworkdir}/prof/output.dot" "{toxworkdir}/prof/output.pstats"
6060
dot -Tsvg -o "{toxworkdir}/prof/output.svg" "{toxworkdir}/prof/output.dot"
6161
python -c 'import pathlib; print("profiler svg output under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "prof" / "output.svg"))'
6262

63+
[testenv:fuzz]
64+
description = run fuzzer on testcase file
65+
; See: https://google.github.io/oss-fuzz/
66+
deps = atheris
67+
commands_pre = python scripts/build_fuzzers.py {envdir}/oss-fuzz
68+
commands = python {envdir}/oss-fuzz/infra/helper.py reproduce markdown-it-py fuzz_markdown {posargs:testcase}
69+
6370
[flake8]
6471
max-line-length = 100
6572
extend-ignore = E203

0 commit comments

Comments
 (0)