Monkey: Support a -w argument to the monkey_driver.py

In order to better support valgrind and friends, add -w to
the monkey driver.  You can use it as:

monkey_driver.py ...normalargs... -w 'valgrind -v --track-origins=yes'

Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
This commit is contained in:
Daniel Silverstone 2019-06-15 20:01:08 +01:00
parent 8b6f590aaa
commit 5c0eee43e2
2 changed files with 25 additions and 8 deletions

View File

@ -121,8 +121,9 @@ def print_usage():
def parse_argv(argv): def parse_argv(argv):
path_monkey = '' path_monkey = ''
path_test = '' path_test = ''
wrapper = None
try: try:
opts, args = getopt.getopt(argv,"hm:t:",["monkey=","test="]) opts, args = getopt.getopt(argv,"hm:t:w:",["monkey=","test=","wrapper="])
except getopt.GetoptError: except getopt.GetoptError:
print_usage() print_usage()
sys.exit(2) sys.exit(2)
@ -134,6 +135,10 @@ def parse_argv(argv):
path_monkey = arg path_monkey = arg
elif opt in ("-t", "--test"): elif opt in ("-t", "--test"):
path_test = arg path_test = arg
elif opt in ("-w", "--wrapper"):
if wrapper is None:
wrapper = []
wrapper.extend(arg.split())
if path_monkey == '': if path_monkey == '':
print_usage() print_usage()
@ -142,7 +147,7 @@ def parse_argv(argv):
print_usage() print_usage()
sys.exit() sys.exit()
return path_monkey, path_test return path_monkey, path_test, wrapper
def load_test_plan(path): def load_test_plan(path):
plan = [] plan = []
@ -200,7 +205,7 @@ def run_test_step_action_launch(ctx, step):
print(get_indent(ctx) + "Action: " + step["action"]) print(get_indent(ctx) + "Action: " + step["action"])
assert(ctx.get('browser') is None) assert(ctx.get('browser') is None)
assert(ctx.get('windows') is None) assert(ctx.get('windows') is None)
ctx['browser'] = DriverBrowser(monkey_cmd=[ctx["monkey"]], quiet=True) ctx['browser'] = DriverBrowser(monkey_cmd=[ctx["monkey"]], quiet=True, wrapper=ctx["wrapper"])
assert_browser(ctx) assert_browser(ctx)
ctx['windows'] = dict() ctx['windows'] = dict()
for arg in step.get('args', []): for arg in step.get('args', []):
@ -513,9 +518,10 @@ def run_preloaded_test(path_monkey, plan):
def main(argv): def main(argv):
ctx = {} ctx = {}
path_monkey, path_test = parse_argv(argv) path_monkey, path_test, wrapper = parse_argv(argv)
plan = load_test_plan(path_test) plan = load_test_plan(path_test)
ctx["monkey"] = path_monkey ctx["monkey"] = path_monkey
ctx["wrapper"] = wrapper
run_test_plan(ctx, plan) run_test_plan(ctx, plan)
# Some python weirdness to get to main(). # Some python weirdness to get to main().

View File

@ -31,11 +31,16 @@ import subprocess
import time import time
class MonkeyFarmer(asyncore.dispatcher): class MonkeyFarmer(asyncore.dispatcher):
def __init__(self, monkey_cmd, online, quiet=False): def __init__(self, monkey_cmd, online, quiet=False, *, wrapper=None):
(mine, monkeys) = socket.socketpair() (mine, monkeys) = socket.socketpair()
asyncore.dispatcher.__init__(self, sock=mine) asyncore.dispatcher.__init__(self, sock=mine)
if wrapper is not None:
new_cmd = list(wrapper)
new_cmd.extend(monkey_cmd)
monkey_cmd = new_cmd
self.monkey = subprocess.Popen( self.monkey = subprocess.Popen(
monkey_cmd, monkey_cmd,
stdin=monkeys, stdin=monkeys,
@ -52,6 +57,7 @@ class MonkeyFarmer(asyncore.dispatcher):
self.online = online self.online = online
self.quiet = quiet self.quiet = quiet
self.discussion = [] self.discussion = []
self.maybe_slower = wrapper is not None
def handle_connect(self): def handle_connect(self):
pass pass
@ -132,8 +138,8 @@ class MonkeyFarmer(asyncore.dispatcher):
break break
class Browser: class Browser:
def __init__(self, monkey_cmd=["./nsmonkey"], quiet=False): def __init__(self, monkey_cmd=["./nsmonkey"], quiet=False, *, wrapper=None):
self.farmer = MonkeyFarmer(monkey_cmd=monkey_cmd, online=self.on_monkey_line, quiet=quiet) self.farmer = MonkeyFarmer(monkey_cmd=monkey_cmd, online=self.on_monkey_line, quiet=quiet, wrapper=wrapper)
self.windows = {} self.windows = {}
self.logins = {} self.logins = {}
self.sslcerts = {} self.sslcerts = {}
@ -142,9 +148,14 @@ class Browser:
self.stopped = False self.stopped = False
self.launchurl = None self.launchurl = None
now = time.time() now = time.time()
timeout = now + 1
if wrapper is not None:
timeout = now + 10
while not self.started: while not self.started:
self.farmer.loop(once=True) self.farmer.loop(once=True)
if (time.time() - now) > 1: if time.time() > timeout:
break break
def pass_options(self, *opts): def pass_options(self, *opts):