Skip to content

Commit

Permalink
Fix python tests and use individual gstd runners for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshilliard committed Mar 5, 2022
1 parent bb7950a commit 90e79ba
Show file tree
Hide file tree
Showing 32 changed files with 183 additions and 87 deletions.
4 changes: 1 addition & 3 deletions tests/libgstc/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
SUBDIRS=c

# FIXME Disable pygstc checks
#SUBDIRS = python

SUBDIRS=python
4 changes: 3 additions & 1 deletion tests/libgstc/python/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ TESTS = \
test_libgstc_python_update.py \
test_libgstc_python_stop_gstd.py

export PYTHONPATH = $PYTHONPATH:$(top_srcdir)/libgstc
check_SCRIPTS = $(TESTS)

export PYTHONPATH = $PYTHONPATH:$(top_srcdir)/libgstc/python
70 changes: 70 additions & 0 deletions tests/libgstc/python/gstd_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env python3
# GStreamer Daemon - gst-launch on steroids
# Python client library abstracting gstd interprocess communication

# Copyright (c) 2015-2020 RidgeRun, LLC (http://www.ridgerun.com)

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:

# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
# OF THE POSSIBILITY OF SUCH DAMAGE.

import pathlib
import socket
import subprocess
import unittest


class GstdTestRunner(unittest.TestCase):

