Chromium Code Reviews| 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 = 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 Loading... | |
| 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): | 95 def get_adb_command(args): |
| 96 adb_path = os.path.join(os.getcwd(), | |
|
Pete Williamson
2016/12/15 01:46:15
This hardcodes the assumption that we are being ru
dougarnett
2016/12/15 17:50:15
I think this is much more sound - to use the same
romax
2016/12/15 20:43:45
There isn't a limit for the directory where you st
| |
| 97 'third_party/android_tools/sdk/platform-tools/adb') | |
| 96 if options.device_id != None: | 98 if options.device_id != None: |
| 97 return ['adb', '-s', options.device_id] + args | 99 return [adb_path, '-s', options.device_id] + args |
| 98 return ['adb'] + args | 100 return [adb_path] + args |
| 99 | 101 |
| 100 # Get the arguments and several paths. | 102 # Get the arguments and several paths. |
| 101 options, extra_args = parser.parse_known_args(args) | 103 options, extra_args = parser.parse_known_args(args) |
| 102 | 104 |
| 103 if extra_args: | 105 if extra_args: |
| 104 print 'Unknown args: ' + ', '.join( | 106 print 'Unknown args: ' + ', '.join( |
| 105 extra_args) + '. Please check and run again.' | 107 extra_args) + '. Please check and run again.' |
| 106 return | 108 return |
| 107 | 109 |
| 108 build_dir_path = os.path.abspath( | 110 build_dir_path = os.path.abspath( |
| 109 os.path.join(os.getcwd(), options.build_output_dir)) | 111 os.path.join(os.getcwd(), options.build_output_dir)) |
| 110 test_runner_path = os.path.join(build_dir_path, | 112 test_runner_path = os.path.join(build_dir_path, |
| 111 'bin/run_chrome_public_test_apk') | 113 'bin/run_chrome_public_test_apk') |
| 112 config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME) | 114 config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME) |
| 115 # In case adb server is not started | |
| 116 subprocess.call(get_adb_command(['start-server'])) | |
| 113 external_dir = subprocess.check_output( | 117 external_dir = subprocess.check_output( |
| 114 get_adb_command(['shell', 'echo', '$EXTERNAL_STORAGE'])).strip() | 118 get_adb_command(['shell', 'echo', '$EXTERNAL_STORAGE'])).strip() |
| 115 | 119 |
| 116 # Create the output directory for results, and have a copy of test config | 120 # Create the output directory for results, and have a copy of test config |
| 117 # there. | 121 # there. |
| 118 if not os.path.exists(options.output_dir): | 122 if not os.path.exists(options.output_dir): |
| 119 print 'Creating output directory for results... ' + options.output_dir | 123 print 'Creating output directory for results... ' + options.output_dir |
| 120 os.makedirs(options.output_dir) | 124 os.makedirs(options.output_dir) |
| 121 with open(config_output_path, 'w') as config: | 125 with open(config_output_path, 'w') as config: |
| 122 config.write( | 126 config.write( |
| 123 CONFIG_TEMPLATE.format( | 127 CONFIG_TEMPLATE.format( |
| 124 is_user_requested=options.user_request, | 128 is_user_requested=options.user_request, |
| 125 use_test_scheduler=options.use_test_scheduler, | 129 use_test_scheduler=options.use_test_scheduler, |
| 126 schedule_batch_size=options.schedule_batch_size)) | 130 schedule_batch_size=options.schedule_batch_size)) |
| 127 | 131 |
| 128 print 'Uploading config file and input file onto the device.' | 132 print 'Uploading config file and input file onto the device.' |
| 129 subprocess.call( | 133 subprocess.call( |
| 130 get_adb_command( | 134 get_adb_command( |
| 131 ['push', config_output_path, external_dir + '/paquete/test_config'])) | 135 ['push', config_output_path, external_dir + '/paquete/test_config'])) |
| 132 subprocess.call( | 136 subprocess.call( |
| 133 get_adb_command([ | 137 get_adb_command([ |
| 134 'push', options.test_urls_file, | 138 'push', options.test_urls_file, external_dir + |
| 135 '/sdcard/paquete/offline_eval_urls.txt' | 139 '/paquete/offline_eval_urls.txt' |
|
Pete Williamson
2016/12/15 01:46:15
Does this require a corresponding change in the sc
dougarnett
2016/12/15 17:50:15
This is just fixing an instance that was missed in
romax
2016/12/15 20:43:45
yeah all the path related with the one we use on t
| |
| 136 ])) | 140 ])) |
| 137 print 'Start running test...' | 141 print 'Start running test with following configurations:' |
| 138 | 142 print CONFIG_TEMPLATE.format( |
| 143 is_user_requested=options.user_request, | |
| 144 use_test_scheduler=options.use_test_scheduler, | |
| 145 schedule_batch_size=options.schedule_batch_size) | |
| 139 # Run test | 146 # Run test |
| 140 test_runner_cmd = [ | 147 test_runner_cmd = [ |
| 141 test_runner_path, '-f', | 148 test_runner_path, '-f', |
| 142 'OfflinePageSavePageLaterEvaluationTest.testFailureRate' | 149 'OfflinePageSavePageLaterEvaluationTest.testFailureRate' |
| 143 ] | 150 ] |
| 144 if options.verbose: | 151 if options.verbose: |
| 145 test_runner_cmd += ['-v'] | 152 test_runner_cmd += ['-v'] |
| 146 subprocess.call(test_runner_cmd) | 153 subprocess.call(test_runner_cmd) |
| 147 | 154 |
| 148 print 'Fetching results from device...' | 155 print 'Fetching results from device...' |
| 149 archive_dir = os.path.join(options.output_dir, 'archives/') | 156 archive_dir = os.path.join(options.output_dir, 'archives/') |
| 150 if os.path.exists(archive_dir): | 157 if os.path.exists(archive_dir): |
| 151 shutil.rmtree(archive_dir) | 158 shutil.rmtree(archive_dir) |
| 152 subprocess.call( | 159 subprocess.call( |
| 153 get_adb_command( | 160 get_adb_command(['pull', external_dir + '/paquete/archives', archive_dir |
| 154 ['pull', external_dir + '/paquete/archives', archive_dir])) | 161 ])) |
| 155 subprocess.call( | 162 subprocess.call( |
| 156 get_adb_command([ | 163 get_adb_command([ |
| 157 'pull', external_dir + '/paquete/offline_eval_results.txt', | 164 'pull', external_dir + '/paquete/offline_eval_results.txt', |
| 158 options.output_dir | 165 options.output_dir |
| 159 ])) | 166 ])) |
| 160 subprocess.call( | 167 subprocess.call( |
| 161 get_adb_command([ | 168 get_adb_command([ |
| 162 'pull', external_dir + '/paquete/offline_eval_logs.txt', | 169 'pull', external_dir + '/paquete/offline_eval_logs.txt', |
| 163 options.output_dir | 170 options.output_dir |
| 164 ])) | 171 ])) |
| 165 print 'Test finished!' | 172 print 'Test finished!' |
| 166 | 173 |
| 167 | 174 |
| 168 if __name__ == '__main__': | 175 if __name__ == '__main__': |
| 169 sys.exit(main(sys.argv[1:])) | 176 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |