The Android Open Source Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 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 | |
| 12 | import logging |
| 13 | import optparse |
| 14 | import os |
| 15 | import subprocess |
| 16 | import sys |
| 17 | import time |
| 18 | |
| 19 | |
| 20 | |
| 21 | def 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#runTest -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 | if adb_output.find('INSTRUMENTATION_FAILED') != -1: |
| 63 | logging.error("Error happened : " + adb_output) |
| 64 | sys.exit(1) |
| 65 | |
| 66 | logging.info(adb_output); |
| 67 | logging.info(adb_error); |
| 68 | logging.info("Done\n"); |
| 69 | |
| 70 | # Pull results from /sdcard/load_test_result.txt |
| 71 | results_dir = options.results_directory |
| 72 | if not os.path.exists(results_dir): |
| 73 | os.makedirs(results_dir) |
| 74 | if not os.path.isdir(results_dir): |
| 75 | logging.error("Cannot create results dir: " + results_dir) |
| 76 | sys.exit(1) |
| 77 | |
| 78 | result_file = "/sdcard/load_test_result.txt" |
| 79 | shell_cmd_str = adb_cmd + " pull " + result_file + " " + results_dir |
| 80 | adb_output = subprocess.Popen(shell_cmd_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0] |
| 81 | logging.info(adb_output) |
| 82 | |
| 83 | logging.info("Results are stored under: " + results_dir + "/load_test_result.txt\n") |
| 84 | |
| 85 | if '__main__' == __name__: |
| 86 | option_parser = optparse.OptionParser() |
| 87 | option_parser.add_option("", "--time-out-ms", |
| 88 | default=None, |
| 89 | help="set the timeout for each test") |
| 90 | option_parser.add_option("", "--verbose", action="store_true", |
| 91 | default=False, |
| 92 | help="include debug-level logging") |
| 93 | option_parser.add_option("", "--adb-options", |
| 94 | default=None, |
| 95 | help="pass options to adb, such as -d -e, etc"); |
| 96 | option_parser.add_option("", "--results-directory", |
| 97 | default="layout-test-results", |
| 98 | help="directory which results are stored.") |
| 99 | |
| 100 | options, args = option_parser.parse_args(); |
| 101 | main(options, args) |