示例#1
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
示例#2
0
def main(args):

    print("running server")
    serv = Server(path=args.path)
    serv.run()

    wait(5)

    print("running source pattern=1")
    sources = TestSources(video_port=3000, audio_port=4000)
    sources.new_test_video(pattern=1)

    wait(5)

    print("running gst-switch-ui")
    # the & will run this in the background so control returns 
    # and we can bring up the 2nd source 
    call("gst-switch-ui &", shell=True)

    wait(5)
       
    print("running source pattern=18")
    sources.new_test_video(pattern=18)

    raw_input("hit enter:")


    # need to kill off the processes.

    # a better wy of doing is would be to use
    # https://docs.python.org/2/library/subprocess.html#subprocess.Popen.kill
    # but I don't feel like figuring it out :p

    call("pkill gst-switch-ui", shell=True)
    call("pkill gst-switch-srv", shell=True)
示例#3
0
    def mark_tracking(self, faces, index, generate_frames=False):
        """Create Controller object and call mark_tracking method"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, video_format="debug")
            try:
                serv.run()
                sources = TestSources(video_port=3000)
                preview = PreviewSinks()
                preview.run()
                out_file = "output-{0}.data".format(index)
                video_sink = VideoFileSink(3001, out_file)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)
                controller = Controller()
                time.sleep(1)
                res = controller.mark_tracking(faces)
                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:
                serv.terminate_and_output_status(cov=True)
示例#4
0
    def switch(self, channel, port, index):
        """Create Controller object and call switch method"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, video_format="debug")
            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(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:
                serv.terminate_and_output_status(cov=True)
示例#5
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()
示例#6
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)
示例#7
0
    def adjust_pip(self,
                   xpos,
                   ypos,
                   width,
                   heigth,
                   index,
                   generate_frames=False):
        """Create Controller object and call adjust_pip"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, video_format="debug")
            try:
                serv.run()
                sources = TestSources(video_port=3000)
                preview = PreviewSinks()
                preview.run()
                out_file = "output-{0}.data".format(index)
                video_sink = VideoFileSink(3001, out_file)
                sources.new_test_video(pattern=4)
                sources.new_test_video(pattern=5)
                controller = Controller()
                controller.set_composite_mode(Controller.COMPOSITE_PIP)
                time.sleep(3)
                res = controller.adjust_pip(xpos, ypos, width, heigth)
                time.sleep(3)
                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:
                serv.terminate_and_output_status(cov=True)
示例#8
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()
示例#9
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()
示例#10
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)
示例#11
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()
示例#12
0
    def test_new_record(self):
        """Test new_record"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, record_file="test-%Y.data")
            try:
                serv.run()

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

                curr_time = datetime.datetime.now()
                time_str = curr_time.strftime('%Y')
                test_filename = "test-{0}.data".format(time_str)

                res = self.new_record()
                print res
                sources.terminate_video()
                serv.terminate(1)
                assert os.path.exists(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()
示例#13
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(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()
示例#14
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()
示例#15
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()
示例#16
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()
示例#17
0
def main(args):

    print("running server")
    serv = Server(path=args.path)
    serv.run()

    wait(5)

    print("running source pattern=1")
    sources = TestSources(video_port=3000, audio_port=4000)
    sources.new_test_video(pattern=1)

    wait(5)

    print("running gst-switch-ui")
    # the & will run this in the background so control returns 
    # and we can bring up the 2nd source 

    # Replaced call with subprocess.Popen. 
    SwitchUi = subprocess.Popen("gst-switch-ui &",shell=True)

    wait(5)
       
    print("running source pattern=18")
    sources.new_test_video(pattern=18)

    raw_input("hit enter:")


    # Replaced pkill call with Popen.kill
    subprocess.Popen.kill(SwitchUi)
    serv.kill()
示例#18
0
    def test_on_preview_port_added(self):
        """Create a Controller object, call add a source method and
        check that the callback fires
        """
        serv = Server(path=PATH, video_port=3000)
        try:
            serv.run()

            controller = Controller()
            controller.establish_connection()

            test_cb = Mock(side_effect=lambda mode, serve, type:
                           self.quit_mainloop_after(2))
            controller.on_preview_port_added(test_cb)

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

            GLib.timeout_add_seconds(5, self.quit_mainloop)
            self.run_mainloop()

            print(test_cb.call_args_list)
            test_cb.assert_any_call(3003, 1, 7)
            test_cb.assert_any_call(3004, 1, 8)
            assert test_cb.call_count == 2

            serv.terminate(1)
        finally:
            serv.terminate_and_output_status(cov=True)
示例#19
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()
示例#20
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
示例#21
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()
示例#22
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()
示例#23
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)
示例#24
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)
示例#25
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(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()
示例#26
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()
示例#27
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()
示例#28
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()
示例#29
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, video_format="debug")
            try:
                serv.run()

                preview = PreviewSinks()
                preview.run()

                out_file = 'output-{0}.data'.format(mode)
                video_sink = VideoFileSink(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:
                    controller = Controller()
                    if mode == Controller.COMPOSITE_DUAL_EQUAL:
                        assert res is False
                    else:
                        assert res is True
                    assert self.verify_output(mode, out_file) is True
                # assert expected_result == res

            finally:
                serv.terminate_and_output_status(cov=True)
示例#30
0
    def test_new_record(self):
        """Test new_record"""
        for _ in range(self.NUM):
            serv = Server(path=PATH, record_file="test-%Y.data",
                          video_format="debug")
            try:
                serv.run()

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

                curr_time = datetime.datetime.now()
                time_str = curr_time.strftime('%Y')
                test_filename = "test-{0}.data".format(time_str)

                res = self.new_record()
                print(res)
                sources.terminate_video()
                serv.terminate(1)
                assert os.path.exists(test_filename) is True
            finally:
                serv.terminate_and_output_status(cov=True)
示例#31
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:
                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)
示例#32
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()
示例#33
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()
示例#34
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)
示例#35
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
示例#36
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