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 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 testZeroRate(self): self.setupComponent(endianness=LITTLE_ENDIAN) sink = sb.StreamSink() #sink = sb.DataSink() self.comp.connect(sink, usesPortName='dataOctetOut') sb.start() target_speed = 1000000.0 run = True sleepTime = 2 target_threshold = 0.7 speed_bump = 10.0 last_num_dropped = 0 packets_requested = 57 command = ["../cpp/test_utils/sddsSrc", self.uni_ip, str(self.port), str(target_speed), str(packets_requested)] p = subprocess.Popen(command, stdout=subprocess.PIPE) packets_sent = int(p.stdout.readline()) self.assertEquals(packets_requested, packets_sent) time.sleep(sleepTime) data=sink.read(timeout=5) self.assertFalse(data==None) packets_received = float(len(data.data))/1024.0 self.assertEquals(packets_requested, packets_received) self.comp.stop()
def testConsistentSize(self): """Test that subsequent timestamps differ by an integer multiple of sri.subsize. """ ####################################################################### # Launch the resource with the default execparams self.launch() sink = sb.StreamSink() sink.start() self.comp.connect(sink) ####################################################################### # Make sure start and stop can be called without throwing exceptions self.comp.start() data = sink.read(eos=True) ts_first = data.timestamps[0][1] ts_last = data.timestamps[-1][1] delta = int(ts_last.twsec - ts_first.twsec) self.assertEquals(delta % data.sri.subsize, 0) ####################################################################### # Simulate regular resource shutdown sink.releaseObject() self.comp.releaseObject()
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 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 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 test_push_packet_cplx(self): """Test input/output port pair of the component.""" in_sri = bulkio.sri.create() in_sri.streamID = "VECTOR-PUSHPACKET-CPLX" in_sri.mode = 1 in_sri.xdelta = 1 / 33.0 source = sb.StreamSource(streamID=in_sri.streamID) source.sri = in_sri sink = sb.StreamSink() c_spd_xml = test_dir + self.c_dir + '/' + self.c_name + '/' + self.c_name + '.spd.xml' print "Test Component:" + c_spd_xml test_comp = self.launch(c_spd_xml, execparams=self.execparams) data_in = self.seq source.connect(test_comp, providesPortName=self.c_inport) test_comp.connect(sink, providesPortName=self.sink_inport, usesPortName=self.c_outport) sb.start() source.write(data_in) source.close() stream_data = sink.read(eos=True) data_out = stream_data.data #print "Result data_in: " + str(len(data_out)) #print data_in #print data_out if isinstance(data_in, basestring): self.assertEqual(data_in, data_out[0], 'PUSH PACKET FAILED....Data Vector Mismatch') else: self.assertEqual(len(data_in), len(data_out), 'PUSH PACKET FAILED....Data Vector Mismatch') # # check sri values # sri = stream_data.sri print "StreamID in:" + str(in_sri.streamID) + " arrive:" + str( sri.streamID) self.assertEqual(sri.streamID, in_sri.streamID, "PUSH PACKET CPLX FAILED....SRI StreamID Mismatch") print "Mode in:" + str(in_sri.mode) + " arrive:" + str(sri.mode) self.assertEqual(sri.mode, in_sri.mode, "PUSH PACKET CPLX FAILED....SRI Mode Mismatch") print "SampleRate in:" + str(in_sri.xdelta) + " arrive:" + str( sri.xdelta) self.assertAlmostEqual( sri.xdelta, in_sri.xdelta, 3, msg="PUSH PACKET CPLX FAILED....SRI SampleRate Mismatch")
def testBackPressure(self): """ Tests the back pressure behavior. """ self.utility() numPackets = 4 # Set the queue depth to the number of packets intending to be sent - 1 self.comp.mqd = numPackets - 1 # Create a blocking source (non-default behavior for StreamSink) # Requires a separate thread to prevent deadlock. class StreamSourceThread(threading.Thread): def __init__(self, parent): threading.Thread.__init__(self) self.src = sb.StreamSource() self.src.blocking = True self.src.connect(parent.comp) self.src.start() def run(self): for x in range(numPackets): self.src.write([x]) self.src.close() def stop(self): self.src.stop() src_thread = StreamSourceThread(self) # Create a sink for the output sink = sb.StreamSink() sink.start() self.comp.connect(sink) # Fill up the queue src_thread.start() # Start the component and let the stream complete self.comp.start() streamData = sink.read(timeout=1, eos=True) data = [] if streamData: data = streamData.data # Should not have flushed, should have gotten all packets self.assertEquals(len(data), numPackets) src_thread.stop() sink.stop() self.comp.stop()
def test_iohelper(self): t1 = sb.launch('../components/Python_Ports/Python_Ports.spd.xml') t2 = sb.launch('../components/Python_Ports/Python_Ports.spd.xml') source = sb.StreamSource() destination = sb.StreamSink() source.connect(t1, usesPortName="shortOut") t1.connect(t2, usesPortName="dataShortOut") t2.connect(destination, providesPortName="shortIn") try: sad = sb.generateSADXML("testsadxml") except: traceback.print_exc() self.fail("Generate SAD raised exception") self.assertEqual(sad.find("StreamSource"), -1, "Found StreamSource in SAD") self.assertEqual(sad.find("StreamSink"), -1, "Found StreamSink in SAD")
def test_push(self): """Test that ... """ # Launch the resource 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) class Connection: def __init__(self, uses, provides): self.uses = uses self.provides = provides # octet test is disabled until python test component supports it connections = ( Connection(uses="dataFloat", provides="floatIn"), Connection(uses="dataDouble", provides="doubleIn"), Connection(uses="dataUshort", provides="ushortIn"), Connection(uses="dataShort", provides="shortIn"), Connection(uses="dataLong", provides="longIn"), Connection(uses="dataUlong", provides="ulongIn"), Connection(uses="dataUlongLong", provides="ulonglongIn"), Connection(uses="dataLongLong", provides="longlongIn"), # Connection(uses = "dataOctet", provides = "octetIn"), ) for connection in connections: print connection.uses if connection.uses.lower().find("long") != -1: isLong = True else: isLong = False if connection.uses.lower().find("octet") != -1: isOctet = True else: isOctet = False sink = sb.StreamSink() self.comp.connect(sink, usesPortName=connection.uses, providesPortName=connection.provides) self.checkData(sink, isLong=isLong, isOctet=isOctet) self.comp.disconnect(sink)
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 setUp(self): print "\nRunning test:", self.id() ossie.utils.testing.ScaComponentTestCase.setUp(self) execparams = {"DEBUG_LEVEL" : DEBUG_LEVEL} self.comp = sb.launch(self.spd_file, impl=self.impl,properties=execparams) #Configure multicast properties self.comp.buffer_size = 200000 # cannot alter this except in base class loadProperties (requires recompile) self.comp.advanced_configuration.pushOnTTValid = False self.port = 29495 self.uni_ip = '127.0.0.1' self.multi_ip = '236.0.10.1' self.mserver = multicast.multicast_server(self.multi_ip, self.port) self.userver = unicast.unicast_server(self.uni_ip, self.port) self.sink = sb.StreamSink() self.sink.start()
def testTwoInstances(self): # ensure log level is set to TRACE self.comp.log_level(CF.LogLevels.TRACE) # launch a second instance (first instance is launched via setUp method comp2 = sb.launch(self.spd_file, impl=self.impl) comp2.log_level(CF.LogLevels.TRACE) comp2.buffer_size = 200000 comp2.advanced_configuration.pushOnTTValid = False port2 = 29495+1 mserver2 = multicast.multicast_server(self.multi_ip, port2) userver2 = unicast.unicast_server(self.uni_ip, port2) sink2 = sb.StreamSink() sink2.start() time.sleep(2) comp2.stop() comp2.releaseObject()
def test_outport_using_component(self): """Test some API calls. These comments appear out of date. bulkio output port none UsesPortStatisticsProvider _get_statistics CF::Port _get_connections connectPort (unused. remove/replace?) disconnectPort (unused. remove/replace?) data<Type> pushPacket (unused. remove/replace?) """ c_spd_xml = test_dir + self.c_dir + '/' + self.c_name + '/' + self.c_name + '.spd.xml' print "Test Component:" + c_spd_xml test_comp = self.launch(c_spd_xml, execparams=self.execparams) ## ## grab port from component... this is a corba port ## oport = test_comp.getPort(self.c_outport) self.assertNotEqual(oport, None, "Cannot get Output Port") ps = oport._get_statistics() self.assertNotEqual(ps, None, "Cannot get Port Statistics") sink = sb.StreamSink() test_comp.connect(sink, providesPortName=self.sink_inport, usesPortName=self.c_outport) cl = oport._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 1, "Incorrect Connections List Length") test_comp.disconnect(sink) cl = oport._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 0, "Incorrect Connections List Length")
def testInValidRFInfoPacket(self): #Create Allocation and Sink for Tuner 1 sink = sb.StreamSink() 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 testSddsPacketsPerBulkIOPush(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') sdds_pkts_per_push = (1, 2, 4, 8, 16, 32, 64) for pkts_per_push in sdds_pkts_per_push: self.comp.advanced_optimizations.sdds_pkts_per_bulkio_push = pkts_per_push # Start components self.comp.start() num_sends = 0 data = [] sink = sb.StreamSink() self.comp.connect(sink, providesPortName='shortIn') while (not(data) and num_sends < 3*max(sdds_pkts_per_push)): # Create data fakeData = [x for x in range(0, 512)] h = Sdds.SddsHeader(num_sends) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) num_sends = num_sends + 1 if num_sends != 0 and num_sends % 32 == 31: num_sends = num_sends + 1 time.sleep(0.05) packet = sink.port.getPacket() if packet.dataBuffer: data = packet.dataBuffer # Validate correct amount of data was received self.assertEqual(len(data), pkts_per_push * 512) self.comp.stop()
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.StreamSink() 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 _testConnectionFail(self, format, data): uses_name = 'data%sOut' % format provides_name = 'data%sIn' % format source = sb.StreamSource(streamID='test_connection_fail') source.connect(self.comp1, providesPortName=provides_name) self.comp1.connect(self.comp2, usesPortName=uses_name) sink = sb.StreamSink() self.comp1.connect(sink, usesPortName=uses_name) sb.start() os.kill(self.comp2._pid, 9) while self.comp2._process.isAlive(): time.sleep(0.1) for _ in xrange(9): source.write(data) source.close() sink.read(eos=True)
def testFlush(self): """ Test the standard flush behavior. """ self.utility() numPackets = 4 # Set the queue depth to the number of packets intending to be sent - 1 self.comp.mqd = numPackets - 1 # Create a non-blocking source source = sb.StreamSource() source.connect(self.comp) # Create a sink for the output sink = sb.StreamSink() self.comp.connect(sink) # Send numPackets without starting the component, should generate a flush for x in xrange(numPackets): source.write([x]) source.start() source.close() # Start the component and let the stream complete self.comp.start() sink.start() streamData = sink.read(timeout=1, eos=True) data = [] if streamData: data = streamData.data self.assertEqual(len(data), 1) source.stop() sink.stop() self.comp.stop()
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")
try: retval = self.comp.allocateCapacity(alloc) 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
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 pushDataAndCheck(self, inputData=range(100), expectedOutput=range(100), pause=PAUSE, streamID='defaultStreamID', sampleRate=1.0, complexData=False, SRIKeywords=[], usesPortName="vectorOut0", providesPortName="vectorIn0"): dataFormat = "double" source = sb.StreamSource(streamID=streamID, format=dataFormat) sink = sb.StreamSink(format=dataFormat) source.xdelta = 1.0 / sampleRate source.complex = complexData interleaved = False if source.complex: interleaved = True for kw in SRIKeywords: source.setKeyword(kw._name, kw._value, format=kw._format) # connect source -> component -> sink source.connect(self.comp) self.comp.connect(sink) # Start all source.start() self.comp.start() sink.start() source.write(inputData, interleaved=interleaved) # Give the component some time to process the data time.sleep(pause) streamData = sink.read() retData = [] retSri = None if streamData: retData = streamData.data retSri = streamData.sri self.assertEquals(retData, expectedOutput) # SRI tests self.assertEquals(streamData.eos, False) self.assertEquals(retSri.streamID, streamID) # sample rate is checked via Xdelta self.assertEquals(retSri.xdelta, 1. / sampleRate) self.assertEquals(retSri.mode, complexData) # SRI keywords if len(SRIKeywords) != len(retSri.keywords): self.fail( "Incorrect number of SRI keywords returned by component.") for expectedKeyword in SRIKeywords: found = False for retKeyword in retSri.keywords: if retKeyword.id == expectedKeyword._name: self.assertEquals(str(retKeyword.value), str(any.to_any(expectedKeyword._value))) found = True break if not found: self.fail("SRI keyword not found: " + expectedKeyword.id) # Check for eos source.close() streamData = sink.read(timeout=pause, eos=True) retData = [] retSri = None if streamData: retData = streamData.data retSri = streamData.sri self.assertEquals(streamData.eos, True) self.assertEquals(retSri.streamID, streamID) source.releaseObject() sink.releaseObject()