avocado.test: Move runner plugin functionality to test module

So that we can make avocado test modules self runnable.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 db54c6b2
......@@ -2,10 +2,7 @@
Base Test Runner Plugins.
"""
import imp
import logging
import os
import time
from avocado.plugins import plugin
from avocado.core import data_dir
......@@ -74,67 +71,7 @@ class TestRunner(plugin.Plugin):
:param args: Command line args received from the run subparser.
"""
test_start_time = time.strftime('%Y-%m-%d-%H.%M.%S')
logdir = args.logdir or data_dir.get_logs_dir()
debugbase = 'run-%s' % test_start_time
debugdir = os.path.join(logdir, debugbase)
latestdir = os.path.join(logdir, "latest")
if not os.path.isdir(debugdir):
os.makedirs(debugdir)
try:
os.unlink(latestdir)
except OSError:
pass
os.symlink(debugbase, latestdir)
debuglog = os.path.join(debugdir, "debug.log")
loglevel = args.log_level or logging.DEBUG
output_manager = output.OutputManager()
output_manager.start_file_logging(debuglog, loglevel)
urls = args.url.split()
total_tests = len(urls)
test_dir = data_dir.get_test_dir()
output_manager.log_header("DEBUG LOG: %s" % debuglog)
output_manager.log_header("TOTAL TESTS: %s" % total_tests)
output_mapping = {'PASS': output_manager.log_pass,
'FAIL': output_manager.log_fail,
'TEST_NA': output_manager.log_skip,
'WARN': output_manager.log_warn}
test_index = 1
for url in urls:
path_attempt = os.path.abspath(url)
if os.path.exists(path_attempt):
test_class = test.DropinTest
test_instance = test_class(path=path_attempt, base_logdir=debugdir)
else:
test_module_dir = os.path.join(test_dir, url)
f, p, d = imp.find_module(url, [test_module_dir])
test_module = imp.load_module(url, f, p, d)
f.close()
test_class = getattr(test_module, url)
test_instance = test_class(name=url, base_logdir=debugdir)
sysinfo_logger = sysinfo.SysInfo(basedir=test_instance.sysinfodir)
test_instance.start_logging()
test_instance.setup()
sysinfo_logger.start_job_hook()
test_instance.run()
test_instance.cleanup()
test_instance.report()
test_instance.stop_logging()
output_func = output_mapping[test_instance.status]
label = "(%s/%s) %s:" % (test_index, total_tests,
test_instance.tagged_name)
output_func(label, test_instance.time_elapsed)
test_index += 1
output_manager.stop_file_logging()
test.run_tests(args)
class SystemInformation(plugin.Plugin):
......
......@@ -3,13 +3,16 @@ Contains the base test implementation, used as a base for the actual
framework tests.
"""
import imp
import logging
import os
import sys
import time
import traceback
from avocado import sysinfo
from avocado.core import data_dir
from avocado.core import exceptions
from avocado.core import output
from avocado.utils import process
......@@ -195,3 +198,67 @@ class DropinTest(Test):
except exceptions.CmdError, details:
self._log_detailed_cmd_info(details.result)
raise exceptions.TestFail(details)
def run_tests(args):
test_start_time = time.strftime('%Y-%m-%d-%H.%M.%S')
logdir = args.logdir or data_dir.get_logs_dir()
debugbase = 'run-%s' % test_start_time
debugdir = os.path.join(logdir, debugbase)
latestdir = os.path.join(logdir, "latest")
if not os.path.isdir(debugdir):
os.makedirs(debugdir)
try:
os.unlink(latestdir)
except OSError:
pass
os.symlink(debugbase, latestdir)
debuglog = os.path.join(debugdir, "debug.log")
loglevel = args.log_level or logging.DEBUG
output_manager = output.OutputManager()
output_manager.start_file_logging(debuglog, loglevel)
urls = args.url.split()
total_tests = len(urls)
test_dir = data_dir.get_test_dir()
output_manager.log_header("DEBUG LOG: %s" % debuglog)
output_manager.log_header("TOTAL TESTS: %s" % total_tests)
output_mapping = {'PASS': output_manager.log_pass,
'FAIL': output_manager.log_fail,
'TEST_NA': output_manager.log_skip,
'WARN': output_manager.log_warn}
test_index = 1
for url in urls:
path_attempt = os.path.abspath(url)
if os.path.exists(path_attempt):
test_class = DropinTest
test_instance = test_class(path=path_attempt, base_logdir=debugdir)
else:
test_module_dir = os.path.join(test_dir, url)
f, p, d = imp.find_module(url, [test_module_dir])
test_module = imp.load_module(url, f, p, d)
f.close()
test_class = getattr(test_module, url)
test_instance = test_class(name=url, base_logdir=debugdir)
sysinfo_logger = sysinfo.SysInfo(basedir=test_instance.sysinfodir)
test_instance.start_logging()
test_instance.setup()
sysinfo_logger.start_job_hook()
test_instance.run()
test_instance.cleanup()
test_instance.report()
test_instance.stop_logging()
output_func = output_mapping[test_instance.status]
label = "(%s/%s) %s:" % (test_index, total_tests,
test_instance.tagged_name)
output_func(label, test_instance.time_elapsed)
test_index += 1
output_manager.stop_file_logging()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册