summaryrefslogtreecommitdiff
path: root/selftest/selftest.py
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-03-11 20:58:00 +0100
committerJelmer Vernooij <jelmer@samba.org>2012-03-11 23:57:04 +0100
commit6f9c333f95956138fbd8245a4cf3f285ca601181 (patch)
treeb6e2653adfa04206d5d912d74134b828757ce3a1 /selftest/selftest.py
parentf5bb26edb36936b08dc2384cf6aa1dee73a355c8 (diff)
downloadsamba-6f9c333f95956138fbd8245a4cf3f285ca601181.tar.gz
samba-6f9c333f95956138fbd8245a4cf3f285ca601181.tar.bz2
samba-6f9c333f95956138fbd8245a4cf3f285ca601181.zip
selftest.py: Move some infrastructure for running commands to selftest.run, with tests.
Diffstat (limited to 'selftest/selftest.py')
-rwxr-xr-xselftest/selftest.py51
1 files changed, 14 insertions, 37 deletions
diff --git a/selftest/selftest.py b/selftest/selftest.py
index 1b2044134c..f35541a3e5 100755
--- a/selftest/selftest.py
+++ b/selftest/selftest.py
@@ -18,8 +18,6 @@
import atexit
from cStringIO import StringIO
-import datetime
-import iso8601
import os
import sys
import signal
@@ -39,10 +37,11 @@ from selftest import (
)
from selftest.client import write_clientconf
from selftest.run import (
- expand_environment_strings,
expand_command_list,
expand_command_run,
exported_envvars_str,
+ now,
+ run_testsuite_command,
)
from selftest.target import (
EnvironmentManager,
@@ -53,9 +52,6 @@ from selftest.target import (
includes = ()
excludes = ()
-def now():
- return datetime.datetime.utcnow().replace(tzinfo=iso8601.iso8601.Utc())
-
def read_excludes(fn):
excludes.extend(testlist.read_test_regexes(fn))
@@ -123,42 +119,20 @@ def cleanup_pcap(pcap_file, exit_code):
os.unlink(pcap_file)
-def run_testsuite(envname, name, cmd):
+def run_testsuite(name, cmd, subunit_ops, env=None):
"""Run a single testsuite.
- :param envname: Name of the environment to ru nin
+ :param env: Environment to run in
:param name: Name of the testsuite
:param cmd: Name of the (fully expanded) command to run
:return: exitcode of the command
"""
pcap_file = setup_pcap(name)
- subunit_ops.start_testsuite(name)
- subunit_ops.progress(None, subunit.PROGRESS_PUSH)
- subunit_ops.time(now())
- try:
- exitcode = subprocess.call(cmd, shell=True)
- except Exception, e:
- subunit_ops.time(now())
- subunit_ops.progress(None, subunit.PROGRESS_POP)
- subunit_ops.end_testsuite(name, "error", "Unable to run %r: %s" % (cmd, e))
+ exitcode = run_testsuite_command(name, cmd, subunit_ops, env)
+ if exitcode is None:
sys.exit(1)
- subunit_ops.time(now())
- subunit_ops.progress(None, subunit.PROGRESS_POP)
-
- envlog = env_manager.getlog_env(envname)
- if envlog != "":
- sys.stdout.write("envlog: %s\n" % envlog)
-
- sys.stdout.write("command: %s\n" % cmd)
- sys.stdout.write("expanded command: %s\n" % expand_environment_strings(cmd, os.environ))
-
- if exitcode == 0:
- subunit_ops.end_testsuite(name, "success")
- else:
- subunit_ops.end_testsuite(name, "failure", "Exit code was %d" % exitcode)
-
cleanup_pcap(pcap_file, exitcode)
if not opts.socket_wrapper_keep_pcap and pcap_file is not None:
@@ -169,6 +143,7 @@ def run_testsuite(envname, name, cmd):
return exitcode
+
if opts.list and opts.testenv:
sys.stderr.write("--list and --testenv are mutually exclusive\n")
sys.exit(1)
@@ -273,9 +248,10 @@ else:
# must terminate in this time, and testenv will only stay alive this
# long
-server_maxtime = 7500
if os.environ.get("SMBD_MAXTIME", ""):
server_maxtime = int(os.environ["SMBD_MAXTIME"])
+else:
+ server_maxtime = 7500
def has_socket_wrapper(bindir):
@@ -466,7 +442,7 @@ def switch_env(name, prefix):
elif name in os.environ:
del os.environ[name]
- return testenv_vars
+ return env
# This 'global' file needs to be empty when we start
dns_host_file_path = os.path.join(prefix_abs, "dns_host_file")
@@ -476,7 +452,8 @@ if os.path.exists(dns_host_file_path):
if opts.testenv:
testenv_name = os.environ.get("SELFTEST_TESTENV", testenv_default)
- testenv_vars = switch_env(testenv_name, prefix)
+ env = switch_env(testenv_name, prefix)
+ testenv_vars = env.get_vars()
os.environ["PIDDIR"] = testenv_vars["PIDDIR"]
os.environ["ENVNAME"] = testenv_name
@@ -515,7 +492,7 @@ elif opts.list:
else:
for (name, envname, cmd, supports_loadfile, supports_idlist, subtests) in todo:
try:
- envvars = switch_env(envname, prefix)
+ env = switch_env(envname, prefix)
except UnsupportedEnvironment:
subunit_ops.start_testsuite(name)
subunit_ops.end_testsuite(name, "skip",
@@ -531,7 +508,7 @@ else:
cmd, tmpf = expand_command_run(cmd, supports_loadfile, supports_idlist,
subtests)
- run_testsuite(envname, name, cmd)
+ run_testsuite(name, cmd, subunit_ops, env=env)
if tmpf is not None:
os.remove(tmpf)