How to use IOC method in fMBT

Best Python code snippet using fMBT_python

ioc_control.py

Source:ioc_control.py Github

copy

Full Screen

1# This file is part of the ISIS IBEX application.2# Copyright (C) 2012-2016 Science & Technology Facilities Council.3# All rights reserved.4#5# This program is distributed in the hope that it will be useful.6# This program and the accompanying materials are made available under the7# terms of the Eclipse Public License v1.0 which accompanies this distribution.8# EXCEPT AS EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM9# AND ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES10# OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more details.11#12# You should have received a copy of the Eclipse Public License v1.013# along with this program; if not, you can obtain a copy from14# https://www.eclipse.org/org/documents/epl-v10.php or15# http://opensource.org/licenses/eclipse-1.0.php16from time import sleep, time17from typing import List18from BlockServer.epics.procserv_utils import ProcServWrapper19from BlockServer.alarm.load_alarm_config import AlarmConfigLoader20from server_common.utilities import print_and_log21from server_common.constants import IOCS_NOT_TO_STOP22class IocControl:23 """A class for starting, stopping and restarting IOCs"""24 def __init__(self, prefix):25 """Constructor.26 Args:27 prefix (string): The PV prefix for the instrument28 """29 self._proc = ProcServWrapper(prefix)30 def start_ioc(self, ioc: str, restart_alarm_server: bool = True):31 """Start an IOC.32 Args:33 ioc (string): The name of the IOC34 restart_alarm_server (bool): whether to also restart the alarm server35 """36 try:37 self._proc.start_ioc(ioc)38 if ioc != "ALARM" and restart_alarm_server:39 AlarmConfigLoader.restart_alarm_server(self)40 except Exception as err:41 print_and_log(f"Could not start IOC {ioc}: {err}", "MAJOR")42 def restart_ioc(self, ioc: str, force: bool = False, restart_alarm_server: bool = True):43 """Restart an IOC.44 Note: restarting an IOC automatically sets the IOC to auto-restart, so it is neccessary to reapply the45 previous auto-restart setting46 Args:47 ioc (string): The name of the IOC48 force (bool): Force it to restart even if it is an IOC not to stop49 restart_alarm_server (bool): whether to also restart the alarm server50 """51 # Check it is okay to stop it52 if not force and ioc.startswith(IOCS_NOT_TO_STOP):53 return54 try:55 self._proc.restart_ioc(ioc)56 if ioc != "ALARM" and restart_alarm_server:57 AlarmConfigLoader.restart_alarm_server(self)58 except Exception as err:59 print_and_log(f"Could not restart IOC {ioc}: {err}", "MAJOR")60 def stop_ioc(self, ioc: str, force: bool = False):61 """Stop an IOC.62 Args:63 ioc (string): The name of the IOC64 force (bool): Force it to stop even if it is an IOC not to stop65 """66 # Check it is okay to stop it67 if not force and ioc.startswith(IOCS_NOT_TO_STOP):68 return69 try:70 self._proc.stop_ioc(ioc)71 if ioc != "ALARM":72 AlarmConfigLoader.restart_alarm_server(self)73 except Exception as err:74 print_and_log(f"Could not stop IOC {ioc}: {err}", "MAJOR")75 def get_ioc_status(self, ioc: str):76 """Get the running status of an IOC.77 Args:78 ioc (string): The name of the IOC79 Returns:80 string : The status of the IOC (RUNNING or SHUTDOWN)81 """82 return self._proc.get_ioc_status(ioc)83 def ioc_restart_pending(self, ioc: str):84 """Tests if the IOC has a pending restart85 Args:86 ioc (string): The name of the IOC87 Returns:88 bool : Whether a restart is pending89 """90 return self._proc.ioc_restart_pending(ioc)91 def start_iocs(self, iocs: List[str]):92 """ Start a number of IOCs.93 Args:94 iocs (list): The IOCs to start95 """96 for ioc in iocs:97 self.start_ioc(ioc)98 def restart_iocs(self, iocs: List[str], reapply_auto: bool = False):99 """ Restart a number of IOCs.100 Args:101 iocs (list): The IOCs to restart102 reapply_auto (bool): Whether to reapply auto restart settings automatically103 """104 auto = dict()105 for ioc in iocs:106 auto[ioc] = self.get_autorestart(ioc)107 self.restart_ioc(ioc)108 # Reapply auto-restart settings109 if reapply_auto:110 for ioc in iocs:111 self.waitfor_running(ioc)112 self.set_autorestart(ioc, auto[ioc])113 def stop_iocs(self, iocs: List[str]):114 """ Stop a number of IOCs.115 Args:116 iocs (list): The IOCs to stop117 """118 for ioc in iocs:119 self.stop_ioc(ioc)120 def ioc_exists(self, ioc: str) -> bool:121 """Checks an IOC exists.122 Args:123 ioc (string): The name of the IOC124 Returns:125 bool : Whether the IOC exists126 """127 try:128 self.get_ioc_status(ioc)129 return True130 except:131 return False132 def set_autorestart(self, ioc: str, enable: bool):133 """Used to set the auto-restart property.134 Args:135 ioc (string): The name of the IOC136 enable (bool): Whether to enable auto-restart137 """138 try:139 if self.get_ioc_status(ioc) == "RUNNING":140 # Get current auto-restart status141 curr = self._proc.get_autorestart(ioc)142 if curr != enable:143 # If different to requested then change it144 self._proc.toggle_autorestart(ioc)145 return146 print_and_log(f"Auto-restart for IOC {ioc} unchanged as value has not changed")147 else:148 print_and_log(f"Auto-restart for IOC {ioc} unchanged as IOC is not running")149 except Exception as err:150 print_and_log(f"Could not set auto-restart IOC {ioc}: {err}", "MAJOR")151 def get_autorestart(self, ioc: str) -> bool:152 """Gets the current auto-restart setting of the specified IOC.153 Args:154 ioc (string): The name of the IOC155 Returns:156 bool : Whether auto-restart is enabled157 """158 try:159 return self._proc.get_autorestart(ioc)160 except Exception as err:161 print_and_log(f"Could not get auto-restart setting for IOC {ioc}: {err}", "MAJOR")162 def waitfor_running(self, ioc: str, timeout: int = 5):163 """Waits for the IOC to start running.164 Args:165 ioc (string): The name of the IOC166 timeout(int, optional): Maximum time to wait before returning167 """168 if self.ioc_exists(ioc):169 start = time()170 while self.ioc_restart_pending(ioc) or self.get_ioc_status(ioc) != "RUNNING":171 sleep(0.5)172 if time() - start >= timeout:173 print_and_log(f"Gave up waiting for IOC {ioc} to be running", "MAJOR")...

