Esempio n. 1
0
 def test_new_test_audio(self, monkeypatch):
     """Test new_test_audio"""
     test = TestSources(audio_port=3000)
     monkeypatch.setattr(testsource, 'AudioSrc', self.MockAudioSrc)
     test.new_test_audio()
     assert test.running_tests_audio[0] is not None
     assert len(test.running_tests_audio) != 0
Esempio n. 2
0
    def test_get_preview_ports(self):
        """Test get_preview_ports"""

        for _ in range(self.NUM):
            serv = Server(path=PATH)
            try:
                serv.run()
                sources = TestSources(video_port=3000, audio_port=4000)
                for _ in range(self.NUM):
                    sources.new_test_audio()
                    sources.new_test_video()
                expected_result = map(
                    tuple, [[x for x in range(3003, 3004 + self.NUM)]] *
                    self.NUM * self.FACTOR)
                res = map(tuple, self.get_preview_ports())
                print '\n', res, '\n'
                print expected_result
                assert set(expected_result) == set(res)
                sources.terminate_video()
                sources.terminate_audio()
                serv.terminate(1)
            finally:
                if serv.proc:
                    poll = serv.proc.poll()
                    print self.__class__
                    if poll == -11:
                        print "SEGMENTATION FAULT OCCURRED"
                    print "ERROR CODE - {0}".format(poll)
                    serv.terminate(1)
                    log = open('server.log')
                    print log.read()
Esempio n. 3
0
def get_audio_port(num):
        """Test get_audio_port"""
        audio_port = 8000
        serv = Server(path=PATH, audio_port=audio_port)
        try:
            serv.run()
            sources = TestSources(audio_port=audio_port)
            sources.new_test_audio()
            
            expected_res = [3003] * num

            controller = Controller()
            controller.establish_connection()
            res = []
            for _ in range(num):
                res.append(controller.get_audio_port())

            assert expected_res == res

        finally:
            if serv.proc:
                    poll = serv.proc.poll()
                    if poll == -11:
                        print "SEGMENTATION FAULT OCCURRED"
                    print "ERROR CODE - {0}".format(poll)
                    serv.terminate(1)
                    log = open('server.log')
                    print log.read()
Esempio n. 4
0
 def test_new_test_audio(self, monkeypatch):
     """Test new_test_audio"""
     test = TestSources(audio_port=3000)
     monkeypatch.setattr(testsource, 'AudioSrc', self.MockAudioSrc)
     test.new_test_audio()
     assert test.running_tests_audio[0] is not None
     assert len(test.running_tests_audio) != 0
Esempio n. 5
0
def get_audio_port(num):
    """Test get_audio_port"""
    audio_port = 8000
    serv = Server(path=PATH, audio_port=audio_port)
    try:
        serv.run()
        sources = TestSources(audio_port=audio_port)
        sources.new_test_audio()

        expected_res = [3003] * num

        controller = Controller()
        controller.establish_connection()
        res = []
        for _ in range(num):
            res.append(controller.get_audio_port())

        assert expected_res == res

    finally:
        if serv.proc:
            poll = serv.proc.poll()
            if poll == -11:
                print "SEGMENTATION FAULT OCCURRED"
            print "ERROR CODE - {0}".format(poll)
            serv.terminate(1)
            log = open('server.log')
            print log.read()
Esempio n. 6
0
    def test_audio_ports(self):
        """Test get_audio_port"""
        res = []
        expected_result = []
        for i in range(1, self.NUM + 1):
            audio_port = (i + 10) * 1000
            expected_result.append([3003] * self.NUM * self.FACTOR)
            serv = Server(path=PATH, video_port=3000, audio_port=audio_port)
            try:
                serv.run()
                sources = TestSources(video_port=3000, audio_port=audio_port)
                sources.new_test_audio()

                res.append(self.get_audio_port())

                sources.terminate_audio()
                serv.terminate(1)

            finally:
                if serv.proc:
                    poll = serv.proc.poll()
                    print self.__class__
                    if poll == -11:
                        print "SEGMENTATION FAULT OCCURRED"
                    print "ERROR CODE - {0}".format(poll)
                    serv.terminate(1)
                    log = open('server.log')
                    print log.read()
        # print res
        # print expected_result
        set_expected = [tuple(i) for i in expected_result]
        set_res = [tuple(i) for i in res]
        assert set(set_expected) == set(set_res)
