Exemplo n.º 1
0
    def switch(self, channel, port, index):
        """Create Controller object and call switch method"""
        for _ in range(self.NUM):
            serv = Server(path=PATH)
            try:
                serv.run()

                sources = TestSources(3000)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)
                preview = PreviewSinks(3001)
                preview.run()
                out_file = "output-{0}.data".format(index)
                video_sink = VideoFileSink(PATH, 3001, out_file)
                time.sleep(3)
                controller = Controller()
                res = controller.switch(channel, port)
                print res
                time.sleep(3)
                video_sink.terminate()
                sources.terminate_video()
                preview.terminate()
                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()
Exemplo n.º 2
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
Exemplo n.º 3
0
    def test_new_record(self):
        """Test new_record"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, record_file="test.data")
            try:
                serv.run()

                sources = TestSources(video_port=3000)
                sources.new_test_video()
                sources.new_test_video()

                curr_time = datetime.datetime.now()
                alt_curr_time = curr_time + datetime.timedelta(0, 1)
                time_str = curr_time.strftime('%Y-%m-%d %H%M%S')
                alt_time_str = alt_curr_time.strftime('%Y-%m-%d %H%M%S')
                test_filename = "test {0}.data".format(time_str)
                alt_test_filename = "test {0}.data".format(alt_time_str)

                res = self.new_record()
                print res
                sources.terminate_video()
                serv.terminate(1)
                assert ((os.path.exists(test_filename)) or
                        (os.path.exists(alt_test_filename))) is True
            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()
Exemplo n.º 4
0
def get_encode_port(num):
    """Test get_encode_port - num times"""
    video_port = 3000
    serv = Server(path=PATH, video_port=video_port)
    try:
        serv.run()
        sources = TestSources(video_port=video_port)
        sources.new_test_video()

        expected_res = [video_port + 2] * num

        controller = Controller()
        controller.establish_connection()
        res = []
        for _ in range(num):
            res.append(controller.get_encode_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()
Exemplo n.º 5
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()
Exemplo n.º 6
0
 def test_new_test_video(self, monkeypatch):
     """Test for new_test_video"""
     test = TestSources(video_port=3000)
     monkeypatch.setattr(testsource, 'VideoSrc', self.MockVideoSrc)
     test.new_test_video()
     assert test.running_tests_video[0] is not None
     assert len(test.running_tests_video) != 0
Exemplo n.º 7
0
def permutate_adjust_pip(num, delay):
    """Adjust_pip num number of times"""
    import random

    video_port = 3000
    serv = Server(path=PATH, video_port=video_port)
    try:
        serv.run()
        sources = TestSources(video_port=video_port)
        sources.new_test_video(pattern=6)
        sources.new_test_video(pattern=5)
        preview = PreviewSinks()
        preview.run()
        controller = Controller()

        for _ in range(num):

            xpos = random.randrange(-20, 20)
            ypos = random.randrange(-20, 20)
            res = controller.adjust_pip(xpos, ypos, 0, 0)
            time.sleep(delay)
            assert res is not None
        preview.terminate()
        sources.terminate_video()

    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()
Exemplo n.º 8
0
def get_preview_ports(num):
    """Get Preview Ports when num number of sources are added"""
    video_port = 3000
    serv = Server(path=PATH, video_port=video_port)
    try:
        serv.run()
        sources = TestSources(video_port=video_port)

        expected_res = [i for i in range(3003, 3003 + num)]

        controller = Controller()

        res = []
        for _ in range(num):
            sources.new_test_video()
        controller.establish_connection()
        res = controller.get_preview_ports()
        print res

        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()
Exemplo n.º 9
0
    def test_compose_ports(self):
        """Test get_compose_port"""
        res = []
        expected_result = []
        for i in range(self.NUM):
            video_port = (i + 7) * 1000
            expected_result.append([video_port + 1] * self.NUM * self.FACTOR)
            serv = Server(path=PATH, video_port=video_port)
            try:
                serv.run()
                sources = TestSources(video_port=video_port)
                sources.new_test_video()
                sources.new_test_video()

                res.append(self.get_compose_port())
                sources.terminate_video()
                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()

        set_expected = [tuple(i) for i in expected_result]
        set_res = [tuple(i) for i in res]
        assert set(set_expected) == set(set_res)
Exemplo n.º 10
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())
Exemplo n.º 11
0
 def add_video_sources(self, num, video_port):
     """Add a video source"""
     sources = TestSources(video_port=video_port)
     for _ in range(num):
         sources.new_test_video(pattern=6)
     # print "done adding" + str(num)
     time.sleep(2)
     sources.terminate_video()
     time.sleep(2)
Exemplo n.º 12
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)
Exemplo n.º 13
0
 def test_get_test_video(self):
     """Test for get_test_video"""
     test = TestSources(video_port=3000)
     test.running_tests_video = [
         self.MockTest(1),
         self.MockTest(2),
         self.MockTest(3),
         self.MockTest(19)
     ]
     test.get_test_video()
Exemplo n.º 14
0
 def test_terminate1_audio(self):
     """Test terminate_audio multiple"""
     test = TestSources(audio_port=4000)
     test.running_tests_audio = [
         self.MockTest2(1),
         self.MockTest2(2),
         self.MockTest2(3),
         self.MockTest2(10)
     ]
     test.terminate_audio()
Exemplo n.º 15
0
 def test_terminate1_video(self):
     """Test terminate_video multiple"""
     test = TestSources(video_port=3000)
     test.running_tests_video = [
         self.MockTest(1),
         self.MockTest(2),
         self.MockTest(3),
         self.MockTest(19)
     ]
     test.terminate_video()
Exemplo n.º 16
0
 def test_terminate_index_normal_audio(self):
     """Test terminate_index_audio valid index"""
     test = TestSources(audio_port=4000)
     test.running_tests_audio = [
         self.MockTest2(1),
         self.MockTest2(2),
         self.MockTest2(3),
         self.MockTest2(10)
     ]
     test.terminate_index_audio(0)
Exemplo n.º 17
0
 def test_get_test_audio(self):
     """Test get_test_audio"""
     test = TestSources(audio_port=4000)
     test.running_tests_audio = [
         self.MockTest2(1),
         self.MockTest2(2),
         self.MockTest2(3),
         self.MockTest2(10)
     ]
     test.get_test_audio()
Exemplo n.º 18
0
 def test_terminate_index_normal_video(self):
     """Test terminate_index_video"""
     test = TestSources(video_port=3000)
     test.running_tests_video = [
         self.MockTest(1),
         self.MockTest(2),
         self.MockTest(3),
         self.MockTest(19)
     ]
     test.terminate_index_video(0)
Exemplo n.º 19
0
 def test_terminate_index_error_video(self):
     """Test for terminate_video"""
     testsrc = TestSources(video_port=3000)
     testsrc.running_tests_video = [
         self.MockTest(1),
         self.MockTest(2),
         self.MockTest(3),
         self.MockTest(19)
     ]
     tests = [-100, 20, 1e10, "hi", [1, 2, 3]]
     for test in tests:
         with pytest.raises(InvalidIndexError):
             testsrc.terminate_index_video(test)
Exemplo n.º 20
0
 def test_terminate_index_error_audio(self):
     """Test terminate_index_audio - invalid index"""
     testsrc = TestSources(audio_port=4000)
     testsrc.running_tests_audio = [
         self.MockTest2(1),
         self.MockTest2(2),
         self.MockTest2(3),
         self.MockTest2(10)
     ]
     tests = [-100, 20, 1e10, "hi", [1, 2, 3]]
     for test in tests:
         with pytest.raises(InvalidIndexError):
             testsrc.terminate_index_audio(test)
Exemplo n.º 21
0
    def set_composite_mode(self, mode, generate_frames=False):
        """Create Controller object and call set_composite_mode method"""
        for _ in range(self.NUM):

            serv = Server(path=PATH)
            try:
                serv.run()

                preview = PreviewSinks()
                preview.run()

                out_file = 'output-{0}.data'.format(mode)
                video_sink = VideoFileSink(PATH, serv.video_port + 1, out_file)

                sources = TestSources(video_port=3000)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)

                time.sleep(3)
                # expected_result = [mode != 3] * self.FACTOR
                # print mode, expected_result
                controller = Controller()
                res = controller.set_composite_mode(mode)
                print res
                time.sleep(3)
                video_sink.terminate()
                preview.terminate()
                sources.terminate_video()
                serv.terminate(1)
                if not generate_frames:
                    if mode == 3:
                        assert res is False
                    else:
                        assert res is True
                    assert self.verify_output(mode, out_file) is True
                # assert expected_result == res

            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()
Exemplo n.º 22
0
    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)
Exemplo n.º 23
0
    def click_video(self,
                    xpos,
                    ypos,
                    width,
                    heigth,
                    index,
                    generate_frames=False):
        """Create Controller object and call click_video method"""
        for _ in range(self.NUM):
            serv = Server(path=PATH)
            try:
                serv.run()
                sources = TestSources(video_port=3000)
                preview = PreviewSinks()
                preview.run()
                out_file = "output-{0}.data".format(index)
                video_sink = VideoFileSink(PATH, 3001, out_file)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)
                controller = Controller()
                time.sleep(1)
                res = controller.click_video(xpos, ypos, width, heigth)
                print res
                time.sleep(1)
                sources.terminate_video()
                preview.terminate()
                video_sink.terminate()
                serv.terminate(1)
                if not generate_frames:
                    assert res is not None
                    assert self.verify_output(index, out_file) is True

            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()
Exemplo n.º 24
0
def permutate_composite_mode(num, delay):
    """Change composite mode num number of times"""
    import random

    video_port = 3000
    serv = Server(path=PATH, video_port=video_port)
    try:
        serv.run()
        sources = TestSources(video_port=video_port)
        sources.new_test_video(pattern=6)
        sources.new_test_video(pattern=5)
        preview = PreviewSinks()
        preview.run()
        controller = Controller()
        res = controller.set_composite_mode(0)
        assert res is True

        prev_mode = 0
        for _ in range(num - 1):

            time.sleep(delay)
            mode = random.randint(0, 3)
            expected_res = bool(prev_mode ^ mode)
            prev_mode = mode
            assert expected_res == controller.set_composite_mode(mode)
        preview.terminate()
        sources.terminate_video()

    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()
Exemplo n.º 25
0
 def test_normal(self):
     """Test when valid"""
     tests = [1, 65535, 1000]
     for test in tests:
         src = TestSources(audio_port=test)
         assert src.audio_port == test
Exemplo n.º 26
0
 def test_invalid(self):
     """Test when not integral value"""
     tests = [[1, 2, 3, 4], {1: 2, 2: 3}, '1e10']
     for test in tests:
         with pytest.raises(TypeError):
             TestSources(audio_port=test)
Exemplo n.º 27
0
 def test_range(self):
     """Test when out of range"""
     tests = [-100, 1e7, 65536]
     for test in tests:
         with pytest.raises(RangeError):
             TestSources(audio_port=test)
Exemplo n.º 28
0
 def test_terminate2_audio(self):
     """Test terminate_audio none present"""
     test = TestSources(audio_port=4000)
     test.running_tests_audio = []
     test.terminate_audio()
Exemplo n.º 29
0
 def test_terminate2_video(self):
     """Test terminate_video none present"""
     test = TestSources(video_port=3000)
     test.running_tests_video = []
     test.terminate_video()