diff options
author | Aníbal Limón <anibal.limon@linux.intel.com> | 2016-10-31 14:42:30 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-01-23 12:05:18 +0000 |
commit | 90f4325dd5f24fa6e79764286a70e87bfa37a673 (patch) | |
tree | 3d3fed9bd5e7e56e37319f6a8b791839a51c86a2 /scripts/oe-test | |
parent | 7bf63b28f1dee0b582769879c1727c5a1171c2b1 (diff) | |
download | poky-90f4325dd5f24fa6e79764286a70e87bfa37a673.tar.gz |
scripts/oe-test: Add new oe-test script
The new oe-test script will be use to run test components with
one single script.
The oe-test script search for test components inside meta/lib/oeqa,
the test components needs to implement OETestContextExecutor inside
context module in order to be supported by oe-test.
[YOCTO #10230]
(From OE-Core rev: 04b69cff3957731fa1ed2f7d23f2f616978ed0b7)
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>
Diffstat (limited to 'scripts/oe-test')
-rwxr-xr-x | scripts/oe-test | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/scripts/oe-test b/scripts/oe-test new file mode 100755 index 0000000000..5731dff485 --- /dev/null +++ b/scripts/oe-test | |||
@@ -0,0 +1,99 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | |||
3 | # OpenEmbedded test tool | ||
4 | # | ||
5 | # Copyright (C) 2016 Intel Corporation | ||
6 | # Released under the MIT license (see COPYING.MIT) | ||
7 | |||
8 | import os | ||
9 | import sys | ||
10 | import argparse | ||
11 | import importlib | ||
12 | import logging | ||
13 | |||
14 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | ||
15 | lib_path = scripts_path + '/lib' | ||
16 | sys.path = sys.path + [lib_path] | ||
17 | import argparse_oe | ||
18 | import scriptutils | ||
19 | import scriptpath | ||
20 | scriptpath.add_oe_lib_path() | ||
21 | |||
22 | from oeqa.core.context import OETestContextExecutor | ||
23 | |||
24 | logger = scriptutils.logger_create('oe-test') | ||
25 | |||
26 | def _load_test_components(logger): | ||
27 | components = {} | ||
28 | |||
29 | for path in sys.path: | ||
30 | base_dir = os.path.join(path, 'oeqa') | ||
31 | if os.path.exists(base_dir) and os.path.isdir(base_dir): | ||
32 | for file in os.listdir(base_dir): | ||
33 | comp_name = file | ||
34 | comp_context = os.path.join(base_dir, file, 'context.py') | ||
35 | if os.path.exists(comp_context): | ||
36 | comp_plugin = importlib.import_module('oeqa.%s.%s' % \ | ||
37 | (comp_name, 'context')) | ||
38 | try: | ||
39 | if not issubclass(comp_plugin._executor_class, | ||
40 | OETestContextExecutor): | ||
41 | raise TypeError("Component %s in %s, _executor_class "\ | ||
42 | "isn't derived from OETestContextExecutor."\ | ||
43 | % (comp_name, comp_context)) | ||
44 | |||
45 | components[comp_name] = comp_plugin._executor_class() | ||
46 | except AttributeError: | ||
47 | raise AttributeError("Component %s in %s don't have "\ | ||
48 | "_executor_class defined." % (comp_name, comp_context)) | ||
49 | |||
50 | return components | ||
51 | |||
52 | def main(): | ||
53 | parser = argparse_oe.ArgumentParser(description="OpenEmbedded test tool", | ||
54 | add_help=False, | ||
55 | epilog="Use %(prog)s <subcommand> --help to get help on a specific command") | ||
56 | parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true') | ||
57 | parser.add_argument('-q', '--quiet', help='Print only errors', action='store_true') | ||
58 | global_args, unparsed_args = parser.parse_known_args() | ||
59 | |||
60 | # Help is added here rather than via add_help=True, as we don't want it to | ||
61 | # be handled by parse_known_args() | ||
62 | parser.add_argument('-h', '--help', action='help', default=argparse.SUPPRESS, | ||
63 | help='show this help message and exit') | ||
64 | |||
65 | if global_args.debug: | ||
66 | logger.setLevel(logging.DEBUG) | ||
67 | elif global_args.quiet: | ||
68 | logger.setLevel(logging.ERROR) | ||
69 | |||
70 | components = _load_test_components(logger) | ||
71 | |||
72 | subparsers = parser.add_subparsers(dest="subparser_name", title='subcommands', metavar='<subcommand>') | ||
73 | subparsers.add_subparser_group('components', 'Test components') | ||
74 | subparsers.required = True | ||
75 | for comp_name in sorted(components.keys()): | ||
76 | comp = components[comp_name] | ||
77 | comp.register_commands(logger, subparsers) | ||
78 | |||
79 | try: | ||
80 | args = parser.parse_args(unparsed_args, namespace=global_args) | ||
81 | results = args.func(logger, args) | ||
82 | ret = 0 if results.wasSuccessful() else 1 | ||
83 | except SystemExit as err: | ||
84 | if err.code != 0: | ||
85 | raise err | ||
86 | ret = err.code | ||
87 | except argparse_oe.ArgumentUsageError as ae: | ||
88 | parser.error_subcommand(ae.message, ae.subcommand) | ||
89 | |||
90 | return ret | ||
91 | |||
92 | if __name__ == '__main__': | ||
93 | try: | ||
94 | ret = main() | ||
95 | except Exception: | ||
96 | ret = 1 | ||
97 | import traceback | ||
98 | traceback.print_exc() | ||
99 | sys.exit(ret) | ||