Skip to content

Commit

Permalink
Merge pull request #168 from mithro/int-tests-fix
Browse files Browse the repository at this point in the history
Fixing the `python-api/tests/integrationtests`
  • Loading branch information
mithro committed Jan 30, 2015
2 parents 47600c7 + 0e2da98 commit 67317e7
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ test-driver
*.avi
*.mkv
*.log
.cache
2 changes: 2 additions & 0 deletions .travis-run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#! /bin/bash -ex

export DISPLAY=:99.0

./autogen.sh --prefix=/usr || {
printf "Failed to do autogen!!!\n"
exit -1
Expand Down
5 changes: 5 additions & 0 deletions .travis-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ if [ $TYPE == 'c' ]; then
else
sudo pip install python-coveralls
fi

# Start an X server so the GUI works
sudo apt-get -y install xvfb xclip
export DISPLAY=:99.0
/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1024x768x16
14 changes: 8 additions & 6 deletions python-api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ unittests:
@rm -rf reports
@mkdir -p reports/coverage/unittests
py.test --cov gstswitch tests/unittests/ --pep8 -v -s
#-@mv htmlcov/*.* reports/coverage/unittests

pep8:
pep8 gstswitch
Expand All @@ -26,16 +27,17 @@ pep8:
pep8 tests/integrationtests
@echo "integration tests are pep8 clean!!"

integration:
@rm -f ../tools/*.c.gcov
@rm -f ../tools/*.gcda
imgurbash.sh:
-wget http://imgur.com/tools/imgurbash.sh -O imgurbash.sh
-chmod +x imgurbash.sh

integration: imgurbash.sh
@rm -f ../tools/*.c.gcov
@rm -f ../tools/*.gcda
@rm -rf reports
@mkdir -p reports/coverage/integration
py.test --cov gstswitch tests/integrationtests/ --pep8 -s -v
-@mv htmlcov/*.* reports/coverage/integration
-rm imgurbash.sh*
#-@mv htmlcov/*.* reports/coverage/integration

performance:
py.test tests/performancetests/*.py -v -s
Expand All @@ -52,4 +54,4 @@ clean:
rm -rf .cache
rm -rf reports

test: lint unittests integration clean
test: pep8 lint unittests integration clean
10 changes: 8 additions & 2 deletions python-api/gstswitch/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Server(object):
:param controller_address: The DBus-Address for remote control -
default = tcp:host=0.0.0.0,port=5000
:param record_file: The record file format
:param video_format: The video format to use on the server.
:returns: nothing
"""
SLEEP_TIME = 0.5
Expand All @@ -41,7 +42,8 @@ def __init__(
video_port=3000,
audio_port=4000,
controller_address='tcp:host=0.0.0.0,port=5000',
record_file=False):
record_file=False,
video_format=None):

super(Server, self).__init__()

Expand All @@ -57,6 +59,7 @@ def __init__(
self.audio_port = audio_port
self.controller_address = controller_address
self.record_file = record_file
self.video_format = video_format

self.proc = None
self.pid = -1
Expand Down Expand Up @@ -150,7 +153,7 @@ def controller_address(self, controller_address):
self._controller_address = controller_address
except ValueError:
raise ValueError("Control Address must contain at least "
" one Colon. It is '{0}'" \
" one Colon. It is '{0}'"
.format(controller_address))

@property
Expand Down Expand Up @@ -226,6 +229,9 @@ def _run_process(self):
if self.record_file is not False:
cmd.append("--record={0}".format(self.record_file))

if self.video_format is not None:
cmd.append("--video-format={0}".format(self.video_format))

proc = self._start_process(cmd)
return proc

Expand Down
44 changes: 34 additions & 10 deletions python-api/gstswitch/testsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def make(cls, elem, description=''):


class VideoPipeline(BasePipeline):

"""A Video Pipeline which can be used by a Video Test Source
:param port: The port of where the TCP stream will be sent
Should be same as video port of gst-switch-src
Expand All @@ -67,10 +66,17 @@ class VideoPipeline(BasePipeline):
:param clockoverlay: True to enable current clock time over video
"""

VIDEO_CAPS = """
video/x-raw,
format=(string)I420, pixel-aspect-ratio=(fraction)1/1,
width=(int){0}, height=(int){1},
framerate=(fraction)25/1
"""

def __init__(
self,
port,
host='localhost',
host='127.0.0.1',
width=300,
height=200,
pattern=None,
Expand Down Expand Up @@ -130,8 +136,7 @@ def make_capsfilter(self, width, height):
element = self.make("capsfilter", "vfilter")
width = str(width)
height = str(height)
capsstring = "video/x-raw, format=(string)I420, width={0},\
height={1}".format(width, height)
capsstring = self.VIDEO_CAPS.format(width, height)
print capsstring
caps = Gst.Caps.from_string(capsstring)
element.set_property('caps', caps)
Expand Down Expand Up @@ -172,13 +177,18 @@ def make_tcpclientsink(self, port):


class AudioPipeline(BasePipeline):

"""docstring for AudioPipeline"""

AUDIO_CAPS = """
audio/x-raw,
rate=48000, channels=2,
format=S16LE, layout=interleaved
"""

def __init__(
self,
port,
host='localhost',
host='127.0.0.1',
freq=110,
wave=None):
super(AudioPipeline, self).__init__()
Expand All @@ -187,13 +197,27 @@ def __init__(

src = self.make_audiotestsrc(freq, wave)
self.add(src)
afilter = self.make_capsfilter()
self.add(afilter)
src.link(afilter)
gdppay = self.make_gdppay()
self.add(gdppay)
src.link(gdppay)
afilter.link(gdppay)
sink = self.make_tcpclientsink(port)
self.add(sink)
gdppay.link(sink)

def make_capsfilter(self):
"""Return a caps filter
:returns: A caps filter element
"""
element = self.make("capsfilter", "afilter")
capsstring = self.AUDIO_CAPS
print capsstring
caps = Gst.Caps.from_string(capsstring)
element.set_property('caps', caps)
return element

def make_audiotestsrc(self, freq, wave=None):
"""Return a Audio Source Element
:freq: The Frequency
Expand Down Expand Up @@ -230,7 +254,7 @@ class PreviewPipeline(BasePipeline):

def __init__(self, port):
super(PreviewPipeline, self).__init__()
self.host = 'localhost'
self.host = '127.0.0.1'
self.preview_port = port
src = self.make_tcpclientsrc()
self.add(src)
Expand Down Expand Up @@ -305,7 +329,7 @@ class VideoSrc(object):
:param timeoverlay: True to enable a running time over video
:param clockoverlay: True to enable current clock time over video
"""
HOST = 'localhost'
HOST = '127.0.0.1'

def __init__(
self,
Expand Down Expand Up @@ -497,7 +521,7 @@ class AudioSrc(object):

"""docstring for AudioSrc"""

HOST = 'localhost'
HOST = '127.0.0.1'

def __init__(
self,
Expand Down
41 changes: 24 additions & 17 deletions python-api/tests/integrationtests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import sys
import os
import pytest
sys.path.insert(0, os.path.abspath(os.path.join(__file__, "../../../")))

from gstswitch.server import Server
Expand Down Expand Up @@ -35,7 +36,7 @@ def establish_connection(self):

def test_establish(self):
"""Test for establish_connection"""
serv = Server(path=PATH)
serv = Server(path=PATH, video_format="debug")
try:
serv.run()
for i in range(self.NUM):
Expand Down Expand Up @@ -219,7 +220,7 @@ def test_get_preview_ports(self):
"""Test get_preview_ports"""

for _ in range(self.NUM):
serv = Server(path=PATH)
serv = Server(path=PATH, video_format="debug")
try:
serv.run()
sources = TestSources(video_port=3000, audio_port=4000)
Expand Down Expand Up @@ -280,7 +281,7 @@ 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)
serv = Server(path=PATH, video_format="debug")
try:
serv.run()

Expand Down Expand Up @@ -331,14 +332,18 @@ def verify_output(self, mode, video):
cmpr = CompareVideo(test, video)
res1, res2 = cmpr.compare()
print "RESULTS", res1, res2
folder = cmpr.test_frame_dir
cmd = "./imgurbash.sh {0}/*.*".format(folder)
print cmd
proc = subprocess.Popen(
cmd,
bufsize=-1,
shell=True)
print proc.wait()

# In the CI environment, upload to imgur the results.
if os.environ.get('CI', "False") == "true":
folder = cmpr.test_frame_dir
cmd = "./imgurbash.sh {0}/*.*".format(folder)
print cmd
proc = subprocess.Popen(
cmd,
bufsize=-1,
shell=True)
print proc.wait()

# Experimental Value
if res1 <= 0.04 and res2 <= 0.04:
return True
Expand Down Expand Up @@ -378,7 +383,8 @@ def new_record(self):
def test_new_record(self):
"""Test new_record"""
for _ in range(self.NUM):
serv = Server(path=PATH, record_file="test-%Y.data")
serv = Server(path=PATH, record_file="test-%Y.data",
video_format="debug")
try:
serv.run()

Expand Down Expand Up @@ -422,7 +428,7 @@ def adjust_pip(self,
generate_frames=False):
"""Create Controller object and call adjust_pip"""
for _ in range(self.NUM):
serv = Server(path=PATH)
serv = Server(path=PATH, video_format="debug")
try:
serv.run()
sources = TestSources(video_port=3000)
Expand Down Expand Up @@ -467,6 +473,7 @@ def verify_output(self, index, video):
return True
return False

@pytest.mark.xfail
def test_adjust_pip(self):
"""Test adjust_pip"""
dic = [
Expand All @@ -490,7 +497,7 @@ class TestSwitch(object):
def switch(self, channel, port, index):
"""Create Controller object and call switch method"""
for _ in range(self.NUM):
serv = Server(path=PATH)
serv = Server(path=PATH, video_format="debug")
try:
serv.run()

Expand Down Expand Up @@ -547,7 +554,7 @@ def click_video(self,
generate_frames=False):
"""Create Controller object and call click_video method"""
for _ in range(self.NUM):
serv = Server(path=PATH)
serv = Server(path=PATH, video_format="debug")
try:
serv.run()
sources = TestSources(video_port=3000)
Expand Down Expand Up @@ -616,7 +623,7 @@ class TestMarkFace(object):
def mark_face(self, faces, index, generate_frames=False):
"""Create the Controller object and call mark_face method"""
for _ in range(self.NUM):
serv = Server(path=PATH)
serv = Server(path=PATH, video_format="debug")
try:
serv.run()
sources = TestSources(video_port=3000)
Expand Down Expand Up @@ -679,7 +686,7 @@ class TestMarkTracking(object):
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)
serv = Server(path=PATH, video_format="debug")
try:
serv.run()
sources = TestSources(video_port=3000)
Expand Down
2 changes: 1 addition & 1 deletion tools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ gst_switch_ptz_LDADD = $(GST_LIBS) $(X_LIBS) $(LIBM) $(GTK_LIBS) \

if GCOV_ENABLED
coverage:
gcov gst_switch_srv-*.o
gcov -d gst_switch_srv-*.o
endif

0 comments on commit 67317e7

Please sign in to comment.