Full Screen

Full Screen

ioctl.py

Source:ioctl.py Github

copy

Full Screen

...71# direction bits72_IOC_NONE = 073_IOC_WRITE = 174_IOC_READ = 275def _IOC(dir, type, nr, FMT):76 return int((((dir) << _IOC_DIRSHIFT) | \77 ((type) << _IOC_TYPESHIFT) | \78 ((nr) << _IOC_NRSHIFT) | \79 ((FMT) << _IOC_SIZESHIFT)) & 0xffffffff)80# used to create numbers81# type is the assigned type from the kernel developers82# nr is the base ioctl number (defined by driver writer)83# FMT is a struct module format string.84def _IO(type, nr): return _IOC(_IOC_NONE, (type), (nr), 0)85def _IOR(type, nr, FMT): return _IOC(_IOC_READ, (type), (nr), sizeof(FMT))86def _IOW(type, nr, FMT): return _IOC(_IOC_WRITE, (type), (nr), sizeof(FMT))87def _IOWR(type, nr, FMT): return _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), sizeof(FMT))88# used to decode ioctl numbers89def _IOC_DIR(nr): return (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)90def _IOC_TYPE(nr): return (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)91def _IOC_NR(nr): return (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)...

Full Screen

Full Screen

asm_generic_ioctl.py

Source:asm_generic_ioctl.py Github

copy

Full Screen

...33# Direction bits34_IOC_NONE = 035_IOC_WRITE = 136_IOC_READ = 237def _IOC(dir, type, nr, size):38 return (dir << _IOC_DIRSHIFT) | \39 (type << _IOC_TYPESHIFT) | \40 (nr << _IOC_NRSHIFT) | \41 (size << _IOC_SIZESHIFT)42def _IOC_TYPECHECK(t):43 return ctypes.sizeof(t)44# used to create ioctl numbers45def _IO(type, nr):46 return _IOC(_IOC_NONE, type, nr, 0)47def _IOR(type, nr, size):48 return _IOC(_IOC_READ, type, nr, _IOC_TYPECHECK(size))49def _IOW(type, nr, size):50 return _IOC(_IOC_WRITE, type, nr, _IOC_TYPECHECK(size))51def _IOWR(type,nr,size):52 return _IOC(_IOC_READ|_IOC_WRITE, type, nr, _IOC_TYPECHECK(size))53def _IOR_BAD(type,nr,size):54 return _IOC(_IOC_READ, type, nr, sizeof(size))55def _IOW_BAD(type,nr,size):56 return _IOC(_IOC_WRITE,type,nr, sizeof(size))57def _IOWR_BAD(type,nr,size):58 return _IOC(_IOC_READ|_IOC_WRITE, type, nr, sizeof(size))59# ...and for the drivers/sound files...60IOC_IN = _IOC_WRITE << _IOC_DIRSHIFT61IOC_OUT = _IOC_READ << _IOC_DIRSHIFT62IOC_INOUT = (_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT63IOCSIZE_MASK = _IOC_SIZEMASK << _IOC_SIZESHIFT...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful