chiark / gitweb /
skeletal test infrastructure
authorRichard Kettlewell <rjk@greenend.org.uk>
Tue, 31 Jul 2007 19:17:18 +0000 (20:17 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Tue, 31 Jul 2007 19:17:18 +0000 (20:17 +0100)
.bzrignore
configure.ac
tests/Makefile.am [new file with mode: 0644]
tests/alltests [new file with mode: 0755]
tests/dtest.py [new file with mode: 0644]
tests/nothing.py [new file with mode: 0755]

index bffd38553ff6c441483978c68d33cfd5f02cf3d7..2ca293c03b8d18b99d0e64c127a4198bd6a279fc 100644 (file)
@@ -90,3 +90,6 @@ core
 vgcore.*
 *.tar.gz
 TAGS
+ktrace.out
+tests/Makefile
+tests/testroot
index 7bf4ebfe676c8222c138081a703350987e195bb2..b022b465a3ded3112f212a8040749036723a8b81 100644 (file)
@@ -64,7 +64,7 @@ AC_ARG_WITH([python],
                            [do not build Python support])],
            [want_python=$withval])
 
-subdirs="scripts lib clients doc examples debian"
+subdirs="scripts lib clients doc examples debian tests"
 
 if test $want_server = yes; then
   subdirs="${subdirs} server plugins driver templates sounds images"
