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

Update mclennan tests #595

Merged
merged 3 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
72 changes: 46 additions & 26 deletions tests/mclennan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
EMULATOR_NAME = "mclennan"

MTR1 = "MTR0101"
MTR_DESC = f"{MTR1}.DESC"
MTR_JOG = f"{MTR1}.JOGF"
MTR_HLM = f"{MTR1}.HLM"
MTR_STOP = f"{MTR1}.STOP"
MTR_MOVN = f"{MTR1}.MOVN"
MTR_RBV = f"{MTR1}.RBV"
MTR_MRES = f"{MTR1}.MRES"
MTR1_NAME = "Test1"
MTR1_DESC = f"{MTR1}.DESC"
MTR1_JOG = f"{MTR1}.JOGF"
MTR1_HLM = f"{MTR1}.HLM"
MTR1_STOP = f"{MTR1}.STOP"
MTR1_MOVN = f"{MTR1}.MOVN"
MTR1_RBV = f"{MTR1}.RBV"
MTR1_MRES = f"{MTR1}.MRES"
MTR1_HVEL = f"{MTR1}.HVEL"
MTR1_HOMR = f"{MTR1}.HOMR"
MTR2 = "MTR0102"
MTR2_NAME = "Test2"
MTR2_MRES = f"{MTR2}.MRES"
MTR2_HVEL = f"{MTR2}.HVEL"
MTR2_HOMR = f"{MTR2}.HOMR"
MTR_NAME = "Test"
MTR2_STOP = f"{MTR2}.STOP"

POLL_RATE = 1

Expand All @@ -35,14 +39,17 @@
"MTRCTRL": "01",
"AXIS1": "yes",
"AXIS2": "yes",
"NAME1": MTR_NAME,
"NAME1": MTR1_NAME,
"NAME2": MTR2_NAME,
"POLL_RATE": POLL_RATE,
"HOME2": 2
"CMOD1": "OPEN",
"CMOD2": "CLOSED",
"HOME1": 3, # SNL home
"HOME2": 2 # builtin controller home to datum
},
},
]


TEST_MODES = [
TestModes.DEVSIM,
]
Expand All @@ -56,41 +63,54 @@ def setUp(self):
self._lewis, self._ioc = get_running_lewis_and_ioc(EMULATOR_NAME, DEVICE_PREFIX)
self.ca = ChannelAccess(device_prefix=DEVICE_PREFIX, default_timeout=10)
self.ca_motor = ChannelAccess(default_timeout=30, device_prefix="MOT")
self.ca_motor.set_pv_value(MTR_STOP, 1, sleep_after_set=0)
self.ca_motor.set_pv_value(MTR1_STOP, 1, sleep_after_set=1)
self.ca_motor.set_pv_value(MTR2_STOP, 1, sleep_after_set=1)

def test_WHEN_ioc_running_THEN_motor_has_correct_description(self):
self.ca_motor.assert_that_pv_is(MTR_DESC, MTR_NAME + " (MCLEN)")
self.ca_motor.assert_that_pv_is(MTR1_DESC, MTR1_NAME + " (MCLEN)")

def test_WHEN_motor_jogged_THEN_motor_moves_and_does_not_stop_after_polled(self):
self.ca_motor.assert_setting_setpoint_sets_readback(10000, MTR_HLM, set_point_pv=MTR_HLM)
self.ca_motor.assert_setting_setpoint_sets_readback(10000, MTR1_HLM, set_point_pv=MTR1_HLM)

self.ca_motor.set_pv_value(MTR_JOG, 1, sleep_after_set=0)
self.ca_motor.set_pv_value(MTR1_JOG, 1, sleep_after_set=0)

self.ca_motor.assert_that_pv_value_is_increasing(MTR_RBV, 1)
self.ca_motor.assert_that_pv_is(MTR_MOVN, 1)
self.ca_motor.assert_that_pv_value_is_unchanged(MTR_MOVN, POLL_RATE * 1.5)
self.ca_motor.assert_that_pv_value_is_increasing(MTR1_RBV, 1)
self.ca_motor.assert_that_pv_is(MTR1_MOVN, 1)
self.ca_motor.assert_that_pv_value_is_unchanged(MTR1_MOVN, POLL_RATE * 1.5)

def test_WHEN_motor_position_changes_outside_IBEX_THEN_motor_position_updated(self):
test_position = -10
self.ca_motor.assert_that_pv_is_not_number(MTR_RBV, test_position)
mres = self.ca_motor.get_pv_value(MTR_MRES)
self.ca_motor.assert_that_pv_is_not_number(MTR1_RBV, test_position)
mres = self.ca_motor.get_pv_value(MTR1_MRES)
self._lewis.backdoor_set_on_device("position", test_position/mres)
self.ca_motor.assert_that_pv_is_number(MTR_RBV, test_position)
self.ca_motor.assert_that_pv_is_number(MTR1_RBV, test_position)

