1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
#!/usr/bin/python
"""Run page cycler tests using Android instrumentation.
First, you need to get an SD card or sdcard image that has page cycler tests.
Usage:
Run a single page cycler test:
run_page_cycler.py "file:///sdcard/webkit/page_cycler/moz/start.html\?auto=1\&iterations=10"
"""
import logging
import optparse
import os
import subprocess
import sys
import time
def main(options, args):
"""Run the tests. Will call sys.exit when complete.
"""
# Set up logging format.
log_level = logging.INFO
if options.verbose:
log_level = logging.DEBUG
logging.basicConfig(level=log_level,
format='%(message)s')
# Include all tests if none are specified.
if not args:
print "need a URL, e.g. file:///sdcard/webkit/page_cycler/moz/start.html\?auto=1\&iterations=10"
print " or remote:android-browser-test:80/page_cycler/"
sys.exit(1)
else:
path = ' '.join(args);
if path[:7] == "remote:":
remote_path = path[7:]
else:
remote_path = None
adb_cmd = "adb ";
if options.adb_options:
adb_cmd += options.adb_options
logging.info("Running the test ...")
# Count crashed tests.
crashed_tests = []
timeout_ms = '0'
if options.time_out_ms:
timeout_ms = options.time_out_ms
# Run test until it's done
run_load_test_cmd_prefix = adb_cmd + " shell am instrument"
run_load_test_cmd_postfix = " -w com.android.dumprendertree/.LayoutTestsAutoRunner"
# Call LoadTestsAutoTest::runTest.
run_load_test_cmd = run_load_test_cmd_prefix + " -e class com.android.dumprendertree.LoadTestsAutoTest#runPageCyclerTest -e timeout " + timeout_ms
if remote_path:
if options.suite:
run_load_test_cmd += " -e suite %s -e forward %s " % (options.suite,
remote_path)
else:
print "for network mode, need to specify --suite as well."
sys.exit(1)
if options.iteration:
run_load_test_cmd += " -e iteration %s" % options.iteration
else:
run_load_test_cmd += " -e path \"%s\" " % path
if options.drawtime:
run_load_test_cmd += " -e drawtime true "
if options.save_image:
run_load_test_cmd += " -e saveimage \"%s\"" % options.save_image
run_load_test_cmd += run_load_test_cmd_postfix
(adb_output, adb_error) = subprocess.Popen(run_load_test_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
fail_flag = False
for line in adb_output.splitlines():
line = line.strip()
if line.find('INSTRUMENTATION_CODE') == 0:
if not line[22:] == '-1':
fail_flag = True
break
if (line.find('INSTRUMENTATION_FAILED') != -1 or
line.find('Process crashed.') != -1):
fail_flag = True
break
if fail_flag:
logging.error("Error happened : " + adb_output)
sys.exit(1)
logging.info(adb_output);
logging.info(adb_error);
logging.info("Done\n");
# Pull results from /sdcard/load_test_result.txt
results_dir = options.results_directory
if not os.path.exists(results_dir):
os.makedirs(results_dir)
if not os.path.isdir(results_dir):
logging.error("Cannot create results dir: " + results_dir)
sys.exit(1)
result_file = "/sdcard/load_test_result.txt"
shell_cmd_str = adb_cmd + " pull " + result_file + " " + results_dir
(adb_output, err) = subprocess.Popen(
shell_cmd_str, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
if not os.path.isfile(os.path.join(results_dir, "load_test_result.txt")):
logging.error("Failed to pull result file.")
logging.error("adb stdout:")
logging.error(adb_output)
logging.error("adb stderr:")
logging.error(err)
logging.info("Results are stored under: " + results_dir + "/load_test_result.txt\n")
if '__main__' == __name__:
option_parser = optparse.OptionParser()
option_parser.add_option("-t", "--time-out-ms",
default=None,
help="set the timeout for each test")
option_parser.add_option("-v", "--verbose", action="store_true",
default=False,
help="include debug-level logging")
option_parser.add_option("-a", "--adb-options",
default=None,
help="pass options to adb, such as -d -e, etc");
option_parser.add_option("-r", "--results-directory",
default="layout-test-results",
help="directory which results are stored.")
option_parser.add_option("-d", "--drawtime", action="store_true",
default=False,
help="log draw time for each page rendered.")
option_parser.add_option("-s", "--save-image",
default=None,
help="stores rendered page to a location on device.")
option_parser.add_option("-u", "--suite",
default=None,
help="(for network mode) specify the suite to"
" run by name")
option_parser.add_option("-i", "--iteration",
default="5",
help="(for network mode) specify how many iterations"
" to run")
options, args = option_parser.parse_args();
main(options, args)
|