diff options
author | Corneliu Stoicescu <corneliux.stoicescu@intel.com> | 2014-07-17 18:10:43 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-07-19 00:09:00 +0100 |
commit | 03e2fb2532780cdca698027f2db244cf737f7544 (patch) | |
tree | 7423d7c5fef253ccc6fbb96b96465c43739092cf | |
parent | 172c5601d46a13aba209f6bf1cfa99649bdb77b2 (diff) | |
download | poky-03e2fb2532780cdca698027f2db244cf737f7544.tar.gz |
scripts/oe-selftest: add command-line parsing and options
[YOCTO #6453]
(From OE-Core rev: d9291390d56cae9c9d0f5e44d5e7293260dad077)
Signed-off-by: Corneliu Stoicescu <corneliux.stoicescu@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-x | scripts/oe-selftest | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest index 8c4ea92610..2332b224ee 100755 --- a/scripts/oe-selftest +++ b/scripts/oe-selftest | |||
@@ -29,6 +29,7 @@ import os | |||
29 | import sys | 29 | import sys |
30 | import unittest | 30 | import unittest |
31 | import logging | 31 | import logging |
32 | import argparse | ||
32 | 33 | ||
33 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'meta/lib'))) | 34 | sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'meta/lib'))) |
34 | 35 | ||
@@ -58,6 +59,16 @@ def logger_create(): | |||
58 | 59 | ||
59 | log = logger_create() | 60 | log = logger_create() |
60 | 61 | ||
62 | def get_args_parser(): | ||
63 | description = "Script that runs unit tests agains bitbake and other Yocto related tools. The goal is to validate tools functionality and metadata integrity. Refer to https://wiki.yoctoproject.org/wiki/Oe-selftest for more information." | ||
64 | parser = argparse.ArgumentParser(description=description) | ||
65 | group = parser.add_mutually_exclusive_group(required=True) | ||
66 | group.add_argument('--run-tests', required=False, action='store', nargs='*', dest="run_tests", default=None, help='Select what tests to run (modules, classes or test methods). Format should be: <module>.<class>.<test_method>') | ||
67 | group.add_argument('--run-all-tests', required=False, action="store_true", dest="run_all_tests", default=False, help='Run all (unhidden) tests') | ||
68 | group.add_argument('--list-modules', required=False, action="store_true", dest="list_modules", default=False, help='List all available test modules.') | ||
69 | return parser | ||
70 | |||
71 | |||
61 | def preflight_check(): | 72 | def preflight_check(): |
62 | 73 | ||
63 | log.info("Checking that everything is in order before running the tests") | 74 | log.info("Checking that everything is in order before running the tests") |
@@ -108,13 +119,13 @@ def remove_inc_files(): | |||
108 | except OSError as e: | 119 | except OSError as e: |
109 | pass | 120 | pass |
110 | 121 | ||
111 | def get_tests(): | 122 | def get_tests(exclusive_modules=[], include_hidden=False): |
112 | testslist = [] | 123 | testslist = [] |
113 | for x in sys.argv[1:]: | 124 | for x in exclusive_modules: |
114 | testslist.append('oeqa.selftest.' + x) | 125 | testslist.append('oeqa.selftest.' + x) |
115 | if not testslist: | 126 | if not testslist: |
116 | testpath = os.path.abspath(os.path.dirname(oeqa.selftest.__file__)) | 127 | testpath = os.path.abspath(os.path.dirname(oeqa.selftest.__file__)) |
117 | files = sorted([f for f in os.listdir(testpath) if f.endswith('.py') and not f.startswith('_') and f != 'base.py']) | 128 | files = sorted([f for f in os.listdir(testpath) if f.endswith('.py') and not (f.startswith('_') and not include_hidden) and not f.startswith('__') and f != 'base.py']) |
118 | for f in files: | 129 | for f in files: |
119 | module = 'oeqa.selftest.' + f[:-3] | 130 | module = 'oeqa.selftest.' + f[:-3] |
120 | testslist.append(module) | 131 | testslist.append(module) |
@@ -122,32 +133,46 @@ def get_tests(): | |||
122 | return testslist | 133 | return testslist |
123 | 134 | ||
124 | def main(): | 135 | def main(): |
125 | if not preflight_check(): | 136 | parser = get_args_parser() |
126 | return 1 | 137 | args = parser.parse_args() |
127 | 138 | ||
128 | testslist = get_tests() | 139 | if args.list_modules: |
129 | suite = unittest.TestSuite() | 140 | log.info('Listing all available test modules:') |
130 | loader = unittest.TestLoader() | 141 | testslist = get_tests(include_hidden=True) |
131 | loader.sortTestMethodsUsing = None | 142 | for test in testslist: |
132 | runner = unittest.TextTestRunner(verbosity=2) | 143 | module = test.split('.')[-1] |
133 | # we need to do this here, otherwise just loading the tests | 144 | info = '' |
134 | # will take 2 minutes (bitbake -e calls) | 145 | if module.startswith('_'): |
135 | oeSelfTest.testlayer_path = get_test_layer() | 146 | info = ' (hidden)' |
136 | for test in testslist: | 147 | print module + info |
137 | log.info("Loading tests from: %s" % test) | 148 | |
138 | try: | 149 | if args.run_tests or args.run_all_tests: |
139 | suite.addTests(loader.loadTestsFromName(test)) | 150 | if not preflight_check(): |
140 | except AttributeError as e: | 151 | return 1 |
141 | log.error("Failed to import %s" % test) | 152 | |
142 | log.error(e) | 153 | testslist = get_tests(exclusive_modules=(args.run_tests or []), include_hidden=False) |
154 | suite = unittest.TestSuite() | ||
155 | loader = unittest.TestLoader() | ||
156 | loader.sortTestMethodsUsing = None | ||
157 | runner = unittest.TextTestRunner(verbosity=2) | ||
158 | # we need to do this here, otherwise just loading the tests | ||
159 | # will take 2 minutes (bitbake -e calls) | ||
160 | oeSelfTest.testlayer_path = get_test_layer() | ||
161 | for test in testslist: | ||
162 | log.info("Loading tests from: %s" % test) | ||
163 | try: | ||
164 | suite.addTests(loader.loadTestsFromName(test)) | ||
165 | except AttributeError as e: | ||
166 | log.error("Failed to import %s" % test) | ||
167 | log.error(e) | ||
168 | return 1 | ||
169 | add_include() | ||
170 | result = runner.run(suite) | ||
171 | log.info("Finished") | ||
172 | if result.wasSuccessful(): | ||
173 | return 0 | ||
174 | else: | ||
143 | return 1 | 175 | return 1 |
144 | add_include() | ||
145 | result = runner.run(suite) | ||
146 | log.info("Finished") | ||
147 | if result.wasSuccessful(): | ||
148 | return 0 | ||
149 | else: | ||
150 | return 1 | ||
151 | 176 | ||
152 | if __name__ == "__main__": | 177 | if __name__ == "__main__": |
153 | try: | 178 | try: |