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

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: 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/python2
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 tests for SavePageLater evaluation.
Pete Williamson 2016/11/02 20:30:29 Are the instructions in "Instructions to run Offli
romax 2016/11/03 01:46:50 Not yet, I'm planning to update the instructions a
9
10 import argparse
11 import os
12 import shutil
13 import subprocess
14 import sys
15
16 DEFAULT_URL_TIMEOUT = 180
dougarnett 2016/11/02 19:34:15 too small for 2g, consider upto 8 minutes instead
Pete Williamson 2016/11/02 20:30:29 Should there be a way to use the current timeout p
romax 2016/11/03 01:46:49 Changed default to 480sec. I think it makes sense
17 DEFAULT_USER_REQUEST = False
18 DEFAULT_USE_TEST_SCHEDULER = False
19 DEFAULT_VERBOSE = False
20 CONFIG_FILENAME = 'test_config'
21 CONFIG_TEMPLATE = """\
22 TimeoutPerUrlInSeconds = {timeout_per_url_in_seconds}
23 IsUserRequested = {is_user_requested}
24 UseTestScheduler = {use_test_scheduler}
25 """
26
Pete Williamson 2016/11/02 20:30:29 Maybe you could provice a bit of guidance here in
romax 2016/11/03 01:46:50 Should I attach the link to the instructions? But
Pete Williamson 2016/11/03 18:21:11 It is better to have instructions here, since Chro
romax 2016/11/03 20:17:20 Done.
27
28 def main(args):
29 # Setting up the argument parser.
30 parser = argparse.ArgumentParser()
31 parser.add_argument(
32 '--output-directory',
33 dest='output_dir',
34 help='Directory for output, default is ~/offline_eval_output/')
Pete Williamson 2016/11/02 20:30:29 Thanks for adding the help!
romax 2016/11/03 01:46:50 :)
35 parser.add_argument(
36 '--url-timeout',
37 type=int,
38 dest='url_timeout',
39 help='Time out per url, in seconds.')
Pete Williamson 2016/11/02 20:30:29 Maybe mention default here, and in other help item
romax 2016/11/03 01:46:49 Done.
40 parser.add_argument(
41 '--user-request',
42 dest='user_request',
43 action='store_true',
44 help='Test as user-requested urls.')
Pete Williamson 2016/11/02 20:30:29 --user-request should default to true, does it? (
romax 2016/11/03 01:46:49 Done.
45 parser.add_argument(
46 '--use-test-scheduler',
47 dest='use_test_scheduler',
48 action='store_true',
49 help='Start processing immediately, no using GCMNetworkManager.')
50 parser.add_argument(
51 '-v',
52 '--verbose',
53 dest='verbose',
54 action='store_true',
55 help='Make test runner verbose.')
56 parser.add_argument('build_output_dir', help='Path to build directory.')
57 parser.add_argument(
58 'test_urls_file', help='Path to input file with urls to be tested.')
59 parser.set_defaults(
60 output_dir=os.path.expanduser('~/offline_eval_output'),
61 url_timeout=DEFAULT_URL_TIMEOUT,
62 user_request=DEFAULT_USER_REQUEST,
63 user_test_scheduler=DEFAULT_USE_TEST_SCHEDULER,
64 verbose=DEFAULT_VERBOSE)
65
66 # Get the arguments and several paths.
67 options, extra_args = parser.parse_known_args(args)
68
69 if extra_args:
70 print 'Unknown args: ' + ', '.join(
71 extra_args) + '. Please check and run again.'
72 return
73
74 build_dir_path = os.path.abspath(
75 os.path.join(os.getcwd(), options.build_output_dir))
76 test_runner_path = os.path.join(build_dir_path,
77 'bin/run_chrome_public_test_apk')
78 config_output_path = os.path.join(options.output_dir, CONFIG_FILENAME)
79
80 # Create the output directory for results, and have a copy of test config
81 # there.
82 if not os.path.exists(options.output_dir):
83 print 'Creating output directory for results... ' + options.output_dir
84 os.makedirs(options.output_dir)
85 with open(config_output_path, 'w') as config:
86 config.write(
87 CONFIG_TEMPLATE.format(
88 timeout_per_url_in_seconds=options.url_timeout,
89 is_user_requested=options.user_request,
90 use_test_scheduler=options.use_test_scheduler))
91
92 print 'Uploading config file and input file onto the device.'
93 subprocess.call(
94 ['adb', 'push', config_output_path, '/sdcard/paquete/test_config'])
95 subprocess.call([
96 'adb', 'push', options.test_urls_file,
97 '/sdcard/paquete/offline_eval_urls.txt'
Pete Williamson 2016/11/02 20:30:29 What happens on a device with no SD card, like the
romax 2016/11/03 01:46:50 the 'virtual' external storage would be mounted to
Pete Williamson 2016/11/03 18:21:11 So will this work on my Nexus 5X and Nexus 6 devic
romax 2016/11/03 20:17:20 Done. Per discussion it should work, but I'd like
98 ])
99 print 'Start running test...'
100
101 # Run test
102 test_runner_cmd = [
103 test_runner_path, '-f',
104 'OfflinePageSavePageLaterEvaluationTest.testFailureRateWithTimeout'
105 ]
106 if options.verbose:
107 test_runner_cmd += ['-v']
108 subprocess.call(test_runner_cmd)
109
110 print 'Fetching results from device...'
111 archive_dir = os.path.join(options.output_dir, 'archives/')
112 if os.path.exists(archive_dir):
113 shutil.rmtree(archive_dir)
114 subprocess.call([
115 'adb', 'pull', '/data/data/org.chromium.chrome/app_chrome/'
116 'Default/Offline Pages/archives', archive_dir
117 ])
118 subprocess.call([
119 'adb', 'pull', '/sdcard/paquete/offline_eval_results.txt',
120 options.output_dir
121 ])
122 subprocess.call([
123 'adb', 'pull', '/sdcard/paquete/offline_eval_logs.txt', options.output_dir
124 ])
125 print 'Test finished!'
126
127
128 if __name__ == '__main__':
129 sys.exit(main(sys.argv[1:]))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698