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 fuzzing test #13

Merged
merged 2 commits into from
Jun 12, 2024
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
Empty file added tests/fuzz/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions tests/fuzz/test_fuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys

import atheris

with atheris.instrument_imports():
from openvino_xai import Explainer, insert_xai


def TestOneInput(input_bytes):
data_provider = atheris.FuzzedDataProvider(input_bytes)

# Test Explainer statefull class API
try:
explainer = Explainer(
model=data_provider.ConsumeBytes(8),
task=data_provider.ConsumeUInt(8),
)
explanation = explainer(data=data_provider.ConsumeBytes(8))
except ValueError as e:
pass

# Test insert_xai() stateless API
try:
insert_xai(
model=data_provider.ConsumeBytes(8),
task=data_provider.ConsumeUInt(8),
)
except ValueError as e:
pass


atheris.Setup(sys.argv, TestOneInput)
atheris.Fuzz()
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ commands =
extras = dev,val
commands =
pytest -ra --showlocals {posargs:tests/}

[testenv:fuzz-{py310, py311}]
deps =
atheris
extras = dev
commands =
python tests/fuzz/test_fuzz.py {posargs:-artifact_prefix={toxworkdir}/ -print_final_stats=1 -runs=10000000}
Loading