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

View File

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