def test_WHEN_velocity_changes_WHEN_sending_home_THEN_velocity_is_changed_then_set_back_after_home(self):
def test_WHEN_velocity_changes_WHEN_sending_builtin_home_THEN_creep_speed_is_changed_then_set_back_after_home(self):
self._lewis.assert_that_emulator_value_is("creep_speed2", str(700))
vel = 0.2
self.ca_motor.set_pv_value(MTR2_HVEL, vel)
self.ca_motor.set_pv_value(MTR2_HOMR, 1)
mres = self.ca_motor.get_pv_value(MTR2_MRES)
self._lewis.assert_that_emulator_value_is("creep_speed", str(int(vel/mres)))
self._lewis.assert_that_emulator_value_is("creep_speed2", str(int(vel/mres)))
self.ca_motor.set_pv_value(MTR2, 1)
self._lewis.assert_that_emulator_value_is("creep_speed", str(700))
self._lewis.assert_that_emulator_value_is("creep_speed2", str(700))

def test_WHEN_velocity_changes_WHEN_sending_SNL_home_THEN_creep_speed_is_not_changed(self):
self._lewis.assert_that_emulator_value_is("creep_speed1", str(700))
vel = 0.2
self.ca_motor.set_pv_value(MTR1_HVEL, vel)
self.ca_motor.set_pv_value(MTR1_HOMR, 1)
mres = self.ca_motor.get_pv_value(MTR1_MRES)
self._lewis.assert_that_emulator_value_is("creep_speed1", str(700))
self.ca_motor.set_pv_value(MTR1, 1)
self._lewis.assert_that_emulator_value_is("creep_speed1", str(700))

def test_WHEN_sending_home_with_high_velocity_THEN_creep_speed_is_capped(self):
self._lewis.assert_that_emulator_value_is("creep_speed2", str(700))
vel = 100
self.ca_motor.set_pv_value(MTR2_HVEL, vel)
self.ca_motor.set_pv_value(MTR2_HOMR, 1)
# Should be capped at the max creep speed (800)
self._lewis.assert_that_emulator_value_is("creep_speed", str(800))
self._lewis.assert_that_emulator_value_is("creep_speed2", str(800))
self.ca_motor.set_pv_value(MTR2, 1)
self._lewis.assert_that_emulator_value_is("creep_speed", str(700))
self._lewis.assert_that_emulator_value_is("creep_speed2", str(700))
7 changes: 2 additions & 5 deletions utils/emulator_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ def backdoor_set_and_assert_set(self, variable, value, *args, **kwargs):

Raises:
AssertionError: if emulator property is not the expected value
UnableToConnectToPVException: if emulator property does not exist within timeout
"""
self.backdoor_set_on_device(variable, value)
self.assert_that_emulator_value_is(variable, str(value))
Expand All @@ -213,11 +212,10 @@ def assert_that_emulator_value_is(self, emulator_property, expected_value, timeo
checking equality. E.g. to cast to float pass the float class as this argument.
Raises:
AssertionError: if emulator property is not the expected value
UnableToConnectToPVException: if emulator property does not exist within timeout
"""

if message is None:
message = "Expected PV to have value {}.".format(format_value(expected_value))
message = "Expected emulator to have value {}.".format(format_value(expected_value))

return self.assert_that_emulator_value_causes_func_to_return_true(
emulator_property, lambda val: cast(val) == expected_value, timeout=timeout, msg=message)
Expand All @@ -231,7 +229,7 @@ def assert_that_emulator_value_causes_func_to_return_true(
emulator_property (string): emulator property to check
func: a function that takes one argument, the emulator property value, and returns True if the value is
valid.
timeout: time to wait for the PV to satisfy the function
timeout: time to wait for the emulator to satisfy the function
msg: custom message to print on failure
Raises:
AssertionError: If the function does not evaluate to true within the given timeout
Expand Down Expand Up @@ -301,7 +299,6 @@ def assert_that_emulator_value_is_greater_than(self, emulator_property, min_valu
timeout: if it hasn't changed within this time raise assertion error
Raises:
AssertionError: if value does not become requested value
UnableToConnectToPVException: if pv does not exist within timeout
"""

message = "Expected emulator property {} to have a value greater than or equal to {}".format(
Expand Down
2 changes: 1 addition & 1 deletion utils/ioc_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ def open(self):
"""
super(ProcServLauncher, self).open()

print("IOC started, connecting to procserv")
print(f"IOC started, connecting to procserv at telnet port {self.procserv_port}")

timeout = 20

Expand Down