Skip to content

Commit

Permalink
TEST: Finalize libca in between caget calls to force new context.
Browse files Browse the repository at this point in the history
Needed to demo undef timestamp bug in gateway >= R2-0-6-0
epics-extensions/ca-gateway#35
  • Loading branch information
bhill-slac committed Jun 9, 2022
1 parent dac2854 commit 73a053d
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions testTop/pyTestsApp/TestEnumUndefinedTimestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,49 @@ def testUndefTimestamp(self):
'''Two caget on an mbbi - both timestamps should be defined.'''
iocPV = epics.PV("ioc:HUGO:ENUM", auto_monitor=None)
iocPV.add_callback(self.onChangeIOC)

# Create a new CA context for the gateway PV
epics.ca.detach_context()
epics.ca.create_context()

gwPV1 = epics.PV("gateway:HUGO:ENUM", auto_monitor=None)
gwPV1.add_callback(self.onChangeGW)
iocEnumValue = iocPV.get()
gwEnumValue = gwPV1.get()
if gwtests.verbose:
print( "iocPV value =", iocEnumValue, " timestamp =", timestamp_to_string(iocPV.timestamp) )
print( "gwPV1 value =", gwEnumValue, " timestamp =", timestamp_to_string(gwPV1.timestamp) )

# Verify timestamp and value match
self.assertTrue( iocEnumValue == gwEnumValue,
self.assertEqual( iocEnumValue, gwEnumValue,
'ioc enum {0} !=\ngw enum {1}'.format( iocEnumValue, gwEnumValue ) )
self.assertEqual( iocPV.timestamp, gwPV1.timestamp,
'ioc timestamp {0} != gw timestamp {1}'.format(
timestamp_to_string(iocPV.timestamp), timestamp_to_string(gwPV1.timestamp)))

# Close current CA context and open a new one
gwPV1 = None
epics.ca.detach_context()
epics.ca.create_context()
epics.ca.finalize_libca()
epics.ca.initialize_libca()
#epics.ca.create_context()

'''Two caget on an mbbi - both timestamps should be defined.'''
# Now get the gateway value again and make sure the timestamp is not undefined
gwPV2 = epics.PV("gateway:HUGO:ENUM", auto_monitor=None)
gwPV2.add_callback(self.onChangeGW)
gwEnumValue = gwPV2.get()
if gwtests.verbose:
print( "gwPV2 value =", gwEnumValue, " timestamp =", timestamp_to_string(gwPV2.timestamp) )
if iocPV.status != epics.dbr.AlarmStatus.UDF:
self.assertTrue( gwPV2.status != epics.dbr.AlarmStatus.UDF,
'2nd CA get is undefined!' )
self.assertTrue( gwPV2.timestamp != 0, '2nd CA get timestamp is undefined!' )
self.assertTrue( iocEnumValue == gwEnumValue,
'ioc enum {0} !=\ngw enum {1}'.format( iocEnumValue, gwEnumValue ) )
self.assertNotEqual( gwPV2.status, epics.dbr.AlarmStatus.UDF, '2nd CA get status is undefined!' )
self.assertEqual( iocEnumValue, gwEnumValue,
'ioc enum {0} != gw enum {1}'.format( iocEnumValue, gwEnumValue ) )
if not timestamp_is_undefined(iocPV.timestamp):
self.assertFalse( timestamp_is_undefined(gwPV2.timestamp), '2nd CA get timestamp is undefined!' )
self.assertEqual( iocPV.timestamp, gwPV2.timestamp,
'ioc timestamp {0} != gw timestamp {1}'.format(
timestamp_to_string(iocPV.timestamp), timestamp_to_string(gwPV2.timestamp)))

if __name__ == '__main__':
unittest.main(verbosity=2)

0 comments on commit 73a053d

Please sign in to comment.