run_layout_tests.py revision 78fbc54c182cfc6b21fe745213b02b7ea18775e7
1#!/usr/bin/python
2
3"""Run layout tests on the device.
4
5  It runs the specified tests on the device, downloads the summaries to the temporary directory
6  and optionally shows the detailed results the host's default browser.
7
8  Usage:
9    run_layout_tests.py --show-results-in-browser test-relative-path
10"""
11
12import logging
13import optparse
14import os
15import sys
16import subprocess
17import tempfile
18import webbrowser
19
20#TODO: These should not be hardcoded
21RESULTS_ABSOLUTE_PATH = "/sdcard/layout-test-results/"
22DETAILS_HTML = "details.html"
23SUMMARY_TXT = "summary.txt"
24
25def main(options, args):
26  if args:
27    path = " ".join(args);
28  else:
29    path = "";
30
31  logging.basicConfig(level=logging.INFO, format='%(message)s')
32
33  tmpdir = tempfile.gettempdir()
34
35  if options.tests_root_directory != None:
36    # if options.tests_root_directory is absolute, os.getcwd() is discarded!
37    tests_root_directory = os.path.normpath(os.path.join(os.getcwd(), options.tests_root_directory))
38    server_options = " --tests-root-directory=" + tests_root_directory
39  else:
40    server_options = "";
41
42  # Restart the server
43  cmd = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "run_apache2.py") + server_options + " restart"
44  os.system(cmd);
45
46  # Run the tests in path
47  cmd = "adb shell am instrument "
48  cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests "
49  cmd += "-e path \"" + path + "\" "
50  cmd +="-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner"
51
52  logging.info("Running the tests...")
53  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
54
55  logging.info("Downloading the summaries...")
56
57  # Download the txt summary to tmp folder
58  summary_txt_tmp_path = os.path.join(tmpdir, SUMMARY_TXT)
59  cmd = "rm -f " + summary_txt_tmp_path + ";"
60  cmd += "adb pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path
61  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
62
63  # Download the html summary to tmp folder
64  details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML)
65  cmd = "rm -f " + details_html_tmp_path + ";"
66  cmd += "adb pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path
67  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
68
69  # Print summary to console
70  logging.info("All done.\n")
71  cmd = "cat " + summary_txt_tmp_path
72  os.system(cmd)
73  logging.info("")
74
75  # Open the browser with summary
76  if options.show_results_in_browser != "false":
77    webbrowser.open(details_html_tmp_path)
78
79if __name__ == "__main__":
80  option_parser = optparse.OptionParser(usage="Usage: %prog [options] test-relative-path")
81  option_parser.add_option("", "--show-results-in-browser", default="true",
82                           help="Show the results the host's default web browser, default=true")
83  option_parser.add_option("", "--tests-root-directory",
84                           help="The directory from which to take the tests, default is external/webkit/LayoutTests in this checkout of the Android tree")
85  options, args = option_parser.parse_args();
86  main(options, args);
87