Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
stbraun committed May 10, 2018
1 parent 3291ef8 commit 6416dea
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 48 deletions.
Empty file removed .projectile
Empty file.
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
22 changes: 13 additions & 9 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#usr/bin/env bash
#!/usr/bin/env bash

# prepare folder for build reports
mkdir reports
Expand All @@ -7,35 +7,39 @@ mkdir reports
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 run_fuzzer.py
flake8 --output-file reports/flake8.txt --benchmark --count --statistics fuzzing gp_decorators run_fuzzer.py

pylint --rcfile=resrc/pylintrc fuzzing > reports/pylint.txt
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 > reports/behave.txt
behave | tee reports/behave.txt

# build source distribution tarball
python setup.py sdist

# install package ...
python setup.py install

rm -rf fuzzing.egg-info
rm dist/*.egg

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

# package documentation
cd build
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())

35 changes: 22 additions & 13 deletions fuzzing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,39 @@
Copyright (c) 2015 Stefan Braun
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and
associated documentation files (the "Software"), to deal in the Software
without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to
whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
The above copyright notice and this permission notice shall be included in
all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""

import logging
from .log import LoggerFactory
from .fuzzer import fuzzer, fuzz_string, FuzzExecutor, TestStatCounter, Status


# Symbols available when importing with *.
__all__ = ['LoggerFactory', 'fuzzer', 'fuzz_string', 'FuzzExecutor', 'TestStatCounter', 'Status']

__all__ = ['LoggerFactory', 'fuzzer', 'fuzz_string', 'FuzzExecutor',
'TestStatCounter', 'Status']

# Configure NullHandler to prevent warning in case logging is not configured.
# See https://docs.python.org/2/howto/logging.html#library-config
Expand Down
4 changes: 3 additions & 1 deletion fuzzing/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ class LoggerFactory(object):
It is important to initialize the logging framework before
the first call to a logger.
"""
def __init__(self, package_name='fuzzing', config_file='resources/log_config.yaml'):

def __init__(self, package_name='fuzzing',
config_file='resources/log_config.yaml'):
self.package_name = package_name
self.config_file = config_file
self.config = None
Expand Down
3 changes: 1 addition & 2 deletions gp_decorators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
Licensed under MIT.
"""

from gp_decorators import singleton
import logging
from gp_decorators import singleton

# Symbols available when importing with *.
__all__ = ['singleton']

# Configure NullHandler to prevent warning in case logging is not configured.
# See https://docs.python.org/2/howto/logging.html#library-config
logging.getLogger('gp_decorators').addHandler(logging.NullHandler())

9 changes: 4 additions & 5 deletions gp_decorators/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import wrapt

_instances = {}
_INSTANCES = {}


@wrapt.decorator
Expand All @@ -15,7 +15,6 @@ def singleton(wrapped, _, args, kwargs):
:param args: optional arguments for wrapped object.
:param kwargs: optional arguments for wrapped object.
"""
global _instances
if wrapped not in _instances:
_instances[wrapped] = wrapped(*args, **kwargs)
return _instances[wrapped]
if wrapped not in _INSTANCES:
_INSTANCES[wrapped] = wrapped(*args, **kwargs)
return _INSTANCES[wrapped]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ setuptools
pylint
pytest
zc.buildout
flake8
34 changes: 22 additions & 12 deletions run_fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@
Copyright (c) 2015 Stefan Braun
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and
associated documentation files (the "Software"), to deal in the Software
without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to
whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
The above copyright notice and this permission notice shall be included in
all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
"""

import sys
Expand All @@ -27,7 +37,6 @@

from fuzzing import FuzzExecutor, TestStatCounter


APPLICATIONS = 'applications'
SEED_FILES = 'seed_files'
PROCESSORS = 'processors'
Expand Down Expand Up @@ -72,7 +81,8 @@ def validate_config(conf_dict):
:raise InvalidConfigurationError:
"""
# TASK improve validation
if APPLICATIONS not in conf_dict.keys() or SEED_FILES not in conf_dict.keys():
if APPLICATIONS not in conf_dict.keys() or SEED_FILES not in \
conf_dict.keys():
raise InvalidConfigurationError
if RUNS not in conf_dict.keys():
conf_dict[RUNS] = DEFAULT_RUNS
Expand Down

0 comments on commit 6416dea

Please sign in to comment.