Chromium Code Reviews| 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 """Utility script to run chromoting test driver tests on the Chromoting bot.""" | 5 """Utility script to run chromoting test driver tests on the Chromoting bot.""" |
| 6 | 6 |
| 7 import argparse | 7 import argparse |
| 8 | 8 |
| 9 from chromoting_test_utilities import GetJidFromHostLog | 9 from chromoting_test_utilities import GetJidFromHostLog |
| 10 from chromoting_test_utilities import InitialiseTestMachineForLinux | 10 from chromoting_test_utilities import InitialiseTestMachineForLinux |
| 11 from chromoting_test_utilities import MAX_RETRIES | |
| 11 from chromoting_test_utilities import PrintHostLogContents | 12 from chromoting_test_utilities import PrintHostLogContents |
| 12 from chromoting_test_utilities import PROD_DIR_ID | 13 from chromoting_test_utilities import PROD_DIR_ID |
| 13 from chromoting_test_utilities import RunCommandInSubProcess | 14 from chromoting_test_utilities import RunCommandInSubProcess |
| 14 from chromoting_test_utilities import TestCaseSetup | 15 from chromoting_test_utilities import TestCaseSetup |
| 15 from chromoting_test_utilities import TestMachineCleanup | 16 from chromoting_test_utilities import TestMachineCleanup |
| 16 | 17 |
| 17 TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR = 'Global test environment tear-down' | 18 TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR = 'Global test environment tear-down' |
| 18 FAILED_INDICATOR = '[ FAILED ]' | 19 FAILED_INDICATOR = '[ FAILED ]' |
| 19 | 20 |
| 20 | 21 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 33 | 34 |
| 34 host_log_file_names.append(TestCaseSetup(args)) | 35 host_log_file_names.append(TestCaseSetup(args)) |
| 35 # Parse the me2me host log to obtain the JID that the host registered. | 36 # Parse the me2me host log to obtain the JID that the host registered. |
| 36 host_jid = GetJidFromHostLog(host_log_file_names[-1]) | 37 host_jid = GetJidFromHostLog(host_log_file_names[-1]) |
| 37 | 38 |
| 38 if not host_jid: | 39 if not host_jid: |
| 39 # Host-JID not found in log. Let's not attempt to run this test. | 40 # Host-JID not found in log. Let's not attempt to run this test. |
| 40 print 'Host-JID not found in log %s.' % host_log_file_names[-1] | 41 print 'Host-JID not found in log %s.' % host_log_file_names[-1] |
| 41 return '[Command failed]: %s, %s' % (command, host_log_file_names) | 42 return '[Command failed]: %s, %s' % (command, host_log_file_names) |
| 42 | 43 |
| 43 # In order to ensure the host is online with the expected JID, pass in the | 44 retries = 0 |
| 44 # jid obtained from the host-log as a command-line parameter. | 45 failed_tests_list = [] |
| 45 command = command.replace('\n', '') + ' --hostjid=%s' % host_jid | 46 while retries <= MAX_RETRIES: |
|
joedow
2016/02/20 17:08:38
Can you add a TODO/bug to track the removal of the
anandc1
2016/02/22 20:58:08
Done.
| |
| 47 # In order to ensure the host is online with the expected JID, pass in the | |
| 48 # jid obtained from the host-log as a command-line parameter. | |
| 49 command = command.replace('\n', '') + ' --hostjid=%s' % host_jid | |
| 46 | 50 |
| 47 results = RunCommandInSubProcess(command) | 51 results = RunCommandInSubProcess(command) |
| 48 | 52 |
| 49 tear_down_index = results.find(TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR) | 53 tear_down_index = results.find(TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR) |
| 50 if tear_down_index == -1: | 54 if tear_down_index == -1: |
| 51 # The test environment did not tear down. Something went horribly wrong. | 55 # The test environment did not tear down. Something went horribly wrong. |
| 52 return '[Command failed]: ' + command, host_log_file_names | 56 return '[Command failed]: ' + command, host_log_file_names |
| 53 | 57 |
| 54 end_results_list = results[tear_down_index:].split('\n') | 58 end_results_list = results[tear_down_index:].split('\n') |
| 55 failed_tests_list = [] | 59 test_failed = False |
| 56 for result in end_results_list: | 60 for result in end_results_list: |
| 57 if result.startswith(FAILED_INDICATOR): | 61 if result.startswith(FAILED_INDICATOR): |
| 58 failed_tests_list.append(result) | 62 test_failed = True |
| 63 if retries == MAX_RETRIES: | |
| 64 # Test failed and we have no more retries left. | |
| 65 failed_tests_list.append(result) | |
| 66 | |
| 67 if test_failed: | |
| 68 retries += 1 | |
| 69 else: | |
| 70 break | |
| 59 | 71 |
| 60 if failed_tests_list: | 72 if failed_tests_list: |
| 61 test_result = '[Command]: ' + command | 73 test_result = '[Command]: ' + command |
| 62 # Note: Skipping the first one is intentional. | 74 # Note: Skipping the first one is intentional. |
| 63 for i in range(1, len(failed_tests_list)): | 75 for i in range(1, len(failed_tests_list)): |
| 64 test_result += ' ' + failed_tests_list[i] | 76 test_result += ' ' + failed_tests_list[i] |
| 65 return test_result, host_log_file_names | 77 return test_result, host_log_file_names |
| 66 | 78 |
| 67 # All tests passed! | 79 # All tests passed! |
| 68 return '', host_log_file_names | 80 return '', host_log_file_names |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 try: | 122 try: |
| 111 failing_tests, host_logs = main(command_line_args) | 123 failing_tests, host_logs = main(command_line_args) |
| 112 if failing_tests: | 124 if failing_tests: |
| 113 print '++++++++++FAILED TESTS++++++++++' | 125 print '++++++++++FAILED TESTS++++++++++' |
| 114 print failing_tests.rstrip('\n') | 126 print failing_tests.rstrip('\n') |
| 115 print '++++++++++++++++++++++++++++++++' | 127 print '++++++++++++++++++++++++++++++++' |
| 116 raise Exception('At least one test failed.') | 128 raise Exception('At least one test failed.') |
| 117 finally: | 129 finally: |
| 118 # Stop host and cleanup user-profile-dir. | 130 # Stop host and cleanup user-profile-dir. |
| 119 TestMachineCleanup(command_line_args.user_profile_dir, host_logs) | 131 TestMachineCleanup(command_line_args.user_profile_dir, host_logs) |
| OLD | NEW |