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

Get rid of coverage.py #32

Merged
merged 1 commit into from Feb 9, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Get rid of coverage.py

  • Loading branch information
jvoisin committed Feb 8, 2020
commit f9eb3d5143c967a6c2e0470afa1e5910caefa17b
@@ -98,8 +98,6 @@ PythonFuzz is a port of [fuzzitdev/jsfuzz](https://github.com/fuzzitdev/jsfuzz)
which is in turn heavily based on [go-fuzz](https://github.com/dvyukov/go-fuzz) originally developed by [Dmitry Vyukov's](https://twitter.com/dvyukov).
Which is in turn heavily based on [Michal Zalewski](https://twitter.com/lcamtuf) [AFL](http://lcamtuf.coredump.cx/afl/).

For coverage PythonFuzz is using [coverage](https://coverage.readthedocs.io/en/v4.5.x/) instrumentation and coverage library.

## Contributions

Contributions are welcome!:) There are still a lot of things to improve, and tests and features to add. We will slowly post those in the
@@ -5,11 +5,10 @@
import psutil
import hashlib
import logging
import coverage
import functools
import multiprocessing as mp

from pythonfuzz import corpus
from pythonfuzz import corpus, tracer

logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
logging.getLogger().setLevel(logging.DEBUG)
@@ -23,29 +22,6 @@
lru_cache = functools32.lru_cache


if coverage.version.version_info <= (5, ):
# Since we're using an old version of coverage.py,
# we're monkey patching it a bit to improve the performances.

# Using memoization here gives +50% in performances, since this
# function triggers a lot of syscalls.
# See the benchmarks here:
# - https://github.com/fuzzitdev/pythonfuzz/issues/9
@lru_cache(None)
def abs_file_cache(path):
"""Return the absolute normalized form of `path`."""
try:
path = os.path.realpath(path)
except UnicodeError:
pass
path = os.path.abspath(path)
path = coverage.files.actual_path(path)
path = coverage.files.unicode_filename(path)
return path

coverage.files.abs_file = abs_file_cache


def worker(target, child_conn, close_fd_mask):
# Silence the fuzzee's noise
class DummyFile:
@@ -59,8 +35,7 @@ def write(self, x):
if close_fd_mask & 2:
sys.stderr = DummyFile()

cov = coverage.Coverage(branch=True, cover_pylib=True)
cov.start()
sys.settrace(tracer.trace)
while True:
buf = child_conn.recv_bytes()
try:
@@ -71,11 +46,7 @@ def write(self, x):
child_conn.send(e)
break
else:
total_coverage = 0
cov_data = cov.get_data()
for filename in cov_data._arcs:
total_coverage += len(cov_data._arcs[filename])
child_conn.send(total_coverage)
child_conn.send(tracer.get_coverage())


class Fuzzer(object):
@@ -0,0 +1,36 @@
import collections
import sys

prev_line = 0
prev_filename = ''
data = collections.defaultdict(set)

def trace(frame, event, arg):
if event != 'line':
return trace

global prev_line
global prev_filename

func_filename = frame.f_code.co_filename
func_line_no = frame.f_lineno

if func_filename != prev_filename:
# We need a way to keep track of inter-files transferts,
# and since we don't really care about the details of the coverage,
# concatenating the two filenames in enough.
data[func_filename + prev_filename].add((prev_line, func_line_no))
else:
data[func_filename].add((prev_line, func_line_no))

prev_line = func_line_no
prev_filename = func_filename

return trace


def get_coverage():
ret = 0
for value in data.values():
ret += len(value)
return ret
@@ -1,4 +1,3 @@
coverage==4.5.4
This conversation was marked as resolved by jvoisin

This comment has been minimized.

Copy link
@gerph

gerph Jan 14, 2020

Contributor

Need to update setup.py too?

psutil==5.6.3
numpy==1.16.6; python_version < '3'
numpy==1.17.3; python_version >= '3'
@@ -14,7 +14,6 @@
url="https://github.com/fuzzitdev/pythonfuzz",
install_requires=[
# WARNING: Keep these values in line with those in requirements.txt
"coverage==4.5.4",
"psutil==5.6.3",
"numpy==1.16.6; python_version < '3'",
"numpy==1.17.3; python_version >= '3'",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.