def testFalseControl(self): center_frequency = 110e6 sample_rate = 2.5e6 bandwidth = 2e6 alloc = self._generateAlloc(cf=center_frequency, sr=sample_rate, bw=bandwidth) retval = self.comp.allocateCapacity(alloc) self.assertEquals(retval, True) _type = properties.props_to_dict(alloc)['FRONTEND::tuner_allocation'][ 'FRONTEND::tuner_allocation::tuner_type'] _alloc_id = properties.props_to_dict( alloc)['FRONTEND::tuner_allocation'][ 'FRONTEND::tuner_allocation::allocation_id'] listen_alloc = [ frontend.createTunerGenericListenerAllocation( _type, allocation_id='foo', center_frequency=center_frequency, bandwidth=bandwidth, sample_rate=sample_rate, returnDict=False) ] retval = self.comp.allocateCapacity(listen_alloc) self.assertEquals(retval, True) self.comp.deallocateCapacity(listen_alloc) self.comp.deallocateCapacity(alloc)
def test_MultipleUsesDevices(self): devices = dict((dev._get_label(), dev) for dev in self._devMgr._get_registeredDevices()) appFact = self.createAppFact("Multiple") self._app = appFact.create(appFact._get_name(), [], []) # Check the usesdevice connections by inspecting the app's external # ports against the devices for connection in self._app.getPort("resource_out")._get_connections(): deviceId = connection.port._get_identifier() if connection.connectionId == "connection1": self.assertTrue(deviceId, devices["SADUsesDevice_1"]._get_identifier()) elif connection.connectionId == "connection2": self.assertTrue(deviceId, devices["BasicTestDevice1"]._get_identifier()) # Try to create another instance of the application; there should only # be enough capacity to satisfy one of the usesdevices prop = CF.DataType("DCE:001fad60-b4b3-4ed2-94cb-40e1d956bf4f", any.to_any(None)) pre_value = properties.props_to_dict(devices["BasicTestDevice1"].query([prop])[0].value._v) try: app2 = appFact.create(appFact._get_name(), [], []) except CF.ApplicationFactory.CreateApplicationError: # The first app instance should have exhausted the capacity on the # SADUsesDevice pass else: self.fail("Device should not have enough capacity to satisfy usesdevice") # Make sure that the successful usesdevice was deallocated post_value = properties.props_to_dict(devices["BasicTestDevice1"].query([prop])[0].value._v) self.assertEqual(pre_value["long_capacity"], post_value["long_capacity"]) self.assertAlmostEqual(pre_value["float_capacity"], post_value["float_capacity"])
def test_keyword_change(self): print "\n... Staring mid stream keyword change test" self._generate_config() self.comp_obj.configure(props_from_dict(self.config_dict)) self._generate_keywords() self._send_data(last_pkt_eos=False) expected_data1 = self.expected_data time.sleep(1) # Allow SCAAudioTagger to process the already sent data before changing config parameters self.updated_config = copy.deepcopy(self.config_dict) self.updated_config["encoding"] = "PCM_SIGNED" self.updated_config["channels"] = 1 self.comp_obj.configure(props_from_dict(self.updated_config)) self._send_data(last_pkt_eos=True) expected_data2 = self.expected_data rx_data = self._get_received_data() rx_data1 = rx_data[:len(rx_data)/2] rx_data2 = rx_data[len(rx_data)/2:] print "Received SRI keywords: %s" % props_to_dict(rx_data1[-1].sri.keywords) print "Received SRI keywords: %s" % props_to_dict(rx_data2[-1].sri.keywords) self._validate_data(rx_data1, expected_data1, expected_frame_size=1, config_dict=self.config_dict) self._validate_data(rx_data2, expected_data2, expected_frame_size=1, config_dict=self.updated_config)
def _compareAllocation(self, lhs, rhs): self.assertEqual(lhs.allocationID, rhs.allocationID) self.assertEqual(lhs.requestingDomain, rhs.requestingDomain) lhsProps = properties.props_to_dict(lhs.allocationProperties) rhsProps = properties.props_to_dict(rhs.allocationProperties) self.assertEqual(lhsProps, rhsProps) self.assert_(lhs.allocatedDevice._is_equivalent(rhs.allocatedDevice)) self.assert_(lhs.allocationDeviceManager._is_equivalent(rhs.allocationDeviceManager))
def testKeywords(self): stream = self.port.createStream("test_keywords") self._writeSinglePacket(stream, 1) self.assertEqual(1, len(self.stub.H)) # Set/get keywords stream.setKeyword('integer', 250) stream.setKeyword('string', "value") stream.setKeyword('double', 101.1e6) stream.setKeyword('boolean', False) self.assertEqual(250, stream.getKeyword('integer')) self.assertEqual('value', stream.getKeyword('string')) self.assertEqual(101.1e6, stream.getKeyword('double')) self.assertEqual(False, stream.getKeyword('boolean')) # Set with a specific type stream.setKeyword('float', -1.25, 'float') self.assertEqual(-1.25, stream.getKeyword('float')) any_value = stream.keywords[-1].value self.assertEqual(CORBA.TC_float, any_value.typecode()) # Erase and check for presence of keywords stream.eraseKeyword('string') self.failUnless(stream.hasKeyword('integer')) self.failIf(stream.hasKeyword('string')) self.failUnless(stream.hasKeyword('double')) self.failUnless(stream.hasKeyword('boolean')) # Write a packet to trigger an SRI update self.assertEqual(1, len(self.stub.H)) self._writeSinglePacket(stream, 1) self.assertEqual(2, len(self.stub.H)) keywords = properties.props_to_dict(self.stub.H[-1].keywords) self.assertEqual(len(stream.keywords), len(keywords)) for key, value in keywords.iteritems(): self.assertEqual(stream.getKeyword(key), value) # Replace keywords with a new set stream.keywords = properties.props_from_dict({ 'COL_RF': 100.0e6, 'CHAN_RF': 101.1e6 }) self.assertEqual(2, len(stream.keywords)) self.assertEqual(100.0e6, stream.getKeyword('COL_RF')) self.assertEqual(101.1e6, stream.getKeyword('CHAN_RF')) # Trigger another SRI update self.assertEqual(2, len(self.stub.H)) self._writeSinglePacket(stream, 1) self.assertEqual(3, len(self.stub.H)) keywords = properties.props_to_dict(self.stub.H[-1].keywords) self.assertEqual(len(stream.keywords), len(keywords)) for key, value in keywords.iteritems(): self.assertEqual(stream.getKeyword(key), value)
def _compareAllocations(lhs, rhs): if lhs.allocationID != rhs.allocationID: return False lhsProps = properties.props_to_dict(lhs.allocationProperties) rhsProps = properties.props_to_dict(rhs.allocationProperties) if lhsProps != rhsProps: return False if not lhs.allocatedDevice._is_equivalent(rhs.allocatedDevice): return False if not lhs.allocationDeviceManager._is_equivalent(rhs.allocationDeviceManager): return False return True
def compareAllocationStatus(lhs, rhs): if lhs.allocationID != rhs.allocationID: return False lhsProps = properties.props_to_dict(lhs.allocationProperties) rhsProps = properties.props_to_dict(rhs.allocationProperties) if lhsProps != rhsProps: return False if not lhs.allocatedDevice._is_equivalent(rhs.allocatedDevice): return False if not lhs.allocationDeviceManager._is_equivalent( rhs.allocationDeviceManager): return False return True
def testTypoErrorAllocation(self): center_frequency = 110e6 sample_rate = 2.5e6 bandwidth = 2e6 alloc = self._generateAlloc(cf=center_frequency,sr=sample_rate,bw=bandwidth) retval = self.comp.allocateCapacity(alloc) self.assertEquals(retval, True) _type = properties.props_to_dict(alloc)['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::tuner_type'] _alloc_id = properties.props_to_dict(alloc)['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::allocation_id'] listen_alloc = [frontend.createTunerListenerAllocation(_alloc_id, listener_allocation_id='foo',returnDict=False)] retval = self.comp.allocateCapacity(listen_alloc) self.assertEquals(retval, True) self.assertRaises(CF.Device.InvalidCapacity, self.comp.allocateCapacity, listen_alloc) self.comp.deallocateCapacity(listen_alloc) self.comp.deallocateCapacity(alloc)
def eventReceived(self, data): dataEvent = any.from_any(data, keep_structs=True) if dataEvent.sourceId != self.sourceId: self.successfullPropChange = False return if len(dataEvent.properties) == 0: self.successfullPropChange = False return props = properties.props_to_dict(dataEvent.properties) if props.has_key('myprop'): self.received_myprop = True if self.successfullPropChange == None: self.successfullPropChange = True if props.has_key('anotherprop'): self.received_anotherprop = True if self.successfullPropChange == None: self.successfullPropChange = True if props.has_key('seqprop'): if props['seqprop'] == [1.0, 2.0, 3.0]: self.received_seqprop = True if self.successfullPropChange == None: self.successfullPropChange = True if props.has_key('some_struct') and props['some_struct'] != None: if props['some_struct'] == {"some_number": 3.0, "some_string": "hello"}: self.received_some_struct = True if self.successfullPropChange == None: self.successfullPropChange = True if props.has_key('structseq_prop'): if len(props['structseq_prop']) == 1: if props['structseq_prop'][0] == {"some_number": 7.0, "some_string": "second message"}: self.received_structseq_prop = True if self.successfullPropChange == None: self.successfullPropChange = True
def testInValidRFInfoSR(self): """ Ask for a Allocation outside the range of the REceiver but should still work because the RFInfo packet tells the receiver a frequency down conversation has already occured""" #Create Allocation and Sink for Tuner 1 sink = sb.DataSink() alloc = self._generateAlloc(cf=9050.1e6, sr=2.5e6, bw=0, rf_flow_id="testRFInfoPacket_FlowID") allocationID = properties.props_to_dict( alloc)['FRONTEND::tuner_allocation'][ 'FRONTEND::tuner_allocation::allocation_id'] self.comp.connect(sink, connectionId=allocationID) sink.start() #Send an RF Info Packet rfInfo_port = self.comp.getPort("RFInfo_in") rf_info_pkt = self._generateRFInfoPkt( rf_freq=9000e6, rf_bw=100e6, if_freq=100e6, rf_flow_id="testRFInfoPacket_FlowID") rfInfo_port._set_rfinfo_pkt(rf_info_pkt) #Allocate a Tuner try: retval = self.comp.allocateCapacity(alloc) except Exception, e: self.assertFalse("Exception thrown on allocateCapactiy %s" % str(e))
def testInValidRFInfoPacket(self): #Create Allocation and Sink for Tuner 1 sink = sb.DataSink() alloc = self._generateAlloc(cf=110e6, sr=2.5e6, bw=2e6, rf_flow_id="invalid_FlowID") allocationID = properties.props_to_dict( alloc)['FRONTEND::tuner_allocation'][ 'FRONTEND::tuner_allocation::allocation_id'] self.comp.connect(sink, connectionId=allocationID) sink.start() #Send an RF Info Packet rfInfo_port = self.comp.getPort("RFInfo_in") rf_info_pkt = self._generateRFInfoPkt( rf_freq=100e6, rf_bw=100e6, if_freq=0, rf_flow_id="testRFInfoPacket_FlowID") rfInfo_port._set_rfinfo_pkt(rf_info_pkt) #Allocate a Tuner try: retval = self.comp.allocateCapacity(alloc) except Exception, e: self.assertFalse("Exception thrown on allocateCapactiy %s" % str(e))
def test_complex(self): print "\n... Staring complex data test" self._generate_config() self.comp_obj.configure(props_from_dict(self.config_dict)) self._generate_keywords() self._send_data(complex=True) rx_data = self._get_received_data() print "Received SRI keywords: %s" % props_to_dict(rx_data[-1].sri.keywords) self._validate_data(rx_data, self.expected_data, expected_frame_size=2)
def testNoneImport(self): """Do a test with import configured to None rather than a sequence """ print "\n... running testNoneImport" self.comp.configure(props_from_dict({'import': None})) props = props_to_dict(self.comp.query(props_from_dict({}))) self.assertEqual( props['import'], [], '"import" property set to "%s" (instead of empty sequence) after configured with "None".' % props['import'])
def test_MultipleUsesDevices(self): devices = dict((dev._get_label(), dev) for dev in self._devMgr._get_registeredDevices()) appFact = self.createAppFact('Multiple') self._app = appFact.create(appFact._get_name(), [], []) # Check the usesdevice connections by inspecting the app's external # ports against the devices for connection in self._app.getPort('resource_out')._get_connections(): deviceId = connection.port._get_identifier() if connection.connectionId == 'connection1': self.assertTrue(deviceId, devices['SADUsesDevice_1']._get_identifier()) elif connection.connectionId == 'connection2': self.assertTrue(deviceId, devices['BasicTestDevice1']._get_identifier()) # Try to create another instance of the application; there should only # be enough capacity to satisfy one of the usesdevices prop = CF.DataType('DCE:001fad60-b4b3-4ed2-94cb-40e1d956bf4f', any.to_any(None)) pre_value = properties.props_to_dict(devices['BasicTestDevice1'].query( [prop])[0].value._v) try: app2 = appFact.create(appFact._get_name(), [], []) except CF.ApplicationFactory.CreateApplicationError: # The first app instance should have exhausted the capacity on the # SADUsesDevice pass else: self.fail( 'Device should not have enough capacity to satisfy usesdevice') # Make sure that the successful usesdevice was deallocated post_value = properties.props_to_dict( devices['BasicTestDevice1'].query([prop])[0].value._v) self.assertEqual(pre_value['long_capacity'], post_value['long_capacity']) self.assertAlmostEqual(pre_value['float_capacity'], post_value['float_capacity']) self.assertEqual(pre_value['struct_simple_seq'], post_value['struct_simple_seq'])
def testRFInfoPkt(self): self.fei_dev, alloc_params = self.getAllocationContext(ALLOCATE_RCV) #create rf_info uses port and connect to MSDD out_rf_info_port=frontend.OutRFInfoPort("out_control") in_rf_info_port=self.fei_dev.getPort("RFInfo_in") out_rf_info_port.connectPort(in_rf_info_port,"test_rf_flow") bw=alloc_params['wbddc_bw'] sr=alloc_params['wbddc_srate'] # allocation params flow_id = "ca-710-flow-2" cf=100e6 # send info pkto pkt=_generateRFInfoPkt(cf,bw,rf_flow_id=flow_id) out_rf_info_port._set_rfinfo_pkt(pkt) # check rf_flow_id was set n=len(self.fei_dev.frontend_tuner_status) expected=[flow_id]*n actual=[ x["FRONTEND::tuner_status::rf_flow_id"] for x in self.fei_dev.frontend_tuner_status ] self.assertEqual(expected,actual, "Mismatch of RF Flow Ids for tuners") # allocation for sample rate and rf_flow_id alloc1=frontend.createTunerAllocation(center_frequency=cf, sample_rate=sr, rf_flow_id=flow_id) ret=self.fei_dev.allocateCapacity( alloc1) alloc1_aid = alloc1["FRONTEND::tuner_allocation"]["FRONTEND::tuner_allocation::allocation_id"] self.assertEqual(True,ret, "Allocation failed using rf_flow_id") self.alloc1=alloc1 alloc2_aid = alloc1_aid if alloc_params['nbddc_srate'] is not None : # allocation for center freq and rf_flow_id alloc2=frontend.createTunerAllocation(center_frequency=cf, rf_flow_id=flow_id) ret=self.fei_dev.allocateCapacity( alloc2) alloc2_aid = alloc2["FRONTEND::tuner_allocation"]["FRONTEND::tuner_allocation::allocation_id"] self.assertEqual(True,ret, "Allocation failed using rf_flow_id again ") self.alloc2=alloc2 # valid rf_flow_id was probagated downstream sink=sb.StreamSink() sdds_in=sb.launch('rh.SourceSDDS', properties={'interface':INTERFACE}) sb.start() self.fei_dev.connect(sdds_in, connectionId=alloc2_aid, usesPortName='dataSDDS_out') sdds_in.connect(sink, usesPortName="dataShortOut") kws=None try: sink_data=sink.read() kws=properties.props_to_dict(sink_data.sri.keywords) except: pass self.assertEqual( kws["FRONTEND::RF_FLOW_ID"] , flow_id, "Missing RF_FLOW_ID from keyword list")
def _messageReceived(self, message): payload = message.value(CF._tc_Properties) if not payload: return for dt in payload: if dt.id == 'state_change': value = properties.props_to_dict(dt.value.value(CF._tc_Properties)) identifier = value['state_change::identifier'] if value['state_change::event'] == 'start': self._started.put(identifier) elif value['state_change::event'] == 'stop': self._stopped.put(identifier)
def testReportedBandwidth(self): self.comp.start() alloc = self._generateAlloc(cf=110e6, sr=24.576e6, bw=20e6) allocationID = properties.props_to_dict( alloc)['FRONTEND::tuner_allocation'][ 'FRONTEND::tuner_allocation::allocation_id'] try: retval = self.comp.allocateCapacity(alloc) except Exception, e: print str(e) self.fail("Exception thrown on allocateCapactiy %s" % str(e))
def test_same_stream_snaps(self): print "\n... Staring multiple snapshots from one stream test" config_dict = self._generate_config() data_filename = config_dict['filename'] if os.path.exists(data_filename): os.system("rm %s" % (data_filename+"*")) while os.path.exists(data_filename): time.sleep(self.t_delta) self._generate_keywords() self.comp.configure(props_from_dict(config_dict)) data_filename = config_dict['filename'] base_filename = data_filename count = 0 expected_data = [] results = [] for i in xrange(6): # Disable file writing, this should cause the current file to be written out # and a new file to be created the next time write in enabled enabled_write = not ((i+1) % 2 == 0) self.comp.configure(props_from_dict({"write": enabled_write})) while props_to_dict(self.comp.query([]))['write']!=enabled_write: time.sleep(self.t_delta) first_pkt_time = None for j in xrange(3): self._send_data(last_pkt_eos=False) # send data but don't send eos (not stopping streaming just yet) first_pkt_time = first_pkt_time or self.first_pkt_time last_pkt_time = self.last_pkt_time if enabled_write: expected_data.extend(self.expected_data) self._sleepTillDone(data_filename, expected_data=expected_data) else: time.sleep(self.t_data_wait) if not enabled_write: # File should have been closed at the start of this pass sri_filename = data_filename + ".sri" self._validate_data(data_filename, expected_data, config_dict["endian"]) self._validate_metadata(sri_filename, self.t_delta, self.stream_id1, self.keywords_dict, first_pkt_time, last_pkt_time) # reset for the next file expected_data = [] count += 1 data_filename = base_filename + ".%d" % count
def testReportedBandwidth(self): self.comp.start() self.fei_dev, alloc_params = self.getAllocationContext(ALLOCATE_RCV) alloc = self._generateAlloc(cf=110e6, sr=alloc_params['wbddc_srate'], bw=alloc_params['wbddc_bw']) allocationID = properties.props_to_dict(alloc)['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::allocation_id'] try: retval = self.fei_dev.allocateCapacity(alloc) except Exception, e: print str(e) self.fail("Exception thrown on allocateCapactiy %s" % str(e))
def propertyChange(self, _propChEv): if type(self._changeCallbacks) != dict: print 'Invalid change callbacks (must be dictionary with property id as a key and a callback function as a value). Printing received event', _propChEv _tmp_props = _propChEv.properties _triggers = {} for _prop_key in self._changeCallbacks: for _prop_idx in range(len(_tmp_props)): if _tmp_props[_prop_idx].id == _prop_key: if not _triggers.has_key(self._changeCallbacks[_prop_key]): _triggers[self._changeCallbacks[_prop_key]] = {} _triggers[self._changeCallbacks[_prop_key]].update( properties.prop_to_dict(_tmp_props[_prop_idx])) _tmp_props.pop(_prop_idx) break if len(_triggers) != 0: for _trigger in _triggers: _trigger(_propChEv.evt_id, _propChEv.reg_id, _propChEv.resource_id, _triggers[_trigger], _propChEv.timestamp) if len(_tmp_props) != 0: if self._defaultCallback: self._defaultCallback(_propChEv.evt_id, _propChEv.reg_id, _propChEv.resource_id, properties.props_to_dict(_tmp_props), _propChEv.timestamp) return print 'Property Change Event:' print ' event id:', _propChEv.evt_id print ' registration id:', _propChEv.reg_id print ' resource id:', _propChEv.resource_id print ' properties:', properties.props_to_dict(_tmp_props) print ' timestamp:', _propChEv.timestamp
def _query(self, props=[], printResults=False): results = self.query(props) # If querying all properties, display all property names and values propDict = _properties.props_to_dict(results) maxNameLen = 0 if printResults: if results != [] and len(props) == 0: for prop in propDict.items(): if len(prop[0]) > maxNameLen: maxNameLen = len(prop[0]) print "_query():" print "Property Name" + " "*(maxNameLen-len("Property Name")) + "\tProperty Value" print "-------------" + " "*(maxNameLen-len("Property Name")) + "\t--------------" for prop in propDict.items(): print str(prop[0]) + " "*(maxNameLen-len(str(prop[0]))) + "\t " + str(prop[1]) return propDict
def _validate_data(self, received_data, expected_data, expected_frame_size=1, config_dict=None): config_dict = config_dict or self.config_dict exp_index = 0 for rx_pkt in received_data: for d in rx_pkt.data: self.assertEqual(d, expected_data[exp_index]) exp_index += 1 # Verify keywords rx_keywords = props_to_dict(rx_pkt.sri.keywords) # Added audio keywords self.assertEqual(rx_keywords["AUDIO_ENCODING"], config_dict["encoding"]) self.assertEqual(rx_keywords["AUDIO_CHANNELS"], config_dict["channels"]) self.assertEqual(rx_keywords["AUDIO_FRAME_SIZE"], expected_frame_size) # 1 - scalar, 2 - complex self.assertEqual(rx_keywords["AUDIO_FRAME_RATE"], 1./self.t_delta) for k, v in self.keywords_dict.items(): self.assertEqual(rx_keywords[k], v)
def get_available_hardware(self): ''' Returns a list of the available RTL devices >> x.get_vailable_rtl() [ { 'index': 0, 'name': 'ezcap USB 2.0 DVB-T/DAB/FM dongle', 'product': 'RTL2838UHIDIR', 'serial': '000000000', 'vendor': 'Realtek' } ] ''' def fixd(d): return dict([(k.split('::')[-1], v) for k, v in d.items()]) self.device.configure(props_from_dict(dict(update_available_devices=True))) q = props_to_dict(self.device.query(props_from_dict(dict(available_devices=None)))) return [ fixd(d) for d in q['available_devices']]
def testDoubleTunerAllocation(self): #self.comp.start() #Create Allocation and Sink for Tuner 1 sink = sb.StreamSink() alloc = self._generateAlloc(cf=110e6,sr=2.5e6,bw=2e6) allocationID = properties.props_to_dict(alloc)['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::allocation_id'] self.comp.connect(sink,connectionId=allocationID) sink.start() #Allocate a Tuner try: retval = self.comp.allocateCapacity(alloc) except Exception, e: self.assertFalse("Exception thrown on allocateCapactiy %s" % str(e))
def testSingleTunerAllocation(self): #self.comp.start() sink = sb.DataSink() alloc = self._generateAlloc(cf=110e6,sr=2.5e6,bw=2e6) allocationID = properties.props_to_dict(alloc)['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::allocation_id'] self.comp.connect(sink,connectionId=allocationID) sink.start() try: retval = self.comp.allocateCapacity(alloc) except Exception, e: print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" print str(e) self.assertFalse("Exception thrown on allocateCapactiy %s" % str(e))
def get_available_hardware(self): ''' Returns a list of the available RTL devices >> x.get_vailable_rtl() [ { 'index': 0, 'name': 'ezcap USB 2.0 DVB-T/DAB/FM dongle', 'product': 'RTL2838UHIDIR', 'serial': '000000000', 'vendor': 'Realtek' } ] ''' def fixd(d): return dict([(k.split('::')[-1], v) for k, v in d.items()]) self.device.configure( props_from_dict(dict(update_available_devices=True))) q = props_to_dict( self.device.query(props_from_dict(dict(available_devices=None)))) return [fixd(d) for d in q['available_devices']]
def testSingleTunerAllocation(self): self.comp.start() self.fei_dev, alloc_params = self.getAllocationContext(ALLOCATE_RCV) sink = sb.DataSinkSDDS() alloc = self._generateAlloc(cf=110e6,sr=0,bw=0) allocationID = properties.props_to_dict(alloc)['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::allocation_id'] self.fei_dev.connect(sink,usesPortName = "dataSDDS_out",connectionId=allocationID) sink.start() try: retval = self.fei_dev.allocateCapacity(alloc) except Exception, e: print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" print str(e) self.assertFalse("Exception thrown on allocateCapactiy %s" % str(e))
def set_target_hardware(self, rtlx): ''' Sets the target RTL to use. To choose a target device use a dictionary with the criteria to select (from the available rtl devices). Returns the target that was just set. > x.set_target_rtl(dict(index=0)) [ { 'index': 0, 'name': None, 'product': None, 'serial': None, 'vendor': None, } ] ''' # the device has a bug in that if it gets the same value, it won't trigger # target device. So set it to some weird number and than change it again self.device.configure(dict(target_device=dict(index=-2))) # FIXME: Validate rtlx has the right fields self.device.configure(dict(target_device=rtlx)) return props_to_dict(self.device.query(props_from_dict(dict(target_device=None))))
def set_target_hardware(self, rtlx): ''' Sets the target RTL to use. To choose a target device use a dictionary with the criteria to select (from the available rtl devices). Returns the target that was just set. > x.set_target_rtl(dict(index=0)) [ { 'index': 0, 'name': None, 'product': None, 'serial': None, 'vendor': None, } ] ''' # the device has a bug in that if it gets the same value, it won't trigger # target device. So set it to some weird number and than change it again self.device.configure(dict(target_device=dict(index=-2))) # FIXME: Validate rtlx has the right fields self.device.configure(dict(target_device=rtlx)) return props_to_dict( self.device.query(props_from_dict(dict(target_device=None))))
def testConfigureQuerySeqs(self): ####################################################################### # Launch the component with the default execparams execparams = self.getPropertySet(kinds=("execparam",), modes=("readwrite", "writeonly"), includeNil=False) execparams = dict([(x.id, any.from_any(x.value)) for x in execparams]) self.launch(execparams) ####################################################################### # Simulate regular component startup # Verify that initialize nor configure throw errors self.comp_obj.initialize() values = [1,2,3,4,5] phrases = ['one','two','three','four','five'] phrase = 'testing' octetData = struct.pack('5b', *[x for x in values]) #octet data must be packed bytes flags = [True, False, True, False] values_r = copy.deepcopy(values) values_r.reverse() phrases_r = copy.deepcopy(phrases) phrases_r.reverse() phrase_r = ([x for x in phrase]) phrase_r.reverse() flags_r = copy.deepcopy(flags) flags_r.reverse() numTestRuns = 10 for x in range(numTestRuns): stringset = ossie.cf.CF.DataType(id='stringSeq', value=any.to_any(phrases)) stringset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.StringSeq) self.comp_obj.configure([stringset]) boolset = ossie.cf.CF.DataType(id='boolSeq', value=any.to_any(flags)) boolset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.BooleanSeq) self.comp_obj.configure([boolset]) ulongset = ossie.cf.CF.DataType(id='ulongSeq', value=any.to_any(values)) ulongset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.ULongSeq) self.comp_obj.configure([ulongset]) shortset = ossie.cf.CF.DataType(id='shortSeq', value=any.to_any(values)) shortset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.ShortSeq) self.comp_obj.configure([shortset]) floatset = ossie.cf.CF.DataType(id='floatSeq', value=any.to_any(values)) floatset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.FloatSeq) self.comp_obj.configure([floatset]) charset = ossie.cf.CF.DataType(id='charSeq', value=any.to_any(phrase)) charset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.CharSeq) self.comp_obj.configure([charset]) octetset = ossie.cf.CF.DataType(id='octetSeq', value=any.to_any(octetData)) octetset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.OctetSeq) self.comp_obj.configure([octetset]) ushortset = ossie.cf.CF.DataType(id='ushortSeq', value=any.to_any(values)) ushortset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.UShortSeq) self.comp_obj.configure([ushortset]) doubleset = ossie.cf.CF.DataType(id='doubleSeq', value=any.to_any(values)) doubleset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.DoubleSeq) self.comp_obj.configure([doubleset]) longset = ossie.cf.CF.DataType(id='longSeq', value=any.to_any(values)) longset.value._t = tcInternal.typeCodeFromClassOrRepoId(CORBA.LongSeq) self.comp_obj.configure([longset]) longlongset = ossie.cf.CF.DataType(id='longlongSeq', value=any.to_any(values)) longlongset.value._t = tcInternal.typeCodeFromClassOrRepoId(PortTypes.LongLongSequence) self.comp_obj.configure([longlongset]) ulonglongset = ossie.cf.CF.DataType(id='ulonglongSeq', value=any.to_any(values)) ulonglongset.value._t = tcInternal.typeCodeFromClassOrRepoId(PortTypes.UlongLongSequence) self.comp_obj.configure([ulonglongset]) simple_list = self.comp_obj.query([ ossie.cf.CF.DataType(id=str('stringSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('boolSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('ulongSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('shortSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('floatSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('charSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('octetSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('ushortSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('doubleSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('longSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('longlongSeq'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('ulonglongSeq'),value=any.to_any(None)) ]) simple_dict = properties.props_to_dict(simple_list) #the onconfigure for the stringSeq is supposed to reverse the order of the phrases self.assertEquals(simple_dict['stringSeq'], phrases_r, msg=str(simple_dict['stringSeq']) + ' != ' + str(phrases_r) + ' for stringSeq') simple_dict.pop('stringSeq') #the onconfigure for the boolSeq is supposed to reverse the order of the flags self.assertEquals(simple_dict['boolSeq'], flags_r, msg=str(simple_dict['boolSeq']) + ' != ' + str(flags_r) + ' for boolSeq') simple_dict.pop('boolSeq') #the onconfigure for the charSeq is supposed to reverse the order of the phrase self.assertEquals([x for x in simple_dict['charSeq']], phrase_r, msg=str(simple_dict['charSeq']) + ' != ' + str(phrase_r) + ' for charSeq') simple_dict.pop('charSeq') #the onconfigure for the octetSeq is supposed to reverse the order of the phrase self.assertEquals([x for x in struct.unpack('5b', simple_dict['octetSeq'])], values_r, msg=str(struct.unpack('5b', simple_dict['octetSeq'])) + ' != ' + str(values_r) + ' for octetSeq') simple_dict.pop('octetSeq') #the rest of the onconfigures are supposed to reverse the values in the list for x in simple_dict: self.assertEquals(simple_dict[x], values_r, msg=str(simple_dict[x]) + ' != ' + str(values_r) + ' for ' + x)
def testConfigureQuerySimples(self): ####################################################################### # Launch the component with the default execparams execparams = self.getPropertySet(kinds=("execparam",), modes=("readwrite", "writeonly"), includeNil=False) execparams = dict([(x.id, any.from_any(x.value)) for x in execparams]) self.launch(execparams) ####################################################################### # Simulate regular component startup # Verify that initialize nor configure throw errors self.comp_obj.initialize() numTestRuns = 10 val = 15 charval = 'a' chardata = struct.pack('1c', charval) flag = True for x in range(numTestRuns): phrase = 'blah' + str(val) flag = not flag self.comp_obj.configure([ossie.cf.CF.DataType(id='stringSimple', value=CORBA.Any(CORBA.TC_string, phrase))]) # Need to reset boolSimple value so value will definitely change self.comp_obj.configure([ossie.cf.CF.DataType(id='boolSimple', value=any.to_any(None))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='boolSimple', value=CORBA.Any(CORBA.TC_boolean, flag))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='ulongSimple', value=CORBA.Any(CORBA.TC_ulong, val))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='shortSimple', value=CORBA.Any(CORBA.TC_short, val))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='floatSimple', value=CORBA.Any(CORBA.TC_float, val))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='octetSimple', value=CORBA.Any(CORBA.TC_octet, val))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='charSimple', value=CORBA.Any(CORBA.TC_char, chardata))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='ushortSimple', value=CORBA.Any(CORBA.TC_ushort, val))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='doubleSimple', value=CORBA.Any(CORBA.TC_double, val))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='longSimple', value=CORBA.Any(CORBA.TC_long, val))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='longlongSimple', value=CORBA.Any(CORBA.TC_longlong, val))]) self.comp_obj.configure([ossie.cf.CF.DataType(id='ulonglongSimple', value=CORBA.Any(CORBA.TC_ulonglong, val))]) simple_list = self.comp_obj.query([ ossie.cf.CF.DataType(id=str('stringSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('boolSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('ulongSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('shortSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('floatSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('octetSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('charSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('ushortSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('doubleSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('longSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('longlongSimple'),value=any.to_any(None)), ossie.cf.CF.DataType(id=str('ulonglongSimple'),value=any.to_any(None)) ]) simple_dict = properties.props_to_dict(simple_list) #the onconfigure for the stringSimple is supposed to double the phrase self.assertEquals(simple_dict['stringSimple'], phrase*2, msg=str(simple_dict['stringSimple']) + ' != ' + str(phrase*2) + ' for stringSimple') simple_dict.pop('stringSimple') #the onconfigure for the boolSimple is supposed to flip the flag self.assertEquals(simple_dict['boolSimple'], not flag, msg=str(simple_dict['boolSimple']) + ' != ' + str(not flag) + ' for boolSimple') simple_dict.pop('boolSimple') self.comp_obj.configure([ossie.cf.CF.DataType(id='boolSimple', value=CORBA.Any(CORBA.TC_boolean, flag))]) #the onconfigure for the charSimple is supposed raise the case self.assertEquals(simple_dict['charSimple'], charval.upper(), msg=str(simple_dict['charSimple']) + ' != ' + str(charval.upper()) + ' for charSimple') simple_dict.pop('charSimple') #the rest of the onconfigures are supposed to double the value for x in simple_dict: self.assertEquals(simple_dict[x], val*2, msg=str(simple_dict[x]) + ' != ' + str(val*2) + ' for ' + x) val = val+1
def testBlueShortPortSwapped(self): ####################################################################### # Test Bluefile Swapped SHORT Functionality print "\n**TESTING BLUEFILE Swapped + SHORT PORT" #Define test files dataFileIn = './bluefile.in' dataFileInSwap = './bluefile.in.swap' #Create Test Data File if it doesn't exist if not os.path.isfile(dataFileIn): tmpSink = bluefile_helpers.BlueFileWriter(dataFileIn, BULKIO__POA.dataShort) tmpSink.start() tmpSri = createSri('bluefileShortSwapped', 5000) #kwVal = 1234 #kwSwap = swap([kwVal], 'long')[0] #tmpSri.keywords = props_from_dict({'TEST_KW':kwSwap}) tmpSri.keywords = props_from_dict({'TEST_KW': 1234}) tmpSink.pushSRI(tmpSri) tmpTs = createTs() #tmpSink.pushPacket(swap(range(1024),'short'), tmpTs, True, 'bluefileShortSwapped') tmpSink.pushPacket(range(1024), tmpTs, True, 'bluefileShortSwapped') #Read in Data from Test File, modify header, and rewrite hdr, d = bluefile.read(dataFileIn, dict) hdr['file_name'] = dataFileInSwap hdr['head_rep'] = 'IEEE' hdr['data_rep'] = 'IEEE' bluefile.write(dataFileInSwap, hdr, d) #Read in Data from Swapped Test File hdr, d = bluefile.read(dataFileInSwap, dict) data = list(d) keywords = hdr['ext_header'] #Create Components and Connections comp = sb.launch('../FileReader.spd.xml') comp.source_uri = dataFileInSwap comp.file_format = 'BLUEFILE' sink = sb.DataSink() comp.connect(sink, usesPortName='dataShort_out') #Start Components & Push Data sb.start() comp.playback_state = 'PLAY' time.sleep(2) readData = sink.getData() readKeywords = props_to_dict(sink.sri().keywords) sb.stop() #Check that the input and output files are the same try: self.assertEqual(data, readData) except self.failureException as e: comp.releaseObject() sink.releaseObject() os.remove(dataFileIn) os.remove(dataFileInSwap) raise e #Check that the keywords are the same try: self.assertEqual(keywords, readKeywords) except self.failureException as e: comp.releaseObject() sink.releaseObject() os.remove(dataFileIn) os.remove(dataFileInSwap) raise e #Release the components and remove the generated files comp.releaseObject() sink.releaseObject() os.remove(dataFileIn) os.remove(dataFileInSwap) print "........ PASSED\n" return
def testRFFlowID(self): #create rf_info uses port and connect to MSDD out_rf_info_port = frontend.OutRFInfoPort("out_control") in_rf_info_port = self.comp.getPort("RFInfo_in") out_rf_info_port.connectPort(in_rf_info_port, "test_rf_flow") # get params for allocations bw = self.alloc_params['wbddc_bw'] sr = self.alloc_params['wbddc_srate'] # allocation params flow_id = "ca-710-flow" cf = 100e6 # set rf flow id out_rf_info_port._set_rf_flow_id(flow_id) # check rf_flow_id was set n = len(self.comp.frontend_tuner_status) expected = [flow_id] * n actual = [ x["FRONTEND::tuner_status::rf_flow_id"] for x in self.comp.frontend_tuner_status ] self.assertEqual(expected, actual, "Mismatch of RF Flow Ids for tuners") # allocation for sample rate and rf_flow_id alloc1 = frontend.createTunerAllocation(center_frequency=cf, sample_rate=sr, rf_flow_id=flow_id) ret = self.comp.allocateCapacity(alloc1) alloc1_aid = alloc1["FRONTEND::tuner_allocation"][ "FRONTEND::tuner_allocation::allocation_id"] self.assertEqual(True, ret, "Allocation failed using rf_flow_id") alloc2_aid = alloc1_aid if self.alloc_params['nbddc_srate'] is not None: # dual channel we need to provide specific rate so the correct DDC is selected that matches the same rf_flow_id if '2w' in self.msdd_id: # allocation for center freq and rf_flow_id alloc2 = frontend.createTunerAllocation( center_frequency=cf, sample_rate=self.alloc_params['nbddc_srate'], sample_rate_tolerance=1.0, rf_flow_id=flow_id) else: # allocation for center freq and rf_flow_id alloc2 = frontend.createTunerAllocation(center_frequency=cf, rf_flow_id=flow_id) ret = self.comp.allocateCapacity(alloc2) alloc2_aid = alloc2["FRONTEND::tuner_allocation"][ "FRONTEND::tuner_allocation::allocation_id"] self.assertEqual(True, ret, "Allocation failed using rf_flow_id again ") # valid rf_flow_id was probagated downstream sink = sb.StreamSink() sdds_in = sb.launch( 'rh.SourceSDDS', properties={ 'interface': INTERFACE, 'advanced_optimizations': { 'advanced_optimizations::sdds_pkts_per_bulkio_push': 5 }, 'attachment_override': { 'attachment_override:endianness': "1234" } }) sb.start() self.comp.connect(sdds_in, connectionId=alloc2_aid, usesPortName='dataSDDS_out') sdds_in.connect(sink, usesPortName="dataShortOut") kws = None try: sink_data = sink.read() kws = properties.props_to_dict(sink_data.sri.keywords) except: pass self.assertEqual(kws["FRONTEND::RF_FLOW_ID"], flow_id, "Missing RF_FLOW_ID from keyword list")
def _runTests(self, props): props = properties.props_from_dict(dict((p, None) for p in props)) result = self.comp.runTest(0, props) return properties.props_to_dict(result)
def getFilterProps(self): """ get the filter properties from the component """ props = self.comp.query([]) d = props_to_dict(props) return d['filterProps']
def testRFFlowID(self): #create rf_info uses port and connect to MSDD out_rf_info_port = frontend.OutRFInfoPort("out_control") in_rf_info_port = self.comp.getPort("RFInfo_in") out_rf_info_port.connectPort(in_rf_info_port, "test_rf_flow") # get params for allocations bw = float(self.comp.frontend_tuner_status[0] ["FRONTEND::tuner_status::available_bandwidth"]) sr = float(self.comp.frontend_tuner_status[0] ["FRONTEND::tuner_status::available_sample_rate"]) # allocation params flow_id = "ca-710-flow" cf = 100e6 # set rf flow id out_rf_info_port._set_rf_flow_id(flow_id) # check rf_flow_id was set n = len(self.comp.frontend_tuner_status) expected = [flow_id] * n actual = [ x["FRONTEND::tuner_status::rf_flow_id"] for x in self.comp.frontend_tuner_status ] self.assertEqual(expected, actual, "Mismatch of RF Flow Ids for tuners") # allocation for sample rate and rf_flow_id alloc1 = frontend.createTunerAllocation(center_frequency=cf, sample_rate=sr, rf_flow_id=flow_id) ret = self.comp.allocateCapacity(alloc1) alloc1_aid = alloc1["FRONTEND::tuner_allocation"][ "FRONTEND::tuner_allocation::allocation_id"] self.assertEqual(True, ret, "Allocation failed using rf_flow_id") # allocation for center freq and rf_flow_id alloc2 = frontend.createTunerAllocation(center_frequency=cf, rf_flow_id=flow_id) ret = self.comp.allocateCapacity(alloc2) alloc2_aid = alloc2["FRONTEND::tuner_allocation"][ "FRONTEND::tuner_allocation::allocation_id"] self.assertEqual(True, ret, "Allocation failed using rf_flow_id again ") # valid rf_flow_id was probagated downstream sink = sb.StreamSink() sdds_in = sb.launch('rh.SourceSDDS', properties={'interface': INTERFACE}) sb.start() self.comp.connect(sdds_in, connectionId=alloc2_aid, usesPortName='dataSDDS_out') sdds_in.connect(sink, usesPortName="dataShortOut") kws = None try: sink_data = sink.read() kws = properties.props_to_dict(sink_data.sri.keywords) except: pass self.assertEqual(kws["FRONTEND::RF_FLOW_ID"], flow_id, "Missing RF_FLOW_ID from keyword list")
except Exception, e: self.assertFalse("Exception thrown on allocateCapactiy %s" % str(e)) if not retval: self.assertFalse("Allocation Failed") #Check Tuner 1 SRI, letting data and SRI flow for up to 1s data = sink.read(timeout=1) self.failIf(data is None) print "SRI 1 1st Time" , data.sri self.assertEqual(data.sri.streamID, allocationID, "SRI 1 Did not Match") self.assertAlmostEqual(data.sri.xdelta, 1.0/2.5e6,5) #Create Allocation and Sink for Tuner 2 sink2 = sb.StreamSink() alloc2 = self._generateAlloc(cf=110e6,sr=5e6,bw=4e6) allocationID2 = properties.props_to_dict(alloc2)['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::allocation_id'] self.comp.connect(sink2,connectionId=allocationID2) sink2.start() #Allocate a Second Tuner try: retval = self.comp.allocateCapacity(alloc2) except Exception, e: print str(e) self.assertFalse("Exception thrown on allocateCapactiy on second Tuner %s" % str(e)) if not retval: self.assertFalse("Allocation Failed on second Tuner") #Sleep and let data and SRI flow time.sleep(1)