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)
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()
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()
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()
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)
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)
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)
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)
def test_terminate2_audio(self): """Test terminate_audio none present""" test = TestSources(audio_port=4000) test.running_tests_audio = [] test.terminate_audio()
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
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