run_layout_tests.py revision d210fd26b2f32fec26c2e7bb355de8b5b3e25b79
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  # Run the tests in path
36  cmd = "adb shell am instrument "
37  cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests "
38  cmd += "-e path \"" + path + "\" "
39  cmd +="-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner"
40
41  logging.info("Running the tests...")
42  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
43
44  logging.info("Downloading the summaries...")
45
46  # Download the txt summary to tmp folder
47  summary_txt_tmp_path = os.path.join(tmpdir, SUMMARY_TXT)
48  cmd = "rm -f " + summary_txt_tmp_path + ";"
49  cmd += "adb pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path
50  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
51
52  # Download the html summary to tmp folder
53  details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML)
54  cmd = "rm -f " + details_html_tmp_path + ";"
55  cmd += "adb pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path
56  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
57
58  # Print summary to console
59  logging.info("All done.\n")
60  cmd = "cat " + summary_txt_tmp_path
61  os.system(cmd)
62  logging.info("")
63
64  # Open the browser with summary
65  if options.show_results_in_browser != "false":
66    webbrowser.open(details_html_tmp_path)
67
68if __name__ == "__main__":
69  option_parser = optparse.OptionParser(usage="Usage: %prog [options] test-relative-path")
70  option_parser.add_option("", "--show-results-in-browser", default="true",
71                           help="Show the results the host's default web browser, default=true")
72  options, args = option_parser.parse_args();
73  main(options, args);
74