Exemple #1
0
import sys, socket, random, time, os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, 'common')))
import memcached_workload_common
from vcoptparse import *

# A hacky function that reads a response from a socket of an expected size.
def read_response_of_expected_size(s, n):
    data = ""
    while (len(data) < n):
        data += s.recv(n - len(data))
        # Stop if we get a shorter than expected response.
        if (data.count("\r\n") >= 3):
            return data
    return data

op = memcached_workload_common.option_parser_for_socket()
op["n_appends"] = IntFlag("--num-appends", 20000)
opts = op.parse(sys.argv)

with memcached_workload_common.make_socket_connection(opts) as s:

    def send(x):
        # print str
        s.sendall(x)

    key = 'fizz'
    val_chunks = ['buzzBUZZZ', 'baazBAAZ', 'bozoBOZO']

    send("set %s 0 0 %d noreply\r\n%s\r\n" % (key, len(val_chunks[0]), val_chunks[0]))

    # All commands have noreply except the last.
Exemple #2
0
        '5', '6', '7', '8', '9', '0', '!', '@', '#', '$', '%', '^', '&', '*',
        '(', ')', '_', '+', ',', '.', '/', ';', '[', ']', '<', '>', ':', '{',
        '}', '?', '\r\n', '\r', '\n', '\t', ' '
    ]
    len = random.randint(1, 1000)
    res = ''
    for i in range(len):
        res += random.choice(chars)
    return res


def funny():
    return "Yo dawg"


op = memcached_workload_common.option_parser_for_socket()
op["duration"] = IntFlag("--duration", 1000)
opts = op.parse(sys.argv)

with memcached_workload_common.make_socket_connection(opts) as s:
    sent_log = open('fuzz_sent', 'w')
    recv_log = open('fuzz_recv', 'w')

    start_time = time.time()

    time.sleep(2)

    while (time.time() - start_time < opts["duration"]):
        time.sleep(.05)
        string = ''
        for i in range(20):