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 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 test_outport_python_api(self): ## ## Create bulkio base class port object ## bio = self.bio_out_module("xxx") cl = bio._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 0, "Incorrect Connections List Length") connectionName = "testing-connection-list" dsink = sb.DataSink() inport = dsink.getPort(self.sink_inport) bio.connectPort(inport, connectionName) cl = bio._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 1, "Incorrect Connections List Length") bio.disconnectPort(connectionName) bio.disconnectPort(connectionName) cl = bio._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 0, "Incorrect Connections List Length") ts = bulkio.timestamp.now() sri = bulkio.sri.create() sri.streamID = "test_port_api" bio.pushSRI(sri) data = range(50) bio.pushPacket(data, ts, False, "test_port_api") bio.pushPacket(data, ts, True, "test_port_api") bio.pushPacket(data, ts, False, "unknown_port_api") ps = bio._get_statistics() self.assertNotEqual(ps, None, "Cannot get Port Statistics") cnt = len(bio.sriDict) self.assertEqual(cnt, 1, "SRI list should be 1") bio.enableStats(False) # repeating connect/disconnect to test ticket #1996 connectionName = "testing-connection-list" dsink = sb.DataSink() inport = dsink.getPort(self.sink_inport) bio.connectPort(inport, connectionName) cl = bio._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 1, "Incorrect Connections List Length") bio.disconnectPort(connectionName) bio.disconnectPort(connectionName)
def setUp(self): """Set up the unit test - this is run before every method that starts with test""" ossie.utils.testing.ScaComponentTestCase.setUp(self) self.src = sb.DataSource() self.fftsink = sb.DataSink() self.psdsink = sb.DataSink() self.comp = sb.launch('../psd.spd.xml', execparams={'DEBUG_LEVEL': DEBUG_LEVEL}) self.src.connect(self.comp) self.comp.connect(self.fftsink, usesPortName='fft_dataFloat_out') self.comp.connect(self.psdsink, usesPortName='psd_dataFloat_out')
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 testShortBigEndianness(self): self.setupComponent(endianness=BIG_ENDIAN) # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') sink = sb.DataSink() # Connect components self.comp.connect(sink, providesPortName='shortIn') # Start components self.comp.start() sink.start() # Create data fakeData = [x for x in range(0, 512)] h = Sdds.SddsHeader(0) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() # Defaults to big endian encoding self.userver.send(p.encodedPacket) time.sleep(0.05) data = sink.getData() self.assertEqual(self.comp.status.input_endianness, "4321", "Status property for endianness is not 4321") self.assertEqual(data, fakeData, "Big Endian short did not match expected")
def setUp(self): ossie.utils.testing.ScaComponentTestCase.setUp(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]) execparams['DEBUG_LEVEL'] = DEBUG_LEVEL self.launch(execparams) ####################################################################### # Verify the basic state of the component self.assertNotEqual(self.comp, None) self.assertEqual(self.comp.ref._non_existent(), False) self.assertEqual(self.comp.ref._is_a("IDL:CF/Resource:1.0"), True) # Load resources for majority of tests self.src = sb.DataSource() self.sink = sb.DataSink() self.sinkSocket = self.comp self.sourceSocket = NetworkSource() self.client = None self.clients = None self.server = None self.servers = None self.sink2 = None self.sourceSocket2 = None
def _check_FileSourceTimecode(self, hdr, data, framesize, delta): # Put a known timecode value into the header and write out the data start = bulkio.timestamp.now() hdr['timecode'] = bluefile_helpers.unix_to_j1950(start.twsec + start.tfsec) filename = self._tempfileName('source_timecode_%d_%s' % (hdr['type'], hdr['format'])) bluefile.write(filename, hdr, data) # Bytes per push is chosen specifically to require multiple packets source = sb.FileSource(filename, bytesPerPush=2048, midasFile=True, dataFormat='float') sink = sb.DataSink() source.connect(sink) sb.start() # There should have been at least two push packets (plus one more for # the end-of-stream, but that's not strictly required) outdata, tstamps = sink.getData(eos_block=True, tstamps=True) self.assertTrue(len(tstamps) >= 2) # Check that the first timestamp (nearly) matches the timestamp created # above offset, ts = tstamps[0] self.assertAlmostEqual(start - ts, 0.0, 5) # Check that the synthesized timestamps match our expectations for offset, tnext in tstamps[1:]: # Offset is in samples, not frames (and/or complex pairs) offset /= float(framesize) self.assertAlmostEqual(tnext - ts, offset * delta, 5)
def testShortLittleEndianness(self): self.setupComponent(endianness=LITTLE_ENDIAN) # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') sink = sb.DataSink() # Connect components self.comp.connect(sink, providesPortName='shortIn') # Start components self.comp.start() sink.start() # Create data fakeData = [x for x in range(0, 512)] # Byte Swap it here to make it little endian on send since encode does big endian (swap) fakeData_bs = list( struct.unpack('>512H', struct.pack('@512H', *fakeData))) # Convert fakeData to BIG ENDIAN h = Sdds.SddsHeader(0) p = Sdds.SddsShortPacket(h.header, fakeData_bs) p.encode() # Defaults to big endian encoding self.userver.send(p.encodedPacket) time.sleep(0.05) data = sink.getData() self.assertEqual(self.comp.status.input_endianness, "1234", "Status property for endianness is not 1234") self.assertEqual(data, fakeData, "Little Endian short did not match expected")
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 (default behavior) source = sb.DataSource() source.connect(self.comp) source.start() # Create a sink for the output sink = sb.DataSink() sink.start() self.comp.connect(sink) # Fill up the queue for x in range(numPackets): source.push([x]) source.push([], EOS=True) # Start the component and let the stream complete self.comp.start() data = sink.getData(eos_block=True) # Should not have flushed, should have gotten all packets self.assertEquals(len(data), numPackets) source.stop() sink.stop() self.comp.stop()
def test_001(self): src_data1 = [0,2,-3,0,12,0,2] src_data2 = [0,3,-4,1,13,1,2] src_data3 = [0,4,-6,3,11,1,4] src_data4 = [0,5,-4,5,16,2,1] max_src_data = ( max(src_data1), max(src_data2), max(src_data3), max(src_data4)) expected_result = float(max((max_src_data))) a = sb.DataSource(dataFormat="long") b = sb.DataSource(dataFormat="long") c = sb.DataSource(dataFormat="long") d = sb.DataSource(dataFormat="long") e = gr.max_(gr.sizeof_int, 4, len(src_data1)) f = sb.DataSink() a.connect(e,providesPortName="long_in_1") b.connect(e,providesPortName="long_in_2") c.connect(e,providesPortName="long_in_3") d.connect(e,providesPortName="long_in_4") e.connect(f) sb.start() a.push(src_data1,EOS=True) b.push(src_data2,EOS=True) c.push(src_data3,EOS=True) d.push(src_data4,EOS=True) result_data = f.getData(eos_block=True) self.assertEqual( expected_result, result_data[0] )
def _test_FileSource(self, format): filename = self._tempfileName('source_%s' % format) complexData = format.startswith('C') typecode = format[1] dataFormat, dataType = self.TYPEMAP[typecode] indata = self._generateSourceData(format, 16) hdr = bluefile.header(1000, format) bluefile.write(filename, hdr, indata) source = sb.FileSource(filename, midasFile=True, dataFormat=dataFormat) sink = sb.DataSink() source.connect(sink) sb.start() outdata = sink.getData(eos_block=True) if complexData: self.assertEqual(sink.sri().mode, 1) if dataFormat in ('float', 'double'): outdata = bulkio_helpers.bulkioComplexToPythonComplexList( outdata) else: outdata = numpy.reshape(outdata, (len(outdata) / 2, 2)) else: self.assertEqual(sink.sri().mode, 0) self.assertTrue(numpy.array_equal(indata, outdata), msg='%s != %s' % (indata, outdata))
def test_outport_using_component(self): 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") dsink = sb.DataSink() test_comp.connect(dsink, 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(dsink) cl = oport._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 0, "Incorrect Connections List Length")
def test_001(self): src_data1 = [0,0.2,-0.3,0.0,12,0.0,2.0] src_data2 = [0,0.3,-0.4,1.0,13.0,1.0,2.0] src_data3 = [0,0.4,-0.6,3.0,11.0,1.0,4.0] src_data4 = [0,0.5,-0.4,5.0,16.0,2.0,1.0] max_src_data = ( max(src_data1), max(src_data2), max(src_data3), max(src_data4)) expected_result = float(max((max_src_data))) a = sb.DataSource(dataFormat="float") b = sb.DataSource(dataFormat="float") c = sb.DataSource(dataFormat="float") d = sb.DataSource(dataFormat="float") e = gr.max_(gr.sizeof_float, 4, len(src_data1)) f = sb.DataSink() a.connect(e,providesPortName="float_in_1") b.connect(e,providesPortName="float_in_2") c.connect(e,providesPortName="float_in_3") d.connect(e,providesPortName="float_in_4") e.connect(f) sb.start() a.push(src_data1,EOS=True) b.push(src_data2,EOS=True) c.push(src_data3,EOS=True) d.push(src_data4,EOS=True) result_data = f.getData(eos_block=True) self.assertEqual( expected_result, result_data[0] )
def test_002(self): src_data1= [-100,-99,-98,-97,-96,-1] src_data2 = [-101,-98, -97,-95, -95,-1] src_data3 = [-98,-102, -95,-90, -91,-3] src_data4 = [-97,-101, -93,-91, -95,-1] max_src_data = ( max(src_data1), max(src_data2), max(src_data3), max(src_data4)) expected_result = float(max((max_src_data))) a = sb.DataSource(dataFormat="long") b = sb.DataSource(dataFormat="long") c = sb.DataSource(dataFormat="long") d = sb.DataSource(dataFormat="long") e = gr.max_(gr.sizeof_int, 4, len(src_data1)) f = sb.DataSink() a.connect(e,providesPortName="long_in_1") b.connect(e,providesPortName="long_in_2") c.connect(e,providesPortName="long_in_3") d.connect(e,providesPortName="long_in_4") e.connect(f) sb.start() a.push(src_data1,EOS=True) b.push(src_data2,EOS=True) c.push(src_data3,EOS=True) d.push(src_data4,EOS=True) result_data = f.getData(eos_block=True) self.assertEqual(expected_result, result_data[0] )
def testUseBulkIOSRI(self): # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') sink = sb.DataSink() # Connect components self.comp.connect(sink, providesPortName='shortIn') # Here we are using the BULKIO SRI with a modified xdelta and complex flag. kw = [ CF.DataType("BULKIO_SRI_PRIORITY", ossie.properties.to_tc_value(1, 'long')) ] sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.234e-9, xunits=1, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=0, streamID='TestStreamID', blocking=False, keywords=kw) self.setupComponent(sri=sri) # Start components self.comp.start() sink.start() # Create data fakeData = [x for x in range(0, 512)] h = Sdds.SddsHeader(0, CX=1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() # Defaults to big endian encoding self.userver.send(p.encodedPacket) time.sleep(0.05) data = sink.getData() sri_rx = sink.sri() # compareSRI does not work for CF.DataType with keywords so we check those first then zero them out self.assertEqual(sri.keywords[0].id, sri_rx.keywords[0].id, "SRI Keyword ID do not match") self.assertEqual(sri.keywords[0].value.value(), sri_rx.keywords[0].value.value(), "SRI Keyword Value do not match") self.assertEqual(sri.keywords[0].value.typecode(), sri_rx.keywords[0].value.typecode(), "SRI Keyword Type codes do not match") sri.keywords = [] sri_rx.keywords = [] self.assertTrue(compareSRI(sri, sri_rx), "Attach SRI does not match received SRI")
def testDoublePort(self): ####################################################################### # Test DOUBLE Functionality print "\n**TESTING DOUBLE PORT" #Define test files dataFileIn = './data.in' #Create Test Data File if it doesn't exist #Floats and Doubles are a special case, as #NaNs can be generated randomly and will #not equal one another if not os.path.isfile(dataFileIn): with open(dataFileIn, 'wb') as dataIn: for i in range(1024 / 8): doubleNum = struct.unpack('d', os.urandom(8))[0] while isnan(doubleNum): doubleNum = struct.unpack('d', os.urandom(8))[0] dataIn.write(struct.pack('d', doubleNum)) #Read in Data from Test File size = os.path.getsize(dataFileIn) with open(dataFileIn, 'rb') as dataIn: data = list(struct.unpack('d' * (size / 8), dataIn.read(size))) #Create Components and Connections comp = sb.launch('../FileReader.spd.xml') comp.source_uri = dataFileIn comp.file_format = 'DOUBLE' sink = sb.DataSink() comp.connect(sink, usesPortName='dataDouble_out') #Start Components & Push Data sb.start() comp.playback_state = 'PLAY' time.sleep(2) readData = sink.getData() 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) raise e #Release the components and remove the generated files comp.releaseObject() sink.releaseObject() os.remove(dataFileIn) print "........ PASSED\n" return
def test_outport_using_component(self): 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") dsink = sb.DataSink() test_comp.connect(dsink, 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(dsink) cl = oport._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 0, "Incorrect Connections List Length") ## ## Create bulkio base class port object ## bio = self.bio_out_module("xxx") cl = bio._get_connections() self.assertNotEqual(cl, None, "Cannot get Connections List") self.assertEqual(len(cl), 0, "Incorrect Connections List Length") ts = bulkio.timestamp.now() sri = bulkio.sri.create() sri.streamID = "test_port_api" bio.pushSRI(sri) data = range(50) bio.pushPacket(data, ts, False, "test_port_api") bio.pushPacket(data, ts, True, "test_port_api") bio.pushPacket(data, ts, False, "unknown_port_api") ps = bio._get_statistics() self.assertNotEqual(ps, None, "Cannot get Port Statistics") cnt = len(bio.sriDict) self.assertEqual(cnt, 1, "SRI list should be 1") bio.enableStats(False)
def testUnicastTTVBecomesTrue(self): self.setupComponent() # Get ports sink = sb.DataSink() # Connect components self.comp.connect(sink, providesPortName='octetIn') # Start components self.comp.start() sink.start() # Create data fakeData = [x % 256 for x in range(1024)] # Create packets and send # 2112 assumes every 31st packet is a parity packet. for i in range(0, 2112): if i != 0 and i % 32 == 31: continue # skip parity packet if i <= 500: h = Sdds.SddsHeader(i, DM=[0, 0, 1], BPS=[0, 1, 0, 0, 0], TTV=0, TT=i, FREQ=60000000) p = Sdds.SddsCharPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) elif i > 500: h = Sdds.SddsHeader(i, DM=[0, 0, 1], BPS=[0, 1, 0, 0, 0], TTV=1, TT=i, FREQ=60000000) p = Sdds.SddsCharPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(3) data = sink.getData() # Validate correct amount of data was received self.assertEqual(len(data), 2095104) self.assertEqual(self.comp.status.dropped_packets, 0) sink.stop()
def setUp(self): """Set up the unit test - this is run before every method that starts with test """ ossie.utils.testing.ScaComponentTestCase.setUp(self) self.src = sb.DataSource() self.sinkAM = sb.DataSink() self.sinkPM = sb.DataSink() self.sinkFM = sb.DataSink() #start all my components self.startComponent() props = { 'freqDeviation': 10.0, 'phaseDeviation': 20.0, 'squelch': -2000.0 } self.comp.configure(props_from_dict(props)) self.comp.start() self.src.start() self.sinkAM.start() self.sinkPM.start() self.sinkFM.start()
def setUp(self): #set up ossie.utils.testing.ScaComponentTestCase.setUp(self) self.src = sb.DataSource() self.sink = sb.DataSink() #connect self.startComponent() self.src.connect(self.comp) self.comp.connect(self.sink) #starts sandbox sb.start()
def test_vector(self): dsource=sb.DataSource() dsink=sb.DataSink() test_comp=sb.Component(self.cname) data=range(100) dsource.connect(test_comp, providesPortName=self.inport ) test_comp.connect(dsink, providesPortName=self.sink_port_name, usesPortName=self.outport) sb.start() dsource.push(data,EOS=True) dest_data=dsink.getData(eos_block=True) sb.stop() self.assertEqual(data, dest_data)
def setUp(self): """Set up the unit test - this is run before every method that starts with test """ ossie.utils.testing.ScaComponentTestCase.setUp(self) self.src = sb.DataSource() self.soft = sb.DataSink() self.bits = sb.DataSink() self.phase = sb.DataSink() #setup my components self.setupComponent() self.comp.start() self.src.start() self.soft.start() self.bits.start() #do the connections self.src.connect(self.comp) self.comp.connect(self.soft, usesPortName='softDecision_dataFloat_out') self.comp.connect(self.bits, usesPortName='bits_dataShort_out') self.comp.connect(self.phase, usesPortName='phase_dataFloat_out')
def testWaitOnTTV(self): ''' Wait on TTV will send nothing unless the pkt contains a TTV flag ''' self.setupComponent(pkts_per_push=10) # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') self.comp.advanced_configuration.wait_on_ttv = True sink = sb.DataSink() # Connect components self.comp.connect(sink, providesPortName='shortIn') # Start components self.comp.start() sink.start() ttv = 0 pktNum = 0 num_changes = 0 # We'll do a ttv change every 7th packet while pktNum < 100: if pktNum % 7 == 0: ttv = (ttv + 1) % 2 # aka if 0 become 1, if 1 become 0 num_changes += 1 # Create data fakeData = [x for x in range(0, 512)] h = Sdds.SddsHeader(pktNum, TTV=ttv) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time.sleep(0.05) data = sink.getData(tstamps=True) self.assertEqual( num_changes / 2, len(data[1]), "The number of bulkIO pushes (" + str(len(data[1])) + ") does not match the expected (" + str(num_changes / 2) + ").") self.comp.stop() sink.stop()
def test_push_packet_cplx(self): in_sri = bulkio.sri.create() in_sri.streamID = "VECTOR-PUSHPACKET-CPLX" in_sri.mode = 1 in_sri.xdelta = 1 / 33.0 dsource = sb.DataSource() dsink = sb.DataSink() 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 = self.seq dsource.connect(test_comp, providesPortName=self.c_inport) test_comp.connect(dsink, providesPortName=self.sink_inport, usesPortName=self.c_outport) sb.start() dsource.push(data, EOS=True, streamID=in_sri.streamID, sampleRate=33.0, complexData=(in_sri.mode == 1)) adata = dsink.getData(eos_block=True) #print "Result data: " + str(len(adata)) #print data #print adata self.assertEqual(len(data), len(adata), "PUSH PACKET CPLX FAILED....Data Vector Mismatch") # # check sri values # sri = dsink.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 ntestUShortPort(self): ####################################################################### # Test USHORT Functionality print "\n**TESTING USHORT PORT" #Define test files dataFileIn = './data.in' #Create Test Data File if it doesn't exist if not os.path.isfile(dataFileIn): with open(dataFileIn, 'wb') as dataIn: dataIn.write(os.urandom(1024)) #Read in Data from Test File size = os.path.getsize(dataFileIn) with open(dataFileIn, 'rb') as dataIn: data = list(struct.unpack('H' * (size / 2), dataIn.read(size))) #Create Components and Connections comp = sb.launch('../FileReader.spd.xml') comp.source_uri = dataFileIn comp.file_format = 'USHORT' sink = sb.DataSink() comp.connect(sink, usesPortName='dataUshort_out') #Start Components & Push Data sb.start() comp.playback_state = 'PLAY' time.sleep(2) readData = sink.getData() 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) raise e #Release the components and remove the generated files comp.releaseObject() sink.releaseObject() os.remove(dataFileIn) print "........ PASSED\n" return
def setUp(self): """Set up the unit test - this is run before every method that starts with test """ ossie.utils.testing.ScaComponentTestCase.setUp(self) self.src1 = sb.DataSource(dataFormat="float") self.sink = sb.DataSink() #start all my components self.startComponent() self.src1.start() self.sink.start() #do the connections self.src1.connect(self.comp, 'dataFloat_in') self.comp.connect(self.sink, 'floatIn')
def test_add_ss(self): src_data = [1, 2, 3, 4, 5, 6, 7, 8] expected_result = [2, 4, 6, 8, 10, 12, 14, 16] a = sb.DataSource(dataFormat="short") b = sb.DataSource(dataFormat="short") c = sb.Component("../components/add_ss_2i/add_ss_2i.spd.xml") d = sb.DataSink() a.connect(c, providesPortName="data_in_0") b.connect(c, providesPortName="data_in_1") c.connect(d) sb.start() a.push(src_data, EOS=True) b.push(src_data, EOS=True) result_data = d.getData(eos_block=True) self.assertEqual(expected_result, result_data)
def testMergeBulkIOSRI(self): # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') sink = sb.DataSink() # Connect components self.comp.connect(sink, providesPortName='shortIn') # Here we are using the BULKIO SRI with a modified xdelta and complex flag but the sdds xdelta and cx should merge in sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.234e-9, xunits=1, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=0, streamID='StreamID1234', blocking=False, keywords=[]) self.setupComponent(sri=sri) # Start components self.comp.start() sink.start() # Create data fakeData = [x for x in range(0, 512)] h = Sdds.SddsHeader(0, CX=1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() # Defaults to big endian encoding self.userver.send(p.encodedPacket) time.sleep(0.05) data = sink.getData() sri_rx = sink.sri() self.assertNotEqual( sri_rx.mode, sri.mode, "SDDS Packet Mode should have overridden the supplied SRI") self.assertNotEqual( sri_rx.xdelta, sri.xdelta, "SDDS Packet xdelta should have overridden the supplied SRI") self.assertEqual( sri_rx.streamID, sri.streamID, "Output SRI StreamID should have been inherited from the SRI")