| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 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 |
| Steve Block | d210fd2 | 2010-09-14 13:34:19 +0100 | [diff] [blame] | 6 | and optionally shows the detailed results the host's default browser. |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 7 | |
| 8 | Usage: |
| Steve Block | d210fd2 | 2010-09-14 13:34:19 +0100 | [diff] [blame] | 9 | run_layout_tests.py --show-results-in-browser test-relative-path |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 10 | """ |
| 11 | |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 12 | import logging |
| Steve Block | d210fd2 | 2010-09-14 13:34:19 +0100 | [diff] [blame] | 13 | import optparse |
| 14 | import os |
| Steve Block | 42bf092 | 2010-09-28 12:52:11 +0100 | [diff] [blame] | 15 | import re |
| Steve Block | d210fd2 | 2010-09-14 13:34:19 +0100 | [diff] [blame] | 16 | import sys |
| 17 | import subprocess |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 18 | import tempfile |
| Steve Block | d210fd2 | 2010-09-14 13:34:19 +0100 | [diff] [blame] | 19 | import webbrowser |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 20 | |
| Steve Block | ae47ce0 | 2010-10-15 17:39:09 +0100 | [diff] [blame] | 21 | import run_apache2 |
| 22 | |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 23 | #TODO: These should not be hardcoded |
| Steve Block | bdebd06 | 2010-09-13 15:55:13 +0100 | [diff] [blame] | 24 | RESULTS_ABSOLUTE_PATH = "/sdcard/layout-test-results/" |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 25 | DETAILS_HTML = "details.html" |
| 26 | SUMMARY_TXT = "summary.txt" |
| 27 | |
| Steve Block | fc16915 | 2010-10-18 12:39:42 +0100 | [diff] [blame] | 28 | def main(path, options): |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 29 | tmpdir = tempfile.gettempdir() |
| 30 | |
| Maksymilian Osowski | 2e36737 | 2010-09-14 16:09:11 +0100 | [diff] [blame] | 31 | # Restart the server |
| Steve Block | ae47ce0 | 2010-10-15 17:39:09 +0100 | [diff] [blame] | 32 | if run_apache2.main("restart", options) == False: |
| 33 | return |
| Maksymilian Osowski | 2e36737 | 2010-09-14 16:09:11 +0100 | [diff] [blame] | 34 | |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 35 | # Run the tests in path |
| Guang Zhu | 82c11b4 | 2010-09-27 11:58:15 -0700 | [diff] [blame] | 36 | adb_cmd = "adb" |
| 37 | if options.serial: |
| 38 | adb_cmd += " -s " + options.serial |
| 39 | cmd = adb_cmd + " shell am instrument " |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 40 | cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests " |
| 41 | cmd += "-e path \"" + path + "\" " |
| Steve Block | 42bf092 | 2010-09-28 12:52:11 +0100 | [diff] [blame] | 42 | cmd += "-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner" |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 43 | |
| 44 | logging.info("Running the tests...") |
| Philippe Marti | 84cc2db | 2010-12-17 14:49:19 +0000 | [diff] [blame] | 45 | logging.debug("Command = %s" % cmd) |
| Steve Block | 42bf092 | 2010-09-28 12:52:11 +0100 | [diff] [blame] | 46 | (stdoutdata, stderrdata) = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() |
| Steve Block | 31e446c | 2011-05-20 17:39:30 +0100 | [diff] [blame] | 47 | if stderrdata != "": |
| 48 | logging.info("Failed to start tests:\n%s", stderrdata) |
| 49 | return |
| Steve Block | 42bf092 | 2010-09-28 12:52:11 +0100 | [diff] [blame] | 50 | 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 Block | 31e446c | 2011-05-20 17:39:30 +0100 | [diff] [blame] | 53 | 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 Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 56 | |
| 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 Block | 5c27bc1c | 2010-09-13 16:00:42 +0100 | [diff] [blame] | 61 | cmd = "rm -f " + summary_txt_tmp_path + ";" |
| Guang Zhu | 82c11b4 | 2010-09-27 11:58:15 -0700 | [diff] [blame] | 62 | cmd += adb_cmd + " pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path |
| Steve Block | 42bf092 | 2010-09-28 12:52:11 +0100 | [diff] [blame] | 63 | subprocess.Popen(cmd, shell=True).wait() |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 64 | |
| 65 | # Download the html summary to tmp folder |
| 66 | details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML) |
| Steve Block | 5c27bc1c | 2010-09-13 16:00:42 +0100 | [diff] [blame] | 67 | cmd = "rm -f " + details_html_tmp_path + ";" |
| Guang Zhu | 82c11b4 | 2010-09-27 11:58:15 -0700 | [diff] [blame] | 68 | cmd += adb_cmd + " pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path |
| Steve Block | 42bf092 | 2010-09-28 12:52:11 +0100 | [diff] [blame] | 69 | subprocess.Popen(cmd, shell=True).wait() |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 70 | |
| 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 Block | d210fd2 | 2010-09-14 13:34:19 +0100 | [diff] [blame] | 78 | if options.show_results_in_browser != "false": |
| 79 | webbrowser.open(details_html_tmp_path) |
| Maksymilian Osowski | 5fb9ff4 | 2010-08-09 14:35:05 +0100 | [diff] [blame] | 80 | |
| 81 | if __name__ == "__main__": |
| Steve Block | d210fd2 | 2010-09-14 13:34:19 +0100 | [diff] [blame] | 82 | 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 Osowski | 78fbc54 | 2010-09-16 19:13:01 +0100 | [diff] [blame] | 85 | 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 Zhu | 82c11b4 | 2010-09-27 11:58:15 -0700 | [diff] [blame] | 87 | option_parser.add_option("-s", "--serial", default=None, help="Specify the serial number of device to run test on") |
| Steve Block | d210fd2 | 2010-09-14 13:34:19 +0100 | [diff] [blame] | 88 | options, args = option_parser.parse_args(); |
| Steve Block | fc16915 | 2010-10-18 12:39:42 +0100 | [diff] [blame] | 89 | |
| 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); |