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

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

Issue 2909943005: Refactor variations_combinations.py to use testing configs (Closed)
Patch Set: 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
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
tbansal1 2017/05/30 23:31:23 May be add: import fieldtrial_util Similar to htt
Robert Ogden 2017/05/30 23:44:35 This is done below, after the sys.path.append. Sho
tbansal1 2017/05/30 23:50:12 Aah, ok. This l-g-t-m.
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'
tbansal1 2017/05/30 23:31:23 add chromeos?
Robert Ogden 2017/05/30 23:44:35 our integration test framework doesn't support Chr
tbansal1 2017/05/30 23:50:12 Acknowledged.
47 return fieldtrial_util.GenerateArgs(config_path, my_platform)
tbansal1 2017/05/30 23:31:23 return an error if the platform is not supported>
Robert Ogden 2017/05/30 23:44:35 Done.
48
49 def GenerateTestSuites():
50 """A generator function that yields non-blacklisted tests to run.
51
52 This function yeilds test suites each with a single test case whose id is not
53 blacklisted in the array at the top of this file.
54
55 Yields:
56 non-blacklisted test suites to run
57 """
58 loader = unittest.TestLoader()
59 for test_suite in loader.discover(os.path.dirname(__file__), pattern='*.py'):
48 for test_case in test_suite: 60 for test_case in test_suite:
49 for test_method in test_case: 61 for test_method in test_case:
50 id_to_test_map[test_method.id()] = test_method 62 if test_method.id() not in test_blacklist:
51 my_test_suite = unittest.TestSuite() 63 ts = unittest.TestSuite()
52 for test_spec in test_list: 64 ts.addTest(test_method)
53 regex = re.compile('^' + test_spec.replace('.', '\\.').replace('*', '.*') 65 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 66
60 def ParseFlagsWithExtraBrowserArgs(extra_args): 67 def ParseFlagsWithExtraBrowserArgs(extra_args):
61 """Generates a function to override common.ParseFlags. 68 """Generates a function to override common.ParseFlags.
62 69
63 The returned function will honor everything in the original ParseFlags(), but 70 The returned function will honor everything in the original ParseFlags(), but
64 adds on additional browser_args. 71 adds on additional browser_args.
65 72
66 Args: 73 Args:
67 extra_args: The extra browser agruments to add. 74 extra_args: The extra browser agruments to add.
68 Returns: 75 Returns:
69 A function to override common.ParseFlags with additional browser_args. 76 A function to override common.ParseFlags with additional browser_args.
70 """ 77 """
71 original_flags = common.ParseFlags() 78 original_flags = common.ParseFlags()
72 def AddExtraBrowserArgs(): 79 def AddExtraBrowserArgs():
73 original_flags.browser_args = ((original_flags.browser_args if 80 original_flags.browser_args = ((original_flags.browser_args if
74 original_flags.browser_args else '') + ' ' + extra_args) 81 original_flags.browser_args else '') + ' ' + extra_args)
75 return original_flags 82 return original_flags
76 return AddExtraBrowserArgs 83 return AddExtraBrowserArgs
77 84
78 def main(): 85 def main():
79 """Runs each set of tests against its set of variations. 86 """Runs all non-blacklisted tests against Chromium field trials.
80 87
81 For each test combination, the above variation specifications will be used to 88 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. 89 blacklisted against the field trial testing configuration used by Chromium
90 perf bots.
83 """ 91 """
84 flags = common.ParseFlags() 92 flags = common.ParseFlags()
85 for variation_test in combinations: 93 experiment_args = ' '.join(GetExperimentArgs())
86 # Set browser arguments to use the given variations. 94 common.ParseFlags = ParseFlagsWithExtraBrowserArgs(experiment_args)
87 extra_args = '--force-fieldtrials=' + '/'.join(variation_test['variations']) 95 # Each test is wrapped in its own test suite so results can be evaluated
88 extra_args += ' --force-fieldtrial-params=' + ','.join( 96 # individually.
89 variation_test['variations-params']) 97 for test_suite, test_id in GenerateTestSuites():
90 common.ParseFlags = ParseFlagsWithExtraBrowserArgs(extra_args) 98 buf = io.BytesIO()
91 # Run the given tests. 99 sys.stdout.write('%s... ' % test_id)
92 loader = unittest.TestLoader() 100 sys.stdout.flush()
93 test_suite_iter = loader.discover(os.path.dirname(__file__), pattern='*.py') 101 testRunner = unittest.runner.TextTestRunner(stream=buf, verbosity=2,
94 my_test_suite = GetAllTestsFromRegexList(variation_test['tests'], 102 buffer=(not flags.disable_buffer))
95 test_suite_iter) 103 result = testRunner.run(test_suite)
96 testRunner = unittest.runner.TextTestRunner(verbosity=2, 104 if result.wasSuccessful():
97 failfast=flags.failfast, buffer=(not flags.disable_buffer)) 105 print 'ok'
98 testRunner.run(my_test_suite) 106 else:
107 print 'failed'
108 print buf.getvalue()
109 print 'To repeat this test, run: '
110 print "%s %s %s --test_filter=%s --browser_args='%s'" % (sys.executable,
111 os.path.join(os.path.dirname(__file__), 'run_all_tests.py'),
112 ' '.join(sys.argv[1:]), '.'.join(test_id.split('.')[1:]),
113 experiment_args)
114 if flags.failfast:
115 return
99 116
100 if __name__ == '__main__': 117 if __name__ == '__main__':
101 main() 118 main()
OLDNEW
« tools/chrome_proxy/webdriver/common.py ('K') | « tools/chrome_proxy/webdriver/common.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698