Esempio n. 7
0
    def test_get_preview_ports(self):
        """Test get_preview_ports"""

        for _ in range(self.NUM):
            serv = Server(path=PATH)
            try:
                serv.run()
                sources = TestSources(video_port=3000, audio_port=4000)
                for _ in range(self.NUM):
                    sources.new_test_audio()
                    sources.new_test_video()
                expected_result = map(
                    tuple,
                    [[x for x in range(3003, 3004 + self.NUM)]]
                    * self.NUM * self.FACTOR)
                res = map(tuple, self.get_preview_ports())
                print '\n', res, '\n'
                print expected_result
                assert set(expected_result) == set(res)
                sources.terminate_video()
                sources.terminate_audio()
                serv.terminate(1)
            finally:
                if serv.proc:
                    poll = serv.proc.poll()
                    print self.__class__
                    if poll == -11:
                        print "SEGMENTATION FAULT OCCURRED"
                    print "ERROR CODE - {0}".format(poll)
                    serv.terminate(1)
                    log = open('server.log')
                    print log.read()
Esempio n. 8
0
    def test_audio_ports(self):
        """Test get_audio_port"""
        res = []
        expected_result = []
        for i in range(1, self.NUM + 1):
            audio_port = (i + 10) * 1000
            expected_result.append([3003] * self.NUM * self.FACTOR)
            serv = Server(path=PATH, video_port=3000, audio_port=audio_port)
            try:
                serv.run()
                sources = TestSources(video_port=3000, audio_port=audio_port)
                sources.new_test_audio()

                res.append(self.get_audio_port())

                sources.terminate_audio()
                serv.terminate(1)

            finally:
                if serv.proc:
                    poll = serv.proc.poll()
                    print self.__class__
                    if poll == -11:
                        print "SEGMENTATION FAULT OCCURRED"
                    print "ERROR CODE - {0}".format(poll)
                    serv.terminate(1)
                    log = open('server.log')
                    print log.read()
        # print res
        # print expected_result
        set_expected = [tuple(i) for i in expected_result]
        set_res = [tuple(i) for i in res]
        assert set(set_expected) == set(set_res)
Esempio n. 9
0
 def add_audio_sources(self, num, audio_port):
     """Add audio sources"""
     sources = TestSources(audio_port=audio_port)
     for _ in range(num):
         sources.new_test_audio(wave=10)
     # print("done adding" + str(num))
     # print(sources.get_test_audio())
     time.sleep(2)
     sources.terminate_audio()
     time.sleep(2)
Esempio n. 10
0
 def add_audio_sources(self, num, audio_port):
     """Add audio sources"""
     sources = TestSources(audio_port=audio_port)
     for _ in range(num):
         sources.new_test_audio(wave=10)
     # print "done adding" + str(num)
     # print sources.get_test_audio()
     time.sleep(2)
     sources.terminate_audio()
     time.sleep(2)
Esempio n. 11
0
    def test_get_preview_ports(self):
        """Test get_preview_ports"""

        for _ in range(self.NUM):
            serv = Server(path=PATH, video_format="debug")
            try:
                serv.run()
                sources = TestSources(video_port=3000, audio_port=4000)
                for _ in range(self.NUM):
                    sources.new_test_audio()
                    sources.new_test_video()
                expected_result = map(
                    tuple,
                    [[x for x in range(3003, 3004 + self.NUM)]] *
                    self.NUM * self.FACTOR)
                res = map(tuple, self.get_preview_ports())
                print('\n', res, '\n')
                print(expected_result)
                assert set(expected_result) == set(res)
                sources.terminate_video()
                sources.terminate_audio()
                serv.terminate(1)
            finally:
                serv.terminate_and_output_status(cov=True)
Esempio n. 12
0
    def test_audio_ports(self):
        """Test get_audio_port"""
        res = []
        expected_result = []
        for i in range(1, self.NUM + 1):
            audio_port = (i + 10) * 1000
            expected_result.append([3003] * self.NUM * self.FACTOR)
            serv = Server(path=PATH, video_port=3000, audio_port=audio_port)
            try:
                serv.run()
                sources = TestSources(video_port=3000, audio_port=audio_port)
                sources.new_test_audio()

                res.append(self.get_audio_port())

                sources.terminate_audio()
                serv.terminate(1)

            finally:
                serv.terminate_and_output_status(cov=True)

        set_expected = [tuple(i) for i in expected_result]
        set_res = [tuple(i) for i in res]
        assert set(set_expected) == set(set_res)
Esempio n. 13
0
class IntegrationTestbase(object):
    """Base class for integration tests."""

    # Tests are not allowed to have an __init__ method
    def setup_method(self, _):
        """Set up called automatically before every test_XXXX method."""
        self.log = logging.getLogger()
        self.log.setLevel(logging.DEBUG)
        logging.basicConfig(
            format="%(filename)s:%(lineno)d (%(funcName)s): %(message)s")

        self.serv = None
        self._sources = None
        self.controller = None

    def setup_server(self, record_file=False):
        """Set up a gst-switch server for testing."""
        assert self.serv is None

        self.log.info("setting up Server")
        self.serv = Server(path=PATH,
                           video_format="debug",
                           record_file=record_file)

        self.log.info("running Server")
        self.serv.run()
        assert self.serv.is_alive()

        self.log.info("waiting for Server to open Controller-Port")
        self.serv.wait_for_output('tcp:host=::,port=5000')

        self.log.info("setting up TestSources")
        self._sources = TestSources(video_port=self.serv.video_port,
                                    audio_port=self.serv.audio_port)

    def setup_controller(self):
        """Create Controller object and call setup_controller."""
        self.log.info("setting up Controller")
        self.controller = Controller()

        self.log.info("connecting Controller to Server")
        self.controller.establish_connection()
        self.serv.wait_for_output('registered: ')

        assert self.controller.connection is not None

    def new_test_video(self, pattern=None):
        """Start a new Video-Testsource and wait until it's ready"""
        self.serv.wait_for_output(':::3000')
        self._sources.new_test_video(pattern=pattern)

    def setup_video_sources(self, count):
        """ Starts some Test-Video streams and waits until they are ready
        """
        self.log.info("starting 2 test-video sources")
        for _ in range(0, count):
            self.new_test_video()

        self.log.info("waiting for the test-video sources to come up")
        self.wait_for_sources(count)

    def new_test_audio(self, freq=110, wave=AudioSrc.WAVE_SINE):
        """Start a new Audio-Testsource and wait until it's ready"""
        self.serv.wait_for_output(':::4000')
        self._sources.new_test_audio(freq=freq, wave=wave)

    def setup_audio_sources(self, count):
        """ Starts some Test-Audio streams and waits until they are ready
        """
        self.log.info("starting 2 test-audio sources")
        for _ in range(0, count):
            self.new_test_audio()

        self.log.info("waiting for the test-audio sources to come up")
        self.wait_for_sources(count)

    def wait_for_sources(self, count):
        """ Blocks until the Server has reported, that the right number of
        preview-ports are is started
        """
        self.log.info("waiting for Server to start preview-port-outputs")
        self.serv.wait_for_output('tcpserversink name=sink', count=count)

    def teardown_method(self, _):
        """Tear down called automatically after every test_XXXX method."""
        self.controller = None

        # Kill all the sources
        if self._sources is not None:
            self.log.info("terminating Video-TestSource")
            self._sources.terminate_video()

            self.log.info("terminating Audio-TestSource")
            self._sources.terminate_audio()
        self._sources = None

        if self.serv is not None:
            self.log.info("terminating Server")
            self.serv.terminate(cov=True)

            if self.serv.proc:
                poll = self.serv.proc.poll()
                if poll == -11:
                    self.log.error("Server exited with Segmentation Fault")
                if poll != 0:
                    self.log.error("Server exited Error Eode %s", poll)

            log = open('server.log')
            print(log.read())

        self.serv = None
