run_layout_tests.py revision 2e367376690282a262cfcbd21d4c18862b48f38c
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 sys 16import subprocess 17import tempfile 18import webbrowser 19 20#TODO: These should not be hardcoded 21RESULTS_ABSOLUTE_PATH = "/sdcard/layout-test-results/" 22DETAILS_HTML = "details.html" 23SUMMARY_TXT = "summary.txt" 24 25def main(options, args): 26 if args: 27 path = " ".join(args); 28 else: 29 path = ""; 30 31 logging.basicConfig(level=logging.INFO, format='%(message)s') 32 33 tmpdir = tempfile.gettempdir() 34 35 # Restart the server 36 cmd = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "run_apache2.py") + " restart" 37 os.system(cmd); 38 39 # Run the tests in path 40 cmd = "adb shell am instrument " 41 cmd += "-e class com.android.dumprendertree2.scriptsupport.Starter#startLayoutTests " 42 cmd += "-e path \"" + path + "\" " 43 cmd +="-w com.android.dumprendertree2/com.android.dumprendertree2.scriptsupport.ScriptTestRunner" 44 45 logging.info("Running the tests...") 46 subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() 47 48 logging.info("Downloading the summaries...") 49 50 # Download the txt summary to tmp folder 51 summary_txt_tmp_path = os.path.join(tmpdir, SUMMARY_TXT) 52 cmd = "rm -f " + summary_txt_tmp_path + ";" 53 cmd += "adb pull " + RESULTS_ABSOLUTE_PATH + SUMMARY_TXT + " " + summary_txt_tmp_path 54 subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() 55 56 # Download the html summary to tmp folder 57 details_html_tmp_path = os.path.join(tmpdir, DETAILS_HTML) 58 cmd = "rm -f " + details_html_tmp_path + ";" 59 cmd += "adb pull " + RESULTS_ABSOLUTE_PATH + DETAILS_HTML + " " + details_html_tmp_path 60 subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() 61 62 # Print summary to console 63 logging.info("All done.\n") 64 cmd = "cat " + summary_txt_tmp_path 65 os.system(cmd) 66 logging.info("") 67 68 # Open the browser with summary 69 if options.show_results_in_browser != "false": 70 webbrowser.open(details_html_tmp_path) 71 72if __name__ == "__main__": 73 option_parser = optparse.OptionParser(usage="Usage: %prog [options] test-relative-path") 74 option_parser.add_option("", "--show-results-in-browser", default="true", 75 help="Show the results the host's default web browser, default=true") 76 options, args = option_parser.parse_args(); 77 main(options, args); 78