run_page_cycler.py revision 60ef21a5daff22dca1c562da8d131c67c8587353
1#!/usr/bin/python 2 3"""Run page cycler tests using Android instrumentation. 4 5 First, you need to get an SD card or sdcard image that has page cycler tests. 6 7 Usage: 8 Run a single page cycler test: 9 run_page_cycler.py "file:///sdcard/android/page_cycler/moz/start.html?auto=1\&iterations=10" 10""" 11 12import logging 13import optparse 14import os 15import subprocess 16import sys 17import time 18 19 20 21def main(options, args): 22 """Run the tests. Will call sys.exit when complete. 23 24 """ 25 26 # Set up logging format. 27 log_level = logging.INFO 28 if options.verbose: 29 log_level = logging.DEBUG 30 logging.basicConfig(level=log_level, 31 format='%(message)s') 32 33 # Include all tests if none are specified. 34 if not args: 35 print "need a URL, e.g. file:///sdcard/android/page_cycler/moz/start.html" 36 sys.exit(1) 37 else: 38 path = ' '.join(args); 39 40 adb_cmd = "adb "; 41 if options.adb_options: 42 adb_cmd += options.adb_options 43 44 logging.info("Running the test ...") 45 46 # Count crashed tests. 47 crashed_tests = [] 48 49 timeout_ms = '0' 50 if options.time_out_ms: 51 timeout_ms = options.time_out_ms 52 53 # Run test until it's done 54 55 run_load_test_cmd_prefix = adb_cmd + " shell am instrument" 56 run_load_test_cmd_postfix = " -w com.android.dumprendertree/.LayoutTestsAutoRunner" 57 58 # Call LoadTestsAutoTest::runTest. 59 run_load_test_cmd = run_load_test_cmd_prefix + " -e class com.android.dumprendertree.LoadTestsAutoTest#runPageCyclerTest -e path \"" + path + "\" -e timeout " + timeout_ms + run_load_test_cmd_postfix 60 61 (adb_output, adb_error) = subprocess.Popen(run_load_test_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() 62 fail_flag = False 63 for line in adb_output.splitlines(): 64 line = line.strip() 65 if line.find('INSTRUMENTATION_CODE') == 0: 66 if not line[22:] == '-1': 67 fail_flag = True 68 break 69 if (line.find('INSTRUMENTATION_FAILED') != -1 or 70 line.find('Process crashed.') != -1): 71 fail_flag = True 72 break 73 if fail_flag: 74 logging.error("Error happened : " + adb_output) 75 sys.exit(1) 76 77 logging.info(adb_output); 78 logging.info(adb_error); 79 logging.info("Done\n"); 80 81 # Pull results from /sdcard/load_test_result.txt 82 results_dir = options.results_directory 83 if not os.path.exists(results_dir): 84 os.makedirs(results_dir) 85 if not os.path.isdir(results_dir): 86 logging.error("Cannot create results dir: " + results_dir) 87 sys.exit(1) 88 89 result_file = "/sdcard/load_test_result.txt" 90 shell_cmd_str = adb_cmd + " pull " + result_file + " " + results_dir 91 adb_output = subprocess.Popen(shell_cmd_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] 92 logging.info(adb_output) 93 logging.info("Results are stored under: " + results_dir + "/load_test_result.txt\n") 94 95if '__main__' == __name__: 96 option_parser = optparse.OptionParser() 97 option_parser.add_option("", "--time-out-ms", 98 default=None, 99 help="set the timeout for each test") 100 option_parser.add_option("", "--verbose", action="store_true", 101 default=False, 102 help="include debug-level logging") 103 option_parser.add_option("", "--adb-options", 104 default=None, 105 help="pass options to adb, such as -d -e, etc"); 106 option_parser.add_option("", "--results-directory", 107 default="layout-test-results", 108 help="directory which results are stored.") 109 110 options, args = option_parser.parse_args(); 111 main(options, args) 112