def get_open_port(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(("",0))
s.listen(1)
port = s.getsockname()[1]
s.close()
return port

def setUp(self):
self.port = self.get_open_port()
self.gstd_path = (pathlib.Path(__file__).parent.parent.parent.parent
.joinpath('gstd').joinpath('gstd').resolve())
self.gstd = subprocess.Popen([self.gstd_path, '-p', str(self.port)])
connected = -1
while connected != 0:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connected = sock.connect_ex(("", self.port))
sock.close()

def tearDown(self):
self.gstd.terminate()
try:
self.gstd.wait(1)
except subprocess.TimeoutExpired:
self.gstd.kill()
self.gstd.wait()


if __name__ == '__main__':
unittest.main()
5 changes: 3 additions & 2 deletions tests/libgstc/python/test_libgstc_python_bus_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcBusFilterMethods(unittest.TestCase):
class TestGstcBusFilterMethods(GstdTestRunner):

def test_bus_filter_eos(self):
pipeline = 'videotestsrc name=v0 ! fakesink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.pipeline_create('p0', pipeline)
self.gstd_client.pipeline_play('p0')
self.gstd_client.event_eos('p0')
Expand Down
7 changes: 4 additions & 3 deletions tests/libgstc/python/test_libgstc_python_bus_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcBusTimeoutMethods(unittest.TestCase):
class TestGstcBusTimeoutMethods(GstdTestRunner):

def test_bus_timeout_eos(self):
pipeline = 'videotestsrc name=v0 ! fakesink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.pipeline_create('p0', pipeline)
self.gstd_client.pipeline_play('p0')
self.gstd_client.event_eos('p0')
Expand All @@ -54,7 +55,7 @@ def test_bus_timeout_eos(self):
def test_bus_timeout_no_response(self):
pipeline = 'videotestsrc name=v0 ! fakesink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.pipeline_create('p0', pipeline)
self.gstd_client.pipeline_play('p0')
self.gstd_client.bus_timeout('p0', 1000)
Expand Down
7 changes: 4 additions & 3 deletions tests/libgstc/python/test_libgstc_python_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcCreateMethods(unittest.TestCase):
class TestGstcCreateMethods(GstdTestRunner):

def test_create_pipeline(self):
pipeline = 'videotestsrc name=v0 ! fakesink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
ret = self.gstd_client.read('pipelines')
initial_n_pipes = len(ret['nodes'])
self.gstd_client.create('pipelines', 'p0', pipeline)
Expand All @@ -52,7 +53,7 @@ def test_create_pipeline(self):
def test_create_bad_pipeline(self):
pipeline = 'source sink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
with self.assertRaises(GstdError):
self.gstd_client.create('pipelines', 'p0', pipeline)

Expand Down
7 changes: 4 additions & 3 deletions tests/libgstc/python/test_libgstc_python_debug_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcDebugColorMethods(unittest.TestCase):
class TestGstcDebugColorMethods(GstdTestRunner):

def test_debug_color_true(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_color(True)

def test_debug_color_false(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_color(False)


Expand Down
7 changes: 4 additions & 3 deletions tests/libgstc/python/test_libgstc_python_debug_enable.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcDebugEnableMethods(unittest.TestCase):
class TestGstcDebugEnableMethods(GstdTestRunner):

def test_debug_enable_true(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_enable(True)

def test_debug_enable_false(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_enable(False)


Expand Down
7 changes: 4 additions & 3 deletions tests/libgstc/python/test_libgstc_python_debug_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,21 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcDebugResetMethods(unittest.TestCase):
class TestGstcDebugResetMethods(GstdTestRunner):

def test_debug_reset_true(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_reset(True)

def test_debug_reset_false(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_reset(False)


Expand Down
23 changes: 12 additions & 11 deletions tests/libgstc/python/test_libgstc_python_debug_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,60 +30,61 @@
# OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcDebugThresholdMethods(unittest.TestCase):
class TestGstcDebugThresholdMethods(GstdTestRunner):

def test_debug_threshold_none(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('0')

def test_debug_threshold_error(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('1')

def test_debug_threshold_warning(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('2')

def test_debug_threshold_fixme(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('3')

def test_debug_threshold_info(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('4')

def test_debug_threshold_debug(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('5')

def test_debug_threshold_log(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('6')

def test_debug_threshold_trace(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('7')

def test_debug_threshold_memdump(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('8')

def test_debug_threshold_invalid(self):
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.debug_threshold('9')


Expand Down
5 changes: 3 additions & 2 deletions tests/libgstc/python/test_libgstc_python_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcDeleteMethods(unittest.TestCase):
class TestGstcDeleteMethods(GstdTestRunner):

def test_delete_pipeline(self):
pipeline = 'videotestsrc name=v0 ! fakesink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
ret = self.gstd_client.read('pipelines')
initial_n_pipes = len(ret['nodes'])
self.gstd_client.create('pipelines', 'p0', pipeline)
Expand Down
5 changes: 3 additions & 2 deletions tests/libgstc/python/test_libgstc_python_element_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcElementGetMethods(unittest.TestCase):
class TestGstcElementGetMethods(GstdTestRunner):

def test_element_get_property_value(self):
pipeline = 'videotestsrc name=v0 pattern=ball ! fakesink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.pipeline_create('p0', pipeline)
self.assertEqual(
self.gstd_client.element_get(
Expand Down
5 changes: 3 additions & 2 deletions tests/libgstc/python/test_libgstc_python_element_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcElementSetMethods(unittest.TestCase):
class TestGstcElementSetMethods(GstdTestRunner):

def test_element_set_property_value(self):
pipeline = 'videotestsrc name=v0 pattern=ball ! fakesink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.pipeline_create('p0', pipeline)
self.assertEqual(
self.gstd_client.element_get(
Expand Down
5 changes: 3 additions & 2 deletions tests/libgstc/python/test_libgstc_python_event_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@

import unittest

from gstd_runner import GstdTestRunner
from pygstc.gstc import *
from pygstc.logger import *


class TestGstcEventEosMethods(unittest.TestCase):
class TestGstcEventEosMethods(GstdTestRunner):

def test_event_eos(self):
pipeline = 'videotestsrc name=v0 ! fakesink'
self.gstd_logger = CustomLogger('test_libgstc', loglevel='DEBUG')
self.gstd_client = GstdClient(logger=self.gstd_logger)
self.gstd_client = GstdClient(port=self.port, logger=self.gstd_logger)
self.gstd_client.pipeline_create('p0', pipeline)
self.gstd_client.pipeline_play('p0')
self.gstd_client.event_eos('p0')
Expand Down
Loading

0 comments on commit 90e79ba

Please sign in to comment.