OLD | NEW |
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=true -use-test-scheduler=true |
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 = False |
| 30 # 0 means the batch would be the whole list of urls. |
| 31 DEFAULT_BATCH_SIZE = 0 |
30 DEFAULT_VERBOSE = False | 32 DEFAULT_VERBOSE = False |
31 CONFIG_FILENAME = 'test_config' | 33 CONFIG_FILENAME = 'test_config' |
32 CONFIG_TEMPLATE = """\ | 34 CONFIG_TEMPLATE = """\ |
33 IsUserRequested = {is_user_requested} | 35 IsUserRequested = {is_user_requested} |
34 UseTestScheduler = {use_test_scheduler} | 36 UseTestScheduler = {use_test_scheduler} |
| 37 ScheduleBatchSize = {schedule_batch_size} |
35 """ | 38 """ |
36 | 39 |
37 | 40 |
38 def main(args): | 41 def main(args): |
39 # Setting up the argument parser. | 42 # Setting up the argument parser. |
40 parser = argparse.ArgumentParser() | 43 parser = argparse.ArgumentParser() |
41 parser.add_argument( | 44 parser.add_argument( |
42 '--output-directory', | 45 '--output-directory', |
43 dest='output_dir', | 46 dest='output_dir', |
44 help='Directory for output. Default is ~/offline_eval_output/') | 47 help='Directory for output. Default is ~/offline_eval_output/') |
(...skipping 11 matching lines...) Expand all Loading... |
56 '--use-test-scheduler', | 59 '--use-test-scheduler', |
57 dest='use_test_scheduler', | 60 dest='use_test_scheduler', |
58 action='store_true', | 61 action='store_true', |
59 help='Use test scheduler to avoid real scheduling') | 62 help='Use test scheduler to avoid real scheduling') |
60 parser.add_argument( | 63 parser.add_argument( |
61 '--not-use-test-scheduler', | 64 '--not-use-test-scheduler', |
62 dest='use_test_scheduler', | 65 dest='use_test_scheduler', |
63 action='store_false', | 66 action='store_false', |
64 help='Use GCMNetworkManager for scheduling. Default option.') | 67 help='Use GCMNetworkManager for scheduling. Default option.') |
65 parser.add_argument( | 68 parser.add_argument( |
| 69 '--batch-size', |
| 70 type=int, |
| 71 dest='schedule_batch_size', |
| 72 help='Number of pages to be queued after previous batch completes.') |
| 73 parser.add_argument( |
66 '-v', | 74 '-v', |
67 '--verbose', | 75 '--verbose', |
68 dest='verbose', | 76 dest='verbose', |
69 action='store_true', | 77 action='store_true', |
70 help='Make test runner verbose.') | 78 help='Make test runner verbose.') |
71 parser.add_argument( | 79 parser.add_argument( |
72 '-d', | 80 '-d', |
73 '--device', | 81 '--device', |
74 type=str, | 82 type=str, |
75 dest='device_id', | 83 dest='device_id', |
(...skipping 30 matching lines...) Expand all Loading... |
106 | 114 |
107 # Create the output directory for results, and have a copy of test config | 115 # Create the output directory for results, and have a copy of test config |
108 # there. | 116 # there. |
109 if not os.path.exists(options.output_dir): | 117 if not os.path.exists(options.output_dir): |
110 print 'Creating output directory for results... ' + options.output_dir | 118 print 'Creating output directory for results... ' + options.output_dir |
111 os.makedirs(options.output_dir) | 119 os.makedirs(options.output_dir) |
112 with open(config_output_path, 'w') as config: | 120 with open(config_output_path, 'w') as config: |
113 config.write( | 121 config.write( |
114 CONFIG_TEMPLATE.format( | 122 CONFIG_TEMPLATE.format( |
115 is_user_requested=options.user_request, | 123 is_user_requested=options.user_request, |
116 use_test_scheduler=options.use_test_scheduler)) | 124 use_test_scheduler=options.use_test_scheduler, |
| 125 schedule_batch_size=options.schedule_batch_size)) |
117 | 126 |
118 print 'Uploading config file and input file onto the device.' | 127 print 'Uploading config file and input file onto the device.' |
119 subprocess.call( | 128 subprocess.call( |
120 get_adb_command( | 129 get_adb_command( |
121 ['push', config_output_path, external_dir + '/paquete/test_config'])) | 130 ['push', config_output_path, external_dir + '/paquete/test_config'])) |
122 subprocess.call( | 131 subprocess.call( |
123 get_adb_command([ | 132 get_adb_command([ |
124 'push', options.test_urls_file, | 133 'push', options.test_urls_file, |
125 '/sdcard/paquete/offline_eval_urls.txt' | 134 '/sdcard/paquete/offline_eval_urls.txt' |
126 ])) | 135 ])) |
(...skipping 23 matching lines...) Expand all Loading... |
150 subprocess.call( | 159 subprocess.call( |
151 get_adb_command([ | 160 get_adb_command([ |
152 'pull', external_dir + '/paquete/offline_eval_logs.txt', | 161 'pull', external_dir + '/paquete/offline_eval_logs.txt', |
153 options.output_dir | 162 options.output_dir |
154 ])) | 163 ])) |
155 print 'Test finished!' | 164 print 'Test finished!' |
156 | 165 |
157 | 166 |
158 if __name__ == '__main__': | 167 if __name__ == '__main__': |
159 sys.exit(main(sys.argv[1:])) | 168 sys.exit(main(sys.argv[1:])) |
OLD | NEW |