mirror of
https://github.com/X11Libre/xf86-video-qxl.git
synced 2026-03-24 01:24:24 +00:00
xspice: add tests for audio remoting
Signed-off-by: Alon Levy <alevy@redhat.com>
This commit is contained in:
19
tests/xspice_audio_test.py
Executable file
19
tests/xspice_audio_test.py
Executable file
@@ -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()
|
||||
19
tests/xspice_audio_test_helper.py
Executable file
19
tests/xspice_audio_test_helper.py
Executable file
@@ -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/')
|
||||
69
tests/xspice_util.py
Executable file
69
tests/xspice_util.py
Executable file
@@ -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)
|
||||
Reference in New Issue
Block a user