diff options
| -rwxr-xr-x | scripts/oe-selftest | 108 |
1 files changed, 44 insertions, 64 deletions
diff --git a/scripts/oe-selftest b/scripts/oe-selftest index de98a6cb0d..4c92f6da62 100755 --- a/scripts/oe-selftest +++ b/scripts/oe-selftest | |||
| @@ -243,93 +243,73 @@ def get_all_tests(): | |||
| 243 | testlist += get_tests_from_module(tmod) | 243 | testlist += get_tests_from_module(tmod) |
| 244 | return testlist | 244 | return testlist |
| 245 | 245 | ||
| 246 | |||
| 247 | def create_testsuite_by(criteria, keyword): | ||
| 248 | # Create a testsuite based on 'keyword' | ||
| 249 | # criteria: name, class, module, id, tag | ||
| 250 | # keyword: a list of tests, classes, modules, ids, tags | ||
| 251 | # NOTE: globing would be nice? | ||
| 252 | |||
| 253 | ts = set() | ||
| 254 | all_tests = get_all_tests() | ||
| 255 | |||
| 256 | if criteria == 'name': | ||
| 257 | for tc in all_tests: | ||
| 258 | if tc.tcname in keyword: | ||
| 259 | ts.add(tc.fullpath) | ||
| 260 | |||
| 261 | elif criteria == 'class': | ||
| 262 | for tc in all_tests: | ||
| 263 | if tc.tcclass in keyword: | ||
| 264 | ts.add(tc.fullpath) | ||
| 265 | |||
| 266 | elif criteria == 'module': | ||
| 267 | for tc in all_tests: | ||
| 268 | if tc.tcmodule in keyword: | ||
| 269 | ts.add(tc.fullpath) | ||
| 270 | elif criteria == 'id': | ||
| 271 | for tc in all_tests: | ||
| 272 | if str(tc.tcid) in keyword: | ||
| 273 | ts.add(tc.fullpath) | ||
| 274 | elif criteria == 'tag': | ||
| 275 | for tc in all_tests: | ||
| 276 | # tc can have multiple tags (as list or tuple) otherwise as str | ||
| 277 | if isinstance(tc.tctag, (list, tuple)): | ||
| 278 | for tag in tc.tctag: | ||
| 279 | if str(tag) in keyword: | ||
| 280 | ts.add(tc.fullpath) | ||
| 281 | elif tc.tctag in keyword: | ||
| 282 | ts.add(tc.fullpath) | ||
| 283 | |||
| 284 | return sorted(list(ts)) | ||
| 285 | |||
| 286 | |||
| 287 | def get_testsuite_by(criteria, keyword): | 246 | def get_testsuite_by(criteria, keyword): |
| 288 | # Get a testsuite based on 'keyword' | 247 | # Get a testsuite based on 'keyword' |
| 289 | # criteria: name, class, module, id, tag | 248 | # criteria: name, class, module, id, tag |
| 290 | # keyword: a list of tests, classes, modules, ids, tags | 249 | # keyword: a list of tests, classes, modules, ids, tags |
| 291 | # NOTE: globing would be nice? | 250 | |
| 292 | ts = set() | 251 | import re |
| 252 | import fnmatch | ||
| 253 | |||
| 254 | ts = [] | ||
| 293 | all_tests = get_all_tests() | 255 | all_tests = get_all_tests() |
| 294 | 256 | ||
| 257 | def get_matches(values): | ||
| 258 | # Get a items and return the ones that match with keyword(s) | ||
| 259 | # values: the list of items (names, modules, classes...) | ||
| 260 | result = [] | ||
| 261 | remaining = values[:] | ||
| 262 | for key in keyword: | ||
| 263 | if key in remaining: | ||
| 264 | # Regular matching of exact item | ||
| 265 | result.append(key) | ||
| 266 | remaining.remove(key) | ||
| 267 | else: | ||
| 268 | # Wildcard matching | ||
| 269 | pattern = re.compile(fnmatch.translate(r"%s" % key)) | ||
| 270 | added = [ x for x in remaining if pattern.match(x) ] | ||
| 271 | result.extend(added) | ||
| 272 | remaining = [ x for x in remaining if not x in added ] | ||
| 273 | |||
| 274 | return result | ||
| 275 | |||
| 295 | if criteria == 'name': | 276 | if criteria == 'name': |
| 296 | for tc in all_tests: | 277 | names = get_matches([ tc.tcname for tc in all_tests ]) |
| 297 | if tc.tcname in keyword: | 278 | ts = [ tc for tc in all_tests if tc.tcname in names ] |
| 298 | ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule)) | ||
| 299 | 279 | ||
| 300 | elif criteria == 'class': | 280 | elif criteria == 'class': |
| 301 | for tc in all_tests: | 281 | classes = get_matches([ tc.tcclass for tc in all_tests ]) |
| 302 | if tc.tcclass in keyword: | 282 | ts = [ tc for tc in all_tests if tc.tcclass in classes ] |
| 303 | ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule)) | ||
| 304 | 283 | ||
| 305 | elif criteria == 'module': | 284 | elif criteria == 'module': |
| 306 | for tc in all_tests: | 285 | modules = get_matches([ tc.tcmodule for tc in all_tests ]) |
| 307 | if tc.tcmodule in keyword: | 286 | ts = [ tc for tc in all_tests if tc.tcmodule in modules ] |
| 308 | ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule)) | 287 | |
| 309 | elif criteria == 'id': | 288 | elif criteria == 'id': |
| 310 | for tc in all_tests: | 289 | ids = get_matches([ str(tc.tcid) for tc in all_tests ]) |
| 311 | if str(tc.tcid) in keyword: | 290 | ts = [ tc for tc in all_tests if str(tc.tcid) in ids ] |
| 312 | ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule)) | 291 | |
| 313 | elif criteria == 'tag': | 292 | elif criteria == 'tag': |
| 293 | values = set() | ||
| 314 | for tc in all_tests: | 294 | for tc in all_tests: |
| 315 | # tc can have multiple tags (as list or tuple) otherwise as str | 295 | # tc can have multiple tags (as list or tuple) otherwise as str |
| 316 | if isinstance(tc.tctag, (list, tuple)): | 296 | if isinstance(tc.tctag, (list, tuple)): |
| 317 | for tag in tc.tctag: | 297 | values |= { str(tag) for tag in tc.tctag } |
| 318 | if str(tag) in keyword: | 298 | else: |
| 319 | ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule)) | 299 | values.add(str(tc.tctag)) |
| 320 | elif str(tc.tctag) in keyword: | 300 | |
| 321 | ts.add((tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule)) | 301 | tags = get_matches(list(values)) |
| 302 | ts = [ tc for tc in all_tests if str(tc.tctag) in tags ] | ||
| 322 | 303 | ||
| 323 | return sorted(list(ts)) | 304 | return ts |
| 324 | 305 | ||
| 325 | 306 | ||
| 326 | def list_testsuite_by(criteria, keyword): | 307 | def list_testsuite_by(criteria, keyword): |
| 327 | # Get a testsuite based on 'keyword' | 308 | # Get a testsuite based on 'keyword' |
| 328 | # criteria: name, class, module, id, tag | 309 | # criteria: name, class, module, id, tag |
| 329 | # keyword: a list of tests, classes, modules, ids, tags | 310 | # keyword: a list of tests, classes, modules, ids, tags |
| 330 | # NOTE: globing would be nice? | ||
| 331 | 311 | ||
| 332 | ts = get_testsuite_by(criteria, keyword) | 312 | ts = sorted([ (tc.tcid, tc.tctag, tc.tcname, tc.tcclass, tc.tcmodule) for tc in get_testsuite_by(criteria, keyword) ]) |
| 333 | 313 | ||
| 334 | print '%-4s\t%-20s\t%-60s\t%-25s\t%-20s' % ('id', 'tag', 'name', 'class', 'module') | 314 | print '%-4s\t%-20s\t%-60s\t%-25s\t%-20s' % ('id', 'tag', 'name', 'class', 'module') |
| 335 | print '_' * 150 | 315 | print '_' * 150 |
| @@ -459,7 +439,7 @@ def main(): | |||
| 459 | else: | 439 | else: |
| 460 | criteria = args.run_tests_by[0] | 440 | criteria = args.run_tests_by[0] |
| 461 | keyword = args.run_tests_by[1:] | 441 | keyword = args.run_tests_by[1:] |
| 462 | ts = create_testsuite_by(criteria, keyword) | 442 | ts = sorted([ tc.fullpath for tc in get_testsuite_by(criteria, keyword) ]) |
| 463 | 443 | ||
| 464 | if args.list_tests_by and len(args.list_tests_by) >= 2: | 444 | if args.list_tests_by and len(args.list_tests_by) >= 2: |
| 465 | valid_options = ['name', 'class', 'module', 'id', 'tag'] | 445 | valid_options = ['name', 'class', 'module', 'id', 'tag'] |
