forked from fuzzitdev/pythonfuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracer.py
More file actions
33 lines (24 loc) · 825 Bytes
/
Copy pathtracer.py
File metadata and controls
33 lines (24 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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():
return sum(map(len, data.values()))