Skip to content

Commit

Permalink
Add fuzzing test (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
goodsong81 authored Jun 12, 2024
1 parent bed7e4c commit c16a344
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
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}

0 comments on commit c16a344

Please sign in to comment.