Commit 7c36949f authored by Jan Hák's avatar Jan Hák Committed by Daniel Salzman

tests-extra: added support for parallelized tests

parent 5f18cb44
This diff is collapsed.
......@@ -5,9 +5,9 @@
import os
import re
import importlib
import dnstest.params
import dnstest.test
from dnstest.utils import *
from dnstest.thread_context import ThreadContext
class IxfrTopology():
'''This class simplifies testing topology.'''
......@@ -102,11 +102,12 @@ patern = re.compile("^([0-9][0-9]_)")
t = dnstest.test.Test()
for dirname in sorted(os.listdir(dnstest.params.test_dir)):
ctx = ThreadContext()
for dirname in sorted(os.listdir(ctx.test_dir)):
if patern.match(dirname):
mod_name = dnstest.params.module + "." + dirname + ".step"
mod_name = ctx.module + "." + dirname + ".step"
mod = importlib.import_module(mod_name)
storage = dnstest.params.test_dir + "/" + dirname
storage = ctx.test_dir + "/" + dirname
i = IxfrTopology(t, storage)
......
......@@ -69,19 +69,3 @@ outs_dir = get_param("KNOT_TEST_OUTS_DIR", "/tmp")
# Common data directory (e.g. zone files).
common_data_dir = ""
# Current module name.
module = ""
# Current case relative directory.
test_dir = ""
# Current case absolute output directory.
out_dir = ""
# Current case log file.
case_log = None
# Current test object (for stopping it from the main script).
test = None
# Indication for failed test.
err = False
# What is wrong.
err_msg = ""
......@@ -22,6 +22,7 @@ import dnstest.keys
import dnstest.module
import dnstest.response
import dnstest.update
from dnstest.thread_context import ThreadContext
import distutils.dir_util
from shutil import copyfile
......@@ -86,7 +87,7 @@ class Zone(object):
def get_module(self, mod_name):
for m in self.modules:
if m.mod_name == mod_name:
return m;
return m
def clear_modules(self):
self.modules.clear()
......@@ -240,7 +241,7 @@ class Server(object):
raise Failed("Can't start server='%s'" % self.name)
# Start inquirer if enabled.
if params.test.stress and self.inquirer:
if ThreadContext().test.stress and self.inquirer:
self.inquirer.start(self)
def ctl(self, cmd, availability=True):
......@@ -361,7 +362,7 @@ class Server(object):
detail_log(SEP)
def stop(self, check=True):
if params.test.stress and self.inquirer:
if ThreadContext().test.stress and self.inquirer:
self.inquirer.stop()
if self.proc:
......@@ -379,7 +380,7 @@ class Server(object):
self._valgrind_check()
def kill(self):
if params.test.stress and self.inquirer:
if ThreadContext().test.stress and self.inquirer:
self.inquirer.stop()
if self.proc:
......@@ -846,7 +847,7 @@ class Bind(Server):
s.begin("controls")
s.item("inet %s port %i allow { %s; } keys { %s; }"
% (self.addr, self.ctlport, params.test.addr, self.ctlkey.name))
% (self.addr, self.ctlport, ThreadContext().test.addr, self.ctlkey.name))
s.end()
if self.tsig:
......@@ -932,7 +933,7 @@ class Bind(Server):
if self.tsig_test:
upd = "key %s; " % self.tsig_test.name
else:
upd = "%s; " % params.test.addr
upd = "%s; " % ThreadContext().test.addr
if z.masters:
s.item("allow-update-forwarding", "{ %s}" % upd)
......@@ -1132,13 +1133,13 @@ class Knot(Server):
s.begin("acl")
s.id_item("id", "acl_local")
s.item_str("address", params.test.addr)
s.item_str("address", ThreadContext().test.addr)
if self.tsig:
s.item_str("key", self.tsig.name)
s.item("action", "[transfer, notify, update]")
s.id_item("id", "acl_test")
s.item_str("address", params.test.addr)
s.item_str("address", ThreadContext().test.addr)
if self.tsig_test:
s.item_str("key", self.tsig_test.name)
s.item("action", "[transfer, notify, update]")
......
......@@ -14,6 +14,7 @@ import dnstest.params as params
import dnstest.server
import dnstest.keys
import dnstest.zonefile
from dnstest.thread_context import ThreadContext
class Test(object):
'''Specification of DNS test topology'''
......@@ -30,11 +31,13 @@ class Test(object):
rel_time = time.time()
def __init__(self, address=None, tsig=None, stress=True):
if not os.path.exists(params.out_dir):
ctx = ThreadContext()
if not os.path.exists(ctx.out_dir):
raise Exception("Output directory doesn't exist")
self.out_dir = params.out_dir
self.data_dir = params.test_dir + "/data/"
self.ctx = ctx
self.out_dir = ctx.out_dir
self.data_dir = ctx.test_dir + "/data/"
self.zones_dir = self.out_dir + "/zones/"
if address == 4 or address == 6:
......@@ -61,7 +64,7 @@ class Test(object):
dnstest.server.Bind.count = 0
dnstest.server.Dummy.count = 0
params.test = self
ctx.test = self
def _check_port(self, port):
if not port:
......@@ -246,7 +249,7 @@ class Test(object):
'''Finish testing'''
self.stop(check=True)
params.test = None
self.ctx.test = None
def sleep(self, seconds):
time.sleep(seconds)
......
#!/usr/bin/env python3
import threading
class ThreadContext:
class _ThreadContext(threading.local):
def __init__(self):
# Current module name.
self.module = ""
# Current case relative directory.
self.test_dir = ""
# Current case absolute output directory.
self.out_dir = ""
# Current case log file.
self.case_log = None
# Current test object (for stopping it from the main script).
self.test = None
# Indication for failed test.
self.err = False
# What is wrong.
self.err_msg = ""
_INSTANCE = None
def __new__(cls):
if not ThreadContext._INSTANCE:
ThreadContext._INSTANCE = ThreadContext._ThreadContext()
return ThreadContext._INSTANCE
def __getattribute__(self, name):
return getattr(self._INSTANCE, name)
def __setattr__(self, name, val):
return setattr(self._INSTANCE, name, val)
\ No newline at end of file
......@@ -5,6 +5,7 @@ import os
import time
import dnstest.params as params
from dnstest.thread_context import ThreadContext
SEP = "------------------------------------"
......@@ -29,8 +30,8 @@ def test_info():
info = ""
frames = inspect.getouterframes(inspect.currentframe())
for frame in frames:
if params.test_dir == os.path.dirname(frame[1]):
info = "%s#%i" % (params.test_dir, frame[2])
if ThreadContext().test_dir == os.path.dirname(frame[1]):
info = "%s#%i" % (ThreadContext().test_dir, frame[2])
break
parts = info.split("/")
......@@ -43,22 +44,25 @@ def check_log(text):
'''Log message header'''
msg = "(%s) %s (%s)\n" % (time.strftime("%H:%M:%S"), str(text), test_info())
params.case_log.write(msg)
params.case_log.flush()
ctx = ThreadContext()
ctx.case_log.write(msg)
ctx.case_log.flush()
def detail_log(text):
'''Log message body'''
msg = "%s\n" % text
params.case_log.write(msg)
params.case_log.flush()
ctx = ThreadContext()
ctx.case_log.write(msg)
ctx.case_log.flush()
def set_err(msg):
'''Set error state'''
params.err = True
if not params.err_msg:
params.err_msg = msg
ctx = ThreadContext()
ctx.err = True
if not ctx.err_msg:
ctx.err_msg = msg
def isset(value, name):
'''Check if value is True'''
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment