| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Apptest is a Mojo application that interacts with another Mojo application | 5 """Apptest is a Mojo application that interacts with another Mojo application |
| 6 and verifies assumptions about behavior of the app being tested. | 6 and verifies assumptions about behavior of the app being tested. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import logging | 9 import logging |
| 10 import time | 10 import time |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 Returns: | 24 Returns: |
| 25 Single list of shell arguments. | 25 Single list of shell arguments. |
| 26 """ | 26 """ |
| 27 result = list(shell_args) | 27 result = list(shell_args) |
| 28 if apptest_args: | 28 if apptest_args: |
| 29 result.append("--args-for=%s %s" % (apptest_url, " ".join(apptest_args))) | 29 result.append("--args-for=%s %s" % (apptest_url, " ".join(apptest_args))) |
| 30 result.append(apptest_url) | 30 result.append(apptest_url) |
| 31 return result | 31 return result |
| 32 | 32 |
| 33 | 33 |
| 34 def run_apptest(shell, shell_args, apptest_url, apptest_args, output_test): | 34 def run_apptest(shell, shell_args, apptest_url, apptest_args, timeout, |
| 35 output_test): |
| 35 """Runs shell with the given arguments, retrieves the output and applies | 36 """Runs shell with the given arguments, retrieves the output and applies |
| 36 |output_test| to determine if the run was successful. | 37 |output_test| to determine if the run was successful. |
| 37 | 38 |
| 38 Args: | 39 Args: |
| 39 shell: Wrapper around concrete Mojo shell, implementing devtools Shell | 40 shell: Wrapper around concrete Mojo shell, implementing devtools Shell |
| 40 interface. | 41 interface. |
| 41 shell_args: List of arguments for the shell run. | 42 shell_args: List of arguments for the shell run. |
| 42 apptest_url: Url of the apptest app to run. | 43 apptest_url: Url of the apptest app to run. |
| 43 apptest_args: Parameters to be passed to the apptest app. | 44 apptest_args: Parameters to be passed to the apptest app. |
| 44 output_test: Function accepting the shell output and returning True iff | 45 output_test: Function accepting the shell output and returning True iff |
| 45 the output indicates a successful run. | 46 the output indicates a successful run. |
| 46 | 47 |
| 47 Returns: | 48 Returns: |
| 48 True iff the test succeeded, False otherwise. | 49 True iff the test succeeded, False otherwise. |
| 49 """ | 50 """ |
| 50 arguments = _build_shell_arguments(shell_args, apptest_url, apptest_args) | 51 arguments = _build_shell_arguments(shell_args, apptest_url, apptest_args) |
| 51 command_line = "mojo_shell " + " ".join(["%r" % x for x in arguments]) | 52 command_line = "mojo_shell " + " ".join(["%r" % x for x in arguments]) |
| 52 | 53 |
| 53 _logger.debug("Starting: " + command_line) | 54 _logger.debug("Starting: " + command_line) |
| 54 start_time = time.time() | 55 start_time = time.time() |
| 55 (exit_code, output) = shell.RunAndGetOutput(arguments) | 56 (exit_code, output, did_time_out) = shell.RunAndGetOutput(arguments, timeout) |
| 56 run_time = time.time() - start_time | 57 run_time = time.time() - start_time |
| 57 _logger.debug("Completed: " + command_line) | 58 _logger.debug("Completed: " + command_line) |
| 58 | 59 |
| 59 # Only log if it took more than 3 second. | 60 # Only log if it took more than 3 second. |
| 60 if run_time >= 3: | 61 if run_time >= 3: |
| 61 _logger.info("Test took %.3f seconds: %s" % (run_time, command_line)) | 62 _logger.info("Test took %.3f seconds: %s" % (run_time, command_line)) |
| 62 | 63 |
| 63 if exit_code or not output_test(output): | 64 if exit_code or did_time_out or not output_test(output): |
| 64 print 'Failed test: %r' % command_line | 65 print 'Failed test: %r' % command_line |
| 65 if exit_code: | 66 if exit_code: |
| 66 print ' due to shell exit code %d' % exit_code | 67 print ' due to shell exit code %d' % exit_code |
| 68 elif did_time_out: |
| 69 print ' due to exceeded timeout of %fs' % timeout |
| 67 else: | 70 else: |
| 68 print ' due to test results' | 71 print ' due to test results' |
| 69 print 72 * '-' | 72 print 72 * '-' |
| 70 print output | 73 print output |
| 71 print 72 * '-' | 74 print 72 * '-' |
| 72 return False | 75 return False |
| 73 return True | 76 return True |
| OLD | NEW |