mirror of
https://github.com/ceph/s3-tests.git
synced 2024-11-24 19:30:38 +00:00
S3 Fuzzer: Added binary mode to random data generator
This commit is contained in:
parent
195571b555
commit
4737652fc1
2 changed files with 17 additions and 3 deletions
|
@ -101,7 +101,13 @@ def test_SpecialVariables_dict():
|
|||
tester = SpecialVariables(testdict, prng)
|
||||
|
||||
eq(tester['foo'], 'bar')
|
||||
eq(tester['random 10-15 printable'], '[/pNI$;92@') #FIXME: how should I test pseudorandom content?
|
||||
eq(tester['random 10-15 printable'], '[/pNI$;92@')
|
||||
|
||||
def test_SpecialVariables_binary():
|
||||
prng = random.Random(1)
|
||||
tester = SpecialVariables({}, prng)
|
||||
|
||||
eq(tester['random 10-15 binary'], '\xdfj\xf1\xd80>a\xcd\xc4\xbb')
|
||||
|
||||
def test_assemble_decision():
|
||||
graph = build_graph()
|
||||
|
@ -154,7 +160,7 @@ def test_expand_decision():
|
|||
eq(request['key1'], 'value1')
|
||||
eq(request['indirect_key1'], 'value1')
|
||||
eq(request['path'], '/my-readable-bucket')
|
||||
eq(request['randkey'], 'value-NI$;92@H/0I') #FIXME: again, how to handle the pseudorandom content?
|
||||
eq(request['randkey'], 'value-NI$;92@H/0I')
|
||||
assert_raises(KeyError, lambda x: decision[x], 'key3')
|
||||
|
||||
def test_weighted_choices():
|
||||
|
|
|
@ -7,6 +7,7 @@ import traceback
|
|||
import itertools
|
||||
import random
|
||||
import string
|
||||
import struct
|
||||
import yaml
|
||||
import sys
|
||||
|
||||
|
@ -82,6 +83,7 @@ def expand_key(decision, key):
|
|||
|
||||
class SpecialVariables(dict):
|
||||
charsets = {
|
||||
'binary': 'binary',
|
||||
'printable': string.printable,
|
||||
'punctuation': string.punctuation,
|
||||
'whitespace': string.whitespace
|
||||
|
@ -116,7 +118,13 @@ class SpecialVariables(dict):
|
|||
charset = self.charsets['printable']
|
||||
|
||||
length = self.prng.randint(size_min, size_max)
|
||||
return ''.join([self.prng.choice(charset) for _ in xrange(length)]) # Won't scale nicely
|
||||
if charset is 'binary':
|
||||
num_bytes = length + 8
|
||||
tmplist = [self.prng.getrandbits(64) for _ in xrange(num_bytes / 8)]
|
||||
tmpstring = struct.pack((num_bytes / 8) * 'Q', *tmplist)
|
||||
return tmpstring[0:length]
|
||||
else:
|
||||
return ''.join([self.prng.choice(charset) for _ in xrange(length)]) # Won't scale nicely; won't do binary
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue