Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amint2 l convert #3

Open
wants to merge 60 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
22ba8ba
Rename plankton_emulators to lewis_emulators because framework name h…
Jan 6, 2017
9b4fefa
Allow connection to back dorr. Add AMINT2-L tests
John-Holt-Tessella May 16, 2017
b071dad
Add AMInt2-L emmulator and factor out command builder.
John-Holt-Tessella May 16, 2017
79f3b30
Add test for disconnect. Allow running in recsim mode.
John-Holt-Tessella May 17, 2017
23c47c6
if ignore is empty do not use it
John-Holt-Tessella May 17, 2017
a0f3442
Allow macros to be set for IOCs
John-Holt-Tessella May 17, 2017
bb2613b
Add AMInt2-L emmulator and factor out command builder.
John-Holt-Tessella May 16, 2017
a4dcbf5
if ignore is empty do not use it
John-Holt-Tessella May 17, 2017
9833dcd
Merge branch 'Ticket2270_int2_l' of https://github.com/ISISComputingG…
FreddieAkeroyd May 19, 2017
081105d
Merge pull request #16 from ISISComputingGroup/Ticket2270_int2_l
FreddieAkeroyd May 19, 2017
46693bf
Make initial timeout longer than usual to give the IOC time to start
Tom-Willemsen May 24, 2017
b770b13
Update __init__.py
Jun 1, 2017
3f9c5a8
Merge pull request #17 from ISISComputingGroup/Ticket2371_EOL_fixes
FreddieAkeroyd Jun 2, 2017
da34b1f
Fix the amlint2l so it passes after the alarm check change.
John-Holt-Tessella Jun 2, 2017
bd09a4f
Merge pull request #4 from ISISComputingGroup/Ticket2111_instron_stre…
AdrianPotter Jun 7, 2017
44348aa
Corrected docstrings
Jun 8, 2017
4853ab0
Resolved merge commits
Jun 8, 2017
e2fea09
Tidied up the formatting for a lot of files
Jun 8, 2017
acd392b
Merge pull request #18 from ISISComputingGroup/Ticket2379_Create_TPG2…
Jun 8, 2017
e2c4890
Merge pull request #5 from ISISComputingGroup/Ticket2379_Create_TPG26…
Jun 15, 2017
0be47f2
Add HLG emulator
John-Holt-Tessella Aug 31, 2017
8facd10
Add prefix into ioc launcher and waitfor into launcher
John-Holt-Tessella Sep 1, 2017
621decf
Revert "Add HLG emulator"
John-Holt-Tessella Sep 1, 2017
33f33c7
Add HLG emulator
John-Holt-Tessella Aug 31, 2017
e24cdf9
Merge pull request #25 from ISISComputingGroup/Ticket2530_He_level_meter
Tom-Willemsen Sep 4, 2017
1ddff77
Merge pull request #36 from ISISComputingGroup/Ticket2530_He_level_meter
Tom-Willemsen Sep 4, 2017
256fe33
Lewis import changed at v1.0.3
Sep 25, 2017
44554f4
Framework versions need to be specified in latest verion of Lewis
Sep 25, 2017
7e77866
Pin emulators to latest version
Sep 25, 2017
e04f108
Refactor starting emulators/iocs
Tom-Willemsen Jan 8, 2018
e1873df
refactor
Tom-Willemsen Jan 9, 2018
77546b1
Upgrade some emulators to new style
Tom-Willemsen Jan 10, 2018
b9ccd88
Convert rest of tests
Tom-Willemsen Jan 11, 2018
f453214
Use python rather than batch files
Tom-Willemsen Jan 17, 2018
794b180
Use better setup of device for amint2L so it canbe a good example
John-Holt-Tessella Jan 18, 2018
0ef9ae8
Add disconnect and tidy code for rework
John-Holt-Tessella Jan 26, 2018
1168f1f
Merge pull request #50 from ISISComputingGroup/Ticket2813_riken_chang…
DominicOram Feb 14, 2018
855e420
Upgrade Lewis
davidkeymer Mar 23, 2018
d3dd190
Update lewis_versions.py
esouthren Apr 3, 2018
f854012
Merge pull request #55 from ISISComputingGroup/Ticket2386_Upgrade_Lewis
esouthren Apr 3, 2018
a8c2282
Changed module name and updated emulator to pass temp test.
Jun 1, 2018
3b9b68d
Re-add lost init file, with comment saying do not delete.
Tom-Willemsen Jun 15, 2018
d321762
Convert docs to new style. Make assertion names consistent.
Tom-Willemsen Jun 20, 2018
626c218
Catch some more old-style alarms
Tom-Willemsen Jun 20, 2018
dadc612
Added connection emulation
LiamPanchaud Dec 11, 2018
af1cfb9
added amint2l connection test
LiamPanchaud Dec 11, 2018
6ab2805
Updated lewis version
DominicOram Sep 25, 2019
4bae432
Merge pull request #54 from ISISComputingGroup/Ticket4775_upgrade_lew…
Tom-Willemsen Sep 25, 2019
85ea0e1
renamed to cryogenic_sms/CRYOSMS
LilithCole Oct 15, 2019
362b7cf
merge master
LilithCole Oct 15, 2019
45d081a
Updated lewis version to 1.2.2
DominicOram Jun 1, 2020
f92bedf
amint2l - PEP8 fix
aaron-long Sep 11, 2020
135cf34
Fixed variable name for lewis version number
aaron-long Sep 16, 2020
a894304
Merge pull request #87 from ISISComputingGroup/Ticket4889_convert_dev…
rerpha Sep 24, 2020
8051ce4
Updated to use latest lewis version and convert strings correctly
DominicOram Nov 10, 2020
d0971b6
Update lewis version
DominicOram Nov 30, 2020
95298bd
Moved utils into lewis itself
DominicOram Jun 10, 2021
e539aec
Merge branch 'master' of c:/Instrument/Dev/EPICS-IOC_Test_Framework i…
aaron-long Oct 28, 2021
f438343
Merge branch 'master' of c:/Instrument/Dev/EPICS-DeviceEmulator into …
aaron-long Oct 28, 2021
d32f045
Added system tests to support module
aaron-long Oct 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ dllPath.bat
runIOC.bat
runIOC.sh
relPaths.sh
__pycache__/
*.py[cod]
*$py.class
/test-reports/
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ iocBoot_DEPEND_DIRS += $(filter %App,$(DIRS))
# Add any additional dependency rules here:

include $(TOP)/configure/RULES_TOP

ioctests:
.\system_tests\run_tests.bat
Empty file added system_tests/__init__.py
Empty file.
2 changes: 2 additions & 0 deletions system_tests/lewis_emulators/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# DO NOT DELETE THIS FILE - LEWIS FRAMEWORK REQUIRES THE DIRECTORY TO BE IMPORTABLE
from __future__ import absolute_import
5 changes: 5 additions & 0 deletions system_tests/lewis_emulators/amint2l/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .device import SimulatedAmint2l
from ..lewis_versions import LEWIS_LATEST

framework_version = LEWIS_LATEST
__all__ = ['SimulatedAmint2l']
36 changes: 36 additions & 0 deletions system_tests/lewis_emulators/amint2l/device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from collections import OrderedDict

from lewis.devices import StateMachineDevice
from .states import DefaultState


class SimulatedAmint2l(StateMachineDevice):
"""
Simulated AM Int2-L pressure transducer.
"""

def _initialize_data(self):
"""
Sets the initial state of the device.
"""
self.connected = True
self.pressure = 2.0
self.address = "AB"

def _get_state_handlers(self):
"""
Returns: states and their names
"""
return {DefaultState.NAME: DefaultState()}

def _get_initial_state(self):
"""
Returns: the name of the initial state
"""
return DefaultState.NAME

def _get_transition_handlers(self):
"""
Returns: the state transitions
"""
return OrderedDict()
3 changes: 3 additions & 0 deletions system_tests/lewis_emulators/amint2l/interfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .stream_interface import Amint2lStreamInterface

__all__ = ['Amint2lStreamInterface']
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
Stream device for amint2l
"""

from lewis.adapters.stream import StreamInterface
from lewis.core.logging import has_log

from lewis.utils.command_builder import CmdBuilder
from lewis.utils.replies import conditional_reply

if_connected = conditional_reply("connected")


@has_log
class Amint2lStreamInterface(StreamInterface):
"""
Stream interface for the serial port
"""

in_terminator = chr(3)
out_terminator = chr(3)

def __init__(self):

super(Amint2lStreamInterface, self).__init__()
self.commands = {
CmdBuilder(self.get_pressure).stx().arg("[A-Fa-f0-9]+").escape("r").build()
}

@if_connected
def handle_error(self, request, error):
"""
If command is not recognised print and error

Args:
request: requested string
error: problem

"""
self.log.error("An error occurred at request " + repr(request) + ": " + repr(error))

@if_connected
def get_pressure(self, address):

"""
Gets the current pressure

:param address: address of request
Returns: pressure in correct format if pressure has a value; if None returns None as if it is disconnected

"""
if address.upper() != self._device.address.upper():
self.log.error("unknown address {0}".format(address))
return None
self.log.info("Pressure: {0}".format(self._device.pressure))
if self._device.pressure is None:
return None
else:
try:
return "{stx}{pressure:+8.3f}".format(stx=chr(2), pressure=self._device.pressure)
except ValueError:
# pressure contains string probably OR (over range) or UR (under range)
return "{stx}{pressure:8s}".format(stx=chr(2), pressure=self._device.pressure)
8 changes: 8 additions & 0 deletions system_tests/lewis_emulators/amint2l/states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from lewis.core.statemachine import State


class DefaultState(State):
"""
Device is in default state.
"""
NAME = 'Default'
2 changes: 2 additions & 0 deletions system_tests/lewis_emulators/lewis_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LEWIS_1_3_0 = "1.3.0"
LEWIS_LATEST = LEWIS_1_3_0
13 changes: 13 additions & 0 deletions system_tests/run_tests.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off
REM Run this directory's tests using the IOC Testing Framework

SET CurrentDir=%~dp0

call "%~dp0..\..\..\..\config_env.bat"

set "PYTHONUNBUFFERED=1"

REM Command line arguments always passed to the test script
SET ARGS=--test_and_emulator %~dp0
call %PYTHON3% "%EPICS_KIT_ROOT%\support\IocTestFramework\master\run_tests.py" %ARGS% %*
IF %ERRORLEVEL% NEQ 0 EXIT /b %errorlevel%
Empty file added system_tests/tests/__init__.py
Empty file.
94 changes: 94 additions & 0 deletions system_tests/tests/amint2l.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import unittest

from utils.test_modes import TestModes
from utils.channel_access import ChannelAccess
from utils.ioc_launcher import get_default_ioc_dir
from utils.testing import skip_if_recsim, get_running_lewis_and_ioc

# Internal Address of device (must be 2 characters)
ADDRESS = "01"

# Device prefix
DEVICE_PREFIX = "AMINT2L_01"

IOCS = [
{
"name": DEVICE_PREFIX,
"directory": get_default_ioc_dir("AMINT2L"),
"macros": {
"ADDR": ADDRESS,
},
"emulator": "amint2l",
},
]


TEST_MODES = [TestModes.RECSIM, TestModes.DEVSIM]


class Amint2lTests(unittest.TestCase):
"""
Tests for the AM Int2-L.
"""

def setUp(self):
self._lewis, self._ioc = get_running_lewis_and_ioc("amint2l", DEVICE_PREFIX)
self.assertIsNotNone(self._lewis)
self.assertIsNotNone(self._ioc)

self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX)
self._lewis.backdoor_set_on_device('connected', True)
self._lewis.backdoor_set_on_device("address", ADDRESS)

def _set_pressure(self, expected_pressure):
self._lewis.backdoor_set_on_device("pressure", expected_pressure)
self._ioc.set_simulated_value("SIM:PRESSURE", expected_pressure)

def test_GIVEN_pressure_set_WHEN_read_THEN_pressure_is_as_expected(self):
expected_pressure = 1.23
self._set_pressure(expected_pressure)

self.ca.assert_that_pv_is("PRESSURE", expected_pressure)
self.ca.assert_that_pv_alarm_is("PRESSURE", self.ca.Alarms.NONE)
self.ca.assert_that_pv_is("RANGE:ERROR", "No Error")

def test_GIVEN_negative_pressure_set_WHEN_read_THEN_pressure_is_as_expected(self):
expected_pressure = -123.34
self._set_pressure(expected_pressure)

self.ca.assert_that_pv_is("PRESSURE", expected_pressure)

def test_GIVEN_pressure_with_no_decimal_places_set_WHEN_read_THEN_pressure_is_as_expected(self):
expected_pressure = 7
self._set_pressure(expected_pressure)

self.ca.assert_that_pv_is("PRESSURE", expected_pressure)

@skip_if_recsim("In rec sim this test fails")
def test_GIVEN_pressure_over_range_set_WHEN_read_THEN_error(self):
expected_pressure = "OR"
self._set_pressure(expected_pressure)

self.ca.assert_that_pv_alarm_is("PRESSURE", self.ca.Alarms.INVALID)
self.ca.assert_that_pv_is("RANGE:ERROR", "Over Range")

@skip_if_recsim("In rec sim this test fails")
def test_GIVEN_pressure_under_range_set_WHEN_read_THEN_error(self):
expected_pressure = "UR"
self._set_pressure(expected_pressure)

self.ca.assert_that_pv_alarm_is("PRESSURE", self.ca.Alarms.INVALID)
self.ca.assert_that_pv_is("RANGE:ERROR", "Under Range")

@skip_if_recsim("In rec sim this test fails")
def test_GIVEN_device_disconnected_WHEN_read_THEN_pv_shows_disconnect(self):
self._lewis.backdoor_set_on_device("pressure", None)
# Setting none simulates no response from device which is like pulling the serial cable. Disconnecting the
# emulator using the backdoor makes the record go udf not timeout which is what the actual device does.

self.ca.assert_that_pv_alarm_is("PRESSURE", self.ca.Alarms.INVALID)

@skip_if_recsim("Can not test disconnection in recsim")
def test_GIVEN_device_not_connected_WHEN_get_pressure_THEN_alarm(self):
self._lewis.backdoor_set_on_device('connected', False)
self.ca.assert_that_pv_alarm_is('PRESSURE', ChannelAccess.Alarms.INVALID)