mirror of
https://git.yoctoproject.org/poky
synced 2026-01-29 21:08:42 +01:00
oeqa/core/context: Add support of OETestContextExecutor
The OETestContextExecutor class supports to use oe-test for run core test component also is a base class for the other test components (runtime, sdk, selftest). Te principal functionality is to support cmdline parsing and execution of OETestContext, the test components could extend the common options to provide specific ones. The common options between test components are test data file, output log and test cases path's to scan. Also it initializes the logger to be passed to the whole OEQA framework. [YOCTO #10230] (From OE-Core rev: 039deafa5f2c8fab31b8373b39f8bc219377b893) Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com> Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
90f4325dd5
commit
94cb20f20d
@@ -146,3 +146,88 @@ class OETestContext(object):
|
||||
else:
|
||||
self.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(),
|
||||
oeid, 'PASSED'))
|
||||
|
||||
class OETestContextExecutor(object):
|
||||
_context_class = OETestContext
|
||||
|
||||
name = 'core'
|
||||
help = 'core test component example'
|
||||
description = 'executes core test suite example'
|
||||
|
||||
default_cases = [os.path.join(os.path.abspath(os.path.dirname(__file__)),
|
||||
'cases/example')]
|
||||
default_test_data = os.path.join(default_cases[0], 'data.json')
|
||||
|
||||
def register_commands(self, logger, subparsers):
|
||||
self.parser = subparsers.add_parser(self.name, help=self.help,
|
||||
description=self.description, group='components')
|
||||
|
||||
self.default_output_log = '%s-results-%s.log' % (self.name,
|
||||
time.strftime("%Y%m%d%H%M%S"))
|
||||
self.parser.add_argument('--output-log', action='store',
|
||||
default=self.default_output_log,
|
||||
help="results output log, default: %s" % self.default_output_log)
|
||||
|
||||
if self.default_test_data:
|
||||
self.parser.add_argument('--test-data-file', action='store',
|
||||
default=self.default_test_data,
|
||||
help="data file to load, default: %s" % self.default_test_data)
|
||||
else:
|
||||
self.parser.add_argument('--test-data-file', action='store',
|
||||
help="data file to load")
|
||||
|
||||
if self.default_cases:
|
||||
self.parser.add_argument('CASES_PATHS', action='store',
|
||||
default=self.default_cases, nargs='*',
|
||||
help="paths to directories with test cases, default: %s"\
|
||||
% self.default_cases)
|
||||
else:
|
||||
self.parser.add_argument('CASES_PATHS', action='store',
|
||||
nargs='+', help="paths to directories with test cases")
|
||||
|
||||
self.parser.set_defaults(func=self.run)
|
||||
|
||||
def _setup_logger(self, logger, args):
|
||||
formatter = logging.Formatter('%(asctime)s - ' + self.name + \
|
||||
' - %(levelname)s - %(message)s')
|
||||
sh = logger.handlers[0]
|
||||
sh.setFormatter(formatter)
|
||||
fh = logging.FileHandler(args.output_log)
|
||||
fh.setFormatter(formatter)
|
||||
logger.addHandler(fh)
|
||||
|
||||
return logger
|
||||
|
||||
def _process_args(self, logger, args):
|
||||
self.tc_kwargs = {}
|
||||
self.tc_kwargs['init'] = {}
|
||||
self.tc_kwargs['load'] = {}
|
||||
self.tc_kwargs['run'] = {}
|
||||
|
||||
self.tc_kwargs['init']['logger'] = self._setup_logger(logger, args)
|
||||
if args.test_data_file:
|
||||
self.tc_kwargs['init']['td'] = json.load(
|
||||
open(args.test_data_file, "r"))
|
||||
else:
|
||||
self.tc_kwargs['init']['td'] = {}
|
||||
|
||||
self.module_paths = args.CASES_PATHS
|
||||
|
||||
def run(self, logger, args):
|
||||
self._process_args(logger, args)
|
||||
|
||||
self.tc = self._context_class(**self.tc_kwargs['init'])
|
||||
self.tc.loadTests(self.module_paths, **self.tc_kwargs['load'])
|
||||
rc = self.tc.runTests(**self.tc_kwargs['run'])
|
||||
self.tc.logSummary(rc, self.name)
|
||||
self.tc.logDetails()
|
||||
|
||||
output_link = os.path.join(os.path.dirname(args.output_log),
|
||||
"%s-results.log" % self.name)
|
||||
if os.path.exists(output_link):
|
||||
os.remove(output_link)
|
||||
os.symlink(args.output_log, output_link)
|
||||
|
||||
return rc
|
||||
|
||||
_executor_class = OETestContextExecutor
|
||||
|
||||
Reference in New Issue
Block a user