def testBasicBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions self.comp.start() self.comp.stop() a = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER', allocation_id='1', returnDict=False) b = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER', allocation_id='2', returnDict=False) c = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER', allocation_id='3', returnDict=False) a_bad = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER', allocation_id='1', returnDict=False) a_bad.id = 'foo' self.assertEquals(self.comp._get_usageState(), CF.Device.IDLE) self.assertEquals(self.comp.allocateCapacity([a]), True) self.assertEquals(self.comp._get_usageState(), CF.Device.ACTIVE) self.assertEquals(self.comp.allocateCapacity([b]), True) self.assertEquals(self.comp._get_usageState(), CF.Device.BUSY) self.assertEquals(self.comp.allocateCapacity([c]), False) self.assertEquals(self.comp._get_usageState(), CF.Device.BUSY) try: self.comp.deallocateCapacity([b, a_bad]) except: pass self.assertEquals(self.comp._get_usageState(), CF.Device.ACTIVE) self.comp.deallocateCapacity([a]) self.assertEquals(self.comp._get_usageState(), CF.Device.IDLE)
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 testNarrowBandDDC_DontCareAllocation(self): wb_alloc = frontend.createTunerAllocation( tuner_type="RX_DIGITIZER_CHANNELIZER", center_frequency=100e6) ret = self.comp.allocateCapacity(wb_alloc) self.assertTrue(ret) alloc = frontend.createTunerAllocation(tuner_type="DDC", center_frequency=100e6) ret = self.comp.allocateCapacity(alloc) self.assertTrue(ret) self.comp.deallocateCapacity(alloc) self.comp.deallocateCapacity(wb_alloc)
def testNarrowBandDDC_BadAllocation2(self): wb_alloc = frontend.createTunerAllocation( tuner_type="RX_DIGITIZER_CHANNELIZER", center_frequency=100e6) ret = self.comp.allocateCapacity(wb_alloc) self.assertTrue(ret) alloc = frontend.createTunerAllocation(tuner_type="DDC", center_frequency=100e6, bandwidth=20, bandwidth_tolerance=100.0) ret = self.comp.allocateCapacity(alloc) self.assertFalse(ret) self.comp.deallocateCapacity(wb_alloc)
def testBasicBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions self.comp.start() bad_tuner = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER', allocation_id='1', bandwidth=0.0, returnDict=False) good_tuner = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER', allocation_id='1', bandwidth=1000.0, returnDict=False) bad_scanner = frontend.createScannerAllocation(returnDict=False) good_scanner = frontend.createScannerAllocation(min_freq=10000.0, returnDict=False) self.assertFalse(self.comp.allocateCapacity([bad_tuner, bad_scanner])) self.assertFalse(self.comp.allocateCapacity([good_tuner, bad_scanner])) self.assertFalse(self.comp.allocateCapacity([bad_tuner, good_scanner])) self.assertTrue(self.comp.allocateCapacity([good_tuner, good_scanner])) self.comp.deallocateCapacity([good_tuner, good_scanner]) self.assertTrue(self.comp.allocateCapacity([good_scanner, good_tuner])) ref = None for port in self.comp.ports: if port.name == 'DigitalScanningTuner_in': ref = port.ref break self.assertEquals(self.comp.strategy_request, 'initial') scan_strategy = FRONTEND.ScanningTuner.ScanStrategy( FRONTEND.ScanningTuner.MANUAL_SCAN, FRONTEND.ScanningTuner.ScanModeDefinition(center_frequency=1.0), FRONTEND.ScanningTuner.TIME_BASED, 0.0) ref.setScanStrategy('1', scan_strategy) self.assertEquals(self.comp.strategy_request, 'manual') scan_strategy = FRONTEND.ScanningTuner.ScanStrategy( FRONTEND.ScanningTuner.DISCRETE_SCAN, FRONTEND.ScanningTuner.ScanModeDefinition(discrete_freq_list=[]), FRONTEND.ScanningTuner.TIME_BASED, 0.0) ref.setScanStrategy('1', scan_strategy) self.assertEquals(self.comp.strategy_request, 'discrete') scan_strategy = FRONTEND.ScanningTuner.ScanStrategy( FRONTEND.ScanningTuner.SPAN_SCAN, FRONTEND.ScanningTuner.ScanModeDefinition(freq_scan_list=[]), FRONTEND.ScanningTuner.TIME_BASED, 0.0) ref.setScanStrategy('1', scan_strategy) self.assertEquals(self.comp.strategy_request, 'span') status = ref.getScanStatus('1') self.assertEquals(status.strategy.control_value, 123) self.comp.stop()
def testConnectBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions alloc=frontend.createTunerAllocation() snk_1 = sb.StreamSink() snk_2 = sb.StreamSink() self.comp.allocateCapacity(alloc) self.comp.connect(snk_1, connectionId='some_connection') tuner_status = self.comp.frontend_tuner_status[0] alloc_id = alloc['FRONTEND::tuner_allocation']['FRONTEND::tuner_allocation::allocation_id'] self.assertEquals(tuner_status.allocation_id_csv, alloc_id) self.comp.connect(snk_2) self.assertEquals(len(self.comp.connectionTable), 2) alloc_id = alloc_id + ',' + self.comp.connectionTable[1].connection_id self.assertEquals(tuner_status.allocation_id_csv, alloc_id) sb.start() time.sleep(0.1) time.sleep(0.25) self.comp.deallocateCapacity(alloc) time.sleep(0.1) data_1 = snk_1.read(timeout=1) self.assertEquals(data_1, None) data_2 = snk_2.read(timeout=1) self.assertEquals(data_2.streamID, 'my_data') self.assertEquals(len(data_2.data), 25) self.assertEquals(len(self.comp.connectionTable), 0) sb.stop()
def testBasicBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions _antennainfo = FRONTEND.AntennaInfo('', '', '', '') _freqrange = FRONTEND.FreqRange(0, 0, []) _feedinfo = FRONTEND.FeedInfo('', '', _freqrange) _sensorinfo = FRONTEND.SensorInfo('', '', '', _antennainfo, _feedinfo) _rfcapabilities = FRONTEND.RFCapabilities(_freqrange, _freqrange) rf_center_freq = 1e7 rf_bandwidth = 3e5 if_center_freq = 1e6 pkt_str = FRONTEND.RFInfoPkt('my_flow', rf_center_freq, rf_bandwidth, if_center_freq, False, _sensorinfo, [], _rfcapabilities, []) request_cf = 9.95e6 request_bw = 2e5 alloc = frontend.createTunerAllocation(allocation_id='foo', center_frequency=request_cf, bandwidth=request_bw, sample_rate=0.0) port = self.comp.ports[1] port.ref._set_rfinfo_pkt(pkt_str) self.comp.max_dev_if_cf = 1e6 self.assertTrue(self.comp.allocateCapacity(alloc)) self.comp.deallocateCapacity(alloc) pkt_inv = FRONTEND.RFInfoPkt('my_flow', rf_center_freq, rf_bandwidth, if_center_freq, True, _sensorinfo, [], _rfcapabilities, []) port.ref._set_rfinfo_pkt(pkt_inv) self.assertFalse(self.comp.allocateCapacity(alloc)) self.comp.max_dev_if_cf = 1.15e6 self.assertTrue(self.comp.allocateCapacity(alloc)) self.comp.deallocateCapacity(alloc)
def runAllocTuneTest(msg, key, expected, dut, ttype, alloc_id='test_alloc', cf=DBOARD['DEFAULT_CF'], sr=DBOARD['DEFAULT_SR'], bw=DBOARD['DEFAULT_BW'], rx_gain=None, tx_gain=None, cf2=None, sr2=None, bw2=None, dealloc=True): alloc = createTunerAllocation( tuner_type = ttype, allocation_id = alloc_id, center_frequency = cf, bandwidth = bw, sample_rate = sr) actual = None try: if not dut.allocateCapacity(alloc): dealloc = True else: if cf2 != None: port = dut.getPort('DigitalTuner_in') port.setTunerCenterFrequency(alloc_id,cf2) elif sr2 != None: port = dut.getPort('DigitalTuner_in') port.setTunerOutputSampleRate(alloc_id,sr2) elif bw2 != None: port = dut.getPort('DigitalTuner_in') port.setTunerBandwidth(alloc_id,bw2) elif rx_gain != None: dut.device_rx_gain_global = rx_gain elif tx_gain != None: dut.device_tx_gain_global = tx_gain for tuner in dut.frontend_tuner_status: if alloc_id in tuner['FRONTEND::tuner_status::allocation_id_csv']: actual = tuner[key] break except Exception, e: print 'Exception', e dealloc = True
def testBasicBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions self.comp.start() alloc = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER',allocation_id='master',center_frequency=100) listen_alloc = frontend.createTunerListenerAllocation('master','slave') another_listen_alloc = frontend.createTunerListenerAllocation('master','another_slave') self.comp.allocateCapacity(alloc) self.comp.allocateCapacity(listen_alloc) self.comp.allocateCapacity(another_listen_alloc) master=sb.DataSink() slave=sb.DataSink() another_slave=sb.DataSink() self.comp.connect(master,connectionId='master') self.comp.connect(slave,connectionId='slave') self.comp.connect(another_slave,connectionId='another_slave') time.sleep(3) self.assertEquals(master.eos(),False) self.assertEquals(slave.eos(),False) self.assertEquals(another_slave.eos(),False) self.comp.deallocateCapacity(listen_alloc) self.assertEquals(master.eos(),False) self.assertEquals(slave.eos(),True) self.assertEquals(another_slave.eos(),False) self.comp.deallocateCapacity(alloc) self.assertEquals(master.eos(),True) self.assertEquals(slave.eos(),True) self.assertEquals(another_slave.eos(),True) sb.release() self.fp.close() self.fp = open(self.filename,'r') stuff = self.fp.read() self.fp.close() self.assertEquals(stuff.find('the application attempted to invoke an operation on a nil reference'), -1)
def testNarrowBandDDC_BadAllocation(self): if self.alloc_params['nbddc_srate'] is None: return wb_alloc = frontend.createTunerAllocation( tuner_type="RX_DIGITIZER_CHANNELIZER", center_frequency=100e6) ret = self.comp.allocateCapacity(wb_alloc) self.assertTrue(ret) alloc = frontend.createTunerAllocation(tuner_type="DDC", center_frequency=100e6, sample_rate=20, sample_rate_tolerance=100.0) ret = self.comp.allocateCapacity(alloc) self.assertFalse(ret) self.comp.deallocateCapacity(wb_alloc)
def testTunerStatus(self): self.fei_dev, alloc_params = self.getAllocationContext(ALLOCATE_RCV) self.alloc1=frontend.createTunerAllocation(tuner_type="RX_DIGITIZER_CHANNELIZER", center_frequency=100e6, sample_rate=alloc_params['wbddc_srate'], sample_rate_tolerance=100.0) ret=self.fei_dev.allocateCapacity(self.alloc1) self.assertTrue(ret) alloc1_aid = self.alloc1["FRONTEND::tuner_allocation"]["FRONTEND::tuner_allocation::allocation_id"] expected=True actual=self.fei_dev.frontend_tuner_status[0].enabled self.assertEqual(expected,actual, "Tuner status enabled failed") expected=True actual=self.fei_dev.frontend_tuner_status[0].output_enabled self.assertEqual(expected,actual, "Tuner status output enabled failed") sink=sb.StreamSink() sdds_in=sb.launch('rh.SourceSDDS', properties={'interface': INTERFACE}) sb.start() self.fei_dev.connect(sdds_in, connectionId=alloc1_aid, usesPortName='dataSDDS_out') sdds_in.connect(sink,usesPortName="dataShortOut") sink_data=None try: sink_data=sink.read(timeout=1.0) except: pass self.assertNotEqual( None, sink_data, "MSDD did not produce data for allocation") self.assertNotEqual( 0, len(sink_data.data), "MSDD did not produce data for allocation")
def testBasicBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions self.comp.start() alloc = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER',allocation_id='master',center_frequency=100) listen_alloc = frontend.createTunerListenerAllocation('master','slave') another_listen_alloc = frontend.createTunerListenerAllocation('master','another_slave') self.comp.allocateCapacity(alloc) self.comp.allocateCapacity(listen_alloc) self.comp.allocateCapacity(another_listen_alloc) master=sb.DataSink() slave=sb.DataSink() another_slave=sb.DataSink() self.comp.connect(master,connectionId='master') self.comp.connect(slave,connectionId='slave') self.comp.connect(another_slave,connectionId='another_slave') time.sleep(3) self.assertEquals(master.eos(),False) self.assertEquals(slave.eos(),False) self.assertEquals(another_slave.eos(),False) self.comp.deallocateCapacity(listen_alloc) self.assertEquals(master.eos(),False) self.assertEquals(slave.eos(),True) self.assertEquals(another_slave.eos(),False) self.comp.deallocateCapacity(alloc) self.assertEquals(master.eos(),True) self.assertEquals(slave.eos(),True) self.assertEquals(another_slave.eos(),True)
def testNarrowBandDDC_DontCareAllocation(self): self.fei_dev, alloc_params = self.getAllocationContext(ALLOCATE_RCV) if alloc_params['nbddc_srate'] is None : return wb_alloc=frontend.createTunerAllocation(tuner_type="RX_DIGITIZER_CHANNELIZER", center_frequency=100e6) ret=self.fei_dev.allocateCapacity( wb_alloc) self.assertTrue(ret) self.alloc1=wb_alloc alloc=frontend.createTunerAllocation(tuner_type="DDC", center_frequency=100e6) ret=self.fei_dev.allocateCapacity( alloc) self.assertTrue(ret) self.alloc2=alloc
def testRFFlowIDFailure(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="noworkie") ret = self.comp.allocateCapacity(alloc2) self.assertEqual( False, ret, "Allocation should have failed for unknown rf_flow_id ")
def testWideBandDDC_BandwidthAllocation(self): self.fei_dev, alloc_params = self.getAllocationContext(ALLOCATE_RCV) alloc=frontend.createTunerAllocation(tuner_type="RX_DIGITIZER_CHANNELIZER", center_frequency=100e6, bandwidth=alloc_params['wbddc_bw'], bandwidth_tolerance=100.0) ret=self.fei_dev.allocateCapacity( alloc) self.assertTrue(ret) self.alloc1=alloc
def testWideBandDDC_SampleRateAllocation(self): alloc = frontend.createTunerAllocation( tuner_type="RX_DIGITIZER_CHANNELIZER", center_frequency=100e6, sample_rate=self.alloc_params['wbddc_srate'], sample_rate_tolerance=100.0) ret = self.comp.allocateCapacity(alloc) self.assertTrue(ret) self.comp.deallocateCapacity(alloc)
def testWideBandDDC_BandwidthAllocation(self): alloc = frontend.createTunerAllocation( tuner_type="RX_DIGITIZER_CHANNELIZER", center_frequency=100e6, bandwidth=self.alloc_params['wbddc_bw'], bandwidth_tolerance=100.0) ret = self.comp.allocateCapacity(alloc) self.assertTrue(ret) self.comp.deallocateCapacity(alloc)
def test_BusyAlloc(self): self.comp.busy_state = True frontend_alloc = frontend.createTunerAllocation(returnDict=False) retval = self.comp.allocateCapacity([frontend_alloc]) self.assertFalse(retval) self.comp.busy_state = False retval = self.comp.allocateCapacity([frontend_alloc]) self.assertTrue(retval) self.comp.deallocateCapacity([frontend_alloc]) self.comp.busy_state = True retval = self.comp.allocateCapacity([frontend_alloc]) self.assertFalse(retval)
def testBasicBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions sb.start() alloc = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER',allocation_id='master',center_frequency=100) listen_alloc = frontend.createTunerListenerAllocation('master','slave') another_listen_alloc = frontend.createTunerListenerAllocation('master','another_slave') self.comp.allocateCapacity(alloc) self.comp.allocateCapacity(listen_alloc) self.comp.allocateCapacity(another_listen_alloc) master = sb.StreamSink() slave = sb.StreamSink() another_slave = sb.StreamSink() self.comp.connect(master,connectionId='master') self.comp.connect(slave,connectionId='slave') self.comp.connect(another_slave,connectionId='another_slave') def get_eos(streamSink, **kwargs): streamData = streamSink.read(**kwargs) if streamData: return streamData.eos return False time.sleep(1) self.assertEquals(get_eos(master), False) self.assertEquals(get_eos(slave), False) self.assertEquals(get_eos(another_slave), False) self.comp.deallocateCapacity(listen_alloc) self.assertEquals(get_eos(master), False) # Save result so we dont call read() twice after eos. eos_slave = get_eos(slave, timeout=1, eos=True) self.assertEquals(eos_slave, True) self.assertEquals(get_eos(another_slave), False) self.comp.deallocateCapacity(alloc) self.assertEquals(get_eos(master, timeout=1, eos=True), True) self.assertEquals(eos_slave, True) self.assertEquals(get_eos(another_slave, timeout=1, eos=True), True) sb.release() self.fp.close() self.fp = open(self.filename,'r') stuff = self.fp.read() self.fp.close() self.assertEquals(stuff.find('the application attempted to invoke an operation on a nil reference'), -1)
def testReentrant(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions for _port in self.comp.ports: if _port.name == 'DigitalTuner_in': port = _port break alloc = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER', allocation_id='hello', center_frequency=100) retval = self.comp.allocateCapacity(alloc) thread = threading.Thread(target=self.threadedFunction, args=(port, )) thread.start() self.sample_rate_2 = port.ref.getTunerBandwidth('hello') time.sleep(1) thread.join() self.assertEquals(self.sample_rate_1, self.sample_rate_2)
def testBasicBehavior(self): ####################################################################### # Make sure start and stop can be called without throwing exceptions sb.start() alloc = frontend.createTunerAllocation(tuner_type='RX_DIGITIZER',allocation_id='master',center_frequency=100) listen_alloc = frontend.createTunerListenerAllocation('master','slave') another_listen_alloc = frontend.createTunerListenerAllocation('master','another_slave') self.comp.allocateCapacity(alloc) self.comp.allocateCapacity(listen_alloc) self.comp.allocateCapacity(another_listen_alloc) master = sb.StreamSink() slave = sb.StreamSink() another_slave = sb.StreamSink() self.comp.connect(master,connectionId='master') self.comp.connect(slave,connectionId='slave') self.comp.connect(another_slave,connectionId='another_slave') time.sleep(1) fake_master_alloc = frontend.createTunerListenerAllocation('master','master') self.assertRaises(CF.Device.InvalidCapacity, self.comp.deallocateCapacity, fake_master_alloc) self.assertEquals(self.comp.frontend_tuner_status[0].allocation_id_csv[:6],'master') def get_eos(streamSink, **kwargs): streamData = streamSink.read(**kwargs) if streamData: return streamData.eos return False self.assertEquals(get_eos(master), False) self.assertEquals(get_eos(slave), False) self.assertEquals(get_eos(another_slave), False) self.comp.deallocateCapacity(listen_alloc) time.sleep(0.5) self.assertEquals(get_eos(master), False) # Save result so we dont call read() twice after eos. eos_slave = get_eos(slave, timeout=1, eos=True) self.assertEquals(eos_slave, True) self.assertEquals(get_eos(another_slave), False) self.comp.deallocateCapacity(alloc) self.assertEquals(get_eos(master, timeout=1, eos=True), True) self.assertEquals(eos_slave, True) self.assertEquals(get_eos(another_slave, timeout=1, eos=True), True)
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")
print '==========================================================================' print 'Ignoring other dboard tuners by allocating them with output disabled' print '==========================================================================' port = dut.getPort('DigitalTuner_in') for chan in xrange(len(dut.device_channels)): if dut.device_channels[chan].tuner_type not in ['RX_DIGITIZER','TX']: continue if DBOARD_IGNORE['NAME'] not in dut.device_channels[chan].ch_name: continue # allocate as many as will succeed cnt = ord('A') alloc_id = 'ignore_tuner_%s.%s'%(chan,chr(cnt)) alloc = createTunerAllocation( tuner_type = str(dut.device_channels[chan].tuner_type), allocation_id = alloc_id, center_frequency = DBOARD_IGNORE['DEFAULT_CF'], bandwidth = DBOARD_IGNORE['DEFAULT_BW'], sample_rate = DBOARD_IGNORE['DEFAULT_SR']) success = True while success: try: success = dut.allocateCapacity(alloc) except: #print 'Exception when allocating a %s (%s)'%(dut.device_channels[chan].tuner_type,alloc_id) success = False else: if success: #print 'Allocated a %s (%s)'%(dut.device_channels[chan].tuner_type,alloc_id) cnt+=1 port.setTunerEnable(alloc_id, False) alloc_id = 'ignore_tuner_%s.%s'%(chan,chr(cnt))
def connectAndTune(self): # Lets make sure we have everything we need before continuing. if not self.InputComponent.componentName: self._log.error("Stopping. Component name must be specified.") self.stop() return if not self.InputComponent.inputPortName: self._log.error("Stopping. Component input port name must be specified.") self.stop() return if not self.FEIDevice.deviceName: self._log.error("Stopping. Device name must be specified.") self.stop() return if not self.FEIDevice.outputPortName: self._log.error("Stopping. Device output port name must be specified.") self.stop() return if not self.FEIDevice.tunerPortName: self._log.error("Stopping. Device tuner port name must be specified.") self.stop() return # While the domain port does give us a direct connection to the domain, the # API exposed is cleaner from the domain instance returned via the redhawk.attach method. try: domainname = self.port_DomainManager_out._get_name() self.domain = redhawk.attach(domainname) except Exception as ex: self._log.error("Failed to connect to domain: " + str(ex)) self.stop() return if self.domain is None: self._log.error("Stopping. Could not connect to domain.") self.stop() return self._log.debug("Searching for the current waveform in the domain") waveform = self.findWaveformByComponentInstanceName(self._name) if waveform is None: self._log.error("Stopping. Could not find the running waveform.") self.stop(); return self._log.debug("Searching for the component in the waveform: " + str(waveform.name)) # Gets the component from the application. The component name can be the name or instantition. ex. DataConverter or DataConveter_3 # This allows you to use the same component multiple times in a waveform and know for certain which one you are connecting to. for comp in waveform.comps: if self.InputComponent.componentName in comp._instanceName: self.targetComponent = comp break if self.targetComponent is None: self._log.error("Stopping. Could not find the component: " + self.InputComponent.componentName) self.stop(); return self._log.debug("Searching device managers for device: " + self.FEIDevice.deviceName) self.targetDevice = self.findByDeviceName(self.FEIDevice.deviceName) if self.targetDevice is None: self._log.error("Stopping. Could not find the device: " + self.FEIDevice.deviceName) self.stop() return # Gets the references to the input and output ports self.targetComponentPort = self.targetComponent.getPort(self.InputComponent.inputPortName) self.targetDevicePort = self.targetDevice.getPort(self.FEIDevice.outputPortName) self.feiTunerPort = self.targetDevice.getPort(self.FEIDevice.tunerPortName) if self.targetComponentPort is None: self._log.error("Stopping. Could not find the component input port: " + self.InputComponent.inputPortName) self.stop() return if self.targetDevicePort is None: self._log.error("Stopping. Could not find the component output port: " + self.FEIDevice.outputPortName) self.stop() return if self.feiTunerPort is None: self._log.error("Stopping. Could not find the tuner port: " + self.FEIDevice.tunerPortName) self.stop() return self.allocationRequest = frontend.createTunerAllocation( tuner_type = self.tunerType, allocation_id = self.allocationId, center_frequency = self.TuneRequest.frequency * 1e6, sample_rate = self.TuneRequest.sampleRate * 1e6, sample_rate_tolerance = 20.0 ) self._log.debug("Performing allocation of FEI Device") self._log.debug("Allocation contains: " + str(self.allocationRequest)) retVal = False try: retVal = self.targetDevice.allocateCapacity(self.allocationRequest) except CF.Device.InvalidCapacity as ex: self._log.error("Device has invalid capacity, allocation failed: " + str(ex)) except CF.Device.InvalidState as ex: self._log.error("Device in invalid state, allocation failed: " + str(ex)) except Exception as ex: self._log.error("Exception thrown while allocating: " + str(ex)) if (retVal is False): self._log.error("Allocation failed. Stopping.") self.stop() return self._log.debug("Allocation succeeded!") # Makes the actual connection self._log.debug("Connecting component and device ports") self.targetDevicePort.connectPort(self.targetComponentPort, self.allocationId) self.connected = True self._log.debug("Starting device and component") # Make sure device and component are started self.targetDevice.start() self.targetComponent.start()
step = "Step0" orb = CORBA.ORB_init() print step, " Setup the ORB ..", orb step = "Step1:" device = orb.string_to_object(dev_ior) if not device: raise Exception("Unable to locate FEI device under test, device ior " + str(dev_ior) + " type " + str(tuner_type)) print step, " Located FEI device under test, device ior ", dev_ior, " type ", tuner_type step = "Step2:" freq = 100e6 + (id * 1e5) print step, " Create allocation request, allocation id ", id, "tuner ", tuner_type, " freq ", freq a = frontend.createTunerAllocation(allocation_id=str(id), tuner_type=tuner_type, center_frequency=freq) step = "Step3:" aprops = properties.props_from_dict(a) print step, " Calling allocateCapacity for allocation id ", id, a device.allocateCapacity(aprops) stop_time = time.time() print("Allocation: {0} PASSED duration: {1} ".format( id, stop_time - start_time)) retval = 0 except Exception as e: traceback.print_exc() print("Create allocation failed, allocation id {0} - {1}: {2}".format( id, step, 3))
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")
def testAllocation(self): frontend_alloc = frontend.createTunerAllocation(returnDict=False) retval = self.comp.allocateCapacity([frontend_alloc]) self.assertEquals(retval, True)
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, 1) 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')