Skip to content

Commit 509ce53

Browse files
Handle resetting severity and alarm
I can't see a reason why we should only set these values if they are non-zero, it's perfectly valid to do this to reset errors
1 parent bc1a67d commit 509ce53

2 files changed

Lines changed: 71 additions & 12 deletions

File tree

‎softioc/device_core.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ def _get_ioinit_info(self, cmd, record, ppvt):
177177

178178
def process_severity(self, record, severity, alarm):
179179
'''Support routine to implement alarm processing.'''
180-
if severity > record.NSEV:
181-
record.NSEV = severity
182-
record.NSTA = alarm
180+
record.NSEV = severity
181+
record.NSTA = alarm
183182

184183
def trigger(self):
185184
'''Call this to trigger processing for records with I/O Intr scan.'''

‎tests/test_records.py‎

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -683,16 +683,16 @@ def test_on_update_true_false(self, out_records):
683683
always_update is True and the put'ed value is always different"""
684684
self.on_update_runner(out_records, True, False)
685685

686-
def on_update_recursive_set_test_func(
687-
self, device_name, conn, severity, alarm
686+
def on_update_recursive_set_value_test_func(
687+
self, device_name, conn,
688688
):
689689
log("CHILD: Child started")
690690

691691
builder.SetDeviceName(device_name)
692692

693693
async def on_update_func(new_val):
694694
log("CHILD: on_update_func started")
695-
record.set(0, process=False, severity=severity, alarm=alarm)
695+
record.set(0, process=False)
696696
conn.send("C") # "Callback"
697697
log("CHILD: on_update_func ended")
698698

@@ -729,8 +729,8 @@ async def test_on_update_recursive_set_value(self):
729729
device_name = create_random_prefix()
730730

731731
process = ctx.Process(
732-
target=self.on_update_recursive_set_test_func,
733-
args=(device_name, child_conn, alarm.NO_ALARM, alarm.NO_ALARM),
732+
target=self.on_update_recursive_set_value_test_func,
733+
args=(device_name, child_conn),
734734
)
735735

736736
process.start()
@@ -773,10 +773,58 @@ async def test_on_update_recursive_set_value(self):
773773
pytest.fail("Process did not terminate")
774774

775775

776+
def on_update_recursive_set_alarm_test_func(
777+
self, device_name, conn, severity, alrm
778+
):
779+
log("CHILD: Child started")
780+
781+
builder.SetDeviceName(device_name)
782+
783+
async def on_update_func(new_val):
784+
log(f"CHILD: on_update_func started value {new_val}")
785+
if new_val == 2:
786+
record.set(
787+
new_val,
788+
process=False,
789+
severity=severity,
790+
alarm=alrm
791+
)
792+
elif new_val == 3:
793+
record.set(
794+
new_val,
795+
process=False,
796+
severity=alarm.NO_ALARM,
797+
alarm=alarm.NO_ALARM
798+
)
799+
conn.send("C") # "Callback"
800+
log("CHILD: on_update_func ended")
801+
802+
record = builder.longOut(
803+
"ACTION",
804+
on_update=on_update_func,
805+
blocking=True,
806+
initial_value=1 # A non-zero value, to check it changes
807+
)
808+
809+
dispatcher = asyncio_dispatcher.AsyncioDispatcher()
810+
builder.LoadDatabase()
811+
softioc.iocInit(dispatcher)
812+
813+
conn.send("R") # "Ready"
814+
815+
log("CHILD: Sent R over Connection to Parent")
816+
817+
# Keep process alive while main thread runs CAGET
818+
if conn.poll(TIMEOUT):
819+
val = conn.recv()
820+
assert val == "D", "Did not receive expected Done character"
821+
822+
log("CHILD: Received exit command, child exiting")
823+
776824
async def test_on_update_recursive_set_alarm(self):
777825
"""Test that on_update sets alarms correctly when the on_update
778826
callback sets the value of the record again (with process=False).
779-
See issue #201"""
827+
See PR #209"""
780828

781829
ctx = get_multiprocessing_context()
782830
parent_conn, child_conn = ctx.Pipe()
@@ -787,7 +835,7 @@ async def test_on_update_recursive_set_alarm(self):
787835
expected_alarm = alarm.HIGH_ALARM # arbitrary choice
788836

789837
process = ctx.Process(
790-
target=self.on_update_recursive_set_test_func,
838+
target=self.on_update_recursive_set_alarm_test_func,
791839
args=(device_name, child_conn, expected_sevr, expected_alarm),
792840
)
793841

@@ -809,8 +857,8 @@ async def test_on_update_recursive_set_alarm(self):
809857

810858
assert val == 1, "ACTION record did not start with value 1"
811859

812-
await caput(record, 1, wait=True)
813-
860+
# Trigger callback to set alarm states
861+
await caput(record, 2, wait=True)
814862

815863
sevr = await caget(record + ".SEVR")
816864
assert sevr == expected_sevr
@@ -821,6 +869,18 @@ async def test_on_update_recursive_set_alarm(self):
821869
# Expect one "C"
822870
select_and_recv(parent_conn, "C")
823871

872+
# Trigger another callback to clear alarm states
873+
await caput(record, 3, wait=True)
874+
875+
sevr = await caget(record + ".SEVR")
876+
assert sevr == alarm.NO_ALARM
877+
878+
sevr = await caget(record + ".STAT")
879+
assert sevr == alarm.NO_ALARM
880+
881+
# Expect second "C"
882+
select_and_recv(parent_conn, "C")
883+
824884
# ...But if we receive another we know there's a problem
825885
if parent_conn.poll(5): # Shorter timeout to make this quicker
826886
pytest.fail("Received unexpected second message")

0 commit comments

Comments
 (0)