| 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 | 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/ --url-timeout 150 --user-requested=true | 18 # ~/offline_eval_short_output/ --url-timeout 150 --user-requested=true |
| 19 # --use-test-scheduler=true $CHROME_SRC/out/Default ~/offline_eval_urls.txt | 19 # --use-test-scheduler=true $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 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 '--not-use-test-scheduler', | 68 '--not-use-test-scheduler', |
| 69 dest='use_test_scheduler', | 69 dest='use_test_scheduler', |
| 70 action='store_false', | 70 action='store_false', |
| 71 help='Use GCMNetworkManager for scheduling. Default option.') | 71 help='Use GCMNetworkManager for scheduling. Default option.') |
| 72 parser.add_argument( | 72 parser.add_argument( |
| 73 '-v', | 73 '-v', |
| 74 '--verbose', | 74 '--verbose', |
| 75 dest='verbose', | 75 dest='verbose', |
| 76 action='store_true', | 76 action='store_true', |
| 77 help='Make test runner verbose.') | 77 help='Make test runner verbose.') |
| 78 parser.add_argument( |
| 79 '-d', |
| 80 '--device', |
| 81 type=str, |
| 82 dest='device_id', |
| 83 help='Specify which device to be used. See \'adb devices\'.') |
| 78 parser.add_argument('build_output_dir', help='Path to build directory.') | 84 parser.add_argument('build_output_dir', help='Path to build directory.') |
| 79 parser.add_argument( | 85 parser.add_argument( |
| 80 'test_urls_file', help='Path to input file with urls to be tested.') | 86 'test_urls_file', help='Path to input file with urls to be tested.') |
| 81 parser.set_defaults( | 87 parser.set_defaults( |
| 82 output_dir=os.path.expanduser('~/offline_eval_output'), | 88 output_dir=os.path.expanduser('~/offline_eval_output'), |
| 83 url_timeout=DEFAULT_URL_TIMEOUT, | 89 url_timeout=DEFAULT_URL_TIMEOUT, |
| 84 user_request=DEFAULT_USER_REQUEST, | 90 user_request=DEFAULT_USER_REQUEST, |
| 85 user_test_scheduler=DEFAULT_USE_TEST_SCHEDULER, | 91 user_test_scheduler=DEFAULT_USE_TEST_SCHEDULER, |
| 86 verbose=DEFAULT_VERBOSE) | 92 verbose=DEFAULT_VERBOSE) |
| 87 | 93 |
| 94 def get_adb_command(args): |
| 95 if options.device_id != None: |
| 96 return ['adb', '-s', options.device_id] + args |
| 97 return ['adb'] + args |
| 98 |
| 88 # Get the arguments and several paths. | 99 # Get the arguments and several paths. |
| 89 options, extra_args = parser.parse_known_args(args) | 100 options, extra_args = parser.parse_known_args(args) |
| 90 | 101 |
| 91 if extra_args: | 102 if extra_args: |
| 92 print 'Unknown args: ' + ', '.join( | 103 print 'Unknown args: ' + ', '.join( |
| 93 extra_args) + '. Please check and run again.' | 104 extra_args) + '. Please check and run again.' |
| 94 return | 105 return |
| 95 | 106 |
| 96 build_dir_path = os.path.abspath( | 107 build_dir_path = os.path.abspath( |
| 97 os.path.join(os.getcwd(), options.build_output_dir)) | 108 os.path.join(os.getcwd(), options.build_output_dir)) |
| 98 test_runner_path = os.path.join(build_dir_path, | 109 test_runner_path = os.path.join(build_dir_path, |
| 99 'bin/run_chrome_public_test_apk') | 110 'bin/run_chrome_public_test_apk') |
| 100 config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME) | 111 config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME) |
| 101 external_dir = subprocess.check_output( | 112 external_dir = subprocess.check_output( |
| 102 ['adb', 'shell', 'echo', '$EXTERNAL_STORAGE']).strip() | 113 get_adb_command(['shell', 'echo', '$EXTERNAL_STORAGE'])).strip() |
| 103 | 114 |
| 104 # 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 |
| 105 # there. | 116 # there. |
| 106 if not os.path.exists(options.output_dir): | 117 if not os.path.exists(options.output_dir): |
| 107 print 'Creating output directory for results... ' + options.output_dir | 118 print 'Creating output directory for results... ' + options.output_dir |
| 108 os.makedirs(options.output_dir) | 119 os.makedirs(options.output_dir) |
| 109 with open(config_output_path, 'w') as config: | 120 with open(config_output_path, 'w') as config: |
| 110 config.write( | 121 config.write( |
| 111 CONFIG_TEMPLATE.format( | 122 CONFIG_TEMPLATE.format( |
| 112 timeout_per_url_in_seconds=options.url_timeout, | 123 timeout_per_url_in_seconds=options.url_timeout, |
| 113 is_user_requested=options.user_request, | 124 is_user_requested=options.user_request, |
| 114 use_test_scheduler=options.use_test_scheduler)) | 125 use_test_scheduler=options.use_test_scheduler)) |
| 115 | 126 |
| 116 print 'Uploading config file and input file onto the device.' | 127 print 'Uploading config file and input file onto the device.' |
| 117 subprocess.call([ | 128 subprocess.call( |
| 118 'adb', 'push', config_output_path, external_dir + '/paquete/test_config' | 129 get_adb_command( |
| 119 ]) | 130 ['push', config_output_path, external_dir + '/paquete/test_config'])) |
| 120 subprocess.call([ | 131 subprocess.call( |
| 121 'adb', 'push', options.test_urls_file, | 132 get_adb_command([ |
| 122 '/sdcard/paquete/offline_eval_urls.txt' | 133 'push', options.test_urls_file, |
| 123 ]) | 134 '/sdcard/paquete/offline_eval_urls.txt' |
| 135 ])) |
| 124 print 'Start running test...' | 136 print 'Start running test...' |
| 125 | 137 |
| 126 # Run test | 138 # Run test |
| 127 test_runner_cmd = [ | 139 test_runner_cmd = [ |
| 128 test_runner_path, '-f', | 140 test_runner_path, '-f', |
| 129 'OfflinePageSavePageLaterEvaluationTest.testFailureRateWithTimeout' | 141 'OfflinePageSavePageLaterEvaluationTest.testFailureRateWithTimeout' |
| 130 ] | 142 ] |
| 131 if options.verbose: | 143 if options.verbose: |
| 132 test_runner_cmd += ['-v'] | 144 test_runner_cmd += ['-v'] |
| 133 subprocess.call(test_runner_cmd) | 145 subprocess.call(test_runner_cmd) |
| 134 | 146 |
| 135 print 'Fetching results from device...' | 147 print 'Fetching results from device...' |
| 136 archive_dir = os.path.join(options.output_dir, 'archives/') | 148 archive_dir = os.path.join(options.output_dir, 'archives/') |
| 137 if os.path.exists(archive_dir): | 149 if os.path.exists(archive_dir): |
| 138 shutil.rmtree(archive_dir) | 150 shutil.rmtree(archive_dir) |
| 139 subprocess.call(['adb', 'root']) | 151 subprocess.call( |
| 140 subprocess.call([ | 152 get_adb_command( |
| 141 'adb', 'pull', '/data/data/org.chromium.chrome/app_chrome/' | 153 ['pull', external_dir + '/paquete/archives', archive_dir])) |
| 142 'Default/Offline Pages/archives', archive_dir | 154 subprocess.call( |
| 143 ]) | 155 get_adb_command([ |
| 144 subprocess.call([ | 156 'pull', external_dir + '/paquete/offline_eval_results.txt', |
| 145 'adb', 'pull', external_dir + '/paquete/offline_eval_results.txt', | 157 options.output_dir |
| 146 options.output_dir | 158 ])) |
| 147 ]) | 159 subprocess.call( |
| 148 subprocess.call([ | 160 get_adb_command([ |
| 149 'adb', 'pull', external_dir + '/paquete/offline_eval_logs.txt', | 161 'pull', external_dir + '/paquete/offline_eval_logs.txt', |
| 150 options.output_dir | 162 options.output_dir |
| 151 ]) | 163 ])) |
| 152 print 'Test finished!' | 164 print 'Test finished!' |
| 153 | 165 |
| 154 | 166 |
| 155 if __name__ == '__main__': | 167 if __name__ == '__main__': |
| 156 sys.exit(main(sys.argv[1:])) | 168 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |