def test_pythonPropsRangeSeq(self): self._app = self._launchApp('TestPythonPropsRange') # Test upper and lower bounds seq_octet = CF.DataType(id='seq_octet', value=any.to_any([ CORBA.Any(CORBA.TC_long, 0), CORBA.Any(CORBA.TC_long, 255) ])) seq_short = CF.DataType(id='seq_short', value=any.to_any([-32768, 32767])) seq_ushort = CF.DataType(id='seq_ushort', value=any.to_any([0, 65535])) seq_long = CF.DataType(id='seq_long', value=any.to_any([-2147483648, 2147483647])) seq_ulong = CF.DataType(id='seq_ulong', value=any.to_any([0,4294967295])) seq_longlong = CF.DataType(id='seq_longlong', value=any.to_any([-9223372036854775808L, 9223372036854775807L])) #seq_ulonglong = CF.DataType(id='seq_ulonglong', value=any.to_any([ # CORBA.Any(CORBA.TC_ulonglong, 9223372036854775808L), # CORBA.Any(CORBA.TC_ulonglong, 0) # ])) self._app.configure([seq_octet, seq_short, seq_ushort, seq_long, seq_ulong, seq_longlong]) #, seq_ulonglong]) res = self._app.query([]) for r in res: if r.id == 'seq_octet': # Octet sequences are treated like strings, so numbers need to be extracted vals = r.value.value().lstrip('[').rstrip(']').split(',') self.assertEquals(int(vals[0].strip()), 0) self.assertEquals(int(vals[1].strip()), 255) elif r.id == 'seq_short': self.assertEquals(r.value.value()[0], -32768) self.assertEquals(r.value.value()[1], 32767) elif r.id == 'seq_ushort': self.assertEquals(r.value.value()[0], 0) self.assertEquals(r.value.value()[1], 65535) elif r.id == 'seq_long': self.assertEquals(r.value.value()[0], -2147483648) self.assertEquals(r.value.value()[1], 2147483647) elif r.id == 'seq_ulong': self.assertEquals(r.value.value()[0], 0) self.assertEquals(r.value.value()[1], 4294967295) elif r.id == 'seq_longlong': self.assertEquals(r.value.value()[0], -9223372036854775808L) self.assertEquals(r.value.value()[1], 9223372036854775807L) # Test one beyond upper bound seq_octet = CF.DataType(id='seq_octet', value=any.to_any([0, 256])) seq_short = CF.DataType(id='seq_short', value=any.to_any([0, 32768])) seq_ushort = CF.DataType(id='seq_ushort', value=any.to_any([0, 65536])) seq_long = CF.DataType(id='seq_long', value=any.to_any([0, 2147483648])) seq_ulong = CF.DataType(id='seq_ulong', value=any.to_any([0, 4294967296])) seq_longlong = CF.DataType(id='seq_longlong', value=any.to_any([0, CORBA.Any(CORBA.TC_ulonglong, 9223372036854775808L)])) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [seq_octet, seq_short, seq_ushort, seq_long, seq_ulong, seq_longlong]) # Test one beyond lower bound seq_octet = CF.DataType(id='seq_octet', value=any.to_any([-1, 0])) seq_short = CF.DataType(id='seq_short', value=any.to_any([-32769, 0])) seq_ushort = CF.DataType(id='seq_ushort', value=any.to_any([-1, 0])) seq_long = CF.DataType(id='seq_long', value=any.to_any([-2147483649, 0])) seq_ulong = CF.DataType(id='seq_ulong', value=any.to_any([-1, 0])) seq_ulonglong = CF.DataType(id='seq_ulonglong', value=any.to_any([-1, 0])) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [seq_octet, seq_short, seq_ushort, seq_long, seq_ulong, seq_ulonglong])
def callback_cut_request(self, msg_id, new_value): splitter_props = self.splitter.componentObject.query([]) for prop in splitter_props: if prop.id == 'bandwidth': bandwidth = prop.value._v if prop.id == 'center_freq': center_freq = prop.value._v if new_value.freq_begin == None or new_value.freq_end == None or new_value.time_begin == None or new_value.time_end == None: return if center_freq - bandwidth / 2 < new_value.freq_begin or center_freq + bandwidth / 2 > new_value.freq_end: print 'bad frequency range:', center_freq - bandwidth / 2, center_freq + bandwidth / 2, 'vs', new_value.freq_begin, new_value.freq_end request_id = new_value.request_id timestring = time.asctime(time.gmtime(new_value.time_begin)).split(' ') month = timestring[1] day = timestring[2] year = timestring[-1] begin_seconds = self.gm_to_seconds(time.gmtime(new_value.time_begin)) begin_compounddate = day + month + year timestring = time.asctime(time.gmtime(new_value.time_end)).split(' ') month = timestring[1] day = timestring[2] year = timestring[-1] end_seconds = self.gm_to_seconds(time.gmtime(new_value.time_end)) end_compounddate = day + month + year filelist = os.listdir(self.basedir) for _file in filelist: fields = _file.split('.') if len(fields) < 6: continue try: format = fields[-1] samplerate = float(fields[-2]) filesize = os.stat(self.basedir + '/' + _file).st_size complexity = fields[-3] filetime_in_seconds = self.string_to_seconds( fields[-5], fields[-4]) compounddate = fields[-6] if compounddate != begin_compounddate: continue if compounddate != end_compounddate: continue if begin_seconds < filetime_in_seconds: continue if end_seconds > filetime_in_seconds + (filesize / (samplerate * 4)): continue self.TFD.DesiredOutputRate = new_value.freq_end - new_value.freq_begin self.TFD.FilterBW = new_value.freq_end - new_value.freq_begin new_center_freq = (new_value.freq_end + new_value.freq_begin) / 2.0 self.TFD.TuningIF = new_center_freq - center_freq self.request_count += 1 newfilename = "datafile_" + str(self.request_count) self.requests[newfilename] = request_id uri = CF.DataType(id='destination_uri', value=any.to_any('sca:///data/' + newfilename)) enabled_true = CF.DataType(id='recording_enabled', value=any.to_any(True)) self.FileWriter_3.componentObject.configure( [uri, enabled_true]) source_uri = CF.DataType(id='source_uri', value=any.to_any('sca:///data/' + _file)) sample_rate = CF.DataType(id='sample_rate', value=any.to_any(str(samplerate))) file_format = CF.DataType(id='file_format', value=any.to_any("FLOAT")) xdelta = CF.DataType(id='xdelta', value=any.to_any(1 / samplerate)) sri = CF.DataType(id='default_sri', value=any.to_any([xdelta])) center_frequency = CF.DataType(id='center_frequency', value=any.to_any( str(center_freq))) self.FileReader_1.componentObject.configure([ source_uri, sri, center_frequency, sample_rate, file_format ]) playback_state = CF.DataType(id='playback_state', value=any.to_any('PLAY')) self.FileReader_1.componentObject.configure([playback_state]) break except: continue
def testBasicBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions self.comp.start() self.comp.stop() for _port in self.comp.ports: if _port.name == 'DigitalTuner_in': port = _port break print self.comp.frontend_tuner_status self.assertEquals(len(self.comp.frontend_tuner_status), 2) alloc = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER', allocation_id='hello', center_frequency=100) self.assertRaises( redhawk.frontendInterfaces.FRONTEND.FrontendException, port.ref.getTunerEnable, 'hello') listen_alloc = frontend.createTunerListenerAllocation( 'hello', 'hello_listen') listen_2_alloc = frontend.createTunerListenerAllocation( 'hello', 'hello_2_listen') retval = self.comp.allocateCapacity(listen_alloc) self.assertEquals(retval, False) retval = self.comp.allocateCapacity(alloc) self.assertEquals(retval, True) retval = self.comp.allocateCapacity(listen_alloc) self.assertEquals(retval, True) retval = self.comp.allocateCapacity(listen_2_alloc) self.assertEquals(retval, True) retval = port.ref.getTunerEnable('hello') self.assertEquals(retval, True) sample_rate = port.ref.getTunerOutputSampleRate('hello') self.assertEquals(sample_rate, 0.0) port.ref.setTunerOutputSampleRate('hello', 5) sample_rate = port.ref.getTunerOutputSampleRate('hello') self.assertEquals(sample_rate, 5) port.ref.setTunerEnable('hello', False) retval = port.ref.getTunerEnable('hello') self.assertEquals(retval, False) port.ref.setTunerEnable('hello', True) retval = port.ref.getTunerEnable('hello') self.assertEquals(retval, True) _id = port.ref.getTunerRfFlowId('hello') self.assertEquals(_id, 'foo') self.assertEquals(self.comp.frontend_tuner_status[0].enabled, True) self.assertEquals(self.comp.frontend_tuner_status[0].center_frequency, 100) self.assertEquals(len(self.comp.connectionTable), 3) allocation_id_csv = self.comp.frontend_tuner_status[ 0].allocation_id_csv allocations = allocation_id_csv.split(',') self.assertEquals(len(allocations), 3) self.assertEquals('hello' in allocations, True) self.assertEquals('hello_2_listen' in allocations, True) self.assertEquals('hello_listen' in allocations, True) listen_alloc['FRONTEND::listener_allocation'].pop( 'FRONTEND::listener_allocation::existing_allocation_id') _old_id = [ CF.DataType( id='FRONTEND::listener_allocation::listener_allocation_id', value=_any.to_any( listen_alloc['FRONTEND::listener_allocation'] ['FRONTEND::listener_allocation::listener_allocation_id'])) ] _listen_alloc = [ CF.DataType(id='FRONTEND::listener_allocation', value=_any.to_any(_old_id)) ] self.comp.ref.deallocateCapacity(_listen_alloc) self.assertEquals(self.comp.frontend_tuner_status[0].enabled, True) self.assertEquals(self.comp.frontend_tuner_status[0].center_frequency, 100) allocation_id_csv = self.comp.frontend_tuner_status[ 0].allocation_id_csv allocations = allocation_id_csv.split(',') self.assertEquals(len(allocations), 2) self.assertEquals('hello' in allocations, True) self.assertEquals('hello_2_listen' in allocations, True) self.assertEquals('hello_listen' in allocations, False) self.comp.deallocateCapacity(alloc) self.assertEquals(self.comp.frontend_tuner_status[0].enabled, False) self.assertEquals(self.comp.frontend_tuner_status[0].center_frequency, 0) self.assertEquals(self.comp.frontend_tuner_status[0].enabled, False) self.assertEquals(self.comp.frontend_tuner_status[0].center_frequency, 0) allocation_id_csv = self.comp.frontend_tuner_status[ 0].allocation_id_csv allocations = allocation_id_csv.split(',') self.assertEquals(len(allocations), 1) self.assertEquals(allocations[0], '') self.assertEquals(len(self.comp.connectionTable), 0) self.assertRaises( redhawk.frontendInterfaces.FRONTEND.FrontendException, port.ref.getTunerEnable, 'hello')
def test_pythonPropsRange(self): self._app = self._launchApp('TestPythonPropsRange') # Test upper bound my_octet = CF.DataType(id='my_octet', value=CORBA.Any(CORBA.TC_long, 255)) my_short = CF.DataType(id='my_short', value=CORBA.Any(CORBA.TC_long, 32767)) my_ushort = CF.DataType(id='my_ushort', value=CORBA.Any(CORBA.TC_long, 65535)) my_long = CF.DataType(id='my_long', value=CORBA.Any(CORBA.TC_longlong, 2147483647)) my_ulong = CF.DataType(id='my_ulong', value=CORBA.Any(CORBA.TC_longlong, 4294967295)) my_longlong = CF.DataType(id='my_longlong', value=CORBA.Any(CORBA.TC_longlong, 9223372036854775807L)) my_ulonglong = CF.DataType(id='my_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 18446744073709551615L)) self._app.configure([my_octet, my_short, my_ushort, my_long, my_ulong, my_longlong, my_ulonglong]) res = self._app.query([]) for r in res: if r.id == 'my_octet': self.assertEquals(r.value.value(), 255) elif r.id == 'my_short': self.assertEquals(r.value.value(), 32767) elif r.id == 'my_ushort': self.assertEquals(r.value.value(), 65535) elif r.id == 'my_long': self.assertEquals(r.value.value(), 2147483647) elif r.id == 'my_ulong': self.assertEquals(r.value.value(), 4294967295) elif r.id == 'my_longlong': self.assertEquals(r.value.value(), 9223372036854775807) elif r.id == 'my_ulonglong': self.assertEquals(r.value.value(), 18446744073709551615) # Test lower boound my_octet = CF.DataType(id='my_octet', value=CORBA.Any(CORBA.TC_long, 0)) my_short = CF.DataType(id='my_short', value=CORBA.Any(CORBA.TC_long, -32768)) my_ushort = CF.DataType(id='my_ushort', value=CORBA.Any(CORBA.TC_long, 0)) my_long = CF.DataType(id='my_long', value=CORBA.Any(CORBA.TC_longlong, -2147483648)) my_ulong = CF.DataType(id='my_ulong', value=CORBA.Any(CORBA.TC_longlong, 0)) my_longlong = CF.DataType(id='my_longlong', value=CORBA.Any(CORBA.TC_longlong, -9223372036854775808L)) my_ulonglong = CF.DataType(id='my_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 0)) self._app.configure([my_octet, my_short, my_ushort, my_long, my_ulong, my_longlong, my_ulonglong]) res = self._app.query([]) for r in res: if r.id == 'my_octet': self.assertEquals(r.value.value(), 0) elif r.id == 'my_short': self.assertEquals(r.value.value(), -32768) elif r.id == 'my_ushort': self.assertEquals(r.value.value(), 0) elif r.id == 'my_long': self.assertEquals(r.value.value(), -2147483648) elif r.id == 'my_ulong': self.assertEquals(r.value.value(), 0) elif r.id == 'my_longlong': self.assertEquals(r.value.value(), -9223372036854775808) elif r.id == 'my_ulonglong': self.assertEquals(r.value.value(), 0) # Test one beyond upper bound my_octet = CF.DataType(id='my_octet', value=CORBA.Any(CORBA.TC_long, 256)) my_short = CF.DataType(id='my_short', value=CORBA.Any(CORBA.TC_long, 32768)) my_ushort = CF.DataType(id='my_ushort', value=CORBA.Any(CORBA.TC_long, 65536)) my_long = CF.DataType(id='my_long', value=CORBA.Any(CORBA.TC_longlong, 2147483648)) my_ulong = CF.DataType(id='my_ulong', value=CORBA.Any(CORBA.TC_longlong, 4294967296)) my_longlong = CF.DataType(id='my_longlong', value=CORBA.Any(CORBA.TC_ulonglong, 9223372036854775808L)) # All should fail causing InvalidConfiguration self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [my_octet, my_short, my_ushort, my_long, my_ulong, my_longlong]) # Test one beyond lower bound my_octet = CF.DataType(id='my_octet', value=CORBA.Any(CORBA.TC_long, -1)) my_short = CF.DataType(id='my_short', value=CORBA.Any(CORBA.TC_long, -32769)) my_ushort = CF.DataType(id='my_ushort', value=CORBA.Any(CORBA.TC_long, -1)) my_long = CF.DataType(id='my_long', value=CORBA.Any(CORBA.TC_longlong, -2147483649)) my_ulong = CF.DataType(id='my_ulong', value=CORBA.Any(CORBA.TC_longlong, -1)) my_ulonglong = CF.DataType(id='my_ulonglong', value=CORBA.Any(CORBA.TC_longlong, -1)) # All should fail causing InvalidConfiguration self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [my_octet, my_short, my_ushort, my_long, my_ulong, my_ulonglong]) # Make sure Partial Configuration error will occur my_octet = CF.DataType(id='my_octet', value=CORBA.Any(CORBA.TC_long, 11)) my_ushort = CF.DataType(id='my_ushort', value=CORBA.Any(CORBA.TC_long, 22)) self.assertRaises(CF.PropertySet.PartialConfiguration, self._app.configure, [my_octet, my_short, my_ushort, my_long, my_ulong]) res = self._app.query([]) for r in res: if r.id == 'my_octet': self.assertEquals(r.value.value(), 11) elif r.id == 'my_short': self.assertEquals(r.value.value(), -32768) elif r.id == 'my_ushort': self.assertEquals(r.value.value(), 22) elif r.id == 'my_long': self.assertEquals(r.value.value(), -2147483648) elif r.id == 'my_ulong': self.assertEquals(r.value.value(), 0) elif r.id == 'my_longlong': self.assertEquals(r.value.value(), -9223372036854775808) elif r.id == 'my_ulonglong': self.assertEquals(r.value.value(), 0)
def setProps(self, TuningRF=None, FilterBW=None, DesiredOutputRate=None, filterProps=None, TuneMode=None, TuningIF=None, TuningNorm=None): myProps = [] if TuningRF != None: self.TuningRF = TuningRF myProps.append( CF.DataType(id='TuningRF', value=CORBA.Any(CORBA.TC_ulonglong, self.TuningRF))) if FilterBW != None: self.FilterBW = FilterBW myProps.append( CF.DataType(id='FilterBW', value=CORBA.Any(CORBA.TC_float, self.FilterBW))) if DesiredOutputRate != None: self.DesiredOutputRate = DesiredOutputRate myProps.append( CF.DataType(id='DesiredOutputRate', value=CORBA.Any(CORBA.TC_float, self.DesiredOutputRate))) if filterProps != None: self.filterProps = filterProps myProps.append( CF.DataType( id='filterProps', value=CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ ossie.cf.CF.DataType( id='FFT_size', value=CORBA.Any(CORBA.TC_ulong, filterProps[0])), ossie.cf.CF.DataType( id='TransitionWidth', value=CORBA.Any(CORBA.TC_double, filterProps[1])), ossie.cf.CF.DataType( id='Ripple', value=CORBA.Any(CORBA.TC_double, filterProps[2])) ]))) if TuneMode != None: self.TuneMode = TuneMode myProps.append( CF.DataType(id='TuneMode', value=CORBA.Any(CORBA.TC_string, TuneMode))) if TuningIF != None: self.TuningIF = TuningIF myProps.append( CF.DataType(id='TuningIF', value=CORBA.Any(CORBA.TC_double, TuningIF))) if TuningNorm != None: self.TuningNorm = TuningNorm myProps.append( CF.DataType(id='TuningNorm', value=CORBA.Any(CORBA.TC_double, TuningNorm))) if myProps: #configure it self.comp.configure(myProps) print self.comp.query([])
def pushSriBigEndian(self,xdelta=1.0,streamID='TestStreamID',mode=0,kw=[]): kw.append(CF.DataType("dataRef", ossie.properties.to_tc_value(BIG_ENDIAN, 'string'))) self.pushSRI(xdelta, streamID, mode, kw)
def test_ExternalProps(self): # Makes sure that duplicate external property names throws an error self.assertRaises(CF.DomainManager.ApplicationInstallationError, self._createApp, 'Duplicate') self.assertRaises(CF.DomainManager.ApplicationInstallationError, self._createApp, 'Duplicate2') self._createApp("") # Internal property IDs should fail pythonProp = CF.DataType(id="DCE:b8f43ac8-26b5-40b3-9102-d127b84f9e4b", value=CORBA.Any(CORBA.TC_string, "test")) javaProp = CF.DataType(id="ulong_prop", value=CORBA.Any(CORBA.TC_ulong, 1)) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [javaProp, pythonProp]) # will throw partial because cppProp is in AC cppProp = CF.DataType(id="DCE:9d1e3621-27ca-4cd0-909d-90b7448b8f71", value=CORBA.Any(CORBA.TC_long, -1)) self.assertRaises(CF.PropertySet.PartialConfiguration, self._app.configure, [pythonProp, cppProp, javaProp]) # Make sure cppProp was set cppProp = CF.DataType(id="DCE:9d1e3621-27ca-4cd0-909d-90b7448b8f71", value=any.to_any(None)) retProp = self._app.query([cppProp])[0] self.assertEquals(retProp.value.value(), -1) cppProp = CF.DataType(id="ext_prop_long", value=CORBA.Any(CORBA.TC_long, -111)) pythonProp = CF.DataType(id="ext_prop_string", value=CORBA.Any(CORBA.TC_string, "hello world")) javaProp = CF.DataType(id="ext_prop_ulong", value=CORBA.Any(CORBA.TC_ulong, 111)) # Configure all self._app.configure([javaProp, pythonProp, cppProp]) # Make sure all were set found = 0 props = self._app.query([]) # Should have 3 external properties and 3 AC properties (the 4th AC prop is promoted as external) self.assertEquals(len(props), 6) for p in props: if p.id == "ext_prop_long": self.assertEquals(p.value.value(), -111) found += 1 elif p.id == "ext_prop_string": self.assertEquals(p.value.value(), "hello world") found += 1 elif p.id == "ext_prop_ulong": self.assertEquals(p.value.value(), 111) found += 1 # Make sure all 3 external prop IDs were found if not found == 3: self.fail('Unable to query() all required external property IDs') # Can still configure other AC internal props cppProp = CF.DataType(id="DCE:4e7c1977-5f53-4061-bae7-cb8c1072f4b7", value=CORBA.Any(CORBA.TC_string, "Hello world")) self._app.configure([cppProp]) cppProp = CF.DataType(id="DCE:4e7c1977-5f53-4061-bae7-cb8c1072f4b7", value=any.to_any(None)) retProp = self._app.query([cppProp])[0] self.assertEquals(retProp.value.value(), "Hello world") # Can not configure/query other components internal props pythonProp = CF.DataType(id="test_float", value=CORBA.Any(CORBA.TC_float, 1.11)) javaProp = CF.DataType(id="DCE:3303ee57-70bb-4325-84ad-fb7fd333c44a", value=any.to_any([1, 1])) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [pythonProp, javaProp]) self.assertRaises(CF.UnknownProperties, self._app.query, [pythonProp, javaProp]) # Make sure can do individual queries on external properties pythonProp = CF.DataType(id="ext_prop_string", value=CORBA.Any(CORBA.TC_string, "HELLO WORLD")) javaProp = CF.DataType(id="ext_prop_ulong", value=CORBA.Any(CORBA.TC_ulong, 222)) self._app.configure([pythonProp, javaProp]) pythonProp = CF.DataType(id="ext_prop_string", value=any.to_any(None)) javaProp = CF.DataType(id="ext_prop_ulong", value=any.to_any(None)) pythonRet = self._app.query([pythonProp, javaProp])[0] javaRet = self._app.query([pythonProp, javaProp])[1] self.assertEquals(pythonRet.value.value(), "HELLO WORLD") self.assertEquals(javaRet.value.value(), 222) # Individual queries of mix of AC & external properties cppProp = CF.DataType(id="ext_prop_long", value=CORBA.Any(CORBA.TC_long, -333)) cppPropInternal = CF.DataType( id="DCE:4e7c1977-5f53-4061-bae7-cb8c1072f4b7", value=CORBA.Any(CORBA.TC_string, "HELLO WORLD2")) pythonProp = CF.DataType(id="ext_prop_string", value=CORBA.Any(CORBA.TC_string, "hello world2")) javaProp = CF.DataType(id="ext_prop_ulong", value=CORBA.Any(CORBA.TC_ulong, 333)) self._app.configure([pythonProp, javaProp, cppProp, cppPropInternal]) cppProp = CF.DataType(id="ext_prop_long", value=any.to_any(None)) cppPropInternal = CF.DataType( id="DCE:4e7c1977-5f53-4061-bae7-cb8c1072f4b7", value=any.to_any(None)) pythonProp = CF.DataType(id="ext_prop_string", value=any.to_any(None)) javaProp = CF.DataType(id="ext_prop_ulong", value=any.to_any(None)) pythonRet = self._app.query( [pythonProp, javaProp, cppPropInternal, cppProp])[0] javaRet = self._app.query( [pythonProp, javaProp, cppPropInternal, cppProp])[1] cppRet2 = self._app.query( [pythonProp, javaProp, cppPropInternal, cppProp])[2] cppRet = self._app.query( [pythonProp, javaProp, cppPropInternal, cppProp])[3] self.assertEquals(pythonRet.value.value(), "hello world2") self.assertEquals(javaRet.value.value(), 333) self.assertEquals(cppRet2.value.value(), "HELLO WORLD2") self.assertEquals(cppRet.value.value(), -333)
def test_InvalidPropertyException(self): bad_prop = CF.DataType(id='bad_cap', value=any.to_any('foo')) self.assertRaises(CF.Device.InvalidCapacity, self._device.allocateCapacity, [bad_prop]) self._device.start() self.assertRaises(CF.Device.InvalidCapacity, self._device.deallocateCapacity, [bad_prop])
def test_HardFailAll(self): # test HardFail of a node # - test that when a DeviceManager and its devices and apps fail hard (ex: power failure) # that things still behave as expected domBooter, domMgr = self.launchDomainManager(debug=self.debuglevel) devBooterA, devMgrA = self.launchDeviceManager("/nodes/test_HardFail_nodeA/DeviceManager.dcd.xml", debug=self.debuglevel) devBooterB, devMgrB = self.launchDeviceManager("/nodes/test_HardFail_nodeB/DeviceManager.dcd.xml", debug=self.debuglevel) devInfo = [] devInfo.append({"booter":devBooterA, "mgr":devMgrA}) devInfo.append({"booter":devBooterB, "mgr":devMgrB}) # ensure both DeviceManagers were started self.assertEqual(len(domMgr._get_deviceManagers()), 2) # store original capacities of devices prop = [CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))] for i in devInfo: i['dev'] = i['mgr']._get_registeredDevices()[0] i['dev_BogoMipsCapacity'] = i['dev'].query(prop)[0].value.value() # install first waveform self.assertEqual(len(domMgr._get_applicationFactories()), 0) self.assertEqual(len(domMgr._get_applications()), 0) domMgr.installApplication("/waveforms/CommandWrapperOneDep/CommandWrapper.sad.xml") self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) appFact = domMgr._get_applicationFactories()[0] app1 = appFact.create(appFact._get_name(), [], []) self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) # find which device manager it got installed on devMgrToKill = None devMgrToRelaunchOn = None if devInfo[0]['dev'].query(prop)[0].value.value() != devInfo[0]['dev_BogoMipsCapacity']: devMgrToKill = 0 devMgrToRelaunchOn = 1 elif devInfo[1]['dev'].query(prop)[0].value.value() != devInfo[1]['dev_BogoMipsCapacity']: devMgrToKill = 1 devMgrToRelaunchOn = 0 else: self.fail("Application didn't launch on either device manager") # kill the device manager, devices, and components to simulate a hard failure killProcesses(devInfo[devMgrToKill]['booter'].pid) # try to stop and release the application (even though everything associated with it is dead) self.assertRaises(CF.Resource.StopError, app1.stop) try: app1.releaseObject() except: self.fail("releaseObject should have completed successfully here") # launch a waveform again on the second device manager appFact = domMgr._get_applicationFactories()[0] app2 = appFact.create(appFact._get_name(), [], []) self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) self.assertNotEqual(devInfo[devMgrToRelaunchOn]['dev'].query(prop)[0].value.value(),devInfo[devMgrToRelaunchOn]['dev_BogoMipsCapacity'])
def test_HardFailDevice(self): # test HardFail of a device # - test that when a device fails hard (ex: seg fault or kill -9) # that things still behave as expected domBooter, domMgr = self.launchDomainManager(debug=self.debuglevel) devBooterA, devMgrA = self.launchDeviceManager("/nodes/test_HardFail_nodeA/DeviceManager.dcd.xml", debug=self.debuglevel) devBooterB, devMgrB = self.launchDeviceManager("/nodes/test_HardFail_nodeB/DeviceManager.dcd.xml", debug=self.debuglevel) devInfo = [] devInfo.append({"booter":devBooterA, "mgr":devMgrA}) devInfo.append({"booter":devBooterB, "mgr":devMgrB}) # ensure both DeviceManagers were started self.assertEqual(len(domMgr._get_deviceManagers()), 2) # store original capacities of devices prop = [CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))] for i in devInfo: i['dev'] = i['mgr']._get_registeredDevices()[0] i['dev_BogoMipsCapacity'] = i['dev'].query(prop)[0].value.value() # install first waveform self.assertEqual(len(domMgr._get_applicationFactories()), 0) self.assertEqual(len(domMgr._get_applications()), 0) domMgr.installApplication("/waveforms/CommandWrapperOneDep/CommandWrapper.sad.xml") self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) appFact = domMgr._get_applicationFactories()[0] app1 = appFact.create(appFact._get_name(), [], []) processIds = app1._get_componentProcessIds() componentProcessId = processIds[0].processId self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) # find which device manager it got installed on devMgrToKill = None devMgrToRelaunchOn = None if devInfo[0]['dev'].query(prop)[0].value.value() != devInfo[0]['dev_BogoMipsCapacity']: devMgrToKill = 0 devMgrToRelaunchOn = 1 elif devInfo[1]['dev'].query(prop)[0].value.value() != devInfo[1]['dev_BogoMipsCapacity']: devMgrToKill = 1 devMgrToRelaunchOn = 0 else: self.fail("Application didn't launch on either device manager") # kill the device on which the waveform was launched devs = getChildren(devInfo[devMgrToKill]['booter'].pid) self.assertEqual(len(devs), 1) try: os.kill(devs[0], signal.SIGKILL) os.waitpid(devs[0], 0) except OSError: pass # check to see if the app and it's components are released for x in range(10): # only try for 5 seconds if len(domMgr._get_applications()) > 0: time.sleep(0.5) self.assertEqual(len(domMgr._get_applications()), 0) # kill off remaining component process if it is still around try: os.kill(componentProcessId, signal.SIGKILL) except: pass
def test_HardFailDeviceManagerRestart(self): # test HardFail of a Device Manager and restart # - test that when a Device Manager fails hard (ex: seg fault or kill -9) # and then it is restarted that things still behave as expected domBooter, domMgr = self.launchDomainManager(debug=self.debuglevel) devBooterA, devMgrA = self.launchDeviceManager("/nodes/test_HardFail_nodeA/DeviceManager.dcd.xml", debug=self.debuglevel) devBooterB, devMgrB = self.launchDeviceManager("/nodes/test_HardFail_nodeB/DeviceManager.dcd.xml", debug=self.debuglevel) devInfo = [] devInfo.append({"booter":devBooterA, "mgr":devMgrA}) devInfo.append({"booter":devBooterB, "mgr":devMgrB}) # ensure both DeviceManagers were started self.assertEqual(len(domMgr._get_deviceManagers()), 2) # store original capacities of devices prop = [CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))] for i in devInfo: i['dev'] = i['mgr']._get_registeredDevices()[0] i['dev_BogoMipsCapacity'] = i['dev'].query(prop)[0].value.value() # install first waveform self.assertEqual(len(domMgr._get_applicationFactories()), 0) self.assertEqual(len(domMgr._get_applications()), 0) domMgr.installApplication("/waveforms/CommandWrapperOneDep/CommandWrapper.sad.xml") self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) appFact = domMgr._get_applicationFactories()[0] app1 = appFact.create(appFact._get_name(), [], []) self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) # find which device manager it got installed on devMgrToKill = None devMgrToRelaunchOn = None if devInfo[0]['dev'].query(prop)[0].value.value() != devInfo[0]['dev_BogoMipsCapacity']: devMgrToKill = 0 devMgrToRelaunchOn = 1 elif devInfo[1]['dev'].query(prop)[0].value.value() != devInfo[1]['dev_BogoMipsCapacity']: devMgrToKill = 1 devMgrToRelaunchOn = 0 else: self.fail("Application didn't launch on either device manager") # kill the device manager, devices, and components to simulate a hard failure killProcesses(devInfo[devMgrToKill]['booter'].pid) # at this point, the domain manager still thinks things are in good shape self.assertEqual(len(domMgr._get_applications()), 1) # relaunch device manager if devMgrToKill == 0: devBooterA, devMgrA = self.launchDeviceManager("/nodes/test_HardFail_nodeA/DeviceManager.dcd.xml", debug=self.debuglevel) devInfo[0]['booter'] = devBooterA devInfo[0]['mgr'] = devMgrA else: devBooterB, devMgrB = self.launchDeviceManager("/nodes/test_HardFail_nodeB/DeviceManager.dcd.xml", debug=self.debuglevel) devInfo[1]['booter'] = devBooterB devInfo[1]['mgr'] = devMgrB # stale app should have been cleaned up self.assertEqual(len(domMgr._get_applications()), 0)
def test_HardFailDeviceManager(self): # test HardFail of a Device Manager # - test that when a Device Manager fails hard (ex: seg fault or kill -9) # that things still behave as expected domBooter, domMgr = self.launchDomainManager(debug=self.debuglevel) devBooterA, devMgrA = self.launchDeviceManager("/nodes/test_HardFail_nodeA/DeviceManager.dcd.xml", debug=self.debuglevel) devBooterB, devMgrB = self.launchDeviceManager("/nodes/test_HardFail_nodeB/DeviceManager.dcd.xml", debug=self.debuglevel) devInfo = [] devInfo.append({"booter":devBooterA, "mgr":devMgrA}) devInfo.append({"booter":devBooterB, "mgr":devMgrB}) # ensure both DeviceManagers were started self.assertEqual(len(domMgr._get_deviceManagers()), 2) # store original capacities of devices prop = [CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))] for i in devInfo: i['dev'] = i['mgr']._get_registeredDevices()[0] i['dev_BogoMipsCapacity'] = i['dev'].query(prop)[0].value.value() # install first waveform self.assertEqual(len(domMgr._get_applicationFactories()), 0) self.assertEqual(len(domMgr._get_applications()), 0) domMgr.installApplication("/waveforms/CommandWrapperOneDep/CommandWrapper.sad.xml") self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) appFact = domMgr._get_applicationFactories()[0] app1 = appFact.create(appFact._get_name(), [], []) self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) # find which device manager it got installed on devMgrToKill = None devMgrToRelaunchOn = None if devInfo[0]['dev'].query(prop)[0].value.value() != devInfo[0]['dev_BogoMipsCapacity']: devMgrToKill = 0 devMgrToRelaunchOn = 1 elif devInfo[1]['dev'].query(prop)[0].value.value() != devInfo[1]['dev_BogoMipsCapacity']: devMgrToKill = 1 devMgrToRelaunchOn = 0 else: self.fail("Application didn't launch on either device manager") # get the DeviceManager's children, so we can clean up devMgr_children = getChildren(devInfo[devMgrToKill]['booter'].pid) # kill the Device Manager on which the waveform was launched try: os.kill(devInfo[devMgrToKill]['booter'].pid, signal.SIGKILL) os.waitpid(devInfo[devMgrToKill]['booter'].pid, 0) except OSError: pass # try to release the waveform from the dead device manager try: app1.stop() except CF.Resource.StopError, msg: self.fail("application->stop() should work here; failed with message: " + msg)
def test_HardFailComponent(self): # test HardFail of the component(s) in and application # - test that when a component fails hard (ex: seg fault or kill -9) # that things still behave as expected domBooter, domMgr = self.launchDomainManager(debug=self.debuglevel) devBooterA, devMgrA = self.launchDeviceManager("/nodes/test_HardFail_nodeA/DeviceManager.dcd.xml", debug=self.debuglevel) devBooterB, devMgrB = self.launchDeviceManager("/nodes/test_HardFail_nodeB/DeviceManager.dcd.xml", debug=self.debuglevel) devInfo = [] devInfo.append({"booter":devBooterA, "mgr":devMgrA}) devInfo.append({"booter":devBooterB, "mgr":devMgrB}) # ensure both DeviceManagers were started self.assertEqual(len(domMgr._get_deviceManagers()), 2) # store original capacities of devices prop = [CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))] for i in devInfo: i['dev'] = i['mgr']._get_registeredDevices()[0] i['dev_BogoMipsCapacity'] = i['dev'].query(prop)[0].value.value() # install first waveform self.assertEqual(len(domMgr._get_applicationFactories()), 0) self.assertEqual(len(domMgr._get_applications()), 0) domMgr.installApplication("/waveforms/CommandWrapperOneDep/CommandWrapper.sad.xml") self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) appFact = domMgr._get_applicationFactories()[0] app1 = appFact.create(appFact._get_name(), [], []) self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) # find which device manager it got installed on devMgrToKill = None devMgrToRelaunchOn = None if devInfo[0]['dev'].query(prop)[0].value.value() != devInfo[0]['dev_BogoMipsCapacity']: devMgrToKill = 0 devMgrToRelaunchOn = 1 elif devInfo[1]['dev'].query(prop)[0].value.value() != devInfo[1]['dev_BogoMipsCapacity']: devMgrToKill = 1 devMgrToRelaunchOn = 0 else: self.fail("Application didn't launch on either device manager") # find & kill the component which is part of the waveform that was launched devs = getChildren(devInfo[devMgrToKill]['booter'].pid) self.assertEqual(len(devs), 1) comps = getChildren(devs[0]) self.failIf(len(comps) < 1, "Should be at least one component in the waveform") try: os.kill(comps[0], signal.SIGKILL) os.waitpid(comps[0], 0) except OSError: pass # try to stop & release the waveform self.assertRaises(CF.Resource.StopError, app1.stop) # expect not to work - AC is dead try: app1.releaseObject() except: self.fail("application->releaseObject should work here") self.assertEqual(len(domMgr._get_applications()), 0) # make sure capacity was deallocated self.assertEqual(devInfo[devMgrToKill]['dev'].query(prop)[0].value.value(), devInfo[devMgrToKill]['dev_BogoMipsCapacity'])
def testSRI(self): self.connectOutputData() self.pushSriBigEndian( xdelta=.0001, mode=1, streamID="testSRIStream", kw=[ CF.DataType("COL_RF", ossie.properties.to_tc_value(100000000, 'double')) ]) attachId = self.callAttach(True, 0) self.comp.start() sri = self.dataSink.sri() self.assertEqual(sri.streamID, "testSRIStream") self.assertEqual(sri.xdelta, .0001) self.assertEqual(sri.mode, 1) expectedkws = [ CF.DataType("dataRef", ossie.properties.to_tc_value(BIG_ENDIAN, 'string')), CF.DataType("COL_RF", ossie.properties.to_tc_value(100000000, 'double')) ] for expectedkw in expectedkws: found = False for keyword in sri.keywords: if expectedkw.id == keyword.id: found = True self.assertEqual(expectedkw.value.value(), keyword.value.value()) break self.assertEqual(found, True) #Change SRI and see if changed on output self.pushSriBigEndian( xdelta=.01, mode=0, streamID="testSRIStream", kw=[ CF.DataType("COL_RF", ossie.properties.to_tc_value(100000000, 'double')) ]) time.sleep(.5) sri = self.dataSink.sri() self.assertEqual(sri.streamID, "testSRIStream") self.assertEqual(sri.xdelta, .01) self.assertEqual(sri.mode, 0) # Update just a keyword self.pushSriBigEndian( xdelta=.01, mode=0, streamID="testSRIStream", kw=[ CF.DataType("COL_RF", ossie.properties.to_tc_value(200000000, 'double')) ]) time.sleep(.5) sri = self.dataSink.sri() expectedkws = [ CF.DataType("dataRef", ossie.properties.to_tc_value(BIG_ENDIAN, 'string')), CF.DataType("COL_RF", ossie.properties.to_tc_value(200000000, 'double')) ] for expectedkw in expectedkws: found = False for keyword in sri.keywords: if expectedkw.id == keyword.id: found = True self.assertEqual(expectedkw.value.value(), keyword.value.value()) break self.assertEqual(found, True) self.input_vita49_port.detach(attachId)
def query(self, configProperties): self.propertySetAccess.acquire() # If the list is empty, get all props if configProperties == []: self._log.trace("query all properties") try: rv = [] for propid in self._props.keys(): if self._props.has_id(propid) and self._props.isQueryable( propid): try: value = self._props.query(propid) except Exception, e: self._log.error('Failed to query %s: %s', propid, e) value = any.to_any(None) prp = self._props.getPropDef(propid) if type(prp) == ossie.properties.struct_property: newvalval = [] for v in value.value(): if prp.fields[v.id][1].optional == True: if isinstance(v.value.value(), list): if v.value.value() != []: newvalval.append(v) else: if v.value.value() != None: newvalval.append(v) else: newvalval.append(v) value = CORBA.Any(value.typecode(), newvalval) rv.append(CF.DataType(propid, value)) except: self.propertySetAccess.release() raise # otherwise get only the requested ones else: self._log.trace("query %s properties", len(configProperties)) try: unknownProperties = [] for prop in configProperties: if self._props.has_id(prop.id) and self._props.isQueryable( prop.id): try: prop.value = self._props.query(prop.id) except Exception, e: self._log.error('Failed to query %s: %s', prop.id, e) prp = self._props.getPropDef(prop.id) if type(prp) == ossie.properties.struct_property: newvalval = [] for v in prop.value.value(): if prp.fields[v.id][1].optional == True: if isinstance(v.value.value(), list): if v.value.value() != []: newvalval.append(v) else: if v.value.value() != None: newvalval.append(v) else: newvalval.append(v) prop.value = CORBA.Any(prop.value.typecode(), newvalval) else: self._log.warning( "property %s cannot be queried. valid Id: %s", prop.id, self._props.has_id(prop.id)) unknownProperties.append(prop) except: self.propertySetAccess.release() raise if len(unknownProperties) > 0: self._log.warning("query called with invalid properties %s", unknownProperties) self.propertySetAccess.release() raise CF.UnknownProperties(unknownProperties) rv = configProperties self.propertySetAccess.release() self._log.trace("query -> %s properties", len(rv)) return rv
def addKeyword(kwds, key, value): kwds.append(CF.DataType(key, any.to_any(value)))
def registerPropertyListener(self, listener, prop_ids, interval): self._log.trace("registerPropertyListener(%s)", prop_ids) self.propertySetAccess.acquire() unknownProperties = [] # list of properties with unknown ids props = {} # maps of callbacks to property ids # If the list is empty, get all props if prop_ids == []: self._log.trace("registering all properties") for propid in self._props.keys(): if self._props.has_id(propid) and self._props.isQueryable( propid): props[propid] = _PCL_Monitor() else: self._log.trace("registering %s properties", len(prop_ids)) for pid in prop_ids: if self._props.has_id(pid) and self._props.isQueryable(pid): props[pid] = _PCL_Monitor() else: value = any.to_any(None) unknownProperties.append(CF.DataType(pid, value)) if len(unknownProperties) > 0: self._log.warning( "registerPropertyListener, called with invalid properties %s", unknownProperties) self.propertySetAccess.release() raise CF.UnknownProperties(unknownProperties) pcl = None is_ec = False try: self._log.debug( "registerPropertyListener, Registering Event Channel...") pcl = _EC_PropertyChangeListener(listener) is_ec = True except: pcl = None self._log.debug( "registerPropertyListener, Try for PropertyChangeListener next..." ) if is_ec == False: try: self._log.debug( "registerPropertyListener, Trying PropertyChangeListener interface..." ) pcl = _INF_PropertyChangeListener(listener) except: pcl = None self._log.warning( "registerPropertyListener, Caller provided invalid registrant." ) self.propertySetAccess.release() raise CF.InvalidObjectReference( "registerPropertyListener, Caller provided invalid registrant." ) # create/add registration record rec = _PropertyChangeRec(self, listener, pcl, props, interval) reg_id = rec.regId self._props.addChangeListener(rec.callback) self._propChangeRegistry[reg_id] = rec self._log.debug("registerPropertyListener .. reg_id/interval: " + str(reg_id) + "/" + str(rec.reportInterval) + " callback: " + str(self._propChangeRegistry[reg_id].callback)) # start if self._propChangeThread and self._propChangeThread.isRunning( ) == False: self._log.debug( "registerPropertyListener Starting PROPERTY CHANGE THREAD ... resource/reg_id: " + str(self._name) + "/" + str(reg_id)) self._propChangeThread.startThread() self.propertySetAccess.release() return reg_id
def test_BasicOperation(self): nodebooter, domMgr = self.launchDomainManager(debug=9) self.assertNotEqual(domMgr, None) self.assertEqual(len(domMgr._get_applicationFactories()), 0) self.assertEqual(len(domMgr._get_applications()), 0) domMgr.installApplication( "/waveforms/CommandWrapper/CommandWrapper.sad.xml") self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) # Load on the device ID das = minidom.parse( os.path.join( scatest.getSdrPath(), "dom/waveforms/CommandWrapper/CommandWrapper_DAS.xml")) ds = [] deviceAssignmentTypeNodeList = das.getElementsByTagName( "deviceassignmenttype") for node in deviceAssignmentTypeNodeList: componentid = node.getElementsByTagName( "componentid")[0].firstChild.data assigndeviceid = node.getElementsByTagName( "assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid), str(assigndeviceid))) # Ensure the expected device is available nodebooter, devMgr = self.launchDeviceManager( dcdFile="/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) self.assertEqual(len(ds), 1) self.assertEqual(len(devMgr._get_registeredDevices()), 1) device = devMgr._get_registeredDevices()[0] self.assertEqual(device._get_identifier(), ds[0].assignedDeviceId) # Query the known allocation properties memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) # query all properties, make sure that only 'external' properties show up allProps = device.query([]) # convert props to a dict allProps = dict([(x.id, x.value) for x in allProps]) # This isn't all of them...but a fair amount self.assertEqual( allProps.has_key("DCE:4a23ad60-0b25-4121-a630-68803a498f75"), False) # os_name self.assertEqual( allProps.has_key("DCE:fefb9c66-d14a-438d-ad59-2cfd1adb272b"), False) # processor_name self.assertEqual( allProps.has_key("DCE:7f36cdfb-f828-4e4f-b84f-446e17f1a85b"), False) # DeviceKind self.assertEqual( allProps.has_key("DCE:64303822-4c67-4c04-9a5c-bf670f27cf39"), False) # RunsAs self.assertEqual( allProps.has_key("DCE:021f10cf-7a05-46ec-a507-04b513b84bd4"), False) # HasXMIDAS appFact = domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], ds) self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 1) self.assertEqual(app._get_started(), False) app.start() self.assertEqual(app._get_started(), True) # Verify that capacity was allocated memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000 - 5000) self.assertEqual(bogoMips.value._v, 100000000 - 1000) app.stop() self.assertEqual(app._get_started(), False) app.releaseObject() self.assertEqual(len(domMgr._get_applicationFactories()), 1) self.assertEqual(len(domMgr._get_applications()), 0) # Verify that capacity was deallocated memCapacity = device.query([ CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None)) ])[0] bogoMips = device.query([ CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None)) ])[0] self.assertEqual(memCapacity.value._v, 100000000) self.assertEqual(bogoMips.value._v, 100000000) domMgr.uninstallApplication(appFact._get_identifier())
def _propertyChangeServiceFunction(self): self._log.debug("_propertyChangeServiceFunction - START") delay = 0.0 now = time.time() self.propertySetAccess.acquire() try: self._log.debug( "_propertyChangeServiceFunction - checking registry.... " + str(len(self._propChangeRegistry))) for regid, rec in self._propChangeRegistry.iteritems(): # process changes for each property for k, p in rec.props.iteritems(): self._log.debug( "_propertyChangeServiceFunction - prop/set. " + str(k) + "/" + str(p.isSet())) try: if self._propMonitors[k].isChanged(): p.recordChanged() self._log.debug( "_propertyChangeServiceFunction - prop/changed. " + str(k) + "/" + str(self._propMonitors[k].isChanged())) except Exception, e: pass # check if time expired dur = rec.expiration - now if dur <= 0.0: rpt_props = [] idx = 0 # process changes for each property for k, p in rec.props.iteritems(): self._log.debug( "_propertyChangeServiceFunction - prop/set. " + str(k) + "/" + str(p.isSet())) if p.isChanged() == True: try: value = self._props.query(k) rpt_props.append(CF.DataType(k, value)) except: pass p.reset() if len(rpt_props) > 0 and rec.pcl: try: self._log.debug( "_propertyChangeServiceFunction - sending notification reg_id:" + str(regid)) if rec.pcl.notify(rec, rpt_props) != 0: self._log.error( "Publishing changes to PropertyChangeListener FAILED, reg_id:" + str(regid)) except: pass rec.expiration = time.time() + rec.reportInterval dur = rec.reportInterval if delay == 0.0: delay = dur if dur > 0: delay = min(delay, dur) self._log.debug("_propertyChangeServiceFunction - delay :" + str(delay)) except: pass # reset monitor's state if len(self._propChangeRegistry) > 0: for k, mon in self._propMonitors.iteritems(): mon.reset() self._log.debug( "_propertyChangeServiceFunction - adjust thread delay :" + str(delay)) if delay > 0: self._propChangeThread.setThreadDelay(delay) self.propertySetAccess.release() self._log.debug("_propertyChangeServiceFunction - STOP") return -1
def testSendDataLittleEndianSF(self): self.connectOutputData(portName= "dataFloat_out") attachId = self.callAttach(True,2) self.pushSriLittleEndian(xdelta=1.0/10000,mode=1,streamID="testSendDataSF", kw=[CF.DataType("COL_RF", ossie.properties.to_tc_value(100000000, 'double'))]) self.comp.start() time.sleep(1) v49 = self.createVITA49Data(streamID="testSendDataSF",format=VITA49.DATA_FORMATS.SF,vector_size=self.vector_size) self.sendDataandCheck(v49, littleEndianPayload=True) print "****Send Detach " self.input_vita49_port.detach(attachId)
def getPropertySet(self, kinds=("configure",), \ modes=("readwrite", "writeonly", "readonly"), \ action="external", \ includeNil=True): """ A useful utility function that extracts specified property types from the PRF file and turns them into a CF.PropertySet """ propertySet = [] # Simples for prop in self.prf.get_simple(): if self.isMatch(prop, modes, kinds, (action, )): if prop.get_value() is not None: if prop.complex.lower() == "true": type = mapComplexType(prop.get_type()) value = stringToComplex(prop.get_value(), type) else: type = prop.get_type() value = prop.get_value() dt = properties.to_tc_value(value, type) elif not includeNil: continue else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Simple Sequences for prop in self.prf.get_simplesequence(): if self.isMatch(prop, modes, kinds, (action, )): if prop.get_values() is not None: seq = [] if prop.complex.lower() == "true": type = mapComplexType(prop.get_type()) for v in prop.get_values().get_value(): seq.append(stringToComplex(v, type)) expectedType = properties.getTypeCode(type) expectedTypeCode = tcInternal.createTypeCode( (tcInternal.tv_sequence, expectedType._d, 0)) dt = CORBA.Any(expectedTypeCode, [ properties._convertComplexToCFComplex(item, type) for item in seq ]) else: type = prop.get_type() for v in prop.get_values().get_value(): value = v seq.append(properties.to_pyvalue(value, type)) dt = any.to_any(seq) elif not includeNil: continue else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Structures for prop in self.prf.get_struct(): if self.isMatch(prop, modes, kinds, (action, )): if prop.get_simple() is not None: fields = [] hasValue = False for s in prop.get_simple(): if s.get_value() is not None: hasValue = True dt = properties.to_tc_value(s.get_value(), s.get_type()) fields.append(CF.DataType(id=str(s.get_id()), value=dt)) if not hasValue and not includeNil: continue dt = any.to_any(fields) else: dt = any.to_any(None) p = CF.DataType(id=str(prop.get_id()), value=dt) propertySet.append(p) # Structures for prop in self.prf.get_structsequence(): if self.isMatch(prop, modes, kinds, (action, )): baseProp = [] if prop.get_struct() != None: fields = [] for internal_prop in prop.get_struct().get_simple(): fields.append( CF.DataType(id=str(internal_prop.get_id()), value=any.to_any(None))) for val in prop.get_structvalue(): baseProp.append(copy.deepcopy(fields)) for entry in val.get_simpleref(): val_type = None for internal_prop in prop.get_struct().get_simple(): if str(internal_prop.get_id()) == entry.refid: val_type = internal_prop.get_type() for subfield in baseProp[-1]: if subfield.id == entry.refid: subfield.value = properties.to_tc_value( entry.get_value(), val_type) anybp = [] for bp in baseProp: anybp.append(properties.props_to_any(bp)) p = CF.DataType(id=str(prop.get_id()), value=any.to_any(anybp)) propertySet.append(p) # Struct Sequence return propertySet
def hdr_to_sri(hdr, stream_id): """ Generates a StreamSRI object based on the information contained in the X-Midas header file. Inputs: <hdr> The X-Midas header file <stream_id> The stream id Output: Returns a BULKIO.StreamSRI object """ hversion = 1 xstart = hdr['xstart'] xdelta = hdr['xdelta'] xunits = hdr['xunits'] data_type = hdr['type'] data_format = hdr['format'] # The subsize needs to be 0 if one-dimensional or > 0 otherwise so # using the data type to find out if data_type == 1000: subsize = 0 ystart = 0 ydelta = 0 yunits = BULKIO.UNITS_NONE else: subsize = hdr['subsize'] ystart = hdr['ystart'] ydelta = hdr['ydelta'] yunits = hdr['yunits'] # The mode is based on the data type: 0 if is Scalar or 1 if it is # Complex. Setting it to -1 for any other type if data_format.startswith('S'): mode = 0 elif data_format.startswith('C'): mode = 1 else: mode = -1 kwds = [] # Getting all the items in the extended header if hdr.has_key('ext_header'): ext_hdr = hdr['ext_header'] if isinstance(ext_hdr, dict): for key, value in ext_hdr.iteritems(): try: data = item[1] if isinstance(item[1], numpy.generic): data = item[1].item() dt = CF.DataType( key, ossie.properties.numpy_to_tc_value( data, type(item[1]).__name__)) #print "DEBUG (dict) AFTER dt.value:", dt.value, dt.value.value(), type(dt.value.value()) kwds.append(dt) except: continue elif isinstance(ext_hdr, list): for item in ext_hdr: try: data = item[1] if isinstance(item[1], numpy.generic): data = item[1].item() dtv = ossie.properties.numpy_to_tc_value( data, type(item[1]).__name__) dt = CF.DataType(item[0], dtv) #print "DEBUG (list) AFTER dt.value:", dt.value, dt.value.value(), type(dt.value.value()) kwds.append(dt) except Exception, e: continue
def test_BasicOperation(self): self._nb_domMgr, self._domMgr = self.launchDomainManager(endpoint="giop:tcp::5679", dbURI=self._dbfile) self._nb_devMgr, devMgr = self.launchDeviceManager("/nodes/test_PortTestDevice_node/DeviceManager.dcd.xml") self._fileMgr = self._domMgr._get_fileMgr() self._files = self._fileMgr.list("/") self.assertEqual(len(self._domMgr._get_applicationFactories()), 0) self.assertEqual(len(self._domMgr._get_applications()), 0) self._domMgr.installApplication("/waveforms/PortConnectProvidesPort/PortConnectProvidesPort.sad.xml") self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Load on the device ID das = minidom.parse(os.path.join(scatest.getSdrPath(), "dom/waveforms/PortConnectProvidesPort/PortConnectProvidesPort_DAS.xml")) ds = [] deviceAssignmentTypeNodeList = das.getElementsByTagName("deviceassignmenttype") for node in deviceAssignmentTypeNodeList: componentid = node.getElementsByTagName("componentid")[0].firstChild.data assigndeviceid = node.getElementsByTagName("assigndeviceid")[0].firstChild.data ds.append( CF.DeviceAssignmentType(str(componentid),str(assigndeviceid)) ) # Ensure the expected device is available self.assertNotEqual(devMgr, None) self.assertEqual(len(devMgr._get_registeredDevices()), 2) device1 = None device2 = None for dev in devMgr._get_registeredDevices(): if dev._get_identifier() == "DCE:322fb9b2-de57-42a2-ad03-217bcb244262": device1 = dev elif dev._get_identifier() == "DCE:47dc45d8-19b5-4b7e-bcd4-b165babe5b84": device2 = dev self.assertNotEqual(device1, None) self.assertNotEqual(device2, None) # Query the known allocation properties memCapacity1 = device1.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips1 = device1.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity1.value._v, 100000000) self.assertEqual(bogoMips1.value._v, 100000000) memCapacity2 = device2.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips2 = device2.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity2.value._v, 100000000) self.assertEqual(bogoMips2.value._v, 100000000) appFact = self._domMgr._get_applicationFactories()[0] app = appFact.create(appFact._get_name(), [], ds) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 1) app = self._domMgr._get_applications()[0] # cache off some variables for later for testing purposes self.assertEqual(len(app._get_componentNamingContexts()), 2) self.assertEqual(len(app._get_componentProcessIds()), 2) self.assertEqual(len(app._get_componentDevices()), 4) self.assertEqual(len(app._get_componentImplementations()), 2) origNamingContexts = app._get_componentNamingContexts() origProcessIds = app._get_componentProcessIds() origDevices = app._get_componentDevices() origImplementations = app._get_componentImplementations() origQuery = app.query([]) # Verify that capacity was allocated memCapacity1 = device1.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips1 = device1.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity1.value._v, 100000000-(5000)) self.assertEqual(bogoMips1.value._v, 100000000-(1000)) memCapacity2 = device2.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips2 = device2.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity2.value._v, 100000000-(5000)) self.assertEqual(bogoMips2.value._v, 100000000-(1000)) # Kill the domainMgr os.kill(self._nb_domMgr.pid, signal.SIGTERM) # TODO if SIGKILL is used (simulating a nodeBooter unexpected abort, # the IOR and the newly spawned domain manager do not work if not self.waitTermination(self._nb_domMgr): self.fail("Domain Manager Failed to Die") # Start the domainMgr again self._nb_domMgr, newDomMgr = self.launchDomainManager(endpoint="giop:tcp::5679", dbURI=self._dbfile) # Verify our client reference still is valid newDomMgr._get_identifier() self.assertEqual(False, newDomMgr._non_existent()) #self.assertEqual(self._orb.object_to_string(newDomMgr), self._orb.object_to_string(self._domMgr)) self.assertEqual(False, self._domMgr._non_existent()) # Verify that the file manager is still valid self.new_files = self._fileMgr.list("/") self.assertEqual(len(self._files), len(self.new_files)) self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) newDevMgr = self._domMgr._get_deviceManagers()[0] self.assertEqual(self._orb.object_to_string(devMgr), self._orb.object_to_string(newDevMgr)) self.assertEqual(len(devMgr._get_registeredDevices()), 2) newDevice1 = None newDevice2 = None for dev in devMgr._get_registeredDevices(): if dev._get_identifier() == "DCE:322fb9b2-de57-42a2-ad03-217bcb244262": newDevice1 = dev elif dev._get_identifier() == "DCE:47dc45d8-19b5-4b7e-bcd4-b165babe5b84": newDevice2 = dev self.assertNotEqual(newDevice1, None) self.assertNotEqual(newDevice2, None) self.assertEqual(self._orb.object_to_string(device1), self._orb.object_to_string(newDevice1)) self.assertEqual(self._orb.object_to_string(device2), self._orb.object_to_string(newDevice2)) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) newAppFact = self._domMgr._get_applicationFactories()[0] self.assertEqual(appFact._get_identifier(), newAppFact._get_identifier()); self.assertEqual(appFact._get_name(), newAppFact._get_name()); self.assertEqual(len(self._domMgr._get_applications()), 1) newApp = self._domMgr._get_applications()[0] # Applications are currently not using persistent POAs, so the IORs will change # self.assertEqual(self._orb.object_to_string(app), self._orb.object_to_string(newApp)) newNamingContexts = app._get_componentNamingContexts() newProcessIds = app._get_componentProcessIds() newDevices = app._get_componentDevices() newImplementations = app._get_componentImplementations() # We have to compare elements individually since newDevices == origDevices even when the contents are identical self.assertEqual(len(newDevices), len(origDevices)) for x in xrange(len(newDevices)): self.assertEqual(newDevices[x].componentId, origDevices[x].componentId) self.assertEqual(newDevices[x].assignedDeviceId, origDevices[x].assignedDeviceId) self.assertEqual(len(newProcessIds), len(origProcessIds)) for x in xrange(len(newProcessIds)): self.assertEqual(newProcessIds[x].componentId, origProcessIds[x].componentId) self.assertEqual(newProcessIds[x].processId, origProcessIds[x].processId) self.assertEqual(len(newImplementations), len(origImplementations)) for x in xrange(len(newImplementations)): self.assertEqual(newImplementations[x].componentId, origImplementations[x].componentId) self.assertEqual(newImplementations[x].elementId, origImplementations[x].elementId) self.assertEqual(len(newNamingContexts), len(origNamingContexts)) for x in xrange(len(newNamingContexts)): self.assertEqual(newNamingContexts[x].componentId, origNamingContexts[x].componentId) self.assertEqual(newNamingContexts[x].elementId, origNamingContexts[x].elementId) # Verify that the connection between the CF::Application and the assemblyController was # restored. newQuery = app.query([]) self.assertEqual(len(newQuery), len(origQuery)) for x in xrange(len(newQuery)): self.assertEqual(newQuery[x].id, origQuery[x].id) self.assertEqual(newQuery[x].value._v, origQuery[x].value._v) # app.stop() app.releaseObject() # TODO how can we verify that the ports were disconnected as part of release? time.sleep(1) self.assertEqual(len(self._domMgr._get_applicationFactories()), 1) self.assertEqual(len(self._domMgr._get_applications()), 0) # Verify that capacity was deallocated memCapacity1 = device1.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips1 = device1.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity1.value._v, 100000000) self.assertEqual(bogoMips1.value._v, 100000000) memCapacity2 = device2.query([CF.DataType(id="DCE:8dcef419-b440-4bcf-b893-cab79b6024fb", value=any.to_any(None))])[0] bogoMips2 = device2.query([CF.DataType(id="DCE:5636c210-0346-4df7-a5a3-8fd34c5540a8", value=any.to_any(None))])[0] self.assertEqual(memCapacity2.value._v, 100000000) self.assertEqual(bogoMips2.value._v, 100000000) newDevMgr.shutdown() self.assertEqual(len(self._domMgr._get_deviceManagers()), 0) self._domMgr.uninstallApplication(appFact._get_identifier()) self.assertEqual(len(self._domMgr._get_applicationFactories()), 0)
def testNonConformingConformingSwitch(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') compDataSddsIn = self.comp.getPort('dataSddsIn') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.start() # Create data fakeData = [x for x in range(0, 512)] pktNum = 0 sr=1e6 xdelta_ns=int(1/(sr*2) * 1e9) time_ns=0 recSRI = False # No time slips here while pktNum < 100: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4), CX=1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!") # Stop the component, detach, then re-attach a new stream that is using the conforming sampleRate self.comp.stop() compDataSddsIn.detach(self.attachId) kw = [CF.DataType("dataRef", ossie.properties.to_tc_value(BIG_ENDIAN, 'long'))] sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.0, xunits=1, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=0, streamID='TestStreamID2', blocking=False, keywords=kw) compDataSddsIn.pushSRI(sri,timestamp.now()) streamDef = BULKIO.SDDSStreamDefinition('id2', BULKIO.SDDS_SI, self.uni_ip, 0, self.port, 8000, True, 'testing') self.attachId = compDataSddsIn.attach(streamDef, 'test') self.comp.start() # Create data fakeData = [x for x in range(0, 512)] pktNum = 0 sr=1e6 xdelta_ns=int(1/(sr) * 1e9) time_ns=0 recSRI = False # No time slips here while pktNum < 100: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4), CX=1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!")
def test_AllocateCapacities(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_AllocateBasicDevice_python_node/DeviceManager.dcd.xml", debug=2) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 self.assertEqual(len(devMgr._get_registeredDevices()), 1) device = devMgr._get_registeredDevices()[0] self.assertNotEqual(device, None) mem_id = 'DCE:7aeaace8-350e-48da-8d77-f97c2e722e06' bog_id = 'DCE:bbdf708f-ce05-469f-8aed-f5c93e353e14' # first we don't have the properties set result = device.query([]) for prop in result: self.assertEqual(prop.value._v, None) # Set the BasicTestDevice to have 2048 MB of memory capacity and 1024 # BogoMips. Attempting to allocate more than that it raises an error # at the BasicTestDevice level props = [ CF.DataType(id=mem_id, value=any.to_any(1024)), CF.DataType(id=bog_id, value=any.to_any(512)) ] # allocating half of maximum capacity device.allocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 1024) elif prop.id == bog_id: self.assertEqual(prop.value._v, 512) else: self.assertTrue(False) # allocating full capacity device.allocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 2048) elif prop.id == bog_id: self.assertEqual(prop.value._v, 1024) else: self.assertTrue(False) # exceeding capacity props = [ CF.DataType(id=mem_id, value=any.to_any(1)), CF.DataType(id=bog_id, value=any.to_any(0)) ] device.allocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 2048) elif prop.id == bog_id: self.assertEqual(prop.value._v, 1024) else: self.assertTrue(False) # deallocating capacity props = [ CF.DataType(id=mem_id, value=any.to_any(1024)), CF.DataType(id=bog_id, value=any.to_any(512)) ] device.deallocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 1024) elif prop.id == bog_id: self.assertEqual(prop.value._v, 512) else: self.assertTrue(False) # allocating capacity props = [ CF.DataType(id=mem_id, value=any.to_any(1025)), CF.DataType(id=bog_id, value=any.to_any(512)) ] # exceeding capacity so no changes should occur device.allocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 1024) elif prop.id == bog_id: self.assertEqual(prop.value._v, 512) else: self.assertTrue(False)
def test_pythonPropsRangeStruct(self): self._app = self._launchApp('TestPythonPropsRange') # Test upper bounds my_struct = CF.DataType(id='my_struct', value=any.to_any([ CF.DataType(id='struct_octet', value=CORBA.Any(CORBA.TC_long, 255)), CF.DataType(id='struct_short', value=CORBA.Any(CORBA.TC_long, 32767)), CF.DataType(id='struct_ushort', value=CORBA.Any(CORBA.TC_long, 65535)), CF.DataType(id='struct_long', value=CORBA.Any(CORBA.TC_longlong, 2147483647)), CF.DataType(id='struct_ulong', value=CORBA.Any(CORBA.TC_longlong, 4294967295)), CF.DataType(id='struct_longlong', value=CORBA.Any(CORBA.TC_longlong, 9223372036854775807L)), CF.DataType(id='struct_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 18446744073709551615L)) ])) self._app.configure([my_struct]) res = self._app.query([]) for r in res: if r.id == 'my_struct': val = r.value.value() for v in val: if v.id == 'struct_octet': self.assertEquals(v.value.value(), 255) elif v.id == 'struct_short': self.assertEquals(v.value.value(), 32767) elif v.id == 'struct_ushort': self.assertEquals(v.value.value(), 65535) elif v.id == 'struct_long': self.assertEquals(v.value.value(), 2147483647) elif v.id == 'struct_ulong': self.assertEquals(v.value.value(), 4294967295) elif v.id == 'struct_longlong': self.assertEquals(v.value.value(), 9223372036854775807L) elif v.id == 'struct_ulonglong': self.assertEquals(v.value.value(), 18446744073709551615L) # Test lower bounds my_struct = CF.DataType(id='my_struct', value=any.to_any([ CF.DataType(id='struct_octet', value=CORBA.Any(CORBA.TC_long, 0)), CF.DataType(id='struct_short', value=CORBA.Any(CORBA.TC_long, -32768)), CF.DataType(id='struct_ushort', value=CORBA.Any(CORBA.TC_long, 0)), CF.DataType(id='struct_long', value=CORBA.Any(CORBA.TC_longlong, -2147483648)), CF.DataType(id='struct_ulong', value=CORBA.Any(CORBA.TC_longlong, 0)), CF.DataType(id='struct_longlong', value=CORBA.Any(CORBA.TC_longlong, -9223372036854775808L)), CF.DataType(id='struct_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 0)) ])) self._app.configure([my_struct]) res = self._app.query([]) for r in res: if r.id == 'my_struct': val = r.value.value() for v in val: if v.id == 'struct_octet': self.assertEquals(v.value.value(), 0) elif v.id == 'struct_short': self.assertEquals(v.value.value(), -32768) elif v.id == 'struct_ushort': self.assertEquals(v.value.value(), 0) elif v.id == 'struct_long': self.assertEquals(v.value.value(), -2147483648) elif v.id == 'struct_ulong': self.assertEquals(v.value.value(), 0) elif v.id == 'struct_longlong': self.assertEquals(v.value.value(), -9223372036854775808L) elif v.id == 'struct_ulonglong': self.assertEquals(v.value.value(), 0) # Loop through each member of the struct to test one beyond the upper bound for r in res: if r.id == 'my_struct': val = r.value.value() for v in val: # All default values are valid octet_val = 0 short_val = 0 ushort_val = 0 long_val = 0 ulong_val = 0 longlong_val = 0 ulonglong_val = 0 # Creates struct with only 1 invalid member, which will still cause invalid configuration if v.id == 'struct_octet': octet_val = 256 elif v.id == 'struct_short': short_val = 32768 elif v.id == 'struct_ushort': ushort_val = 65536 elif v.id == 'struct_long': long_val = 2147483648 elif v.id == 'struct_ulong': ulong_val = 4294967296 elif v.id == 'struct_longlong': longlong_val = 9223372036854775808L elif v.id == 'struct_ulonglong': # No value large enough to test outside range of ulonglong continue my_struct = CF.DataType(id='my_struct', value=any.to_any([ CF.DataType(id='struct_octet', value=CORBA.Any(CORBA.TC_long, octet_val)), CF.DataType(id='struct_short', value=CORBA.Any(CORBA.TC_long, short_val)), CF.DataType(id='struct_ushort', value=CORBA.Any(CORBA.TC_long, ushort_val)), CF.DataType(id='struct_long', value=CORBA.Any(CORBA.TC_longlong, long_val)), CF.DataType(id='struct_ulong', value=CORBA.Any(CORBA.TC_longlong, ulong_val)), CF.DataType(id='struct_longlong', value=CORBA.Any(CORBA.TC_ulonglong, longlong_val)), CF.DataType(id='struct_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, ulonglong_val)) ])) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [my_struct]) # Loop through each member of the struct to test one beyond the lower bound for r in res: if r.id == 'my_struct': val = r.value.value() for v in val: # All default values are valid octet_val = 0 short_val = 0 ushort_val = 0 long_val = 0 ulong_val = 0 longlong_val = 0 ulonglong_val = 0 # Creates struct with only 1 invalid member, which will still cause invalid configuration if v.id == 'struct_octet': octet_val = -1 elif v.id == 'struct_short': short_val = -32769 elif v.id == 'struct_ushort': ushort_val = -1 elif v.id == 'struct_long': long_val = -2147483649 elif v.id == 'struct_ulong': ulong_val = -1 elif v.id == 'struct_longlong': # No value to test below range of longlong continue elif v.id == 'struct_ulonglong': ulonglong_val = -1 my_struct = CF.DataType(id='my_struct', value=any.to_any([ CF.DataType(id='struct_octet', value=CORBA.Any(CORBA.TC_long, octet_val)), CF.DataType(id='struct_short', value=CORBA.Any(CORBA.TC_long, short_val)), CF.DataType(id='struct_ushort', value=CORBA.Any(CORBA.TC_long, ushort_val)), CF.DataType(id='struct_long', value=CORBA.Any(CORBA.TC_longlong, long_val)), CF.DataType(id='struct_ulong', value=CORBA.Any(CORBA.TC_longlong, ulong_val)), CF.DataType(id='struct_longlong', value=CORBA.Any(CORBA.TC_ulonglong, longlong_val)), CF.DataType(id='struct_ulonglong', value=CORBA.Any(CORBA.TC_longlong, ulonglong_val)) ])) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [my_struct])
class DeviceManagerTest(scatest.CorbaTestCase): def setUp(self): nodebooter, self._domMgr = self.launchDomainManager(debug=9) self._domBooter = nodebooter def tearDown(self): scatest.CorbaTestCase.tearDown(self) killChildProcesses(os.getpid()) def test_CleanShutDown(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 devMgr.shutdown() self.assert_(self.waitTermination(devmgr_nb), "Nodebooter did not die after shutdown") self.assertEqual(len(self._domMgr._get_deviceManagers()), 0) def test_BadReleaseShutDown(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BadReleaseDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 5) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 try: devMgr.shutdown() except: self.assertEqual(True, False) else: self.assertEqual(True, True) self.assert_(self.waitTermination(devmgr_nb), "Nodebooter did not die after shutdown") self.assertEqual(len(self._domMgr._get_deviceManagers()), 0) def test_deadDeviceShutdownNode(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_SelfTerminatingDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) devs = devMgr._get_registeredDevices() devs[0].start() time.sleep(0.5) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 devMgr.shutdown() self.assert_(self.waitTermination(devmgr_nb), "Nodebooter did not die after shutdown") self.assertEqual(len(self._domMgr._get_deviceManagers()), 0) def test_deadDeviceManager(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_SelfTerminatingDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) devs = devMgr._get_registeredDevices() pids = getChildren(os.getpid()) devMgrPid = 0 for entry in pids: tmp_pids = getChildren(entry) if len(tmp_pids) > 0: devMgrPid = entry self.assertNotEqual(devMgrPid, 0) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 devMgr.shutdown() time.sleep(0.5) self.assertNotEqual(devmgr_nb.poll(), None, "Nodebooter did not die after shutdown") def test_CatatrophicUnregister(self): # Test that if a device manager dies unexpectedly and then re-registers there are no problems devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_SelfTerminatingDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) devs = devMgr._get_registeredDevices() pids = getChildren(devmgr_nb.pid) for devpid in pids: os.kill(devpid, signal.SIGKILL) os.kill(devmgr_nb.pid, signal.SIGKILL) self.waitTermination(devmgr_nb) devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_SelfTerminatingDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 devMgr.shutdown() self.assert_(self.waitTermination(devmgr_nb), "Nodebooter did not die after shutdown") def test_IgnoreDevMgrDuplicate(self): # These two nodes use the same identifier, but have different names to distinguish them devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Because the DeviceManager has the same identifier, we cannot use the launchDeviceManager # method; however, to get automatic cleanup in the event of a failure, we manually add the # nodebooter to the list of DeviceManager nodebooters. devmgr2_nb = scatest.spawnNodeBooter( dcdFile= "/nodes/test_BasicTestDeviceSameDevMgrId_node/DeviceManager.dcd.xml", debug=9) self._deviceBooters.append(devmgr2_nb) time.sleep(2) # Verify that the second DeviceManager is no longer alive, # This is REDHAWK specific, the spec would have let this go without # giving the user clear warning that something was wrong self.assertNotEqual(devmgr2_nb.poll(), None) self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) devMgr = self._domMgr._get_deviceManagers()[0] self.assertEqual(devMgr._get_label(), "BasicTestDevice_node" ) # If the second one won, it would be DeviceManager2 self.assertEqual(len(devMgr._get_registeredDevices()), 1) def test_IgnoreDeviceDuplicate(self): # These two nodes use the same identifier, but have different names to distinguish them devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_DuplicateTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) self.assertEqual(len(devMgr._get_registeredDevices()), 1) def test_ReRegDevMgrDuplicate(self): # These two nodes use the same identifier, but have different names to distinguish them devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) self.assertEqual(len(devMgr._get_registeredDevices()), 1) self.terminateChild(devmgr_nb, signals=(signal.SIGKILL, )) self.assertNotEqual(devmgr_nb.poll(), None) devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDeviceSameDevMgrId_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Verify that the second DeviceManager is no longer alive, # This is REDHAWK specific, the spec would have let this go without # giving the user clear warning that something was wrong self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) devMgr = self._domMgr._get_deviceManagers()[0] self.assertEqual(devMgr._get_label(), "BasicTestDeviceSameDevMgrId_node" ) # If the second one won, it would be DeviceManager2 self.assertEqual(len(devMgr._get_registeredDevices()), 1) def test_IgnoreDevDuplicate(self): # These two nodes have devices with the same identifier, but have different names to distinguish them devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) self.assertEqual(len(devMgr._get_registeredDevices()), 1) dev = devMgr._get_registeredDevices()[0] self.assertEqual(dev._get_label(), "BasicTestDevice1") devmgr2_nb, devMgr2 = self.launchDeviceManager( "/nodes/test_BasicTestDeviceSameDevId_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) self.assertEqual(len(self._domMgr._get_deviceManagers()), 2) self.assertEqual(len(devMgr2._get_registeredDevices()), 1) dev2 = devMgr2._get_registeredDevices()[0] self.assertEqual(dev2._get_label(), "BasicTestDeviceSameDevId") # TODO how do we test that this indeed worked? def test_ReRegDevDuplicate(self): # These two nodes have devices with the same identifier, but have different names to distinguish them devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) self.assertEqual(len(self._domMgr._get_deviceManagers()), 1) self.assertEqual(len(devMgr._get_registeredDevices()), 1) dev = devMgr._get_registeredDevices()[0] self.assertEqual(dev._get_label(), "BasicTestDevice1") self.terminateChildren(devmgr_nb, signals=(signal.SIGKILL, )) self.assertNotEqual(devmgr_nb.poll(), None) devmgr2_nb, devMgr2 = self.launchDeviceManager( "/nodes/test_BasicTestDeviceSameDevId_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) self.assertEqual(len(self._domMgr._get_deviceManagers()), 2) self.assertEqual(len(devMgr2._get_registeredDevices()), 1) dev2 = devMgr2._get_registeredDevices()[0] self.assertEqual(dev2._get_label(), "BasicTestDeviceSameDevId") # TODO how do we test that this indeed worked? def test_ComponentPlacementPropertyOverride(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 device = devMgr._get_registeredDevices()[0] propId = "DCE:6b298d70-6735-43f2-944d-06f754cd4eb9" prop = CF.DataType(id=propId, value=any.to_any(None)) result = device.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the dcd self.assertEqual(result[0].value._v, "BasicTestDevice1_no_default_prop") propId = "DCE:456310b2-7d2f-40f5-bfef-9fdf4f3560ea" prop = CF.DataType(id=propId, value=any.to_any(None)) result = device.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the dcd self.assertEqual(result[0].value._v, "BasicTestDevice1_default_prop") structprop = device.query([ CF.DataType(id="DCE:ffe634c9-096d-425b-86cc-df1cce50612f", value=any.to_any(None)) ])[0] struct_propseq = any.from_any(structprop.value) d = dict([(d["id"], d["value"]) for d in struct_propseq]) self.assertEqual(d, { "item1": "the new value", "item2": 400, "item3": 1.414 }) def test_ComponentPlacementSimpleSeqPropertyOverride(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_DCDSimpleSeq_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 device = devMgr._get_registeredDevices()[0] propId = "testsimpleseq" prop = CF.DataType(id=propId, value=any.to_any(None)) result = device.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(len(any.from_any(result[0].value)), 2) def test_ComponentPlacementNoPropOverride(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_DCDSimpleSeq_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) device = devMgr._get_registeredDevices()[0] # this device implementation will put a non-nil value on the property (even if a nil has been passed in a configure call) propId = "nil_property" prop = CF.DataType(id=propId, value=any.to_any(None)) result = device.query([prop]) self.assertEqual(any.from_any(result[0].value), None) device.configure([prop]) result = device.query([prop]) self.assertEqual(any.from_any(result[0].value), -1.0) def test_ComponentPlacementNoPropertyOverride(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDeviceNoOverrides_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 device = devMgr._get_registeredDevices()[0] propId = "modified_default" prop = CF.DataType(id=propId, value=any.to_any(None)) result = device.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the dcd self.assertEqual(result[0].value._v, "modified_default_value") def test_DevicePlacementPropertyOverride_cpp(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_ExecParamOverride_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 device = devMgr._get_registeredDevices()[0] propId = "DCE:68dc0d3b-deb2-4fae-b898-62273b74614b" prop = CF.DataType(id=propId, value=any.to_any(None)) result = device.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the dcd self.assertEqual(result[0].value._v, "new execparam value") propId = "DCE:07350439-e917-45ef-b71f-e387a737fd9c" prop = CF.DataType(id=propId, value=any.to_any(None)) result = device.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the dcd self.assertEqual(result[0].value._v, "new configured value") try: propId = "DCE:07350439-e917-45ef-b71f-a-bad-id" prop = CF.DataType(id=propId, value=any.to_any(None)) result = self._app.query([prop]) self.assertTrue(False) except: self.assertTrue(True) def test_AllocateCapacities(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_AllocateBasicDevice_python_node/DeviceManager.dcd.xml", debug=2) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 self.assertEqual(len(devMgr._get_registeredDevices()), 1) device = devMgr._get_registeredDevices()[0] self.assertNotEqual(device, None) mem_id = 'DCE:7aeaace8-350e-48da-8d77-f97c2e722e06' bog_id = 'DCE:bbdf708f-ce05-469f-8aed-f5c93e353e14' # first we don't have the properties set result = device.query([]) for prop in result: self.assertEqual(prop.value._v, None) # Set the BasicTestDevice to have 2048 MB of memory capacity and 1024 # BogoMips. Attempting to allocate more than that it raises an error # at the BasicTestDevice level props = [ CF.DataType(id=mem_id, value=any.to_any(1024)), CF.DataType(id=bog_id, value=any.to_any(512)) ] # allocating half of maximum capacity device.allocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 1024) elif prop.id == bog_id: self.assertEqual(prop.value._v, 512) else: self.assertTrue(False) # allocating full capacity device.allocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 2048) elif prop.id == bog_id: self.assertEqual(prop.value._v, 1024) else: self.assertTrue(False) # exceeding capacity props = [ CF.DataType(id=mem_id, value=any.to_any(1)), CF.DataType(id=bog_id, value=any.to_any(0)) ] device.allocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 2048) elif prop.id == bog_id: self.assertEqual(prop.value._v, 1024) else: self.assertTrue(False) # deallocating capacity props = [ CF.DataType(id=mem_id, value=any.to_any(1024)), CF.DataType(id=bog_id, value=any.to_any(512)) ] device.deallocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 1024) elif prop.id == bog_id: self.assertEqual(prop.value._v, 512) else: self.assertTrue(False) # allocating capacity props = [ CF.DataType(id=mem_id, value=any.to_any(1025)), CF.DataType(id=bog_id, value=any.to_any(512)) ] # exceeding capacity so no changes should occur device.allocateCapacity(props) result = device.query([]) for prop in result: if prop.id == mem_id: self.assertEqual(prop.value._v, 1024) elif prop.id == bog_id: self.assertEqual(prop.value._v, 512) else: self.assertTrue(False) def test_ComponentPropertyOverride_cpp(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/SimpleDevMgr/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file componentproperties get pushed to configure() # as per DeviceManager requirement SR:482 self.assertEqual(len(devMgr._get_registeredDevices()), 1) device = devMgr._get_registeredDevices()[0] self.assertNotEqual(device, None) # Now trying the component if self._domMgr: try: sadpath = "/waveforms/SimpleWaveform/SimpleWaveform.sad.xml" self._domMgr.installApplication(sadpath) appFact = self._domMgr._get_applicationFactories()[0] self._app = appFact.create(appFact._get_name(), [], []) except Exception, e: pass propId = "DCE:c709f95e-6b05-439a-9db9-dba95e70888e" prop = CF.DataType(id=propId, value=any.to_any(None)) result = self._app.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the sad file self.assertEqual(result[0].value._v, "new execparam value") propId = "DCE:6ea8108d-76ea-4532-9255-01684ad68429" prop = CF.DataType(id=propId, value=any.to_any(None)) result = self._app.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the sad file self.assertEqual(result[0].value._v, "new configured value") try: propId = "DCE:07350439-e917-45ef-b71f-a-bad-id" prop = CF.DataType(id=propId, value=any.to_any(None)) result = self._app.query([prop]) self.assertTrue(False) except: self.assertTrue(True) # testing the Octect octetId = 'DCE:10add64d-1160-4de0-885b-46a991f52f1d' self._app.configure( [CF.DataType(id=octetId, value=CORBA.Any(CORBA.TC_octet, 254))]) prop = CF.DataType(id=octetId, value=any.to_any(None)) result = self._app.query([prop]) self.assertEqual(len(result), 1) self.assertEqual(result[0].id, octetId) self.assertEqual(result[0].value._v, 254)
def test_pythonPropsRangeStructSeq(self): self._app = self._launchApp('TestPythonPropsRange') # Struct with upper bound upper = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_long, 255)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_long, 32767)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_long, 65535)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_longlong, 2147483647)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_longlong, 4294967295)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_ulonglong, 9223372036854775807L)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, 18446744073709551615L))]) # Struct with lower bound lower = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_long, 0)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_long, -32768)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_long, 0)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_longlong, -2147483648)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_longlong, 0)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, -9223372036854775808L)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_longlong, 0))]) my_structseq = CF.DataType(id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [ upper , lower ] )) self._app.configure([my_structseq]) # Make sure values all got set res = self._app.query([]) for r in res: if r.id == 'my_structseq': upper = r.value.value()[0] lower = r.value.value()[1] for v in upper.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 255) elif v.id == 'ss_short': self.assertEquals(v.value.value(), 32767) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 65535) elif v.id == 'ss_long': self.assertEquals(v.value.value(), 2147483647) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 4294967295) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), 9223372036854775807L) elif v.id == 'ss_ulonglong': self.assertEquals(v.value.value(), 18446744073709551615L) for v in lower.value(): if v.id == 'ss_octet': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_short': self.assertEquals(v.value.value(), -32768) elif v.id == 'ss_ushort': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_long': self.assertEquals(v.value.value(), -2147483648) elif v.id == 'ss_ulong': self.assertEquals(v.value.value(), 0) elif v.id == 'ss_longlong': self.assertEquals(v.value.value(), -9223372036854775808L) elif v.id == 'ss_ulonglong': self.assertEquals(v.value.value(), 0) # Loop through each member of the struct to test one beyond the upper bound for r in res: if r.id == 'my_structseq': val = r.value.value()[1] for v in val.value(): # All default values are valid octet_val = 0 short_val = 0 ushort_val = 0 long_val = 0 ulong_val = 0 longlong_val = 0 ulonglong_val = 0 # Creates struct with only 1 invalid member, which will still cause invalid configuration if v.id == 'ss_octet': octet_val = 256 elif v.id == 'ss_short': short_val = 32768 elif v.id == 'ss_ushort': ushort_val = 65536 elif v.id == 'ss_long': long_val = 2147483648 elif v.id == 'ss_ulong': ulong_val = 4294967296 elif v.id == 'ss_longlong': longlong_val = 9223372036854775808L elif v.id == 'ss_ulonglong': # No value large enough to test outside range of ulonglong continue bad_struct = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_long, octet_val)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_long, short_val)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_long, ushort_val)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_longlong, long_val)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_longlong, ulong_val)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_ulonglong, longlong_val)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_ulonglong, ulonglong_val))]) my_structseq = CF.DataType(id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [ upper , bad_struct ] )) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [my_structseq]) # Loop through each member of the struct to test one beyond the lower bound for r in res: if r.id == 'my_structseq': val = r.value.value()[0] for v in val.value(): # All default values are valid octet_val = 0 short_val = 0 ushort_val = 0 long_val = 0 ulong_val = 0 longlong_val = 0 ulonglong_val = 0 # Creates struct with only 1 invalid member, which will still cause invalid configuration if v.id == 'ss_octet': octet_val = -1 elif v.id == 'ss_short': short_val = -32769 elif v.id == 'ss_ushort': ushort_val = -1 elif v.id == 'ss_long': long_val = -2147483649 elif v.id == 'ss_ulong': ulong_val = -1 elif v.id == 'ss_longlong': # No value to test below range of longlong continue elif v.id == 'ss_ulonglong': ulonglong_val = -1 bad_struct = CORBA.Any(CORBA.TypeCode("IDL:CF/Properties:1.0"), [ CF.DataType(id='ss_octet', value=CORBA.Any(CORBA.TC_long, octet_val)), CF.DataType(id='ss_short', value=CORBA.Any(CORBA.TC_long, short_val)), CF.DataType(id='ss_ushort', value=CORBA.Any(CORBA.TC_long, ushort_val)), CF.DataType(id='ss_long', value=CORBA.Any(CORBA.TC_longlong, long_val)), CF.DataType(id='ss_ulong', value=CORBA.Any(CORBA.TC_longlong, ulong_val)), CF.DataType(id='ss_longlong', value=CORBA.Any(CORBA.TC_longlong, longlong_val)), CF.DataType(id='ss_ulonglong', value=CORBA.Any(CORBA.TC_longlong, ulonglong_val))]) my_structseq = CF.DataType(id='my_structseq', value=CORBA.Any(CORBA.TypeCode("IDL:omg.org/CORBA/AnySeq:1.0"), [ bad_struct, lower ] )) self.assertRaises(CF.PropertySet.InvalidConfiguration, self._app.configure, [my_structseq])
def test_DeviceExecParamOverride(self): devmgr_nb, devMgr = self.launchDeviceManager( "/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9) self.assertNotEqual(devMgr, None) props = devMgr.query([]) # NOTE These assert check must be kept in-line with the DeviceManager.dcd.xml self.assertEqual(len(devMgr._get_registeredDevices()), 1) # Test that the DCD file execparam get's sent to Device device = devMgr._get_registeredDevices()[0] propId = "DCE:c03e148f-e9f9-4d70-aa00-6e23d33fa648" prop = CF.DataType(id=propId, value=any.to_any(None)) try: result = device.query([prop]) except: pass self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the dcd self.assertEqual(result[0].value._v, "path/to/some/config/file") # Test that the DCD file execparam that are readonly get sent the default value in the PRF file device = devMgr._get_registeredDevices()[0] propId = "DCE:6f5881b3-433e-434b-8204-d39c89ff4be2" prop = CF.DataType(id=propId, value=any.to_any(None)) try: result = device.query([prop]) except: pass self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should not have been overrided by the dcd self.assertEqual(result[0].value._v, "DefaultValueGood") # Test whether the execparam "ImplementationSpecificProperty" was overloaded properly from the implementation-specific PRF file propId = "DCE:dc4289a8-bb98-435b-b914-305ffaa7594f" prop = CF.DataType(id=propId, value=any.to_any(None)) try: result = device.query([prop]) except: pass self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the implementation-specific PRF file self.assertEqual(result[0].value._v, "NewLinuxx86Value") # Test whether the implementation-specific execparam property get's overloaded by the DCD propId = "DCE:716ea1c4-059a-4b18-8b66-74804bd8d435" prop = CF.DataType(id=propId, value=any.to_any(None)) try: result = device.query([prop]) except: pass self.assertEqual(len(result), 1) self.assertEqual(result[0].id, propId) # This should have been overrided by the implementation-specific PRF file self.assertEqual(result[0].value._v, "OverloadedTheImplementationSpecific") self.assertNotEqual(result[0].value._v, "NewLinuxx86Value2")
def test_complexFloat(self): testStruct = (_DataTypeTest("complexFloatProp", CF.complexFloat(4.0, 5.0), CF.complexFloat(2.0, 3.0), CF._tc_complexFloat)) self._runTest(testStruct)
def getIdentifiers(self): props = [] for id in self.outPorts: value = any.to_any(self.outPorts[id]._get_identifier()) props.append(CF.DataType(id=id, value=value)) return props