Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gst_video_sync integration test #408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lg_media/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ if(CATKIN_ENABLE_TESTING)
find_package(rostest REQUIRED)
add_rostest(test/online/test_mplayer_adhoc_media.test)
add_rostest(test/online/test_mplayer_director_bridge.test)
add_rostest(test/online/test_gst_video_sync_integration.test)
# exclude this test. it's starting real mplayer in a ManagedWindow
# and it sometimes hangs, exceeds ROS allotted time for a test and fails
# details: https://github.com/EndPointCorp/lg_ros_nodes/issues/215
Expand Down
87 changes: 87 additions & 0 deletions lg_media/test/online/test_gst_video_sync_integration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python

PKG = 'lg_media'
NAME = 'test_gst_video_sync_integration'

import unittest
import rospy
import json
import subprocess

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider possible security implications associated with subprocess module.

import tempfile
import wave
from interactivespaces_msgs.msg import GenericMessage
from contextlib import contextmanager


@contextmanager
def generate_silence():
with tempfile.NamedTemporaryFile() as f:
wav = wave.open(f.name, mode='wb')
wav.setsampwidth(2)
wav.setnchannels(1)
wav.setframerate(8000)
wav.writeframes(bytes([0 * 800000]))
wav.close()
yield f.name


class TestGstVideoSyncIntegration(unittest.TestCase):
def setUp(self):
self.scene_pub = rospy.Publisher('/director/scene', GenericMessage, queue_size=10)
rospy.sleep(1)

def test_scene(self):
with generate_silence() as fname:
content_url = 'file://{}'.format(fname)
scene = {
'name': NAME,
'description': NAME,
'duration': 60,
'slug': NAME,
'windows': [
{
'activity': 'video',
'activity_config': {
},
'assets': [
content_url,
],
'presentation_viewport': 'center',
'width': 640,
'height': 480,
'x_coord': 0,
'y_coord': 0,
},
],
}
self.scene_pub.publish(GenericMessage(type='json', message=json.dumps(scene)))
rospy.sleep(1)

subprocess.check_call([

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subprocess call - check for execution of untrusted input.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting a process with a partial executable path

'pgrep',
'-af',
'gst_video_sync\s.*-u\s{}'.format(content_url),
])

scene = {
'name': NAME + '_off',
'description': NAME + '_off',
'duration': 0,
'slug': NAME + '_off',
'windows': [],
}
self.scene_pub.publish(GenericMessage(type='json', message=json.dumps(scene)))
rospy.sleep(1)

with self.assertRaises(subprocess.CalledProcessError):
subprocess.check_call([

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subprocess call - check for execution of untrusted input.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting a process with a partial executable path

'pgrep',
'-af',
'gst_video_sync\s.*-u\s{}'.format(content_url),
])


if __name__ == '__main__':
import rostest
rospy.init_node(NAME)
rostest.rosrun(PKG, NAME, TestGstVideoSyncIntegration)
7 changes: 7 additions & 0 deletions lg_media/test/online/test_gst_video_sync_integration.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<launch>
<param name="/viewport/center" value="640x480+0+0" />
<node name="gst_video_sync" pkg="lg_media" type="gstreamer.py">
<param name="viewport" value="center" />
</node>
<test test-name="test_gst_video_sync_integration" pkg="lg_media" type="test_gst_video_sync_integration.py" />
</launch>