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

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

Issue 2465303003: [Offline Pages] Script for running evaluation tests. (Closed)
Patch Set: fix build. Created 4 years, 1 month 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
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
5 # found in the LICENSE file.
6 #
7 #
8 # This script is used to run OfflinePageSavePageLaterEvaluationTests.
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
11 # results to the output directory.
12 #
13 # Example Steps:
14 # 1. Build chrome_public_test_apk
15 # 2. Prepare a list of urls.
16 # 3. Run the script
17 # run_offline_page_evaluation_test.py --output-directory
18 # ~/offline_eval_short_output/ --url-timeout 150 --user-requested=true
19 # --use-test-scheduler=true $CHROME_SRC/out/Default ~/offline_eval_urls.txt
20 # 4. Check the results in the output directory.
21
22 import argparse
23 import os
24 import shutil
25 import subprocess
26 import sys
27
28 DEFAULT_URL_TIMEOUT = 60 * 8
29 DEFAULT_USER_REQUEST = True
30 DEFAULT_USE_TEST_SCHEDULER = False
31 DEFAULT_VERBOSE = False
32 CONFIG_FILENAME = 'test_config'
33 CONFIG_TEMPLATE = """\
34 TimeoutPerUrlInSeconds = {timeout_per_url_in_seconds}
35 IsUserRequested = {is_user_requested}
36 UseTestScheduler = {use_test_scheduler}
37 """
38
39
40 def main(args):
41 # Setting up the argument parser.
42 parser = argparse.ArgumentParser()
43 parser.add_argument(
44 '--output-directory',
45 dest='output_dir',
46 help='Directory for output. Default is ~/offline_eval_output/')
47 parser.add_argument(
48 '--url-timeout',
49 type=int,
50 dest='url_timeout',
51 help='Time out per url, in seconds. Default is 480 seconds.')
52 parser.add_argument(
53 '--user-requested',
54 dest='user_request',
55 action='store_true',
56 help='Testing as user-requested urls. Default option.')
57 parser.add_argument(
58 '--not-user-requested',
59 dest='user_request',
60 action='store_false',
61 help='Testing as not user-requested urls.')
62 parser.add_argument(
63 '--use-test-scheduler',
64 dest='use_test_scheduler',
65 action='store_true',
66 help='Use test scheduler to avoid real scheduling')
67 parser.add_argument(
68 '--not-use-test-scheduler',
69 dest='use_test_scheduler',
70 action='store_false',
71 help='Use GCMNetworkManager for scheduling. Default option.')
72 parser.add_argument(
73 '-v',
74 '--verbose',
75 dest='verbose',
76 action='store_true',
77 help='Make test runner verbose.')
78 parser.add_argument('build_output_dir', help='Path to build directory.')
79 parser.add_argument(
80 'test_urls_file', help='Path to input file with urls to be tested.')
81 parser.set_defaults(
82 output_dir=os.path.expanduser('~/offline_eval_output'),
83 url_timeout=DEFAULT_URL_TIMEOUT,
84 user_request=DEFAULT_USER_REQUEST,
85 user_test_scheduler=DEFAULT_USE_TEST_SCHEDULER,
86 verbose=DEFAULT_VERBOSE)
87
88 # Get the arguments and several paths.
89 options, extra_args = parser.parse_known_args(args)
90
91 if extra_args:
92 print 'Unknown args: ' + ', '.join(
93 extra_args) + '. Please check and run again.'
94 return
95
96 build_dir_path = os.path.abspath(
97 os.path.join(os.getcwd(), options.build_output_dir))
98 test_runner_path = os.path.join(build_dir_path,
99 'bin/run_chrome_public_test_apk')
100 config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME)
101 external_dir = subprocess.check_output(
102 ['adb', 'shell', 'echo', '$EXTERNAL_STORAGE']).strip()
103
104 # Create the output directory for results, and have a copy of test config
105 # there.
106 if not os.path.exists(options.output_dir):
107 print 'Creating output directory for results... ' + options.output_dir
108 os.makedirs(options.output_dir)
109 with open(config_output_path, 'w') as config:
110 config.write(
111 CONFIG_TEMPLATE.format(
112 timeout_per_url_in_seconds=options.url_timeout,
113 is_user_requested=options.user_request,
114 use_test_scheduler=options.use_test_scheduler))
115
116 print 'Uploading config file and input file onto the device.'
117 subprocess.call([
118 'adb', 'push', config_output_path, external_dir + '/paquete/test_config'
119 ])
120 subprocess.call([
121 'adb', 'push', options.test_urls_file,
122 '/sdcard/paquete/offline_eval_urls.txt'
123 ])
124 print 'Start running test...'
125
126 # Run test
127 test_runner_cmd = [
128 test_runner_path, '-f',
129 'OfflinePageSavePageLaterEvaluationTest.testFailureRateWithTimeout'
130 ]
131 if options.verbose:
132 test_runner_cmd += ['-v']
133 subprocess.call(test_runner_cmd)
134
135 print 'Fetching results from device...'
136 archive_dir = os.path.join(options.output_dir, 'archives/')
137 if os.path.exists(archive_dir):
138 shutil.rmtree(archive_dir)
139 subprocess.call(['adb', 'root'])
140 subprocess.call([
141 'adb', 'pull', '/data/data/org.chromium.chrome/app_chrome/'
142 'Default/Offline Pages/archives', archive_dir
143 ])
144 subprocess.call([
145 'adb', 'pull', external_dir + '/paquete/offline_eval_results.txt',
146 options.output_dir
147 ])
148 subprocess.call([
149 'adb', 'pull', external_dir + '/paquete/offline_eval_logs.txt',
150 options.output_dir
151 ])
152 print 'Test finished!'
153
154
155 if __name__ == '__main__':
156 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/offlinepages/OfflinePageSavePageLaterEvaluationTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698