Esempio n. 14
0
class IntegrationTestbase(object):
    """Base class for integration tests."""

    # Tests are not allowed to have an __init__ method
    def setup_method(self, _):
        """Set up called automatically before every test_XXXX method."""
        self.log = logging.getLogger()
        self.log.setLevel(logging.DEBUG)
        logging.basicConfig(
            format="%(filename)s:%(lineno)d (%(funcName)s): %(message)s")

        self.serv = None
        self._sources = None
        self.controller = None

    def setup_server(self, record_file=False):
        """Set up a gst-switch server for testing."""
        assert self.serv is None

        self.log.info("setting up Server")
        self.serv = Server(path=PATH, video_format="debug",
                           record_file=record_file)

        self.log.info("running Server")
        self.serv.run()
        assert self.serv.is_alive()

        self.log.info("waiting for Server to open Controller-Port")
        self.serv.wait_for_output('tcp:host=::,port=5000')

        self.log.info("setting up TestSources")
        self._sources = TestSources(
            video_port=self.serv.video_port,
            audio_port=self.serv.audio_port)

    def setup_controller(self):
        """Create Controller object and call setup_controller."""
        self.log.info("setting up Controller")
        self.controller = Controller()

        self.log.info("connecting Controller to Server")
        self.controller.establish_connection()
        self.serv.wait_for_output('registered: ')

        assert self.controller.connection is not None

    def new_test_video(self, pattern=None):
        """Start a new Video-Testsource and wait until it's ready"""
        self.serv.wait_for_output(':::3000')
        self._sources.new_test_video(pattern=pattern)

    def setup_video_sources(self, count):
        """ Starts some Test-Video streams and waits until they are ready
        """
        self.log.info("starting 2 test-video sources")
        for _ in range(0, count):
            self.new_test_video()

        self.log.info("waiting for the test-video sources to come up")
        self.wait_for_sources(count)

    def new_test_audio(self, freq=110, wave=AudioSrc.WAVE_SINE):
        """Start a new Audio-Testsource and wait until it's ready"""
        self.serv.wait_for_output(':::4000')
        self._sources.new_test_audio(freq=freq, wave=wave)

    def setup_audio_sources(self, count):
        """ Starts some Test-Audio streams and waits until they are ready
        """
        self.log.info("starting 2 test-audio sources")
        for _ in range(0, count):
            self.new_test_audio()

        self.log.info("waiting for the test-audio sources to come up")
        self.wait_for_sources(count)

    def wait_for_sources(self, count):
        """ Blocks until the Server has reported, that the right number of
        preview-ports are is started
        """
        self.log.info("waiting for Server to start preview-port-outputs")
        self.serv.wait_for_output('tcpserversink name=sink', count=count)

    def teardown_method(self, _):
        """Tear down called automatically after every test_XXXX method."""
        self.controller = None

        # Kill all the sources
        if self._sources is not None:
            self.log.info("terminating Video-TestSource")
            self._sources.terminate_video()

            self.log.info("terminating Audio-TestSource")
            self._sources.terminate_audio()
        self._sources = None

        if self.serv is not None:
            self.log.info("terminating Server")
            self.serv.terminate(cov=True)

            if self.serv.proc:
                poll = self.serv.proc.poll()
                if poll == -11:
                    self.log.error("Server exited with Segmentation Fault")
                if poll != 0:
                    self.log.error("Server exited Error Eode %s", poll)

            log = open('server.log')
            print(log.read())

        self.serv = None