2010-08-09 14:35:05 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
"""Run layout tests on the device.
|
|
|
|
|
|
|
|
It runs the specified tests on the device, downloads the summaries to the temporary directory
|
2010-09-14 13:34:19 +01:00
|
|
|
and optionally shows the detailed results the host's default browser.
|
2010-08-09 14:35:05 +01:00
|
|
|
|
|
|
|
Usage:
|
2010-09-14 13:34:19 +01:00
|
|
|
run_layout_tests.py --show-results-in-browser test-relative-path
|
2010-08-09 14:35:05 +01:00
|
|
|
"""
|
|
|
|
|
2010-09-14 13:34:19 +01:00
|
|
|
import logging
|
|
|
|
import optparse
|
2010-08-09 14:35:05 +01:00
|
|
|
import os
|
2010-09-28 12:52:11 +01:00
|
|
|
import re
|
2010-09-14 13:34:19 +01:00
|
|
|
import sys
|
2010-08-09 14:35:05 +01:00
|
|
|
import subprocess
|
|
|
|
import tempfile
|
2010-09-14 13:34:19 +01:00
|
|
|
import webbrowser
|
2010-08-09 14:35:05 +01:00
|
|
|
|
2010-10-15 17:39:09 +01:00
|
|
|
import run_apache2
|
|
|
|
|
2010-08-09 14:35:05 +01:00
|
|
|
#TODO: These should not be hardcoded
|
2010-09-13 15:55:13 +01:00
|
|
|
RESULTS_ABSOLUTE_PATH = "/sdcard/layout-test-results/"
|
2010-08-09 14:35:05 +01:00
|
|
|
DETAILS_HTML = "details.html"
|
|
|
|
SUMMARY_TXT = "summary.txt"
|
|
|
|
|
2010-10-18 12:39:42 +01:00
|
|
|
def main(path, options):
|
2010-08-09 14:35:05 +01:00
|
|
|
tmpdir = tempfile.gettempdir()
|
|
|
|
|
2010-09-14 16:09:11 +01:00
|
|
|
# Restart the server
|
2010-10-15 17:39:09 +01:00
|
|
|
if run_apache2.main("restart", options) == False:
|
|
|
|
return
|
2010-09-14 16:09:11 +01:00
|
|
|
|
2010-08-09 14:35:05 +01:00
|
|
|
# Run the tests in path
|
2010-09-27 11:58:15 -07:00
|
|
|
adb_cmd = "adb"
|
|
|
|
if options.serial:
|
|
|
|
adb_cmd += " -s " + options.serial
|
|
|
|
cmd = adb_cmd + " shell am instrument "
|
2010-08-09 14:35:05 +01:00
|
|
|
cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests "
|
|
|
|
cmd += "-e path \"" + path + "\" "
|
2010-09-28 12:52:11 +01:00
|
|
|
cmd += "-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner"
|
2010-08-09 14:35:05 +01:00
|
|
|
|
|
|
|
logging.info("Running the tests...")
|
2010-12-17 14:49:19 +00:00
|
|
|
logging.debug("Command = %s" % cmd)
|
2010-09-28 12:52:11 +01:00
|
|
|
(stdoutdata, stderrdata) = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
2011-05-20 17:39:30 +01:00
|
|
|
if stderrdata != "":
|
|
|
|
logging.info("Failed to start tests:\n%s", stderrdata)
|
|
|
|
return
|
2010-09-28 12:52:11 +01:00
|
|
|
if re.search("^INSTRUMENTATION_STATUS_CODE: -1", stdoutdata, re.MULTILINE) != None:
|
|
|
|
logging.info("Failed to run the tests. Is DumpRenderTree2 installed on the device?")
|
|
|
|
return
|
2011-05-20 17:39:30 +01:00
|
|
|
if re.search("^OK \([0-9]+ tests?\)", stdoutdata, re.MULTILINE) == None:
|
|
|
|
logging.info("DumpRenderTree2 failed to run correctly:\n%s", stdoutdata)
|
|
|
|
return
|
2010-08-09 14:35:05 +01:00
|
|
|
|
|
|
|
logging.info("Downloading the summaries...")
|
|
|
|
|
|
|
|
# Download the txt summary to tmp folder
|
|
|
|
summary_txt_tmp_path = os.path.join(tmpdir, SUMMARY_TXT)
|
2010-09-13 16:00:42 +01:00
|
|
|
cmd = "rm -f " + summary_txt_tmp_path + ";"
|
2010-09-27 11:58:15 -07:00
|
|
|
cmd += adb_cmd + " pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path
|
2010-09-28 12:52:11 +01:00
|
|
|
subprocess.Popen(cmd, shell=True).wait()
|
2010-08-09 14:35:05 +01:00
|
|
|
|
|
|
|
# Download the html summary to tmp folder
|
|
|
|
details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML)
|
2010-09-13 16:00:42 +01:00
|
|
|
cmd = "rm -f " + details_html_tmp_path + ";"
|
2010-09-27 11:58:15 -07:00
|
|
|
cmd += adb_cmd + " pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path
|
2010-09-28 12:52:11 +01:00
|
|
|
subprocess.Popen(cmd, shell=True).wait()
|
2010-08-09 14:35:05 +01:00
|
|
|
|
|
|
|
# Print summary to console
|
|
|
|
logging.info("All done.\n")
|
|
|
|
cmd = "cat " + summary_txt_tmp_path
|
|
|
|
os.system(cmd)
|
|
|
|
logging.info("")
|
|
|
|
|
|
|
|
# Open the browser with summary
|
2010-09-14 13:34:19 +01:00
|
|
|
if options.show_results_in_browser != "false":
|
|
|
|
webbrowser.open(details_html_tmp_path)
|
2010-08-09 14:35:05 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2010-09-14 13:34:19 +01:00
|
|
|
option_parser = optparse.OptionParser(usage="Usage: %prog [options] test-relative-path")
|
|
|
|
option_parser.add_option("", "--show-results-in-browser", default="true",
|
|
|
|
help="Show the results the host's default web browser, default=true")
|
2010-09-16 19:13:01 +01:00
|
|
|
option_parser.add_option("", "--tests-root-directory",
|
|
|
|
help="The directory from which to take the tests, default is external/webkit/LayoutTests in this checkout of the Android tree")
|
2010-09-27 11:58:15 -07:00
|
|
|
option_parser.add_option("-s", "--serial", default=None, help="Specify the serial number of device to run test on")
|
2010-09-14 13:34:19 +01:00
|
|
|
options, args = option_parser.parse_args();
|
2010-10-18 12:39:42 +01:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
|
|
|
|
|
|
|
if len(args) > 1:
|
|
|
|
logging.fatal("Usage: run_layout_tests.py [options] test-relative-path")
|
|
|
|
else:
|
|
|
|
if len(args) < 1:
|
|
|
|
path = "";
|
|
|
|
else:
|
|
|
|
path = args[0]
|
|
|
|
main(path, options);
|