Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: tools/chrome_proxy/webdriver/variations_combinations.py

Issue 2909943005: Refactor variations_combinations.py to use testing configs (Closed)
Patch Set: tbansal comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/chrome_proxy/webdriver/common.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2017 The Chromium Authors. All rights reserved. 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 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 io
5 import os 6 import os
6 import re 7 import platform
7 import sys 8 import sys
8 import time 9 import time
9 import unittest 10 import unittest
10 11
11 import common 12 import common
12 13
14 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
15 os.pardir, 'tools', 'variations'))
16 import fieldtrial_util
13 17
14 combinations = [ 18 test_blacklist = [
15 # One object for each set of tests to run with the given variations. 19 # These tests set their own field trials and should be ignored.
16 { 20 'lofi.LoFi.testLoFiSlowConnection',
17 'label': 'dummy example', 21 'lofi.LoFi.testLoFiIfHeavyFastConnection',
18 'tests': [ 22 'quic.Quic.testCheckPageWithQuicProxy',
19 # Of the form <file_name>.<class_name>.<method_name> 23 'quic.Quic.testCheckPageWithQuicProxyTransaction',
20 # Also accepts wildcard (*) as matching anything. 24 'lite_page.LitePage.testLitePageFallback',
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 ] 25 ]
35 26
27 def GetExperimentArgs():
28 """Returns a list of arguments with all tested field trials.
36 29
37 def GetAllTestsFromRegexList(test_list, test_suite_iter): 30 This function is a simple wrapper around the variation team's fieldtrail_util
38 """A helper function to make a test suite from tests matching the given list. 31 script that generates command line arguments to test Chromium field trials.
39 32
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: 33 Returns:
44 a test suite with all the tests specified by the test_list 34 an array of command line arguments to pass to chrome
45 """ 35 """
46 id_to_test_map = {} 36 config_path = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir,
47 for test_suite in test_suite_iter: 37 os.pardir, 'testing', 'variations', 'fieldtrial_testing_config.json')
38 my_platform = ''
39 if common.ParseFlags().android:
40 my_platform = 'android'
41 elif platform.system().lower() == 'linux':
42 my_platform = 'linux'
43 elif platform.system().lower() == 'windows':
44 my_platform = 'win'
45 elif platform.system().lower() == 'darwin':
46 my_platform = 'mac'
47 else:
48 raise Exception('unknown platform!')
49 return fieldtrial_util.GenerateArgs(config_path, my_platform)
50
51 def GenerateTestSuites():
52 """A generator function that yields non-blacklisted tests to run.
53
54 This function yeilds test suites each with a single test case whose id is not
55 blacklisted in the array at the top of this file.
56
57 Yields:
58 non-blacklisted test suites to run
59 """
60 loader = unittest.TestLoader()
61 for test_suite in loader.discover(os.path.dirname(__file__), pattern='*.py'):
48 for test_case in test_suite: 62 for test_case in test_suite:
49 for test_method in test_case: 63 for test_method in test_case:
50 id_to_test_map[test_method.id()] = test_method 64 if test_method.id() not in test_blacklist:
51 my_test_suite = unittest.TestSuite() 65 ts = unittest.TestSuite()
52 for test_spec in test_list: 66 ts.addTest(test_method)
53 regex = re.compile('^' + test_spec.replace('.', '\\.').replace('*', '.*') 67 yield (ts, test_method.id())
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 68
60 def ParseFlagsWithExtraBrowserArgs(extra_args): 69 def ParseFlagsWithExtraBrowserArgs(extra_args):
61 """Generates a function to override common.ParseFlags. 70 """Generates a function to override common.ParseFlags.
62 71
63 The returned function will honor everything in the original ParseFlags(), but 72 The returned function will honor everything in the original ParseFlags(), but
64 adds on additional browser_args. 73 adds on additional browser_args.
65 74
66 Args: 75 Args:
67 extra_args: The extra browser agruments to add. 76 extra_args: The extra browser agruments to add.
68 Returns: 77 Returns:
69 A function to override common.ParseFlags with additional browser_args. 78 A function to override common.ParseFlags with additional browser_args.
70 """ 79 """
71 original_flags = common.ParseFlags() 80 original_flags = common.ParseFlags()
72 def AddExtraBrowserArgs(): 81 def AddExtraBrowserArgs():
73 original_flags.browser_args = ((original_flags.browser_args if 82 original_flags.browser_args = ((original_flags.browser_args if
74 original_flags.browser_args else '') + ' ' + extra_args) 83 original_flags.browser_args else '') + ' ' + extra_args)
75 return original_flags 84 return original_flags
76 return AddExtraBrowserArgs 85 return AddExtraBrowserArgs
77 86
78 def main(): 87 def main():
79 """Runs each set of tests against its set of variations. 88 """Runs all non-blacklisted tests against Chromium field trials.
80 89
81 For each test combination, the above variation specifications will be used to 90 This script run all chrome proxy integration tests that haven't been
82 setup the browser arguments for each test given above that will be run. 91 blacklisted against the field trial testing configuration used by Chromium
92 perf bots.
83 """ 93 """
84 flags = common.ParseFlags() 94 flags = common.ParseFlags()
85 for variation_test in combinations: 95 experiment_args = ' '.join(GetExperimentArgs())
86 # Set browser arguments to use the given variations. 96 common.ParseFlags = ParseFlagsWithExtraBrowserArgs(experiment_args)
87 extra_args = '--force-fieldtrials=' + '/'.join(variation_test['variations']) 97 # Each test is wrapped in its own test suite so results can be evaluated
88 extra_args += ' --force-fieldtrial-params=' + ','.join( 98 # individually.
89 variation_test['variations-params']) 99 for test_suite, test_id in GenerateTestSuites():
90 common.ParseFlags = ParseFlagsWithExtraBrowserArgs(extra_args) 100 buf = io.BytesIO()
91 # Run the given tests. 101 sys.stdout.write('%s... ' % test_id)
92 loader = unittest.TestLoader() 102 sys.stdout.flush()
93 test_suite_iter = loader.discover(os.path.dirname(__file__), pattern='*.py') 103 testRunner = unittest.runner.TextTestRunner(stream=buf, verbosity=2,
94 my_test_suite = GetAllTestsFromRegexList(variation_test['tests'], 104 buffer=(not flags.disable_buffer))
95 test_suite_iter) 105 result = testRunner.run(test_suite)
96 testRunner = unittest.runner.TextTestRunner(verbosity=2, 106 if result.wasSuccessful():
97 failfast=flags.failfast, buffer=(not flags.disable_buffer)) 107 print 'ok'
98 testRunner.run(my_test_suite) 108 else:
109 print 'failed'
110 print buf.getvalue()
111 print 'To repeat this test, run: '
112 print "%s %s %s --test_filter=%s --browser_args='%s'" % (sys.executable,
113 os.path.join(os.path.dirname(__file__), 'run_all_tests.py'),
114 ' '.join(sys.argv[1:]), '.'.join(test_id.split('.')[1:]),
115 experiment_args)
116 if flags.failfast:
117 return
99 118
100 if __name__ == '__main__': 119 if __name__ == '__main__':
101 main() 120 main()
OLDNEW
« no previous file with comments | « tools/chrome_proxy/webdriver/common.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698