chiark / gitweb /
exit not _exit, for benefit of coverage testing
[disorder] / tests / dtest.py
index 68a130d8b4b501c8f5ddf494e2ed64e1ab41a798..cd14cfbbce5cd7df210bcd9241c25153cd510079 100644 (file)
@@ -21,7 +21,7 @@
 
 """Utility module used by tests"""
 
-import os,os.path,subprocess,sys,re,time,unicodedata
+import os,os.path,subprocess,sys,re,time,unicodedata,random
 
 def fatal(s):
     """Write an error message and exit"""
@@ -41,9 +41,10 @@ else:
 sys.path.insert(0, os.path.join(top_builddir, "python"))
 import disorder
 
-# Make sure the server build directory is on the executable search path
+# Make sure the build directories are on the executable search path
 ospath = os.environ["PATH"].split(os.pathsep)
 ospath.insert(0, os.path.join(top_builddir, "server"))
+ospath.insert(0, os.path.join(top_builddir, "clients"))
 os.environ["PATH"] = os.pathsep.join(ospath)
 
 # Parse the makefile in the current directory to identify the source directory
@@ -153,9 +154,10 @@ def stdtracks():
 def common_setup():
     remove_dir(testroot)
     os.mkdir(testroot)
+    global port
+    port = random.randint(49152, 65535)
     open("%s/config" % testroot, "w").write(
-    """player *.ogg shell 'echo "$TRACK" >> %s/played.log'
-home %s
+    """home %s
 collection fs UTF-8 %s/tracks
 scratch %s/scratch.ogg
 gap 0
@@ -167,7 +169,10 @@ stopword the a an and to too in on of we i am as im for is
 username fred
 password fredpass
 allow fred fredpass
+trust fred
+plugins
 plugins %s/plugins
+plugins %s/plugins/.libs
 player *.mp3 execraw disorder-decode
 player *.ogg execraw disorder-decode
 player *.wav execraw disorder-decode
@@ -176,7 +181,11 @@ tracklength *.mp3 disorder-tracklength
 tracklength *.ogg disorder-tracklength
 tracklength *.wav disorder-tracklength
 tracklength *.flac disorder-tracklength
-""" % (testroot, testroot, testroot, testroot, top_builddir))
+speaker_backend network
+broadcast 127.0.0.1 %d
+broadcast_from 127.0.0.1 %d
+""" % (testroot, testroot, testroot, top_builddir, top_builddir,
+       port, port + 1))
     copyfile("%s/sounds/scratch.ogg" % top_srcdir,
              "%s/scratch.ogg" % testroot)
 
@@ -185,7 +194,7 @@ def start_daemon():
 
 Start the daemon."""
     global daemon, errs
-    assert daemon == None
+    assert daemon == None, "no daemon running"
     print " starting daemon"
     # remove the socket if it exists
     socket = "%s/socket" % testroot
@@ -224,7 +233,7 @@ Stop the daemon if it has not stopped already"""
     rc = daemon.poll()
     if rc == None:
         print " stopping daemon"
-        os.kill(daemon.pid, 15)
+        disorder.client().shutdown()
         print "  waiting for daemon"
         rc = daemon.wait()
         print "  daemon has stopped"
@@ -266,7 +275,7 @@ def run(module=None, report=True):
         except AssertionError, e:
             global failures
             failures += 1
-            print e
+            print "assertion failed: %s" % e.message
     finally:
         stop_daemon()
     if report:
@@ -315,6 +324,14 @@ def check_files():
             failures += 1
     return failures
 
+def command(args):
+    """Execute a command given as a list and return its stdout"""
+    p = subprocess.Popen(args, stdout=subprocess.PIPE)
+    lines = p.stdout.readlines()
+    rc = p.wait()
+    assert rc == 0, ("%s returned status %s" % (args, rc))
+    return lines
+
 # -----------------------------------------------------------------------------
 # Common setup