def testRestart(self): """Checks that an Component will run after being stopped without a new attach """ self.setupComponent() # Get ports compDataFloatOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.start() compDataSddsIn = self.comp.getPort('dataSddsIn') # Create data fakeData = [x for x in range(0, 512)] # Create packet and send h = Sdds.SddsHeader(0, DM = [0, 1, 0], TTV = 1, TT = 0) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(1) # Get data data,stream = self.getData() # Validate correct amount of data was received self.assertEqual(len(data), 512) # Validate data is correct self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data)))) self.comp.stop() time.sleep(1) # Get data data,stream = self.getData() self.assertTrue(stream.eos) #Restart Component and send more data self.comp.start() self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(1) # Get data data,stream = self.getData() # Validate correct amount of data was received self.assertEqual(len(data), 512) # Validate data is correct self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data))))
def testNewYear(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Start components self.comp.start() # Create data fakeData = [x for x in range(0, 512)] pktNum = 0 sr=1e6 xdelta_ns=int(1/sr * 1e9) ns_in_year = 1e9*31536000 time_ns=ns_in_year - xdelta_ns*512*20 # No time slips here while pktNum < 100: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4)) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns if time_ns > ns_in_year: time_ns = time_ns - ns_in_year self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!")
def testShortLittleEndianness(self): self.setupComponent(endianness=LITTLE_ENDIAN) # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.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,stream = self.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 testUnicastBadFsn(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.start() # Create data fakeData = [x for x in range(0, 512)] # Create packets and send for i in range(0, 2): h = Sdds.SddsHeader(1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(1) # Get data data,stream = self.getData() # Validate correct amount of data was received self.assertEqual(len(data), 1024) self.assertEqual(2*fakeData, list(struct.unpack('>1024H', struct.pack('>1024H', *data[:])))) self.assertEqual(self.comp.status.dropped_packets, 65535)
def testUnicastShortPort(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.start() # Create data fakeData = [x for x in range(0, 512)] # Create packet and send h = Sdds.SddsHeader(0, DM = [0, 1, 0], TTV = 1, TT = 0) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(1) # Get data data,stream = self.getData() # Validate correct amount of data was received self.assertEqual(len(data), 512) # Validate data is correct self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data))))
def testUnicastCxBit(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.start() # Create data fakeData = [x for x in range(0, 512)] # Create packet and send h = Sdds.SddsHeader(0, SF = 0, TTV = 1, TT = 7820928000000000000, CX = 1, DM = [0, 1, 0]) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(1) data,stream = self.getData() # Validate sri mode is correct self.assertEqual(stream.sri.mode, 1)
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 testMergeBulkIOSRI(self): # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.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() # 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,stream = self.getData() sri_rx = stream.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")
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 testBulkIOTiming(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.start() # Create data fakeData = [x for x in range(0, 512)] pktNum = 0 sr=1e6 xdelta_ns=int(1/(sr) * 1e9) time_ns=0 # No time slips here while pktNum < 100: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4), CX=1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns time.sleep(0.5) data,stream,tsamps = self.getData(wanttstamps=True) now = datetime.datetime.utcnow() first_of_year = datetime.datetime(now.year, 1, 1, tzinfo=UTC()) begin_of_time = datetime.datetime(1970, 1, 1, tzinfo=UTC()) seconds_since_new_year = timedelta_total_seconds(first_of_year - begin_of_time) expected_time_ns = 0 # So we expect the received bulkIO stream to be the start of the year + the time delta from the sample rate. for bulkIO_time in tsamps: twsec = bulkIO_time[1].twsec tfsec = bulkIO_time[1].tfsec self.assertEqual(twsec, seconds_since_new_year, "BulkIO time stamp does not match received SDDS time stamp") self.assertEqual(tfsec, expected_time_ns/1.0e9) expected_time_ns = expected_time_ns + 512*xdelta_ns
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 testEOSonDetach(self): """Checks that an EOS is sent on Detach""" self.setupComponent() # Get ports compDataFloatOut_out = self.comp.getPort('dataShortOut') sink = sb.DataSink() # Connect components self.comp.connect(sink, providesPortName='shortIn') # Start components self.comp.start() sink.start() compDataSddsIn = self.comp.getPort('dataSddsIn') # Create data fakeData = [x for x in range(0, 512)] # Create packet and send h = Sdds.SddsHeader(0, DM=[0, 1, 0], TTV=1, TT=0) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(1) # Get data data = sink.getData() # Validate correct amount of data was received self.assertEqual(len(data), 512) # Validate data is correct self.assertEqual( fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data)))) #Send Detach compDataSddsIn.detach(self.attachId) time.sleep(1) data = sink.getData() self.assertTrue(sink.eos())
def testXDeltaChange(self): self.setupComponent() # 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)] pktNum = 0 sr = 1e6 xdelta_ns = int(1 / (sr) * 1e9) time_ns = 0 # No time slips here while pktNum < 100: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr * 73786976294.838211), TT=(time_ns * 4), CX=1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512 * xdelta_ns if pktNum > 50: sr = 1e6 * 4 xdelta_ns = int(1 / (sr) * 1e9) time.sleep(0.5) self.assertEqual( self.comp.status.time_slips, 0, "There should be no time slips! However %s reported" % self.comp.status.time_slips)
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 testUseBulkIOSRI(self): # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Here we are using the BULKIO SRI with a modified xdelta and complex flag. # Adding other keywords to ensure they are passed through correctly kw=[CF.DataType("BULKIO_SRI_PRIORITY", ossie.properties.to_tc_value(1, 'long'))] kw.append(CF.DataType("Test_Keyword_string", ossie.properties.to_tc_value('test', 'string'))) kw.append(CF.DataType("Test_Keyword_long", ossie.properties.to_tc_value(10, 'long'))) kw.append(CF.DataType("COL_RF", ossie.properties.to_tc_value(100000000, 'double'))) 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() # 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,stream = self.getData() sri_rx = stream.sri # compareSRI does not work for CF.DataType with keywords so we check those first then zero them out for index,keyword in enumerate(sri.keywords): self.assertEqual(keyword.id, sri_rx.keywords[index].id, "SRI Keyword ID do not match") self.assertEqual(keyword.value.value(), sri_rx.keywords[index].value.value(), "SRI Keyword Value do not match") self.assertEqual(keyword.value.typecode().kind(), sri_rx.keywords[index].value.typecode().kind(), "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 testTimeSlips(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') # Start components self.comp.start() # Create data fakeData = [x for x in range(0, 512)] pktNum = 0 sr=1e6 xdelta_ns=int(1/sr * 1e9) time_ns=0 # No time slips here while pktNum < 100: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4)) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!") # Introduce accumulator time slip while pktNum < 200: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4)) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns + 15 # The additional 15 ps is enough for ana cumulator time slip self.assertEqual(self.comp.status.time_slips, 1, "There should be one time slip from the accumulator") # Introduce one jump time slip while pktNum < 300: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4)) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum == 245: time_ns += 5000 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns self.assertEqual(self.comp.status.time_slips, 2, "There should be one time slip from the jump time slip!")
def testRestartAfterDetach(self): """Checks that an Component will run after being detached and reattached without stopping """ self.setupComponent() # Get ports compDataFloatOut_out = self.comp.getPort('dataShortOut') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.start() compDataSddsIn = self.comp.getPort('dataSddsIn') # Create data fakeData = [x for x in range(0, 512)] # Create packet and send h = Sdds.SddsHeader(0, DM = [0, 1, 0], TTV = 1, TT = 0) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(1) # Get data data,stream = self.getData() # Validate correct amount of data was received self.assertEqual(len(data), 512) # Validate data is correct self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data)))) #Send Detach compDataSddsIn.detach(self.attachId ) time.sleep(1) # Get data data,stream = self.getData() self.assertTrue(stream.eos) #Re-Attach streamDef = BULKIO.SDDSStreamDefinition('id', BULKIO.SDDS_SI, self.uni_ip, 0, self.port, 8000, True, 'testing') # Try to attach self.attachId = '' try: self.attachId = compDataSddsIn.attach(streamDef, 'test') except: print "ATTACH FAILED" attachId = '' self.assertTrue(self.attachId != '', "Failed to attach to SourceSDDS component") #Resend Data self.userver.send(p.encodedPacket) # Wait for data to be received time.sleep(1) # Get data data,stream = self.getData() # Validate correct amount of data was received self.assertEqual(len(data), 512) # Validate data is correct self.assertEqual(fakeData, list(struct.unpack('>512H', struct.pack('>512H', *data))))
def testNonConformingConformingSwitch(self): self.setupComponent() # Get ports compDataShortOut_out = self.comp.getPort('dataShortOut') compDataSddsIn = self.comp.getPort('dataSddsIn') # Connect components self.comp.connect(self.sink, providesPortName='shortIn') # Start components self.comp.start() # Create data fakeData = [x for x in range(0, 512)] pktNum = 0 sr=1e6 xdelta_ns=int(1/(sr*2) * 1e9) time_ns=0 recSRI = False # No time slips here while pktNum < 100: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4), CX=1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!") # Stop the component, detach, then re-attach a new stream that is using the conforming sampleRate self.comp.stop() compDataSddsIn.detach(self.attachId) kw = [CF.DataType("dataRef", ossie.properties.to_tc_value(BIG_ENDIAN, 'long'))] sri = BULKIO.StreamSRI(hversion=1, xstart=0.0, xdelta=1.0, xunits=1, subsize=0, ystart=0.0, ydelta=0.0, yunits=0, mode=0, streamID='TestStreamID2', blocking=False, keywords=kw) compDataSddsIn.pushSRI(sri,timestamp.now()) streamDef = BULKIO.SDDSStreamDefinition('id2', BULKIO.SDDS_SI, self.uni_ip, 0, self.port, 8000, True, 'testing') self.attachId = compDataSddsIn.attach(streamDef, 'test') self.comp.start() # Create data fakeData = [x for x in range(0, 512)] pktNum = 0 sr=1e6 xdelta_ns=int(1/(sr) * 1e9) time_ns=0 recSRI = False # No time slips here while pktNum < 100: # Create data h = Sdds.SddsHeader(pktNum, FREQ=(sr*73786976294.838211), TT=(time_ns*4), CX=1) p = Sdds.SddsShortPacket(h.header, fakeData) p.encode() self.userver.send(p.encodedPacket) pktNum = pktNum + 1 if pktNum != 0 and pktNum % 32 == 31: pktNum = pktNum + 1 time_ns = time_ns + 512*xdelta_ns self.assertEqual(self.comp.status.time_slips, 0, "There should be no time slips!")