OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import Queue | 5 import Queue |
6 import glob | 6 import glob |
7 import multiprocessing | 7 import multiprocessing |
8 import re | 8 import re |
9 import signal | 9 import signal |
10 import traceback | 10 import traceback |
11 | 11 |
12 from .type_definitions import ( | 12 from .type_definitions import ( |
13 Test, UnknownError, TestError, Result, ResultStageAbort) | 13 Test, UnknownError, TestError, NoMatchingTestsError, |
| 14 Result, ResultStageAbort) |
14 | 15 |
15 | 16 |
16 def gen_loop_process(gen, test_queue, result_queue, opts, kill_switch, | 17 def gen_loop_process(gen, test_queue, result_queue, opts, kill_switch, |
17 cover_ctx): | 18 cover_ctx): |
18 """Generate `Test`'s from |gen|, and feed them into |test_queue|. | 19 """Generate `Test`'s from |gen|, and feed them into |test_queue|. |
19 | 20 |
20 Non-Test instances will be translated into `UnknownError` objects. | 21 Non-Test instances will be translated into `UnknownError` objects. |
21 | 22 |
22 On completion, feed |opts.jobs| None objects into |test_queue|. | 23 On completion, feed |opts.jobs| None objects into |test_queue|. |
23 | 24 |
24 @param gen: generator yielding Test() instances. | 25 @param gen: generator yielding Test() instances. |
25 @type test_queue: multiprocessing.Queue() | 26 @type test_queue: multiprocessing.Queue() |
26 @type result_queue: multiprocessing.Queue() | 27 @type result_queue: multiprocessing.Queue() |
27 @type opts: argparse.Namespace | 28 @type opts: argparse.Namespace |
28 @type kill_switch: multiprocessing.Event() | 29 @type kill_switch: multiprocessing.Event() |
29 @type cover_ctx: cover.CoverageContext().create_subprocess_context() | 30 @type cover_ctx: cover.CoverageContext().create_subprocess_context() |
30 """ | 31 """ |
| 32 # Implicitly append '*'' to globs that don't specify it. |
| 33 globs = ['%s%s' % (g, '*' if '*' not in g else '') for g in opts.test_glob] |
| 34 |
31 matcher = re.compile( | 35 matcher = re.compile( |
32 '^%s$' % '|'.join('(?:%s)' % glob.fnmatch.translate(g) | 36 '^%s$' % '|'.join('(?:%s)' % glob.fnmatch.translate(g) |
33 for g in opts.test_glob if g[0] != '-')) | 37 for g in globs if g[0] != '-')) |
34 if matcher.pattern == '^$': | 38 if matcher.pattern == '^$': |
35 matcher = re.compile('^.*$') | 39 matcher = re.compile('^.*$') |
36 | 40 |
37 neg_matcher = re.compile( | 41 neg_matcher = re.compile( |
38 '^%s$' % '|'.join('(?:%s)' % glob.fnmatch.translate(g[1:]) | 42 '^%s$' % '|'.join('(?:%s)' % glob.fnmatch.translate(g[1:]) |
39 for g in opts.test_glob if g[0] == '-')) | 43 for g in globs if g[0] == '-')) |
40 | 44 |
41 def generate_tests(): | 45 def generate_tests(): |
42 paths_seen = set() | 46 paths_seen = set() |
| 47 seen_tests = False |
43 try: | 48 try: |
44 for test in gen(): | 49 for test in gen(): |
45 if kill_switch.is_set(): | 50 if kill_switch.is_set(): |
46 break | 51 break |
47 | 52 |
48 if not isinstance(test, Test): | 53 if not isinstance(test, Test): |
49 result_queue.put_nowait( | 54 result_queue.put_nowait( |
50 UnknownError( | 55 UnknownError( |
51 'Got non-Test isinstance from generator: %r' % test)) | 56 'Got non-Test isinstance from generator: %r' % test)) |
52 continue | 57 continue |
53 | 58 |
54 test_path = test.expect_path() | 59 test_path = test.expect_path() |
55 if test_path in paths_seen: | 60 if test_path in paths_seen: |
56 result_queue.put_nowait( | 61 result_queue.put_nowait( |
57 TestError(test, 'Duplicate expectation path!')) | 62 TestError(test, 'Duplicate expectation path!')) |
58 else: | 63 else: |
59 paths_seen.add(test_path) | 64 paths_seen.add(test_path) |
60 if not neg_matcher.match(test.name) and matcher.match(test.name): | 65 if not neg_matcher.match(test.name) and matcher.match(test.name): |
| 66 seen_tests = True |
61 yield test | 67 yield test |
| 68 if not seen_tests: |
| 69 result_queue.put_nowait(NoMatchingTestsError()) |
62 except KeyboardInterrupt: | 70 except KeyboardInterrupt: |
63 pass | 71 pass |
64 finally: | 72 finally: |
65 for _ in xrange(opts.jobs): | 73 for _ in xrange(opts.jobs): |
66 test_queue.put_nowait(None) | 74 test_queue.put_nowait(None) |
67 | 75 |
68 | 76 |
69 next_stage = (result_queue if opts.handler.SKIP_RUNLOOP else test_queue) | 77 next_stage = (result_queue if opts.handler.SKIP_RUNLOOP else test_queue) |
70 with cover_ctx: | 78 with cover_ctx: |
71 opts.handler.gen_stage_loop(opts, generate_tests(), next_stage.put_nowait, | 79 opts.handler.gen_stage_loop(opts, generate_tests(), next_stage.put_nowait, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 except ResultStageAbort: | 181 except ResultStageAbort: |
174 pass | 182 pass |
175 | 183 |
176 for p in procs: | 184 for p in procs: |
177 p.join() | 185 p.join() |
178 | 186 |
179 if not kill_switch.is_set() and not result_queue.empty(): | 187 if not kill_switch.is_set() and not result_queue.empty(): |
180 error = True | 188 error = True |
181 | 189 |
182 return error, kill_switch.is_set() | 190 return error, kill_switch.is_set() |
OLD | NEW |