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")
Example #2
0
    def testBPSOverride(self):
        self.source = sb.StreamSource(self.id(), 'octet')
        self.source.connect(self.comp, usesPortName='octetOut')
        self.comp.override_sdds_header.enabled = True

        for bps in range(32):
            time.sleep(0.1)
            self.comp.override_sdds_header.bps = bps
            sb.start()
            fakeData = 1024 * [1]
            self.source.write(fakeData)
            rcv = self.getPacket()
            sdds_header = self.getHeader(rcv)
            self.assertEqual(bps, sum(sdds_header.bps),
                             "Received BPS that did not match expected")
            sb.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")
Example #4
0
    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)
Example #5
0
    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()
Example #6
0
 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 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()