Skip to content

Commit

Permalink
Fuzzing CMA with atheris
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bata committed Jun 25, 2021
1 parent 2cd2dec commit ff63cc0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
37 changes: 37 additions & 0 deletions fuzzing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
import atheris
import hypothesis.extra.numpy as npst
from hypothesis import given, strategies as st

from cmaes import CMA


@given(data=st.data())
def test_cma_tell(data):
dim = data.draw(st.integers(min_value=2, max_value=100))
mean = data.draw(npst.arrays(dtype=float, shape=dim))
sigma = data.draw(st.floats(min_value=1e-16))
n_iterations = data.draw(st.integers(min_value=1))
try:
optimizer = CMA(mean, sigma)
except AssertionError:
return
popsize = optimizer.population_size
for _ in range(n_iterations):
tell_solutions = data.draw(
st.lists(
st.tuples(npst.arrays(dtype=float, shape=dim), st.floats()),
min_size=popsize,
max_size=popsize,
)
)
optimizer.ask()
try:
optimizer.tell(tell_solutions)
except AssertionError:
return
optimizer.ask()


atheris.Setup(sys.argv, test_cma_tell.hypothesis.fuzz_one_input)
atheris.Fuzz()
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ numpy>=1.20.0
matplotlib
scipy

# tests
# Fuzzing
hypothesis
atheris

# lint
mypy
Expand Down

0 comments on commit ff63cc0

Please sign in to comment.