Separated IOC startup from running tests
This commit is contained in:
@@ -10,7 +10,7 @@ require masterMacs, $(MASTERMACS_VERSION)
|
|||||||
# Motors
|
# Motors
|
||||||
|
|
||||||
# Initialize the motors itself
|
# Initialize the motors itself
|
||||||
< motors/turboPmac1.cmd
|
#< motors/turboPmac1.cmd
|
||||||
#< motors/masterMacs1.cmd
|
#< motors/masterMacs1.cmd
|
||||||
|
|
||||||
# Create the test record which is used to detect if the IOC is running
|
# Create the test record which is used to detect if the IOC is running
|
||||||
|
|||||||
12
ioc/startioc
12
ioc/startioc
@@ -1,12 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
export EPICS_BASE=/usr/local/epics/base-7.0.7
|
|
||||||
export EPICS_HOST_ARCH=RHEL8-x86_64
|
|
||||||
|
|
||||||
# Get the full directory path of the script
|
|
||||||
SCRIPT_DIR=$(dirname "$(realpath "$0")")
|
|
||||||
|
|
||||||
# Needed so st.cmd finds other .cmd files
|
|
||||||
cd "$SCRIPT_DIR" || exit 1
|
|
||||||
|
|
||||||
# Run the IOC shell script
|
|
||||||
st.cmd
|
|
||||||
@@ -7,6 +7,8 @@
|
|||||||
import yaml
|
import yaml
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
def startioc():
|
def startioc():
|
||||||
@@ -38,14 +40,27 @@ def startioc():
|
|||||||
out.write(
|
out.write(
|
||||||
f'epicsEnvSet("MASTERMACS1_PORT", "{config["controllers"]["masterMacs1"]["port"]}")\n')
|
f'epicsEnvSet("MASTERMACS1_PORT", "{config["controllers"]["masterMacs1"]["port"]}")\n')
|
||||||
|
|
||||||
# Start the IOC itself and keep it running in the background.
|
# Set environment variables
|
||||||
# We need to start a new session so Pytest doesn't kill the process
|
os.environ["EPICS_BASE"] = "/usr/local/epics/base-7.0.7"
|
||||||
proc = subprocess.Popen([root_dir + 'ioc/startioc'], start_new_session=True)
|
os.environ["EPICS_HOST_ARCH"] = "RHEL8-x86_64"
|
||||||
|
|
||||||
print(f"Started IOC with PID {proc.pid}")
|
# Get the full directory path of the script
|
||||||
|
script_dir = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
# Change working directory so st.cmd can find other .cmd files
|
||||||
|
os.chdir(script_dir)
|
||||||
|
|
||||||
|
print("Current working directory:", os.getcwd())
|
||||||
|
print("Script directory:", script_dir)
|
||||||
|
print("Files in directory:", os.listdir())
|
||||||
|
|
||||||
|
# Run the IOC shell script
|
||||||
|
try:
|
||||||
|
subprocess.run(["/usr/local/bin/iocsh", "st.cmd"], check=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Failed to start IOC: {e}", file=sys.stderr)
|
||||||
|
sys.exit(e.returncode)
|
||||||
|
|
||||||
# Yield control back to the test
|
|
||||||
# yield
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
startioc()
|
startioc()
|
||||||
0
maketestenv
Normal file → Executable file
0
maketestenv
Normal file → Executable file
@@ -1,24 +1,21 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from caproto.sync.client import read, write
|
from caproto.sync.client import read, write
|
||||||
from ioc.pystartioc import startioc
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from common import read_config
|
from common import read_config
|
||||||
|
|
||||||
TIMEOUT_IOC_STARTUP = 10
|
|
||||||
TIMEOUT_READ = 2
|
TIMEOUT_READ = 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def prepare_ioc():
|
def check_ioc_running():
|
||||||
|
|
||||||
config = read_config()
|
config = read_config()
|
||||||
pvprefix = config['pvprefix']
|
pvprefix = config['pvprefix']
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This function checks if the test IOC is already running and attempts to
|
This function checks if the test IOC is already running.
|
||||||
start it, if that is not the case.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
read(f'{pvprefix}:IOCREADY', timeout=TIMEOUT_READ)
|
read(f'{pvprefix}:IOCREADY', timeout=TIMEOUT_READ)
|
||||||
@@ -27,18 +24,5 @@ def prepare_ioc():
|
|||||||
# is running
|
# is running
|
||||||
return
|
return
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
# Received a timeout error -> Start the IOC
|
|
||||||
startioc()
|
|
||||||
|
|
||||||
# Check periodically if the IOC started successfully
|
|
||||||
now = time.time()
|
|
||||||
while now + TIMEOUT_IOC_STARTUP > time.time():
|
|
||||||
try:
|
|
||||||
read(f'{pvprefix}:IOCREADY', timeout=TIMEOUT_READ)
|
|
||||||
return
|
|
||||||
except TimeoutError:
|
|
||||||
time.sleep(0.5)
|
|
||||||
|
|
||||||
# IOC startup failed in the given time -> Raise an error
|
# IOC startup failed in the given time -> Raise an error
|
||||||
raise TimeoutError(
|
raise Exception('Start the test IOC first ()')
|
||||||
f'Starting the IOC within {TIMEOUT_IOC_STARTUP} seconds failed.')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user