diff options
| -rw-r--r-- | meta/lib/oeqa/core/context.py | 1 | ||||
| -rw-r--r-- | meta/lib/oeqa/utils/__init__.py | 37 | ||||
| -rwxr-xr-x | scripts/oe-test | 31 |
3 files changed, 39 insertions, 30 deletions
diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py index 5f399fdfcc..0dbf5c353e 100644 --- a/meta/lib/oeqa/core/context.py +++ b/meta/lib/oeqa/core/context.py | |||
| @@ -65,6 +65,7 @@ class OETestContext(object): | |||
| 65 | 65 | ||
| 66 | class OETestContextExecutor(object): | 66 | class OETestContextExecutor(object): |
| 67 | _context_class = OETestContext | 67 | _context_class = OETestContext |
| 68 | _script_executor = 'oe-test' | ||
| 68 | 69 | ||
| 69 | name = 'core' | 70 | name = 'core' |
| 70 | help = 'core test component example' | 71 | help = 'core test component example' |
diff --git a/meta/lib/oeqa/utils/__init__.py b/meta/lib/oeqa/utils/__init__.py index 485de031a9..d38a323013 100644 --- a/meta/lib/oeqa/utils/__init__.py +++ b/meta/lib/oeqa/utils/__init__.py | |||
| @@ -2,7 +2,6 @@ | |||
| 2 | from pkgutil import extend_path | 2 | from pkgutil import extend_path |
| 3 | __path__ = extend_path(__path__, __name__) | 3 | __path__ = extend_path(__path__, __name__) |
| 4 | 4 | ||
| 5 | |||
| 6 | # Borrowed from CalledProcessError | 5 | # Borrowed from CalledProcessError |
| 7 | 6 | ||
| 8 | class CommandError(Exception): | 7 | class CommandError(Exception): |
| @@ -66,3 +65,39 @@ def make_logger_bitbake_compatible(logger): | |||
| 66 | logger.info = _bitbake_log_info | 65 | logger.info = _bitbake_log_info |
| 67 | 66 | ||
| 68 | return logger | 67 | return logger |
| 68 | |||
| 69 | def load_test_components(logger, executor): | ||
| 70 | import sys | ||
| 71 | import os | ||
| 72 | import importlib | ||
| 73 | |||
| 74 | from oeqa.core.context import OETestContextExecutor | ||
| 75 | |||
| 76 | components = {} | ||
| 77 | |||
| 78 | for path in sys.path: | ||
| 79 | base_dir = os.path.join(path, 'oeqa') | ||
| 80 | if os.path.exists(base_dir) and os.path.isdir(base_dir): | ||
| 81 | for file in os.listdir(base_dir): | ||
| 82 | comp_name = file | ||
| 83 | comp_context = os.path.join(base_dir, file, 'context.py') | ||
| 84 | if os.path.exists(comp_context): | ||
| 85 | comp_plugin = importlib.import_module('oeqa.%s.%s' % \ | ||
| 86 | (comp_name, 'context')) | ||
| 87 | try: | ||
| 88 | if not issubclass(comp_plugin._executor_class, | ||
| 89 | OETestContextExecutor): | ||
| 90 | raise TypeError("Component %s in %s, _executor_class "\ | ||
| 91 | "isn't derived from OETestContextExecutor."\ | ||
| 92 | % (comp_name, comp_context)) | ||
| 93 | |||
| 94 | if comp_plugin._executor_class._script_executor \ | ||
| 95 | != executor: | ||
| 96 | continue | ||
| 97 | |||
| 98 | components[comp_name] = comp_plugin._executor_class() | ||
| 99 | except AttributeError: | ||
| 100 | raise AttributeError("Component %s in %s don't have "\ | ||
| 101 | "_executor_class defined." % (comp_name, comp_context)) | ||
| 102 | |||
| 103 | return components | ||
diff --git a/scripts/oe-test b/scripts/oe-test index f90d85b3da..0a36b78ff7 100755 --- a/scripts/oe-test +++ b/scripts/oe-test | |||
| @@ -8,7 +8,6 @@ | |||
| 8 | import os | 8 | import os |
| 9 | import sys | 9 | import sys |
| 10 | import argparse | 10 | import argparse |
| 11 | import importlib | ||
| 12 | import logging | 11 | import logging |
| 13 | 12 | ||
| 14 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | 13 | scripts_path = os.path.dirname(os.path.realpath(__file__)) |
| @@ -25,37 +24,11 @@ try: | |||
| 25 | except ImportError: | 24 | except ImportError: |
| 26 | pass | 25 | pass |
| 27 | 26 | ||
| 28 | from oeqa.core.context import OETestContextExecutor | 27 | from oeqa.utils import load_test_components |
| 29 | from oeqa.core.exception import OEQAPreRun | 28 | from oeqa.core.exception import OEQAPreRun |
| 30 | 29 | ||
| 31 | logger = scriptutils.logger_create('oe-test') | 30 | logger = scriptutils.logger_create('oe-test') |
| 32 | 31 | ||
| 33 | def _load_test_components(logger): | ||
| 34 | components = {} | ||
| 35 | |||
| 36 | for path in sys.path: | ||
| 37 | base_dir = os.path.join(path, 'oeqa') | ||
| 38 | if os.path.exists(base_dir) and os.path.isdir(base_dir): | ||
| 39 | for file in os.listdir(base_dir): | ||
| 40 | comp_name = file | ||
| 41 | comp_context = os.path.join(base_dir, file, 'context.py') | ||
| 42 | if os.path.exists(comp_context): | ||
| 43 | comp_plugin = importlib.import_module('oeqa.%s.%s' % \ | ||
| 44 | (comp_name, 'context')) | ||
| 45 | try: | ||
| 46 | if not issubclass(comp_plugin._executor_class, | ||
| 47 | OETestContextExecutor): | ||
| 48 | raise TypeError("Component %s in %s, _executor_class "\ | ||
| 49 | "isn't derived from OETestContextExecutor."\ | ||
| 50 | % (comp_name, comp_context)) | ||
| 51 | |||
| 52 | components[comp_name] = comp_plugin._executor_class() | ||
| 53 | except AttributeError: | ||
| 54 | raise AttributeError("Component %s in %s don't have "\ | ||
| 55 | "_executor_class defined." % (comp_name, comp_context)) | ||
| 56 | |||
| 57 | return components | ||
| 58 | |||
| 59 | def main(): | 32 | def main(): |
| 60 | parser = argparse_oe.ArgumentParser(description="OpenEmbedded test tool", | 33 | parser = argparse_oe.ArgumentParser(description="OpenEmbedded test tool", |
| 61 | add_help=False, | 34 | add_help=False, |
| @@ -74,7 +47,7 @@ def main(): | |||
| 74 | elif global_args.quiet: | 47 | elif global_args.quiet: |
| 75 | logger.setLevel(logging.ERROR) | 48 | logger.setLevel(logging.ERROR) |
| 76 | 49 | ||
| 77 | components = _load_test_components(logger) | 50 | components = load_test_components(logger, 'oe-test') |
| 78 | 51 | ||
| 79 | subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>') | 52 | subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>') |
| 80 | subparsers.add_subparser_group('components', 'Test components') | 53 | subparsers.add_subparser_group('components', 'Test components') |
