1r""" 2This is a script that can be used to run tests that require multiple 3executables to be run e.g. those client-server tests. 4 5Usage: 6 python vtkTestDriver.py --process exe1 arg11 arg12 ... 7 --process exe2 arg21 arg22 ... 8 --process ... 9""" 10 11from __future__ import print_function 12 13import sys 14import subprocess 15import time 16 17# Extract arguments for each process to execute. 18command_lists = [] 19prev = None 20for idx in range(1, len(sys.argv)): 21 if sys.argv[idx] == "--process": 22 if prev: 23 command_lists.append(sys.argv[prev:idx]) 24 prev = idx+1 25if prev <= len(sys.argv): 26 command_lists.append(sys.argv[prev:]) 27 28procs = [] 29for cmdlist in command_lists: 30 print("Executing '", " ".join(cmdlist), "'", file=sys.stderr) 31 proc = subprocess.Popen(cmdlist) 32 procs.append(proc) 33 # sleep to ensure that the process starts. 34 time.sleep(0.1) 35 36# Now wait for each of the processes to terminate. 37# If ctest times out, it will kill this process and all subprocesses will be 38# terminated anyways, so we don't need to handle timeout specially. 39for proc in procs: 40 proc.wait() 41 42for proc in procs: 43 if proc.returncode != 0: 44 print("ERROR: A process exited with error. Test will fail.", file=sys.stderr) 45 sys.exit(1) # error 46print("All's well!") 47