OLD | NEW |
| (Empty) |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 """Generate test runner factory and tests for content_browsertests.""" | |
6 | |
7 import logging | |
8 import os | |
9 import sys | |
10 | |
11 from pylib import android_commands | |
12 from pylib import cmd_helper | |
13 from pylib import constants | |
14 from pylib import ports | |
15 from pylib.base import base_test_result | |
16 from pylib.gtest import setup as gtest_setup | |
17 from pylib.gtest import test_runner | |
18 from pylib.utils import report_results | |
19 | |
20 | |
21 def Setup(test_arguments, timeout, cleanup_test_files, tool, build_type, | |
22 push_deps, gtest_filter): | |
23 """Create the test runner factory and tests. | |
24 | |
25 Args: | |
26 test_arguments: Additional arguments to pass to the test binary. | |
27 timeout: Timeout for each test. | |
28 cleanup_test_files: Whether or not to cleanup test files on device. | |
29 tool: Name of the Valgrind tool. | |
30 build_type: 'Release' or 'Debug'. | |
31 push_deps: If True, push all dependencies to the device. | |
32 gtest_filter: filter for tests. | |
33 | |
34 Returns: | |
35 A tuple of (TestRunnerFactory, tests). | |
36 """ | |
37 | |
38 if not ports.ResetTestServerPortAllocation(): | |
39 raise Exception('Failed to reset test server port.') | |
40 | |
41 suite_path = os.path.join(cmd_helper.OutDirectory.get(), build_type, 'apks', | |
42 constants.BROWSERTEST_SUITE_NAME + '.apk') | |
43 | |
44 gtest_setup._GenerateDepsDirUsingIsolate( | |
45 constants.BROWSERTEST_SUITE_NAME, build_type) | |
46 | |
47 # Constructs a new TestRunner with the current options. | |
48 def TestRunnerFactory(device, shard_index): | |
49 return test_runner.TestRunner( | |
50 device, | |
51 suite_path, | |
52 test_arguments, | |
53 timeout, | |
54 cleanup_test_files, | |
55 tool, | |
56 build_type, | |
57 push_deps, | |
58 constants.BROWSERTEST_TEST_PACKAGE_NAME, | |
59 constants.BROWSERTEST_TEST_ACTIVITY_NAME, | |
60 constants.BROWSERTEST_COMMAND_LINE_FILE) | |
61 | |
62 # TODO(gkanwar): This breaks the abstraction of having test_dispatcher.py deal | |
63 # entirely with the devices. Can we do this another way? | |
64 attached_devices = android_commands.GetAttachedDevices() | |
65 | |
66 all_tests = gtest_setup.GetTestsFiltered( | |
67 constants.BROWSERTEST_SUITE_NAME, gtest_filter, TestRunnerFactory, | |
68 attached_devices) | |
69 | |
70 return (TestRunnerFactory, all_tests) | |
71 | |
72 | |
73 def _FilterTests(all_enabled_tests): | |
74 """Filters out tests and fixtures starting with PRE_ and MANUAL_.""" | |
75 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)] | |
76 | |
77 | |
78 def _ShouldRunOnBot(test): | |
79 fixture, case = test.split('.', 1) | |
80 if _StartsWith(fixture, case, 'PRE_'): | |
81 return False | |
82 if _StartsWith(fixture, case, 'MANUAL_'): | |
83 return False | |
84 return True | |
85 | |
86 | |
87 def _StartsWith(a, b, prefix): | |
88 return a.startswith(prefix) or b.startswith(prefix) | |
OLD | NEW |