run_layout_tests.py revision 5c27bc1c64a06ccec64da81bd0217b7aa3592786
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 = "rm -f " + summary_txt_tmp_path + ";"
48  cmd += "adb pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path
49  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
50
51  # Download the html summary to tmp folder
52  details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML)
53  cmd = "rm -f " + details_html_tmp_path + ";"
54  cmd += "adb pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path
55  subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
56
57  # Print summary to console
58  logging.info("All done.\n")
59  cmd = "cat " + summary_txt_tmp_path
60  os.system(cmd)
61  logging.info("")
62
63  # Open the browser with summary
64  webbrowser.open(details_html_tmp_path)
65
66if __name__ == "__main__":
67  main();
68