From 5c9e7fdc7ebe82ed699927fc47f999beaef5bcf6 Mon Sep 17 00:00:00 2001 From: Edouard Tisserant Date: Thu, 10 Nov 2016 18:15:28 +0100 Subject: [PATCH] Multiprocess test : Added option to attach debugger before a particular action in tests --- test/mp_sync_test.py | 4 ++-- test/multipEp.py | 40 +++++++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/test/mp_sync_test.py b/test/mp_sync_test.py index 853ac3c..9f6e902 100644 --- a/test/mp_sync_test.py +++ b/test/mp_sync_test.py @@ -107,7 +107,7 @@ def keygen_in_a_group_of_3_members(pre_actions=[]): ("GroupA1", [decrypt_message, [enc_msg]], expect(PEP_rating_reliable)), ] : yield action -def group_suvives_restart(): +def group_survives_restart(): yield from keygen_in_a_group_of_3_members([ (restart_instance, ["GroupA1"]), (restart_instance, ["GroupA2"]), @@ -134,6 +134,6 @@ if __name__ == "__main__": run_scenario(group_on_cannotdecrypt) run_scenario(group_of_3_members) run_scenario(keygen_in_a_group_of_3_members) - run_scenario(group_suvives_restart) + run_scenario(group_survives_restart) run_scenario(nokey_in_a_group_of_3_members) diff --git a/test/multipEp.py b/test/multipEp.py index b8f2e7b..72264a6 100644 --- a/test/multipEp.py +++ b/test/multipEp.py @@ -121,6 +121,7 @@ def printmsg(msg): def execute_order(order, handler): global handshakes_pending, handshakes_to_accept, handshakes_seen global handshakes_validated, msgs_folders, own_addresses + func, args, kwargs, timeoff = order[0:] + [None, [], {}, 0][len(order):] printheader("DECRYPT messages") @@ -239,6 +240,19 @@ def pEp_instance_main(iname, tmpdirname, *args): pEp_instance_run(iname, *args) print(iname + " exiting") +def start_debug(iname, proc): + print("#"*80 + "\n" + + "INSTANCE " + iname + "\n" + + "launching debugger attaching to process " + + str(proc.pid) + "\n" + + "#"*80 + "\n") + # TODO : linux terminal support + #import subprocess + #subprocess.call(['xterm', '-e', 'lldb', '-p', str(proc.pid)]) + import appscript + appscript.app('Terminal').do_script('lldb -p ' + str(proc.pid)) + time.sleep(2) + def start_instance(iname, tmpdir=None, instance_addresses = []): global handshakes_seen, handshakes_validated, msgs_folders @@ -266,19 +280,9 @@ def start_instance(iname, tmpdir=None, instance_addresses = []): if yes in ["y", "Y", "yes" "YES"]: debug = True if debug : - print("#"*80 + "\n" + - "INSTANCE " + iname + "\n" + - "launching debugger attaching to process " + - str(proc.pid) + "\n" + - "#"*80 + "\n") - # TODO : linux terminal support - #import subprocess - #subprocess.call(['xterm', '-e', 'lldb', '-p', str(proc.pid)]) - import appscript - appscript.app('Terminal').do_script('lldb -p ' + str(proc.pid)) - time.sleep(2) + start_debug(iname, proc) - return (proc, conn, tmpdir) + return (proc, conn, tmpdir, 0) def get_instance(iname): global instances @@ -290,7 +294,7 @@ def get_instance(iname): return instances[iname] def stop_instance(iname): - proc, conn, tmpdir = instances.pop(iname) + proc, conn, tmpdir, execnt = instances.pop(iname) # tell process to terminate conn.send(None) instance_addresses = conn.recv() @@ -308,7 +312,13 @@ def restart_instance(iname): def run_instance_action(action): iname, order = action - proc, conn, tmpdir = get_instance(iname) + proc, conn, tmpdir, execnt = get_instance(iname) + execnt = execnt + 1 + instances[iname] = (proc, conn, tmpdir, execnt) + debug_here_arg = "debug_"+iname+"_"+str(execnt) + print(iname, ": execution number :", execnt , "(add", debug_here_arg, "to args to debug from here)") + if debug_here_arg in sys.argv : + start_debug(iname, proc) conn.send(order) return conn.recv() @@ -346,7 +356,7 @@ def run_scenario(scenario): except StopIteration: pass if "wait_for_cleanup" in sys.argv: - for iname,(proc, conn, tmpdir) in instances.items(): + for iname,(proc, conn, tmpdir, execnt) in instances.items(): print("Instance " + iname + " waits into " + tmpdir.name) input("#"*80 + "\n" + "Press ENTER to cleanup\n" +