Skip to content

Commit c16a344

Browse files
author
Songki Choi
authored
Add fuzzing test (#13)
1 parent bed7e4c commit c16a344

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

tests/fuzz/__init__.py

Whitespace-only changes.

tests/fuzz/test_fuzz.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import sys
5+
6+
import atheris
7+
8+
with atheris.instrument_imports():
9+
from openvino_xai import Explainer, insert_xai
10+
11+
12+
def TestOneInput(input_bytes):
13+
data_provider = atheris.FuzzedDataProvider(input_bytes)
14+
15+
# Test Explainer statefull class API
16+
try:
17+
explainer = Explainer(
18+
model=data_provider.ConsumeBytes(8),
19+
task=data_provider.ConsumeUInt(8),
20+
)
21+
explanation = explainer(data=data_provider.ConsumeBytes(8))
22+
except ValueError as e:
23+
pass
24+
25+
# Test insert_xai() stateless API
26+
try:
27+
insert_xai(
28+
model=data_provider.ConsumeBytes(8),
29+
task=data_provider.ConsumeUInt(8),
30+
)
31+
except ValueError as e:
32+
pass
33+
34+
35+
atheris.Setup(sys.argv, TestOneInput)
36+
atheris.Fuzz()

tox.ini

+7
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ commands =
2525
extras = dev,val
2626
commands =
2727
pytest -ra --showlocals {posargs:tests/}
28+
29+
[testenv:fuzz-{py310, py311}]
30+
deps =
31+
atheris
32+
extras = dev
33+
commands =
34+
python tests/fuzz/test_fuzz.py {posargs:-artifact_prefix={toxworkdir}/ -print_final_stats=1 -runs=10000000}

0 commit comments

Comments
 (0)