[Spice-devel] [PATCH xspice 2/2] xspice: add tests for audio remoting
Alon Levy
alevy at redhat.com
Sun Oct 20 15:34:08 CEST 2013
Signed-off-by: Alon Levy <alevy at redhat.com>
---
tests/xspice_audio_test.py | 19 +++++++++++
tests/xspice_audio_test_helper.py | 19 +++++++++++
tests/xspice_util.py | 69 +++++++++++++++++++++++++++++++++++++++
3 files changed, 107 insertions(+)
create mode 100755 tests/xspice_audio_test.py
create mode 100755 tests/xspice_audio_test_helper.py
create mode 100755 tests/xspice_util.py
diff --git a/tests/xspice_audio_test.py b/tests/xspice_audio_test.py
new file mode 100755
index 0000000..455c1aa
--- /dev/null
+++ b/tests/xspice_audio_test.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+from time import sleep
+from xspice_audio_test_helper import produce_audio
+from xspice_util import launch_xspice, launch_client
+
+def main():
+ port = 8000
+ xspice = launch_xspice(port)
+ sleep(2)
+ client = launch_client(port)
+ sleep(1)
+ produce_audio(xspice.audio_fifo_dir)
+ sleep(2)
+ client.kill()
+ xspice.kill()
+
+if __name__ == '__main__':
+ main()
diff --git a/tests/xspice_audio_test_helper.py b/tests/xspice_audio_test_helper.py
new file mode 100755
index 0000000..fbe3a54
--- /dev/null
+++ b/tests/xspice_audio_test_helper.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+# coding: utf-8
+import os
+import sys
+import struct
+from math import sin, pi
+
+def produce_audio(basedir):
+ filename = os.path.join(basedir, 'testaudio')
+ os.system(u'mkfifo %s' % filename)
+ if not os.path.exists(basedir):
+ print "missing fifo dir %s" % repr(basedir)
+ f=open(filename,'w')
+ singen = lambda f: lambda t: (int(min(32767, 32768*sin(t*f/1000.0*pi))), int(min(32767, 32768*sin(t*f/1000.0*pi))))
+ f.write(''.join( struct.pack('hh', *singen(40)(t)) for t in xrange(44100) ) )
+ os.unlink(filename)
+
+if __name__ == '__main__':
+ produce_audio(sys.argv[-1] if len(sys.argv) > 1 else '/tmp/xspice-audio/')
diff --git a/tests/xspice_util.py b/tests/xspice_util.py
new file mode 100755
index 0000000..a2e8578
--- /dev/null
+++ b/tests/xspice_util.py
@@ -0,0 +1,69 @@
+#!/usr/bin/python
+
+import os
+from time import sleep
+import subprocess
+import atexit
+
+class Process(object):
+ processes = []
+ @classmethod
+ def new(clazz, *args, **kw):
+ clazz.processes.append(subprocess.Popen(*args, **kw))
+ return clazz.processes[-1]
+
+ @classmethod
+ def atexit(clazz):
+ for p in reversed(clazz.processes):
+ print "child %s" % p.pid
+ if False:
+ slp = subprocess.Popen(['/usr/bin/sleep', '10000'])
+ print "wait on %d" % slp.pid
+ slp.wait()
+ if len(clazz.processes) == 0:
+ return
+ for p in reversed(clazz.processes):
+ print "kill %s" % p.pid
+ try:
+ p.kill()
+ except:
+ pass
+ if not any(p.poll() for p in clazz.processes):
+ return
+ sleep(1)
+ for p in reversed(clazz.processes):
+ if not p.poll():
+ print "terminate %s" % p.pid
+ try:
+ p.terminate()
+ except:
+ pass
+
+atexit.register(Process.atexit)
+
+def which(prog):
+ for path_element in os.environ['PATH'].split(':'):
+ candidate = os.path.join(path_element, prog)
+ if os.path.exists(candidate):
+ return candidate
+ return None
+
+client_executable = which('remote-viewer')
+if not client_executable:
+ raise SystemExit('missing remote-viewer in path')
+
+def launch_xspice(port):
+ basedir = '/tmp/xspice_test_audio'
+ if not os.path.exists(basedir):
+ os.mkdir(basedir)
+ assert(os.path.exists(basedir))
+ xspice = Process.new(['../scripts/Xspice', '--port', '8000', '--auto', '--audio-fifo-dir', basedir, '--disable-ticketing', ':15.0'])
+ xspice.audio_fifo_dir = basedir
+ return xspice
+
+def launch_client(port):
+ client = Process.new([client_executable, 'spice://localhost:%s' % port])
+ return client
+
+if __name__ == '__main__':
+ launch_xspice(port=8000)
--
1.8.3.1
More information about the Spice-devel
mailing list