blob: 161416ad168160188233ae3ddbaa2779823602f6 [file] [log] [blame]
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +01001#!/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
Steve Blockd210fd22010-09-14 13:34:19 +01006 and optionally shows the detailed results the host's default browser.
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +01007
8 Usage:
Steve Blockd210fd22010-09-14 13:34:19 +01009 run_layout_tests.py --show-results-in-browser test-relative-path
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010010"""
11
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010012import logging
Steve Blockd210fd22010-09-14 13:34:19 +010013import optparse
14import os
Steve Block42bf0922010-09-28 12:52:11 +010015import re
Steve Blockd210fd22010-09-14 13:34:19 +010016import sys
17import subprocess
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010018import tempfile
Steve Blockd210fd22010-09-14 13:34:19 +010019import webbrowser
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010020
Steve Blockae47ce02010-10-15 17:39:09 +010021import run_apache2
22
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010023#TODO: These should not be hardcoded
Steve Blockbdebd062010-09-13 15:55:13 +010024RESULTS_ABSOLUTE_PATH = "/sdcard/layout-test-results/"
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010025DETAILS_HTML = "details.html"
26SUMMARY_TXT = "summary.txt"
27
Steve Blockfc169152010-10-18 12:39:42 +010028def main(path, options):
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010029 tmpdir = tempfile.gettempdir()
30
Maksymilian Osowski2e367372010-09-14 16:09:11 +010031 # Restart the server
Steve Blockae47ce02010-10-15 17:39:09 +010032 if run_apache2.main("restart", options) == False:
33 return
Maksymilian Osowski2e367372010-09-14 16:09:11 +010034
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010035 # Run the tests in path
Guang Zhu82c11b42010-09-27 11:58:15 -070036 adb_cmd = "adb"
37 if options.serial:
38 adb_cmd += " -s " + options.serial
39 cmd = adb_cmd + " shell am instrument "
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010040 cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests "
41 cmd += "-e path \"" + path + "\" "
Steve Block42bf0922010-09-28 12:52:11 +010042 cmd += "-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner"
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010043
44 logging.info("Running the tests...")
Philippe Marti84cc2db2010-12-17 14:49:19 +000045 logging.debug("Command = %s" % cmd)
Steve Block42bf0922010-09-28 12:52:11 +010046 (stdoutdata, stderrdata) = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
Steve Block31e446c2011-05-20 17:39:30 +010047 if stderrdata != "":
48 logging.info("Failed to start tests:\n%s", stderrdata)
49 return
Steve Block42bf0922010-09-28 12:52:11 +010050 if re.search("^INSTRUMENTATION_STATUS_CODE: -1", stdoutdata, re.MULTILINE) != None:
51 logging.info("Failed to run the tests. Is DumpRenderTree2 installed on the device?")
52 return
Steve Block31e446c2011-05-20 17:39:30 +010053 if re.search("^OK \([0-9]+ tests?\)", stdoutdata, re.MULTILINE) == None:
54 logging.info("DumpRenderTree2 failed to run correctly:\n%s", stdoutdata)
55 return
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010056
57 logging.info("Downloading the summaries...")
58
59 # Download the txt summary to tmp folder
60 summary_txt_tmp_path = os.path.join(tmpdir, SUMMARY_TXT)
Steve Block5c27bc1c2010-09-13 16:00:42 +010061 cmd = "rm -f " + summary_txt_tmp_path + ";"
Guang Zhu82c11b42010-09-27 11:58:15 -070062 cmd += adb_cmd + " pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path
Steve Block42bf0922010-09-28 12:52:11 +010063 subprocess.Popen(cmd, shell=True).wait()
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010064
65 # Download the html summary to tmp folder
66 details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML)
Steve Block5c27bc1c2010-09-13 16:00:42 +010067 cmd = "rm -f " + details_html_tmp_path + ";"
Guang Zhu82c11b42010-09-27 11:58:15 -070068 cmd += adb_cmd + " pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path
Steve Block42bf0922010-09-28 12:52:11 +010069 subprocess.Popen(cmd, shell=True).wait()
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010070
71 # Print summary to console
72 logging.info("All done.\n")
73 cmd = "cat " + summary_txt_tmp_path
74 os.system(cmd)
75 logging.info("")
76
77 # Open the browser with summary
Steve Blockd210fd22010-09-14 13:34:19 +010078 if options.show_results_in_browser != "false":
79 webbrowser.open(details_html_tmp_path)
Maksymilian Osowski5fb9ff42010-08-09 14:35:05 +010080
81if __name__ == "__main__":
Steve Blockd210fd22010-09-14 13:34:19 +010082 option_parser = optparse.OptionParser(usage="Usage: %prog [options] test-relative-path")
83 option_parser.add_option("", "--show-results-in-browser", default="true",
84 help="Show the results the host's default web browser, default=true")
Maksymilian Osowski78fbc542010-09-16 19:13:01 +010085 option_parser.add_option("", "--tests-root-directory",
86 help="The directory from which to take the tests, default is external/webkit/LayoutTests in this checkout of the Android tree")
Guang Zhu82c11b42010-09-27 11:58:15 -070087 option_parser.add_option("-s", "--serial", default=None, help="Specify the serial number of device to run test on")
Steve Blockd210fd22010-09-14 13:34:19 +010088 options, args = option_parser.parse_args();
Steve Blockfc169152010-10-18 12:39:42 +010089
90 logging.basicConfig(level=logging.INFO, format='%(message)s')
91
92 if len(args) > 1:
93 logging.fatal("Usage: run_layout_tests.py [options] test-relative-path")
94 else:
95 if len(args) < 1:
96 path = "";
97 else:
98 path = args[0]
99 main(path, options);