Make app list recommendations ignore KnownResults.
[chromium-blink-merge.git] / testing / chromoting / chromoting_test_driver_launcher.py
blobc982279d0c83a5473a7da02f88f882e97c50037f
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.
5 """Utility script to run chromoting test driver tests on the Chromoting bot."""
7 import argparse
9 from chromoting_test_utilities import InitialiseTestMachineForLinux
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
16 TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR = 'Global test environment tear-down'
17 FAILED_INDICATOR = '[ FAILED ]'
20 def LaunchCTDCommand(args, command):
21 """Launches the specified chromoting test driver command.
23 Args:
24 args: Command line args, used for test-case startup tasks.
25 command: Chromoting Test Driver command line.
26 Returns:
27 "command" if there was a test environment failure, otherwise a string of the
28 names of failed tests.
29 """
31 TestCaseSetup(args)
32 results = RunCommandInSubProcess(command)
34 tear_down_index = results.find(TEST_ENVIRONMENT_TEAR_DOWN_INDICATOR)
35 if tear_down_index == -1:
36 # The test environment did not tear down. Something went horribly wrong.
37 return '[Command failed]: ' + command
39 end_results_list = results[tear_down_index:].split('\n')
40 failed_tests_list = []
41 for result in end_results_list:
42 if result.startswith(FAILED_INDICATOR):
43 failed_tests_list.append(result)
45 if failed_tests_list:
46 test_result = '[Command]: ' + command
47 # Note: Skipping the first one is intentional.
48 for i in range(1, len(failed_tests_list)):
49 test_result += ' ' + failed_tests_list[i]
50 return test_result
52 # All tests passed!
53 return ''
56 def main(args):
57 InitialiseTestMachineForLinux(args.cfg_file)
59 failed_tests = ''
61 with open(args.commands_file) as f:
62 for line in f:
63 # Replace the PROD_DIR value in the command-line with
64 # the passed in value.
65 line = line.replace(PROD_DIR_ID, args.prod_dir)
66 # Launch specified command line for test.
67 failed_tests += LaunchCTDCommand(args, line)
69 # All tests completed. Include host-logs in the test results.
70 PrintHostLogContents()
72 if failed_tests:
73 print '++++++++++FAILED TESTS++++++++++'
74 print failed_tests.rstrip('\n')
75 print '++++++++++++++++++++++++++++++++'
76 raise Exception('At least one test failed.')
78 if __name__ == '__main__':
79 parser = argparse.ArgumentParser()
80 parser.add_argument('-f', '--commands_file',
81 help='path to file listing commands to be launched.')
82 parser.add_argument('-p', '--prod_dir',
83 help='path to folder having product and test binaries.')
84 parser.add_argument('-c', '--cfg_file',
85 help='path to test host config file.')
86 parser.add_argument('--me2me_manifest_file',
87 help='path to me2me host manifest file.')
88 parser.add_argument('--it2me_manifest_file',
89 help='path to it2me host manifest file.')
90 parser.add_argument(
91 '-u', '--user_profile_dir',
92 help='path to user-profile-dir, used by connect-to-host tests.')
93 command_line_args = parser.parse_args()
94 try:
95 main(command_line_args)
96 finally:
97 # Stop host and cleanup user-profile-dir.
98 TestMachineCleanup(command_line_args.user_profile_dir)