chiark / gitweb /
Include sys/time.h in a few places, necessary for older libc versions.
[disorder] / tests / dtest.py
index d2bb20111e86adda41f63b1445476142f33e4361..8a4644a128e2efc94887ab6d72a9749fdc7e66c5 100644 (file)
@@ -1,7 +1,7 @@
 #-*-python-*-
 #
 # This file is part of DisOrder.
-# Copyright (C) 2007, 2008 Richard Kettlewell
+# Copyright (C) 2007-2009 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
@@ -19,7 +19,7 @@
 
 """Utility module used by tests"""
 
-import os,os.path,subprocess,sys,re,time,unicodedata,random,socket
+import os,os.path,subprocess,sys,re,time,unicodedata,random,socket,traceback
 
 def fatal(s):
     """Write an error message and exit"""
@@ -202,10 +202,10 @@ def common_setup():
     os.mkdir(testroot)
     # Choose a port
     global port
-    port = random.randint(49152, 65535)
+    port = random.randint(49152, 65530)
     while not bindable(port + 1):
         print "port %d is not bindable, trying another" % (port + 1)
-        port = random.randint(49152, 65535)
+        port = random.randint(49152, 65530)
     # Log anything sent to that port
     packetlog = "%s/packetlog" % testroot
     subprocess.Popen(["disorder-udplog",
@@ -230,10 +230,8 @@ Start the daemon."""
     print " starting daemon"
     # remove the socket if it exists
     socket = "%s/home/socket" % testroot
-    try:
+    if os.path.exists(socket):
         os.remove(socket)
-    except:
-        pass
     daemon = subprocess.Popen(["disorderd",
                                "--foreground",
                                "--config", "%s/config" % testroot],
@@ -254,6 +252,10 @@ Start the daemon."""
         time.sleep(1)
     if waited > 0:
         print "  took about %ds for socket to appear" % waited
+    # Wait for root user to be created
+    command(["disorder",
+             "--config", disorder._configfile, "--no-per-user-config",
+             "--wait-for-root"])
 
 def create_user(username="fred", password="fredpass"):
     """create_user(USERNAME, PASSWORD)
@@ -285,10 +287,10 @@ Stop the daemon if it has not stopped already"""
     rc = daemon.poll()
     if rc == None:
         print " stopping daemon"
-        disorder.client().shutdown()
+        os.kill(daemon.pid, 15)
         print "  waiting for daemon"
         rc = daemon.wait()
-        print "  daemon has stopped"
+        print "  daemon has stopped (rc=%d)" % rc
     else:
         print "  daemon already stopped"
     daemon = None
@@ -300,7 +302,7 @@ def run(module=None, report=True):
 
     Run the test in MODULE.  This can be a string (in which case the module
     will be imported) or a module object."""
-    global tests
+    global tests, failures
     tests += 1
     # Locate the test module
     if module is None:
@@ -331,8 +333,10 @@ def run(module=None, report=True):
     stdtracks()
     try:
         module.test()
-    finally:
-        stop_daemon()
+    except:
+        traceback.print_exc(None, sys.stderr)
+        failures += 1
+    stop_daemon()
     if report:
         if failures:
             print " FAILED"