Skip to content

Commit

Permalink
clean up, no functional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stbraun committed Jun 10, 2018
2 parents af7f5d4 + 6416dea commit 974a644
Show file tree
Hide file tree
Showing 20 changed files with 741 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ src/
fuzzing.log*
.installed.cfg
statistics
.coverage
.pytest_cache
develop-eggs
11 changes: 11 additions & 0 deletions .idea/fuzzing.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/libraries/Buildout_Eggs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: python
python:
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "pypy3"
install:
- "pip install -r requirements.txt"
Expand All @@ -14,4 +14,4 @@ after_success:
- true

# TODO:
# [ ] deploy package
# [ ] deploy package
45 changes: 45 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

# prepare folder for build reports
mkdir reports

# setup virtual environment ...
python3 -m venv venv

# ... and activate it
echo "activate virtual environment ..."
source venv/bin/activate

# install required packages
pip install -r requirements.txt

# run sanity checks
flake8 --output-file reports/flake8.txt --benchmark --count --statistics fuzzing gp_decorators run_fuzzer.py

pylint --rcfile=resrc/pylintrc fuzzing gp_decorators | tee reports/pylint.txt

# run test and measure coverage
nosetests --with-coverage --cover-branches --cover-inclusive --with-xunit --xunit-file=reports/nosetests.xml --cover-html --cover-html-dir=reports/coverage --cover-xml --cover-xml-file=reports/coverage.xml tests/

# run behave tests
behave | tee reports/behave.txt

# build source distribution tarball
python setup.py sdist

# install package ...
python setup.py install

# ... and generate documentation
pushd docs
make html
popd

# package documentation
echo "package documentation ..."
pushd docs/build
zip -r ../../dist/fuzzing-docs.zip html
popd

rm -rf fuzzing.egg-info
rm dist/*.egg
9 changes: 5 additions & 4 deletions features/resources/testfuzz.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ def main():
description = "Simple app to test our fuzzer."
parser = argparse.ArgumentParser(description=description)
parser.add_argument('in_path', help='The name of a file to read.')
parser.add_argument('-c', '--crash', help='Crash the app!', action="store_true")
parser.add_argument('-c', '--crash', help='Crash the app!',
action="store_true")
parser.add_argument('-p', '--probability',
help='Crash the app with given probability (0.0-1.0)',
type=float,
default=0.0)
args = parser.parse_args()
if args.crash:
return 1/0
return 1 / 0
if random() < args.probability:
return 2/0
return 2 / 0
time.sleep(3)
return 0


if __name__ == '__main__':
sys.exit(main())

38 changes: 21 additions & 17 deletions features/steps/ft_fuzzer.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# coding=utf-8
"""Test steps for feature 'fuzzer'."""

from behave import *
from behave import given, when, then

from fuzzing.fuzzer import fuzzer, fuzz_string, FuzzExecutor, Status


@given("a byte array of len 10")
def step_impl(context):
def step_impl01(context):
"""Prepare a byte array.
:param context: test context.
Expand All @@ -16,7 +16,7 @@ def step_impl(context):


@when("feeding it into the fuzzer, setting the fuzz_factor to 10")
def step_impl(context):
def step_impl02(context):
"""Execute fuzzer.
:param context: test context.
Expand All @@ -25,7 +25,7 @@ def step_impl(context):


@then("it will return a buffer with up to two modified bytes.")
def step_impl(context):
def step_impl03(context):
"""Check assertions.
:param context: test context.
Expand All @@ -37,7 +37,7 @@ def step_impl(context):


@when("feeding it into the fuzzer, setting the fuzz_factor to {fuzz_factor:d}")
def step_impl(context, fuzz_factor):
def step_impl04(context, fuzz_factor):
"""Execute fuzzer.
:param fuzz_factor: specified fuzz_factor.
Expand All @@ -60,7 +60,7 @@ def step_impl(context, max_modified):


@given("a string as seed.")
def step_impl(context):
def step_impl05(context):
"""Provide a string.
:param context: test context.
Expand All @@ -69,7 +69,7 @@ def step_impl(context):


@when("feeding the seed into the fuzzer, providing a count of {count:d}")
def step_impl(context, count):
def step_impl06(context, count):
"""Execute fuzzer.
:param count: number of string variants to generate.
Expand All @@ -80,7 +80,7 @@ def step_impl(context, count):


@then("it will return a list of {len_list:d} fuzzed variants of the seed.")
def step_impl(context, len_list):
def step_impl07(context, len_list):
"""Check assertions.
:param len_list: expected number of variants.
Expand All @@ -92,11 +92,12 @@ def step_impl(context, len_list):
count = number_of_modified_bytes(context.seed, fuzzed_string)
assert count >= 0


# ## file fuzzer


@given("a list of file paths")
def step_impl(context):
def step_impl08(context):
"""Create file list.
:param context: test context.
Expand All @@ -106,7 +107,7 @@ def step_impl(context):


@given("a list of applications")
def step_impl(context):
def step_impl09(context):
"""Create application list.
:param context: test context.
Expand All @@ -116,19 +117,21 @@ def step_impl(context):


@given("a FuzzExecutor instance created with those lists.")
def step_impl(context):
def step_impl10(context):
"""Create application list.
:param context: test context.
"""
assert context.app_list and len(context.app_list) > 0, "ENSURE: app list is provided."
assert context.file_list and len(context.file_list) > 0, "ENSURE: file list is provided."
assert context.app_list and len(
context.app_list) > 0, "ENSURE: app list is provided."
assert context.file_list and len(
context.file_list) > 0, "ENSURE: file list is provided."
context.fuzz_executor = FuzzExecutor(context.app_list, context.file_list)
assert context.fuzz_executor, "VERIFY: fuzz executor created."


@when("running a test {runs:d} times")
def step_impl(context, runs):
def step_impl11(context, runs):
"""Execute multiple runs.
:param runs: number of test runs to perform.
Expand All @@ -142,7 +145,7 @@ def step_impl(context, runs):


@then("{runs:d} results are recorded.")
def step_impl(context, runs):
def step_impl12(context, runs):
"""Check called apps / files.
:param runs: expected number of records.
Expand All @@ -155,7 +158,7 @@ def step_impl(context, runs):


@then("{runs:d} results are recorded and succeeded.")
def step_impl(context, runs):
def step_impl13(context, runs):
"""Check called apps / files.
:param runs: expected number of records.
Expand All @@ -170,7 +173,7 @@ def step_impl(context, runs):


@then("{runs:d} results are recorded and failed.")
def step_impl(context, runs):
def step_impl14(context, runs):
"""Check called apps / files.
:param runs: expected number of records.
Expand All @@ -183,6 +186,7 @@ def step_impl(context, runs):
failed_runs = stats.cumulated_counts_for_status(Status.FAILED)
assert failed_runs == runs


# ##### helpers


Expand Down

0 comments on commit 974a644

Please sign in to comment.