import subprocess import sys import signal from time import sleep from caproto_wrapper import CaprotoWrapper def is_ioc_running(): return "" != CaprotoWrapper.raw_read("ePowerSwitch_set_outlet_1") def start_iocshell(): attempt = 0; res = subprocess.Popen(["./startioc.sh"]) while not is_ioc_running() and attempt < 10: sleep(1) attempt += 1 pass if attempt == 10: print("IOCSHELL didn't start on time"); sys.exit(-1) return res def start_sim(): return subprocess.Popen(["python", "./sim/ePowerSwitch8_sim.py"]) def start_pytest(): return subprocess.Popen(["pytest","test"]) sim_process = start_sim() iocsh_process = start_iocshell() pytest_process = start_pytest() exit_code = 0 try: exit_code = pytest_process.wait() finally: sim_process.send_signal(sig=signal.SIGTERM) iocsh_process.send_signal(sig=signal.SIGTERM) pytest_process.send_signal(sig=signal.SIGTERM) sys.exit(exit_code)