run_layout_tests.py revision 84cc2dbb1d9f935182fcbeb1ef68dc340d2ebade
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 re 16import sys 17import subprocess 18import tempfile 19import webbrowser 20 21import run_apache2 22 23#TODO: These should not be hardcoded 24RESULTS_ABSOLUTE_PATH = "/sdcard/layout-test-results/" 25DETAILS_HTML = "details.html" 26SUMMARY_TXT = "summary.txt" 27 28def main(path, options): 29 tmpdir = tempfile.gettempdir() 30 31 # Restart the server 32 if run_apache2.main("restart", options) == False: 33 return 34 35 # Run the tests in path 36 adb_cmd = "adb" 37 if options.serial: 38 adb_cmd += " -s " + options.serial 39 cmd = adb_cmd + " shell am instrument " 40 cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests " 41 cmd += "-e path \"" + path + "\" " 42 cmd += "-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner" 43 44 logging.info("Running the tests...") 45 logging.debug("Command = %s" % cmd) 46 (stdoutdata, stderrdata) = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() 47 if re.search("^INSTRUMENTATION_STATUS_CODE: -1", stdoutdata, re.MULTILINE) != None: 48 logging.info("Failed to run the tests. Is DumpRenderTree2 installed on the device?") 49 return 50 51 logging.info("Downloading the summaries...") 52 53 # Download the txt summary to tmp folder 54 summary_txt_tmp_path = os.path.join(tmpdir, SUMMARY_TXT) 55 cmd = "rm -f " + summary_txt_tmp_path + ";" 56 cmd += adb_cmd + " pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path 57 subprocess.Popen(cmd, shell=True).wait() 58 59 # Download the html summary to tmp folder 60 details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML) 61 cmd = "rm -f " + details_html_tmp_path + ";" 62 cmd += adb_cmd + " pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path 63 subprocess.Popen(cmd, shell=True).wait() 64 65 # Print summary to console 66 logging.info("All done.\n") 67 cmd = "cat " + summary_txt_tmp_path 68 os.system(cmd) 69 logging.info("") 70 71 # Open the browser with summary 72 if options.show_results_in_browser != "false": 73 webbrowser.open(details_html_tmp_path) 74 75if __name__ == "__main__": 76 option_parser = optparse.OptionParser(usage="Usage: %prog [options] test-relative-path") 77 option_parser.add_option("", "--show-results-in-browser", default="true", 78 help="Show the results the host's default web browser, default=true") 79 option_parser.add_option("", "--tests-root-directory", 80 help="The directory from which to take the tests, default is external/webkit/LayoutTests in this checkout of the Android tree") 81 option_parser.add_option("-s", "--serial", default=None, help="Specify the serial number of device to run test on") 82 options, args = option_parser.parse_args(); 83 84 logging.basicConfig(level=logging.INFO, format='%(message)s') 85 86 if len(args) > 1: 87 logging.fatal("Usage: run_layout_tests.py [options] test-relative-path") 88 else: 89 if len(args) < 1: 90 path = ""; 91 else: 92 path = args[0] 93 main(path, options); 94