chromoting_test_driver_launcher.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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
  3. # found in the LICENSE file.
  4. """Utility script to run chromoting test driver tests on the Chromoting bot."""
  5. from __future__ import print_function
  6. import argparse
  7. from chromoting_test_utilities import GetJidFromHostLog
  8. from chromoting_test_utilities import InitialiseTestMachineForLinux
  9. from chromoting_test_utilities import MAX_RETRIES
  10. from chromoting_test_utilities import PrintHostLogContents
  11. from chromoting_test_utilities import PROD_DIR_ID
  12. from chromoting_test_utilities import RunCommandInSubProcess
  13. from chromoting_test_utilities import TestCaseSetup
  14. from chromoting_test_utilities import TestMachineCleanup
  15. TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR = 'Global test environment tear-down'
  16. FAILED_INDICATOR = '[ FAILED ]'
  17. def LaunchCTDCommand(args, command):
  18. """Launches the specified chromoting test driver command.
  19. Args:
  20. args: Command line args, used for test-case startup tasks.
  21. command: Chromoting Test Driver command line.
  22. Returns:
  23. command, host_log_file_names: Tuple of:
  24. "command" if there was a test-environment failure, or any failing test, and
  25. list of host-log file-names.
  26. """
  27. host_log_file_names = []
  28. host_log_file_names.append(TestCaseSetup(args))
  29. # Parse the me2me host log to obtain the JID that the host registered.
  30. host_jid = GetJidFromHostLog(host_log_file_names[-1])
  31. if not host_jid:
  32. # Host-JID not found in log. Let's not attempt to run this test.
  33. print('Host-JID not found in log %s.' % host_log_file_names[-1])
  34. return '[Command failed]: %s, %s' % (command, host_log_file_names)
  35. retries = 0
  36. failed_tests_list = []
  37. # TODO(anandc): Remove this retry-logic once http://crbug/570840 is fixed.
  38. while retries <= MAX_RETRIES:
  39. # In order to ensure the host is online with the expected JID, pass in the
  40. # jid obtained from the host-log as a command-line parameter.
  41. command = command.replace('\n', '') + ' --hostjid=%s' % host_jid
  42. results = RunCommandInSubProcess(command)
  43. tear_down_index = results.find(TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR)
  44. if tear_down_index == -1:
  45. # The test environment did not tear down. Something went horribly wrong.
  46. return '[Command failed]: ' + command, host_log_file_names
  47. end_results_list = results[tear_down_index:].split('\n')
  48. test_failed = False
  49. for result in end_results_list:
  50. if result.startswith(FAILED_INDICATOR):
  51. test_failed = True
  52. if retries == MAX_RETRIES:
  53. # Test failed and we have no more retries left.
  54. failed_tests_list.append(result)
  55. if test_failed:
  56. retries += 1
  57. else:
  58. break
  59. if failed_tests_list:
  60. test_result = '[Command]: ' + command
  61. # Note: Skipping the first one is intentional.
  62. for i in range(1, len(failed_tests_list)):
  63. test_result += ' ' + failed_tests_list[i]
  64. return test_result, host_log_file_names
  65. # All tests passed!
  66. return '', host_log_file_names
  67. def main(args):
  68. InitialiseTestMachineForLinux(args.cfg_file)
  69. failed_tests = ''
  70. host_log_files = []
  71. with open(args.commands_file) as f:
  72. for line in f:
  73. # Replace the PROD_DIR value in the command-line with
  74. # the passed in value.
  75. line = line.replace(PROD_DIR_ID, args.prod_dir)
  76. # Launch specified command line for test.
  77. test_results, log_files = LaunchCTDCommand(args, line)
  78. failed_tests += test_results
  79. host_log_files.extend(log_files)
  80. # All tests completed. Include host-logs in the test results.
  81. PrintHostLogContents(host_log_files)
  82. return failed_tests, host_log_files
  83. if __name__ == '__main__':
  84. parser = argparse.ArgumentParser()
  85. parser.add_argument('-f', '--commands_file',
  86. help='path to file listing commands to be launched.')
  87. parser.add_argument('-p', '--prod_dir',
  88. help='path to folder having product and test binaries.')
  89. parser.add_argument('-c', '--cfg_file',
  90. help='path to test host config file.')
  91. parser.add_argument('--me2me_manifest_file',
  92. help='path to me2me host manifest file.')
  93. parser.add_argument('--it2me_manifest_file',
  94. help='path to it2me host manifest file.')
  95. parser.add_argument(
  96. '-u', '--user_profile_dir',
  97. help='path to user-profile-dir, used by connect-to-host tests.')
  98. command_line_args = parser.parse_args()
  99. host_logs = ''
  100. failing_tests = ''
  101. try:
  102. failing_tests, host_logs = main(command_line_args)
  103. if failing_tests:
  104. print('++++++++++FAILED TESTS++++++++++')
  105. print(failing_tests.rstrip('\n'))
  106. print('++++++++++++++++++++++++++++++++')
  107. raise Exception('At least one test failed.')
  108. finally:
  109. # Stop host and cleanup user-profile-dir.
  110. TestMachineCleanup(command_line_args.user_profile_dir, host_logs)