-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #327 from fandango-fuzzer/andreas
Andreas
- Loading branch information
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<start> ::= <html> | ||
<html> ::= <text> | <element> | ||
<element> ::= <open_tag> <html> <close_tag> | <self_closing_tag> | ||
where <open_tag>.<tag_name> == <close_tag>.<tag_name> | ||
|
||
<open_tag> ::= r'\x3c' <tag_name> r'\x3e' | ||
<close_tag> ::= r'\x3c/' <tag_name> r'\x3e' | ||
<self_closing_tag> ::= r'\x3c' <tag_name> r'/\x3e' | ||
<tag_name> ::= 'html' | 'head' | 'body' | 'title' | 'p' | 'h1' | 'h2' | 'h3' | ||
<text> ::= r'[^\x3c\x3e]+' := 'Some beautiful text' | ||
|
||
|
||
import sys | ||
|
||
def coverage(fun, *args, **kwargs): | ||
covered_lines = set() | ||
|
||
def traceit(frame, event, arg): | ||
if event == 'line': | ||
filename = frame.f_code.co_filename | ||
lineno = frame.f_lineno | ||
covered_lines.add((filename, lineno)) | ||
return traceit | ||
|
||
sys.settrace(traceit) | ||
ret = fun(*args, **kwargs) | ||
sys.settrace(None) | ||
|
||
return len(covered_lines) | ||
|
||
def remove_html_markup(s): | ||
tag = False | ||
quote = False | ||
out = "" | ||
|
||
for c in s: | ||
if c == '<' and not quote: | ||
tag = True | ||
elif c == '>' and not quote: | ||
tag = False | ||
elif (c == '"' or c == "'") and tag: | ||
quote = not quote | ||
elif not tag: | ||
out = out + c | ||
|
||
return out | ||
|
||
where coverage(remove_html_markup, str(<start>)) >= 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
# Simple coverage measurement for Python | ||
|
||
import sys | ||
|
||
def coverage(fun, *args, **kwargs): | ||
covered_lines = set() | ||
|
||
def traceit(frame, event, arg): | ||
if event == 'line': | ||
filename = frame.f_code.co_filename | ||
lineno = frame.f_lineno | ||
covered_lines.add((filename, lineno)) | ||
return traceit | ||
|
||
sys.settrace(traceit) | ||
ret = fun(*args, **kwargs) | ||
sys.settrace(None) | ||
|
||
return ret, covered_lines | ||
|
||
if __name__ == '__main__': | ||
def remove_html_markup(s): | ||
tag = False | ||
quote = False | ||
out = "" | ||
|
||
for c in s: | ||
if c == '<' and not quote: | ||
tag = True | ||
elif c == '>' and not quote: | ||
tag = False | ||
elif (c == '"' or c == "'") and tag: | ||
quote = not quote | ||
elif not tag: | ||
out = out + c | ||
|
||
return out | ||
|
||
ret, covered_lines = coverage(remove_html_markup, "foo") | ||
print('Return value:', ret) | ||
print('Covered lines:', len(covered_lines)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<start> ::= <bit>{8} | ||
<bit> ::= 0 | 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters