diff --git a/src/test/fuzz/peerconnection/corpus/template.html b/src/test/fuzz/peerconnection/corpus/template.html
index a93e27d7f4..5cb8e2dfe8 100644
--- a/src/test/fuzz/peerconnection/corpus/template.html
+++ b/src/test/fuzz/peerconnection/corpus/template.html
@@ -11,8 +11,8 @@
WebRTC PeerConnection Fuzz Test Template
-
-
+INCLUDE_RANDOM_JS
+INCLUDE_FUZZ_SDP_JS
diff --git a/src/test/fuzz/peerconnection/fuzz_main_run.py b/src/test/fuzz/peerconnection/fuzz_main_run.py
index 90db4a08b8..86b3e6238a 100755
--- a/src/test/fuzz/peerconnection/fuzz_main_run.py
+++ b/src/test/fuzz/peerconnection/fuzz_main_run.py
@@ -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 = (' \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()
\ No newline at end of file
diff --git a/src/test/fuzz/peerconnection/peerconnection_fuzz.py b/src/test/fuzz/peerconnection/peerconnection_fuzz.py
index 7bc3947903..a638f821a1 100644
--- a/src/test/fuzz/peerconnection/peerconnection_fuzz.py
+++ b/src/test/fuzz/peerconnection/peerconnection_fuzz.py
@@ -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
\ No newline at end of file