Chromium Code Reviews| Index: chrome/browser/android/offline_pages/evaluation/run_offline_page_evaluation_test.py |
| diff --git a/chrome/browser/android/offline_pages/evaluation/run_offline_page_evaluation_test.py b/chrome/browser/android/offline_pages/evaluation/run_offline_page_evaluation_test.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..3f69e3370221f6455b99501a3537ea6236825e4c |
| --- /dev/null |
| +++ b/chrome/browser/android/offline_pages/evaluation/run_offline_page_evaluation_test.py |
| @@ -0,0 +1,137 @@ |
| +#!/usr/bin/env python |
| +# |
| +# Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +# |
| +# |
| +# This script is used to run OfflinePageSavePageLaterEvaluationTests. |
| +# Example: |
| +# run_offline_page_evaluation_test.py --output-directory |
| +# ~/offline_eval_short_output/ --url-timeout 150 --not-user-requested |
| +# --use-test-scheduler $CHROME_SRC/out/Default ~/offline_eval_urls.txt |
| + |
| +import argparse |
| +import os |
| +import shutil |
| +import subprocess |
| +import sys |
| + |
| +DEFAULT_URL_TIMEOUT = 60 * 8 |
| +DEFAULT_USER_REQUEST = True |
| +DEFAULT_USE_TEST_SCHEDULER = False |
| +DEFAULT_VERBOSE = False |
| +CONFIG_FILENAME = 'test_config' |
| +CONFIG_TEMPLATE = """\ |
| +TimeoutPerUrlInSeconds = {timeout_per_url_in_seconds} |
| +IsUserRequested = {is_user_requested} |
| +UseTestScheduler = {use_test_scheduler} |
| +""" |
| + |
| + |
| +def main(args): |
| + # Setting up the argument parser. |
| + parser = argparse.ArgumentParser() |
| + parser.add_argument( |
| + '--output-directory', |
| + dest='output_dir', |
| + help='Directory for output. Default is ~/offline_eval_output/') |
| + parser.add_argument( |
| + '--url-timeout', |
| + type=int, |
| + dest='url_timeout', |
| + help='Time out per url, in seconds. Default is 480 seconds.') |
| + parser.add_argument( |
| + '--not-user-requested', |
|
Pete Williamson
2016/11/03 18:21:11
It is generally better to phrase options in the po
romax
2016/11/03 20:17:20
after some self-struggling i'm adding all options(
|
| + dest='user_request', |
| + action='store_false', |
| + help='Test as not user-requested urls.') |
| + parser.add_argument( |
| + '--use-test-scheduler', |
| + dest='use_test_scheduler', |
| + action='store_true', |
| + help='Start processing immediately. Using GCMNetworkManager by default.') |
| + parser.add_argument( |
| + '-v', |
| + '--verbose', |
| + dest='verbose', |
| + action='store_true', |
| + help='Make test runner verbose.') |
| + parser.add_argument('build_output_dir', help='Path to build directory.') |
| + parser.add_argument( |
| + 'test_urls_file', help='Path to input file with urls to be tested.') |
| + parser.set_defaults( |
| + output_dir=os.path.expanduser('~/offline_eval_output'), |
| + url_timeout=DEFAULT_URL_TIMEOUT, |
| + user_request=DEFAULT_USER_REQUEST, |
| + user_test_scheduler=DEFAULT_USE_TEST_SCHEDULER, |
| + verbose=DEFAULT_VERBOSE) |
| + |
| + # Get the arguments and several paths. |
| + options, extra_args = parser.parse_known_args(args) |
| + |
| + if extra_args: |
| + print 'Unknown args: ' + ', '.join( |
| + extra_args) + '. Please check and run again.' |
| + return |
| + |
| + build_dir_path = os.path.abspath( |
| + os.path.join(os.getcwd(), options.build_output_dir)) |
| + test_runner_path = os.path.join(build_dir_path, |
| + 'bin/run_chrome_public_test_apk') |
| + config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME) |
| + external_dir = subprocess.check_output( |
| + ['adb', 'shell', 'echo', '$EXTERNAL_STORAGE']).strip() |
| + |
| + # Create the output directory for results, and have a copy of test config |
| + # there. |
| + if not os.path.exists(options.output_dir): |
| + print 'Creating output directory for results... ' + options.output_dir |
| + os.makedirs(options.output_dir) |
| + with open(config_output_path, 'w') as config: |
| + config.write( |
| + CONFIG_TEMPLATE.format( |
| + timeout_per_url_in_seconds=options.url_timeout, |
| + is_user_requested=options.user_request, |
| + use_test_scheduler=options.use_test_scheduler)) |
| + |
| + print 'Uploading config file and input file onto the device.' |
| + subprocess.call([ |
| + 'adb', 'push', config_output_path, external_dir + '/paquete/test_config' |
| + ]) |
| + subprocess.call([ |
| + 'adb', 'push', options.test_urls_file, |
| + '/sdcard/paquete/offline_eval_urls.txt' |
| + ]) |
| + print 'Start running test...' |
| + |
| + # Run test |
| + test_runner_cmd = [ |
| + test_runner_path, '-f', |
| + 'OfflinePageSavePageLaterEvaluationTest.testFailureRateWithTimeout' |
| + ] |
| + if options.verbose: |
| + test_runner_cmd += ['-v'] |
| + subprocess.call(test_runner_cmd) |
| + |
| + print 'Fetching results from device...' |
| + archive_dir = os.path.join(options.output_dir, 'archives/') |
| + if os.path.exists(archive_dir): |
| + shutil.rmtree(archive_dir) |
| + subprocess.call([ |
| + 'adb', 'pull', '/data/data/org.chromium.chrome/app_chrome/' |
| + 'Default/Offline Pages/archives', archive_dir |
| + ]) |
| + subprocess.call([ |
| + 'adb', 'pull', external_dir + '/paquete/offline_eval_results.txt', |
| + options.output_dir |
| + ]) |
| + subprocess.call([ |
| + 'adb', 'pull', external_dir + '/paquete/offline_eval_logs.txt', |
| + options.output_dir |
| + ]) |
| + print 'Test finished!' |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv[1:])) |