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
|
|
|
|
|
|
|
#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-09-14 13:34:19 +01:00
|
|
|
def main(options, args):
|
|
|
|
if args:
|
|
|
|
path = " ".join(args);
|
2010-08-09 14:35:05 +01:00
|
|
|
else:
|
2010-09-14 13:34:19 +01:00
|
|
|
path = "";
|
2010-08-09 14:35:05 +01:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO, format='%(message)s')
|
|
|
|
|
|
|
|
tmpdir = tempfile.gettempdir()
|
|
|
|
|
2010-09-16 19:13:01 +01:00
|
|
|
if options.tests_root_directory != None:
|
|
|
|
# if options.tests_root_directory is absolute, os.getcwd() is discarded!
|
|
|
|
tests_root_directory = os.path.normpath(os.path.join(os.getcwd(), options.tests_root_directory))
|
|
|
|
server_options = " --tests-root-directory=" + tests_root_directory
|
|
|
|
else:
|
|
|
|
server_options = "";
|
|
|
|
|
2010-09-14 16:09:11 +01:00
|
|
|
# Restart the server
|
2010-09-16 19:13:01 +01:00
|
|
|
cmd = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "run_apache2.py") + server_options + " restart"
|
2010-09-14 16:09:11 +01:00
|
|
|
os.system(cmd);
|
|
|
|
|
2010-08-09 14:35:05 +01:00
|
|
|
# Run the tests in path
|
|
|
|
cmd = "adb shell am instrument "
|
|
|
|
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-09-28 12:52:11 +01:00
|
|
|
(stdoutdata, stderrdata) = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
|
|
|
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
|
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 + ";"
|
|
|
|
cmd += "adb 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 + ";"
|
|
|
|
cmd += "adb 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-14 13:34:19 +01:00
|
|
|
options, args = option_parser.parse_args();
|
|
|
|
main(options, args);
|