Adapted fuzzer for launch.
BUG= Review URL: https://webrtc-codereview.appspot.com/813006 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2787 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
ef33fc431c
commit
daf32a4cb9
@ -11,8 +11,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>WebRTC PeerConnection Fuzz Test Template</title>
|
||||
<script type="text/javascript" src="random.js"></script>
|
||||
<script type="text/javascript" src="fuzz_sdp.js"></script>
|
||||
INCLUDE_RANDOM_JS
|
||||
INCLUDE_FUZZ_SDP_JS
|
||||
<script type="text/javascript">
|
||||
var gFirstConnection = null;
|
||||
var gSecondConnection = null;
|
||||
@ -20,7 +20,6 @@
|
||||
// Variables in caps are filled in by the fuzzer.
|
||||
var gTransformOfferSdp = TRANSFORM_OFFER_SDP;
|
||||
var gTransformAnswerSdp = TRANSFORM_ANSWER_SDP;
|
||||
var gRandomRolls = ARRAY_OF_RANDOM_ROLLS;
|
||||
|
||||
function startTest() {
|
||||
navigator.webkitGetUserMedia(REQUEST_AUDIO_AND_VIDEO,
|
||||
@ -99,6 +98,9 @@
|
||||
setRandomRolls(gRandomRolls);
|
||||
startTest();
|
||||
}
|
||||
|
||||
// This variable is placed here since its value is pretty big.
|
||||
var gRandomRolls = ARRAY_OF_RANDOM_ROLLS;
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@ -16,24 +16,50 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from common.fuzz_parameters import FillInParameter
|
||||
import peerconnection_fuzz
|
||||
|
||||
# TODO(phoglund): remove duplication wrt getusermedia once this code stabilizes.
|
||||
|
||||
|
||||
def ReadFile(input_dir, file):
|
||||
file_handle = open(os.path.join(input_dir, file))
|
||||
def _ReadFile(path):
|
||||
file_handle = open(path)
|
||||
file_data = file_handle.read()
|
||||
file_handle.close()
|
||||
return file_data
|
||||
|
||||
|
||||
def GenerateData(input_dir):
|
||||
template = ReadFile(input_dir, 'template.html')
|
||||
file_extension = 'html'
|
||||
def _Indent(file_data, num_spaces):
|
||||
spaces = ' ' * num_spaces
|
||||
return spaces + file_data.replace('\n', '\n' + spaces)
|
||||
|
||||
|
||||
def _IncludeJsFile(js_include_to_replace, js_path, file_data):
|
||||
js_file_data = _ReadFile(js_path)
|
||||
js_file_data = _Indent(js_file_data, 4)
|
||||
js_file_data = (' <script type="text/javascript">\n' +
|
||||
js_file_data + '\n </script>\n')
|
||||
return FillInParameter(js_include_to_replace, js_file_data, file_data)
|
||||
|
||||
|
||||
def GenerateData():
|
||||
this_scripts_path = os.path.dirname(os.path.realpath(__file__))
|
||||
corpus_path = os.path.join(this_scripts_path, 'corpus');
|
||||
|
||||
template = _ReadFile(os.path.join(corpus_path, 'template.html'))
|
||||
|
||||
file_extension = 'html'
|
||||
file_data = peerconnection_fuzz.Fuzz(template)
|
||||
|
||||
# Paste the javascript code in directly since it's hard to make javascript
|
||||
# includes work without data bundles.
|
||||
file_data = _IncludeJsFile('INCLUDE_RANDOM_JS',
|
||||
os.path.join(corpus_path, 'random.js'),
|
||||
file_data)
|
||||
file_data = _IncludeJsFile('INCLUDE_FUZZ_SDP_JS',
|
||||
os.path.join(corpus_path, 'fuzz_sdp.js'),
|
||||
file_data)
|
||||
|
||||
return file_data, file_extension
|
||||
|
||||
|
||||
@ -54,13 +80,13 @@ if __name__ == '__main__':
|
||||
assert input_dir is not None, 'Missing "--input_dir" argument'
|
||||
|
||||
for file_no in range(no_of_files):
|
||||
file_data, file_extension = GenerateData(input_dir)
|
||||
file_data, file_extension = GenerateData()
|
||||
file_data = file_data.encode('utf-8')
|
||||
file_descriptor, file_path = tempfile.mkstemp(
|
||||
prefix='fuzz-%d-%d' % (start_time, file_no),
|
||||
prefix='fuzz-http-%d-%d' % (start_time, file_no),
|
||||
suffix='.' + file_extension,
|
||||
dir=output_dir)
|
||||
file = os.fdopen(file_descriptor, 'wb')
|
||||
print 'Writing %d bytes to "%s"' % (len(file_data), file_path)
|
||||
print file_data
|
||||
file.write(file_data.encode('utf-8'))
|
||||
file.write(file_data)
|
||||
file.close()
|
||||
@ -15,11 +15,11 @@ from common.fuzz_parameters import FillInParameter
|
||||
from common.random_javascript import *
|
||||
|
||||
|
||||
def ArrayOfRandomRolls(num_rolls):
|
||||
def _ArrayOfRandomRolls(num_rolls):
|
||||
return str([random.random() for x in xrange(num_rolls)])
|
||||
|
||||
|
||||
def RandomAudioOrVideo():
|
||||
def _RandomAudioOrVideo():
|
||||
roll = random.random()
|
||||
if roll < 0.5:
|
||||
return '{ video: true, audio:true }'
|
||||
@ -31,29 +31,29 @@ def RandomAudioOrVideo():
|
||||
return '{ video: false, audio: true }'
|
||||
|
||||
|
||||
def ReturnFirstArgument():
|
||||
def _ReturnFirstArgument():
|
||||
return 'function(arg) { return arg; }'
|
||||
|
||||
|
||||
def ReturnRandomUtf8String():
|
||||
def _ReturnRandomUtf8String():
|
||||
unicode_glyphs = ''.join(unichr(char) for char in xrange(0x10ffff + 1)
|
||||
if unicodedata.category(unichr(char))[0] in ('LMNPSZ'))
|
||||
oh_dear = random.sample(unicode_glyphs, random.randint(50, 1500))
|
||||
return 'function(arg) { return "%s"; }' % ''.join(oh_dear)
|
||||
|
||||
|
||||
def ReturnFuzzedSdp():
|
||||
def _ReturnFuzzedSdp():
|
||||
return 'function(arg) { return fuzzSdp(arg); }'
|
||||
|
||||
|
||||
def RandomSdpTransform():
|
||||
def _RandomSdpTransform():
|
||||
roll = random.random()
|
||||
if roll < 0.1:
|
||||
return ReturnRandomUtf8String()
|
||||
return _ReturnRandomUtf8String()
|
||||
elif roll < 0.5:
|
||||
return ReturnFuzzedSdp()
|
||||
return _ReturnFuzzedSdp()
|
||||
else:
|
||||
return ReturnFirstArgument()
|
||||
return _ReturnFirstArgument()
|
||||
|
||||
|
||||
def Fuzz(file_data):
|
||||
@ -62,16 +62,16 @@ def Fuzz(file_data):
|
||||
# Generate a bunch of random numbers and encode them into the page. Since the
|
||||
# values get hard-coded into the page the page's choices will be reproducible.
|
||||
file_data = FillInParameter('ARRAY_OF_RANDOM_ROLLS',
|
||||
ArrayOfRandomRolls(500),
|
||||
_ArrayOfRandomRolls(500),
|
||||
file_data)
|
||||
file_data = FillInParameter('REQUEST_AUDIO_AND_VIDEO',
|
||||
RandomAudioOrVideo(),
|
||||
_RandomAudioOrVideo(),
|
||||
file_data)
|
||||
file_data = FillInParameter('TRANSFORM_OFFER_SDP',
|
||||
RandomSdpTransform(),
|
||||
_RandomSdpTransform(),
|
||||
file_data)
|
||||
file_data = FillInParameter('TRANSFORM_ANSWER_SDP',
|
||||
RandomSdpTransform(),
|
||||
_RandomSdpTransform(),
|
||||
file_data)
|
||||
|
||||
return file_data
|
||||
Loading…
x
Reference in New Issue
Block a user