run_layout_tests.py revision bdebd0621b2a4422a30bea21ea549afd20a9e918
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 opens html details in the default browser.
7
8  Usage:
9    run_layout_tests.py PATH
10"""
11
12import sys
13import os
14import subprocess
15import logging
16import webbrowser
17import tempfile
18
19#TODO: These should not be hardcoded
20RESULTS_ABSOLUTE_PATH = "/sdcard/layout-test-results/"
21DETAILS_HTML = "details.html"
22SUMMARY_TXT = "summary.txt"
23
24def main():
25  if len(sys.argv) > 1:
26    path = sys.argv[1]
27  else:
28    path = ""
29
30  logging.basicConfig(level=logging.INFO, format='%(message)s')
31
32  tmpdir = tempfile.gettempdir()
33
34  # Run the tests in path
35  cmd = "adb shell am instrument "
36  cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests "
37  cmd += "-e path \"" + path + "\" "
38  cmd +="-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner"
39
40  logging.info("Running the tests...")
41  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
42
43  logging.info("Downloading the summaries...")
44
45  # Download the txt summary to tmp folder
46  summary_txt_tmp_path = os.path.join(tmpdir, SUMMARY_TXT)
47  cmd = "adb pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path
48  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
49
50  # Download the html summary to tmp folder
51  details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML)
52  cmd = "adb pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path
53  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
54
55  # Print summary to console
56  logging.info("All done.\n")
57  cmd = "cat " + summary_txt_tmp_path
58  os.system(cmd)
59  logging.info("")
60
61  # Open the browser with summary
62  webbrowser.open(details_html_tmp_path)
63
64if __name__ == "__main__":
65  main();
66