@@ -394,5 +394,6 @@ AC_CONFIG_FILES([Makefile
                 debian/Makefile
                 sounds/Makefile
                 python/Makefile
-                examples/Makefile])
+                examples/Makefile
+                tests/Makefile])
 AC_OUTPUT
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644 (file)
index 0000000..377855e
--- /dev/null
@@ -0,0 +1,25 @@
+#
+# This file is part of DisOrder.
+# Copyright (C) 2004, 2005 Richard Kettlewell
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+#
+
+check:
+       PATH=../server:$$PATH \
+       PYTHONPATH=../python \
+               topsrcdir=${top_srcdir} \
+               ${PYTHON} alltests
diff --git a/tests/alltests b/tests/alltests
new file mode 100755 (executable)
index 0000000..fe0f383
--- /dev/null
@@ -0,0 +1,19 @@
+#! /usr/bin/env python
+import dtest
+
+tests = ["nothing"]
+
+for test in tests:
+    print "Test '%s'" % test
+    m = __import__(test)
+    dtest.run(getattr(m, "test"),
+              setup=getattr(m, "setup", None),
+              report=False,
+              name=test)
+
+print "%d tests" % dtest.tests
+if dtest.failures:
+    print "%d failures" % dtest.failures
+    sys.exit(1)
+else:
+    print "All tests OK"
diff --git a/tests/dtest.py b/tests/dtest.py
new file mode 100644 (file)
index 0000000..fcafb13
--- /dev/null
@@ -0,0 +1,137 @@
+#-*-python-*-
+
+"""Utility module used by tests"""
+
+import os,os.path,subprocess,sys
+
+def copyfile(a,b):
+    """copyfile(A, B)
+Copy A to B."""
+    open(b,"w").write(open(a).read())
+
+def maketrack(s):
+    """maketrack(S)
+
+Make track with relative path S exist"""
+    trackpath = "%s/%s" % (testroot, s)
+    trackdir = os.path.dirname(trackpath)
+    if not os.path.exists(trackdir):
+        os.makedirs(trackdir)
+    copyfile("%s/sounds/slap.ogg" % topsrcdir, trackpath)
+
+def stdtracks():
+    maketrack("Joe Bloggs/First Album/01:First track.ogg")
+    maketrack("Joe Bloggs/First Album/02:Second track.ogg")
+    maketrack("Joe Bloggs/First Album/03:Third track.ogg")
+    maketrack("Joe Bloggs/First Album/04:Fourth track.ogg")
+    maketrack("Joe Bloggs/First Album/05:Fifth track.ogg")
+    maketrack("Joe Bloggs/First Album/05:Fifth track.ogg")
+    maketrack("Joe Bloggs/Second Album/01:First track.ogg")
+    maketrack("Joe Bloggs/Second Album/02:Second track.ogg")
+    maketrack("Joe Bloggs/Second Album/03:Third track.ogg")
+    maketrack("Joe Bloggs/Second Album/04:Fourth track.ogg")
+    maketrack("Joe Bloggs/Second Album/05:Fifth track.ogg")
+    maketrack("Joe Bloggs/Second Album/05:Fifth track.ogg")
+    maketrack("Joe Bloggs/First Album/01:First track.ogg")
+    maketrack("Joe Bloggs/First Album/02:Second track.ogg")
+    maketrack("Joe Bloggs/First Album/03:Third track.ogg")
+    maketrack("Joe Bloggs/First Album/04:Fourth track.ogg")
+    maketrack("Joe Bloggs/First Album/05:Fifth track.ogg")
+    maketrack("Fred Smith/Boring/01:Dull.ogg")
+    maketrack("Fred Smith/Boring/02:Tedious.ogg")
+    maketrack("Fred Smith/Boring/03:Drum Solo.ogg")
+    maketrack("Fred Smith/Boring/04:Yawn.ogg")
+    maketrack("misc/blahblahblah.ogg")
+    maketrack("Various/Greatest Hits/01:Jim Whatever - Spong.ogg")
+    maketrack("Various/Greatest Hits/02:Joe Bloggs - Yadda.ogg")
+
+def notracks():
+    pass
+
+def start(test):
+    """start(TEST)
+
+Start the daemon for test called TEST."""
+    global daemon
+    assert daemon == None
+    if test == None:
+        errs = sys.stderr
+    else:
+        errs = open("%s/%s.log" % (testroot, test), "w")
+    server = None
+    print " starting daemon"
+    daemon = subprocess.Popen(["disorderd",
+                               "--foreground",
+                               "--config", "%s/config" % testroot],
+                              stderr=errs)
+
+def stop():
+    """stop()
+
+Stop the daemon if it has not stopped already"""
+    global daemon
+    rc = daemon.poll()
+    if rc == None:
+        os.kill(daemon.pid, 15)
+        rc = daemon.wait()
+    print " daemon has stopped"
+    daemon = None
+
+def run(test, setup=None, report=True, name=None): 
+    global tests
+    tests += 1
+    if setup == None:
+        setup = stdtracks
+    setup()
+    start(name)
+    try:
+        test()
+    except AssertionError, e:
+        global failures
+        failures += 1
+        print e
+        
+    stop()
+    if report:
+        if failures:
+            print " FAILED"
+            sys.exit(1)
+        else:
+            print " OK"
+
+def remove_dir(d):
+    """remove_dir(D)
+
+Recursively delete directory D"""
+    if os.path.lexists(d):
+        if os.path.isdir(d):
+            for dd in os.listdir(d):
+                remove_dir("%s/%s" % (d, dd))
+            os.rmdir(d)
+        else:
+            os.remove(d)
+
+# -----------------------------------------------------------------------------
+# Common setup
+
+tests = 0
+failures = 0
+daemon = None
+testroot = "%s/testroot" % os.getcwd()
+topsrcdir = os.path.abspath(os.getenv("topsrcdir"))
+remove_dir(testroot)
+os.mkdir(testroot)
+open("%s/config" % testroot, "w").write("""
+player *.ogg shell 'echo "$TRACK" >> %s/played.log'
+home %s
+collection fs ASCII %s/tracks
+scratch %s/scratch.ogg
+gap 0
+stopword 01 02 03 04 05 06 07 08 09 10
+stopword 1 2 3 4 5 6 7 8 9
+stopword 11 12 13 14 15 16 17 18 19 20
+stopword 21 22 23 24 25 26 27 28 29 30
+stopword the a an and to too in on of we i am as im for is
+""" % (testroot, testroot, testroot, testroot))
+copyfile("%s/sounds/scratch.ogg" % topsrcdir,
+         "%s/scratch.ogg" % testroot)
diff --git a/tests/nothing.py b/tests/nothing.py
new file mode 100755 (executable)
index 0000000..f946bf9
--- /dev/null
@@ -0,0 +1,9 @@
+#! /usr/bin/env python
+import dtest,time
+
+def test():
+    """Just start the server and then stop it a few seconds later"""
+    time.sleep(5)
+
+if __name__ == '__main__':
+    dtest.run(test)