2008-02-25 10:55:36 +01:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
import twill
|
2009-04-30 16:58:24 +02:00
|
|
|
import urllib2
|
2009-08-27 14:07:40 +02:00
|
|
|
import os.path
|
|
|
|
import re
|
2008-02-25 10:55:36 +01:00
|
|
|
|
2009-08-27 14:07:40 +02:00
|
|
|
CONFIG_FILE = os.path.expanduser('~/.config/lasso_integration.conf')
|
|
|
|
CONFIG = dict()
|
|
|
|
|
|
|
|
if os.path.exists(CONFIG_FILE):
|
|
|
|
lines = open(CONFIG_FILE).read().splitlines()
|
|
|
|
i = 1
|
|
|
|
for line in lines:
|
|
|
|
try:
|
|
|
|
m = re.match('(\w*) = (.*)', line)
|
|
|
|
CONFIG[m.groups()[0]] = m.groups()[1]
|
|
|
|
except:
|
|
|
|
print "Line", i, " of configuration file", CONFIG_FILE, "is invalid:", line
|
|
|
|
i +=1
|
|
|
|
|
|
|
|
# Combine default and configuration file
|
|
|
|
AUTHENTIC_SRCDIR = CONFIG.get('AUTHENTIC_SRCDIR') or '/usr/local/src/authentic'
|
|
|
|
AUTHENTICCTL = CONFIG.get('AUTHENTICCTL') or '/usr/sbin/authenticctl.py'
|
|
|
|
AUTHENTIC_DATA_DIR = CONFIG.get('AUTHENTIC_DATA_DIR') or '/usr/share/authentic/'
|
|
|
|
LCSCTL = CONFIG.get('LCSCTL') or '/usr/sbin/lcsctl.py'
|
|
|
|
LCS_DATADIR = CONFIG.get('LCS_DATADIR') or '/usr/share/lcs/'
|
|
|
|
LASSO_BUILDDIR = os.environ.get('LASSO_BUILDDIR') or \
|
|
|
|
CONFIG.get('LASSO_BUILDDIR') or \
|
2009-10-30 15:47:32 +01:00
|
|
|
os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
|
2009-08-27 14:07:40 +02:00
|
|
|
|
|
|
|
os.environ['LD_LIBRARY_PATH'] = os.path.join(LASSO_BUILDDIR, "lasso", ".libs") + ":" + \
|
|
|
|
os.environ.get('LD_LIBRARY_PATH', '')
|
|
|
|
os.environ['PYTHONPATH'] = os.path.join(LASSO_BUILDDIR, "bindings", "python") + \
|
|
|
|
":" + os.path.join(LASSO_BUILDDIR, "bindings", "python", ".libs") + ":" + \
|
|
|
|
os.environ.get('PYTHONPATH', '')
|
2008-02-25 10:55:36 +01:00
|
|
|
|
|
|
|
try:
|
|
|
|
from config import *
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
pids = []
|
|
|
|
|
2009-04-30 16:58:24 +02:00
|
|
|
def waitforport(port, start):
|
|
|
|
while True:
|
|
|
|
if time.time() - start > 90:
|
|
|
|
raise Exception('Servers did not start in 90 seconds!!')
|
|
|
|
time.sleep(5)
|
|
|
|
try:
|
|
|
|
urllib2.urlopen('http://localhost:%s' % port)
|
|
|
|
except urllib2.URLError:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
break
|
|
|
|
|
2008-02-25 10:55:36 +01:00
|
|
|
def setup():
|
|
|
|
if not os.path.exists(AUTHENTIC_SRCDIR):
|
|
|
|
print >> sys.stderr, 'Authentic source dir (%s) does not exist' % AUTHENTIC_SRCDIR
|
|
|
|
print >> sys.stderr, 'Create it or edit tests/config.py to match your local installation'
|
|
|
|
sys.exit(1)
|
|
|
|
|
2009-08-27 14:07:40 +02:00
|
|
|
silent = os.environ.get('NO_SILENT') is None
|
2008-02-25 23:20:53 +01:00
|
|
|
twill.commands.reset_browser()
|
|
|
|
twill.set_output(file('/dev/null', 'w'))
|
2009-04-30 16:58:24 +02:00
|
|
|
base = []
|
2009-08-27 14:07:40 +02:00
|
|
|
if os.environ.get('VALGRIND') is '1' and os.path.exists('/usr/bin/valgrind'):
|
2009-04-30 16:58:24 +02:00
|
|
|
base = ['./valgrind-wrapper.sh', 'python']
|
2008-02-25 23:20:53 +01:00
|
|
|
|
2008-02-25 10:55:36 +01:00
|
|
|
os.mkdir('/tmp/.tests')
|
2009-04-30 16:58:24 +02:00
|
|
|
authentic_command = base + [AUTHENTICCTL, 'start',
|
2008-02-25 10:55:36 +01:00
|
|
|
'--app-dir', '/tmp/.tests/authentictests',
|
|
|
|
'--data-dir', AUTHENTIC_DATADIR,
|
|
|
|
'--extra', os.path.join(AUTHENTIC_SRCDIR, 'extra', 'conformance'),
|
2009-08-27 14:07:40 +02:00
|
|
|
'--port', '10001', '--http']
|
|
|
|
if silent:
|
|
|
|
authentic_command.append('--silent')
|
2009-04-30 16:58:24 +02:00
|
|
|
sp = subprocess.Popen(authentic_command)
|
2008-02-25 10:55:36 +01:00
|
|
|
pids.append(sp.pid)
|
2009-04-30 16:58:24 +02:00
|
|
|
lcs_command = base + [LCSCTL, 'start',
|
2008-02-25 10:55:36 +01:00
|
|
|
'--app-dir', '/tmp/.tests/lcstests',
|
|
|
|
'--data-dir', LCS_DATADIR,
|
2009-08-27 14:07:40 +02:00
|
|
|
'--port', '10002', '--http']
|
|
|
|
if silent:
|
|
|
|
lcs_command.append('--silent')
|
2009-04-30 16:58:24 +02:00
|
|
|
sp = subprocess.Popen(lcs_command)
|
2008-02-25 10:55:36 +01:00
|
|
|
pids.append(sp.pid)
|
|
|
|
|
2009-04-30 16:58:24 +02:00
|
|
|
# Wait for the daemons to load themselves
|
|
|
|
starttime = time.time()
|
|
|
|
waitforport(10001, starttime)
|
|
|
|
waitforport(10002, starttime)
|
2008-02-25 10:55:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
def teardown():
|
|
|
|
for pid in pids:
|
2008-02-25 23:20:53 +01:00
|
|
|
try:
|
2009-04-30 16:58:24 +02:00
|
|
|
# valgrind seems to prefer SIGINT to SIGTERM
|
|
|
|
os.kill(pid, signal.SIGINT)
|
2008-02-25 23:20:53 +01:00
|
|
|
except OSError:
|
|
|
|
print >> sys.stderr, 'failed to kill pid %s' % pid
|
2008-02-25 10:55:36 +01:00
|
|
|
os.system('rm -rf /tmp/.tests/')
|
|
|
|
|