Separated IOC startup from running tests

This commit is contained in:
2025-07-23 08:48:51 +02:00
parent e2e025cbbc
commit 4afa6a35e2
5 changed files with 25 additions and 38 deletions

View File

@@ -10,7 +10,7 @@ require masterMacs, $(MASTERMACS_VERSION)
# Motors
# Initialize the motors itself
< motors/turboPmac1.cmd
#< motors/turboPmac1.cmd
#< motors/masterMacs1.cmd
# Create the test record which is used to detect if the IOC is running

View File

@@ -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

View File

@@ -7,6 +7,8 @@
import yaml
import os
import subprocess
import sys
from pathlib import Path
def startioc():
@@ -38,14 +40,27 @@ def startioc():
out.write(
f'epicsEnvSet("MASTERMACS1_PORT", "{config["controllers"]["masterMacs1"]["port"]}")\n')
# Start the IOC itself and keep it running in the background.
# We need to start a new session so Pytest doesn't kill the process
proc = subprocess.Popen([root_dir + 'ioc/startioc'], start_new_session=True)
# Set environment variables
os.environ["EPICS_BASE"] = "/usr/local/epics/base-7.0.7"
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__':
startioc()

0
maketestenv Normal file → Executable file
View File

View File

@@ -1,24 +1,21 @@
import time
from caproto.sync.client import read, write
from ioc.pystartioc import startioc
import pytest
from common import read_config
TIMEOUT_IOC_STARTUP = 10
TIMEOUT_READ = 2
@pytest.fixture(autouse=True)
def prepare_ioc():
def check_ioc_running():
config = read_config()
pvprefix = config['pvprefix']
"""
This function checks if the test IOC is already running and attempts to
start it, if that is not the case.
This function checks if the test IOC is already running.
"""
try:
read(f'{pvprefix}:IOCREADY', timeout=TIMEOUT_READ)
@@ -27,18 +24,5 @@ def prepare_ioc():
# is running
return
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
raise TimeoutError(
f'Starting the IOC within {TIMEOUT_IOC_STARTUP} seconds failed.')
raise Exception('Start the test IOC first ()')