OLD | NEW |
(Empty) | |
| 1 # Copyright 2017 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 import os |
| 6 import re |
| 7 import sys |
| 8 import time |
| 9 import unittest |
| 10 |
| 11 import common |
| 12 |
| 13 |
| 14 combinations = [ |
| 15 # One object for each set of tests to run with the given variations. |
| 16 { |
| 17 'label': 'dummy example', |
| 18 'tests': [ |
| 19 # Of the form <file_name>.<class_name>.<method_name> |
| 20 # Also accepts wildcard (*) as matching anything. |
| 21 "lite_page.LitePage.testLitePage", |
| 22 "lite_page.LitePage.testLitePageFallback", |
| 23 "quic*" |
| 24 ], |
| 25 'variations': [ |
| 26 "DataReductionProxyUseQuic/Enabled", |
| 27 "DataCompressionProxyLoFi/Enabled_Preview", |
| 28 "DataCompressionProxyLitePageFallback/Enabled" |
| 29 ], |
| 30 'variations-params': [ |
| 31 "DataCompressionProxyLoFi.Enabled_Preview:effective_connection_type/4G" |
| 32 ] |
| 33 } |
| 34 ] |
| 35 |
| 36 |
| 37 def GetAllTestsFromRegexList(test_list, test_suite_iter): |
| 38 """A helper function to make a test suite from tests matching the given list. |
| 39 |
| 40 Args: |
| 41 test_list: a string list of all tests to run, allowing for simple regex |
| 42 test_suite_iter: An iterator of all test suites to search |
| 43 Returns: |
| 44 a test suite with all the tests specified by the test_list |
| 45 """ |
| 46 id_to_test_map = {} |
| 47 for test_suite in test_suite_iter: |
| 48 for test_case in test_suite: |
| 49 for test_method in test_case: |
| 50 id_to_test_map[test_method.id()] = test_method |
| 51 my_test_suite = unittest.TestSuite() |
| 52 for test_spec in test_list: |
| 53 regex = re.compile('^' + test_spec.replace('.', '\\.').replace('*', '.*') |
| 54 + '$') |
| 55 for test_id in sorted(id_to_test_map): |
| 56 if regex.match(test_id): |
| 57 my_test_suite.addTest(id_to_test_map[test_id]) |
| 58 return my_test_suite |
| 59 |
| 60 def ParseFlagsWithExtraBrowserArgs(extra_args): |
| 61 """Generates a function to override common.ParseFlags. |
| 62 |
| 63 The returned function will honor everything in the original ParseFlags(), but |
| 64 adds on additional browser_args. |
| 65 |
| 66 Args: |
| 67 extra_args: The extra browser agruments to add. |
| 68 Returns: |
| 69 A function to override common.ParseFlags with additional browser_args. |
| 70 """ |
| 71 original_flags = common.ParseFlags() |
| 72 def AddExtraBrowserArgs(): |
| 73 original_flags.browser_args = ((original_flags.browser_args if |
| 74 original_flags.browser_args else '') + ' ' + extra_args) |
| 75 return original_flags |
| 76 return AddExtraBrowserArgs |
| 77 |
| 78 def main(): |
| 79 """Runs each set of tests against its set of variations. |
| 80 |
| 81 For each test combination, the above variation specifications will be used to |
| 82 setup the browser arguments for each test given above that will be run. |
| 83 """ |
| 84 flags = common.ParseFlags() |
| 85 for variation_test in combinations: |
| 86 # Set browser arguments to use the given variations. |
| 87 extra_args = '--force-fieldtrials=' + '/'.join(variation_test['variations']) |
| 88 extra_args += ' --force-fieldtrial-params=' + ','.join( |
| 89 variation_test['variations-params']) |
| 90 common.ParseFlags = ParseFlagsWithExtraBrowserArgs(extra_args) |
| 91 # Run the given tests. |
| 92 loader = unittest.TestLoader() |
| 93 test_suite_iter = loader.discover(os.path.dirname(__file__), pattern='*.py') |
| 94 my_test_suite = GetAllTestsFromRegexList(variation_test['tests'], |
| 95 test_suite_iter) |
| 96 testRunner = unittest.runner.TextTestRunner(verbosity=2, |
| 97 failfast=flags.failfast, buffer=(not flags.disable_buffer)) |
| 98 testRunner.run(my_test_suite) |
| 99 |
| 100 if __name__ == '__main__': |
| 101 main() |
OLD | NEW |