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

Side by Side Diff: chrome/browser/android/offline_pages/evaluation/run_offline_page_evaluation_test.py

Issue 2576213002: [Offline Pages] Improvements on test harness scripts. (Closed)
Patch Set: Change the adb path to relative. Created 4 years 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 | « no previous file | 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2016 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 # 6 #
7 # 7 #
8 # This script is used to run OfflinePageSavePageLaterEvaluationTests. 8 # This script is used to run OfflinePageSavePageLaterEvaluationTests.
9 # The test will try to call SavePageLater on the list provided as the input, 9 # The test will try to call SavePageLater on the list provided as the input,
10 # and generate results of the background offlining. Then it will pull the 10 # and generate results of the background offlining. Then it will pull the
11 # results to the output directory. 11 # results to the output directory.
12 # 12 #
13 # Example Steps: 13 # Example Steps:
14 # 1. Build chrome_public_test_apk 14 # 1. Build chrome_public_test_apk
15 # 2. Prepare a list of urls. 15 # 2. Prepare a list of urls.
16 # 3. Run the script (use -d when you have more than one device connected.) 16 # 3. Run the script (use -d when you have more than one device connected.)
17 # run_offline_page_evaluation_test.py --output-directory 17 # run_offline_page_evaluation_test.py --output-directory
18 # ~/offline_eval_short_output/ --user-requested=true -use-test-scheduler=true 18 # ~/offline_eval_short_output/ --user-requested -use-test-scheduler
19 # $CHROME_SRC/out/Default ~/offline_eval_urls.txt 19 # $CHROME_SRC/out/Default ~/offline_eval_urls.txt
20 # 4. Check the results in the output directory. 20 # 4. Check the results in the output directory.
21 21
22 import argparse 22 import argparse
23 import os 23 import os
24 import shutil 24 import shutil
25 import subprocess 25 import subprocess
26 import sys 26 import sys
27 27
28 DEFAULT_USER_REQUEST = True 28 DEFAULT_USER_REQUEST = True
29 DEFAULT_USE_TEST_SCHEDULER = False 29 DEFAULT_USE_TEST_SCHEDULER = True
30 # 0 means the batch would be the whole list of urls. 30 # 0 means the batch would be the whole list of urls.
31 DEFAULT_BATCH_SIZE = 0 31 DEFAULT_BATCH_SIZE = 0
32 DEFAULT_VERBOSE = False 32 DEFAULT_VERBOSE = False
33 CONFIG_FILENAME = 'test_config' 33 CONFIG_FILENAME = 'test_config'
34 CONFIG_TEMPLATE = """\ 34 CONFIG_TEMPLATE = """\
35 IsUserRequested = {is_user_requested} 35 IsUserRequested = {is_user_requested}
36 UseTestScheduler = {use_test_scheduler} 36 UseTestScheduler = {use_test_scheduler}
37 ScheduleBatchSize = {schedule_batch_size} 37 ScheduleBatchSize = {schedule_batch_size}
38 """ 38 """
39 39
(...skipping 12 matching lines...) Expand all
52 help='Testing as user-requested urls. Default option.') 52 help='Testing as user-requested urls. Default option.')
53 parser.add_argument( 53 parser.add_argument(
54 '--not-user-requested', 54 '--not-user-requested',
55 dest='user_request', 55 dest='user_request',
56 action='store_false', 56 action='store_false',
57 help='Testing as not user-requested urls.') 57 help='Testing as not user-requested urls.')
58 parser.add_argument( 58 parser.add_argument(
59 '--use-test-scheduler', 59 '--use-test-scheduler',
60 dest='use_test_scheduler', 60 dest='use_test_scheduler',
61 action='store_true', 61 action='store_true',
62 help='Use test scheduler to avoid real scheduling') 62 help='Use test scheduler to avoid real scheduling. Default option.')
63 parser.add_argument( 63 parser.add_argument(
64 '--not-use-test-scheduler', 64 '--not-use-test-scheduler',
65 dest='use_test_scheduler', 65 dest='use_test_scheduler',
66 action='store_false', 66 action='store_false',
67 help='Use GCMNetworkManager for scheduling. Default option.') 67 help='Use GCMNetworkManager for scheduling.')
68 parser.add_argument( 68 parser.add_argument(
69 '--batch-size', 69 '--batch-size',
70 type=int, 70 type=int,
71 dest='schedule_batch_size', 71 dest='schedule_batch_size',
72 help='Number of pages to be queued after previous batch completes.') 72 help='Number of pages to be queued after previous batch completes.')
73 parser.add_argument( 73 parser.add_argument(
74 '-v', 74 '-v',
75 '--verbose', 75 '--verbose',
76 dest='verbose', 76 dest='verbose',
77 action='store_true', 77 action='store_true',
78 help='Make test runner verbose.') 78 help='Make test runner verbose.')
79 parser.add_argument( 79 parser.add_argument(
80 '-d', 80 '-d',
81 '--device', 81 '--device',
82 type=str, 82 type=str,
83 dest='device_id', 83 dest='device_id',
84 help='Specify which device to be used. See \'adb devices\'.') 84 help='Specify which device to be used. See \'adb devices\'.')
85 parser.add_argument('build_output_dir', help='Path to build directory.') 85 parser.add_argument('build_output_dir', help='Path to build directory.')
86 parser.add_argument( 86 parser.add_argument(
87 'test_urls_file', help='Path to input file with urls to be tested.') 87 'test_urls_file', help='Path to input file with urls to be tested.')
88 parser.set_defaults( 88 parser.set_defaults(
89 output_dir=os.path.expanduser('~/offline_eval_output'), 89 output_dir=os.path.expanduser('~/offline_eval_output'),
90 user_request=DEFAULT_USER_REQUEST, 90 user_request=DEFAULT_USER_REQUEST,
91 user_test_scheduler=DEFAULT_USE_TEST_SCHEDULER, 91 user_test_scheduler=DEFAULT_USE_TEST_SCHEDULER,
92 schedule_batch_size=DEFAULT_BATCH_SIZE, 92 schedule_batch_size=DEFAULT_BATCH_SIZE,
93 verbose=DEFAULT_VERBOSE) 93 verbose=DEFAULT_VERBOSE)
94 94
95 def get_adb_command(args):
96 if options.device_id != None:
97 return ['adb', '-s', options.device_id] + args
98 return ['adb'] + args
99
100 # Get the arguments and several paths. 95 # Get the arguments and several paths.
101 options, extra_args = parser.parse_known_args(args) 96 options, extra_args = parser.parse_known_args(args)
102 97
103 if extra_args: 98 if extra_args:
104 print 'Unknown args: ' + ', '.join( 99 print 'Unknown args: ' + ', '.join(
105 extra_args) + '. Please check and run again.' 100 extra_args) + '. Please check and run again.'
106 return 101 return
107 102
108 build_dir_path = os.path.abspath( 103 build_dir_path = os.path.abspath(
109 os.path.join(os.getcwd(), options.build_output_dir)) 104 os.path.join(os.getcwd(), options.build_output_dir))
110 test_runner_path = os.path.join(build_dir_path, 105 test_runner_path = os.path.join(build_dir_path,
111 'bin/run_chrome_public_test_apk') 106 'bin/run_chrome_public_test_apk')
112 config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME) 107 config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME)
108
109 def get_adb_command(args):
110 adb_path = os.path.join(
111 build_dir_path,
112 '../../third_party/android_tools/sdk/platform-tools/adb')
113 if options.device_id != None:
114 return [adb_path, '-s', options.device_id] + args
115 return [adb_path] + args
116
117 # In case adb server is not started
118 subprocess.call(get_adb_command(['start-server']))
113 external_dir = subprocess.check_output( 119 external_dir = subprocess.check_output(
114 get_adb_command(['shell', 'echo', '$EXTERNAL_STORAGE'])).strip() 120 get_adb_command(['shell', 'echo', '$EXTERNAL_STORAGE'])).strip()
115 121
116 # Create the output directory for results, and have a copy of test config 122 # Create the output directory for results, and have a copy of test config
117 # there. 123 # there.
118 if not os.path.exists(options.output_dir): 124 if not os.path.exists(options.output_dir):
119 print 'Creating output directory for results... ' + options.output_dir 125 print 'Creating output directory for results... ' + options.output_dir
120 os.makedirs(options.output_dir) 126 os.makedirs(options.output_dir)
121 with open(config_output_path, 'w') as config: 127 with open(config_output_path, 'w') as config:
122 config.write( 128 config.write(
123 CONFIG_TEMPLATE.format( 129 CONFIG_TEMPLATE.format(
124 is_user_requested=options.user_request, 130 is_user_requested=options.user_request,
125 use_test_scheduler=options.use_test_scheduler, 131 use_test_scheduler=options.use_test_scheduler,
126 schedule_batch_size=options.schedule_batch_size)) 132 schedule_batch_size=options.schedule_batch_size))
127 133
128 print 'Uploading config file and input file onto the device.' 134 print 'Uploading config file and input file onto the device.'
129 subprocess.call( 135 subprocess.call(
130 get_adb_command( 136 get_adb_command(
131 ['push', config_output_path, external_dir + '/paquete/test_config'])) 137 ['push', config_output_path, external_dir + '/paquete/test_config']))
132 subprocess.call( 138 subprocess.call(
133 get_adb_command([ 139 get_adb_command([
134 'push', options.test_urls_file, 140 'push', options.test_urls_file, external_dir +
135 '/sdcard/paquete/offline_eval_urls.txt' 141 '/paquete/offline_eval_urls.txt'
136 ])) 142 ]))
137 print 'Start running test...' 143 print 'Start running test with following configurations:'
138 144 print CONFIG_TEMPLATE.format(
145 is_user_requested=options.user_request,
146 use_test_scheduler=options.use_test_scheduler,
147 schedule_batch_size=options.schedule_batch_size)
139 # Run test 148 # Run test
140 test_runner_cmd = [ 149 test_runner_cmd = [
141 test_runner_path, '-f', 150 test_runner_path, '-f',
142 'OfflinePageSavePageLaterEvaluationTest.testFailureRate' 151 'OfflinePageSavePageLaterEvaluationTest.testFailureRate'
143 ] 152 ]
144 if options.verbose: 153 if options.verbose:
145 test_runner_cmd += ['-v'] 154 test_runner_cmd += ['-v']
146 subprocess.call(test_runner_cmd) 155 subprocess.call(test_runner_cmd)
147 156
148 print 'Fetching results from device...' 157 print 'Fetching results from device...'
149 archive_dir = os.path.join(options.output_dir, 'archives/') 158 archive_dir = os.path.join(options.output_dir, 'archives/')
150 if os.path.exists(archive_dir): 159 if os.path.exists(archive_dir):
151 shutil.rmtree(archive_dir) 160 shutil.rmtree(archive_dir)
152 subprocess.call( 161 subprocess.call(
153 get_adb_command( 162 get_adb_command(['pull', external_dir + '/paquete/archives', archive_dir
154 ['pull', external_dir + '/paquete/archives', archive_dir])) 163 ]))
155 subprocess.call( 164 subprocess.call(
156 get_adb_command([ 165 get_adb_command([
157 'pull', external_dir + '/paquete/offline_eval_results.txt', 166 'pull', external_dir + '/paquete/offline_eval_results.txt',
158 options.output_dir 167 options.output_dir
159 ])) 168 ]))
160 subprocess.call( 169 subprocess.call(
161 get_adb_command([ 170 get_adb_command([
162 'pull', external_dir + '/paquete/offline_eval_logs.txt', 171 'pull', external_dir + '/paquete/offline_eval_logs.txt',
163 options.output_dir 172 options.output_dir
164 ])) 173 ]))
165 print 'Test finished!' 174 print 'Test finished!'
166 175
167 176
168 if __name__ == '__main__': 177 if __name__ == '__main__':
169 sys.exit(main(sys.argv[1:])) 178 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698