| Index: testing/chromoting/browser_tests_launcher.py
|
| diff --git a/testing/chromoting/browser_tests_launcher.py b/testing/chromoting/browser_tests_launcher.py
|
| index a265f56c389a283a7f66940d35f589f79c38819f..2fceb7c658ba1ddf0f21701818922888ca3a8206 100644
|
| --- a/testing/chromoting/browser_tests_launcher.py
|
| +++ b/testing/chromoting/browser_tests_launcher.py
|
| @@ -21,15 +21,19 @@ NATIVE_MESSAGING_DIR = 'NativeMessagingHosts'
|
| CRD_ID = 'chrome-remote-desktop' # Used in a few file/folder names
|
| CHROMOTING_HOST_PATH = '/opt/google/chrome-remote-desktop/chrome-remote-desktop'
|
| TEST_FAILURE = False
|
| +FAILING_TESTS = ''
|
| +HOST_READY_INDICATOR = 'Host ready to receive connections.'
|
|
|
|
|
| def LaunchBTCommand(command):
|
| - global TEST_FAILURE
|
| + global TEST_FAILURE, FAILING_TESTS
|
| results = RunCommandInSubProcess(command)
|
|
|
| # Check that the test passed.
|
| if SUCCESS_INDICATOR not in results:
|
| TEST_FAILURE = True
|
| + # Add this command-line to list of tests that failed.
|
| + FAILING_TESTS += command
|
|
|
|
|
| def RunCommandInSubProcess(command):
|
| @@ -43,17 +47,16 @@ def RunCommandInSubProcess(command):
|
|
|
| cmd_line = [command]
|
| try:
|
| - p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True)
|
| - results, error = p.communicate()
|
| + results = subprocess.check_output(cmd_line, stderr=subprocess.STDOUT,
|
| + shell=True)
|
| except subprocess.CalledProcessError, e:
|
| - raise Exception('Exception %s running command %s\nError: %s' %
|
| - (e, command, error))
|
| - else:
|
| + results = e.output
|
| + finally:
|
| print results
|
| return results
|
|
|
|
|
| -def TestCleanUp(user_profile_dir):
|
| +def TestMachineCleanup(user_profile_dir):
|
| """Cleans up test machine so as not to impact other tests.
|
|
|
| Args:
|
| @@ -81,6 +84,9 @@ def InitialiseTestMachineForLinux(cfg_file):
|
|
|
| Args:
|
| cfg_file: location of test account's host-config file.
|
| +
|
| + Raises:
|
| + Exception: if host did not start properly.
|
| """
|
|
|
| # First get home directory on current machine.
|
| @@ -98,8 +104,31 @@ def InitialiseTestMachineForLinux(cfg_file):
|
| config_file_src,
|
| os.path.join(default_config_file_location, default_config_file_name))
|
|
|
| - # Finally, start chromoting host.
|
| - RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start')
|
| + # Make sure chromoting host is running.
|
| + if not RestartMe2MeHost():
|
| + # Host start failed. Don't run any tests.
|
| + raise Exception('Host restart failed.')
|
| +
|
| +
|
| +def RestartMe2MeHost():
|
| + """Stops and starts the Me2Me host on the test machine.
|
| +
|
| + Waits to confirm that host is ready to receive connections before returning.
|
| +
|
| + Returns:
|
| + True: if HOST_READY_INDICATOR is found in stdout, indicating host is ready.
|
| + False: if HOST_READY_INDICATOR not found in stdout.
|
| + """
|
| +
|
| + # Stop chromoting host.
|
| + RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop')
|
| + # Start chromoting host.
|
| + results = RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start')
|
| + # Confirm that the start process completed, and we got:
|
| + # "Host ready to receive connections." in the log.
|
| + if HOST_READY_INDICATOR not in results:
|
| + return False
|
| + return True
|
|
|
|
|
| def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file,
|
| @@ -133,23 +162,7 @@ def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file,
|
| shutil.copyfile(manifest_file_src, manifest_file_dest)
|
|
|
|
|
| -def main():
|
| - parser = argparse.ArgumentParser()
|
| - parser.add_argument('-f', '--commands_file',
|
| - help='path to file listing commands to be launched.')
|
| - parser.add_argument('-p', '--prod_dir',
|
| - help='path to folder having product and test binaries.')
|
| - parser.add_argument('-c', '--cfg_file',
|
| - help='path to test host config file.')
|
| - parser.add_argument('--me2me_manifest_file',
|
| - help='path to me2me host manifest file.')
|
| - parser.add_argument('--it2me_manifest_file',
|
| - help='path to it2me host manifest file.')
|
| - parser.add_argument(
|
| - '-u', '--user_profile_dir',
|
| - help='path to user-profile-dir, used by connect-to-host tests.')
|
| -
|
| - args = parser.parse_args()
|
| +def main(args):
|
|
|
| InitialiseTestMachineForLinux(args.cfg_file)
|
|
|
| @@ -162,22 +175,49 @@ def main():
|
| # Replace the PROD_DIR value in the command-line with
|
| # the passed in value.
|
| line = line.replace(PROD_DIR_ID, args.prod_dir)
|
| + # Launch specified command line for test.
|
| LaunchBTCommand(line)
|
| + # After each test, stop+start me2me host process.
|
| + if not RestartMe2MeHost():
|
| + # Host restart failed. Don't run any more tests.
|
| + raise Exception('Host restart failed.')
|
| +
|
| + # All tests completed. Include host-logs in the test results.
|
| + host_log_contents = ''
|
| + # There should be only 1 log file, as we delete logs on test completion.
|
| + # Loop through matching files, just in case there are more.
|
| + for log_file in glob.glob('/tmp/chrome_remote_desktop_*'):
|
| + with open(log_file, 'r') as log:
|
| + host_log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % (
|
| + log_file, log.read())
|
| + print host_log_contents
|
|
|
| # Was there any test failure?
|
| if TEST_FAILURE:
|
| - # Obtain contents of Chromoting host logs.
|
| - log_contents = ''
|
| - # There should be only 1 log file, as we delete logs on test completion.
|
| - # Loop through matching files, just in case there are more.
|
| - for log_file in glob.glob('/tmp/chrome_remote_desktop_*'):
|
| - with open(log_file, 'r') as log:
|
| - log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % (log_file, log.read())
|
| - print log_contents
|
| + print '++++++++++AT LEAST 1 TEST FAILED++++++++++'
|
| + print FAILING_TESTS.rstrip('\n')
|
| + print '++++++++++++++++++++++++++++++++++++++++++'
|
| raise Exception('At least one test failed.')
|
|
|
| - # Now, stop host, and cleanup user-profile-dir
|
| - TestCleanUp(args.user_profile_dir)
|
| -
|
| if __name__ == '__main__':
|
| - main()
|
| +
|
| + parser = argparse.ArgumentParser()
|
| + parser.add_argument('-f', '--commands_file',
|
| + help='path to file listing commands to be launched.')
|
| + parser.add_argument('-p', '--prod_dir',
|
| + help='path to folder having product and test binaries.')
|
| + parser.add_argument('-c', '--cfg_file',
|
| + help='path to test host config file.')
|
| + parser.add_argument('--me2me_manifest_file',
|
| + help='path to me2me host manifest file.')
|
| + parser.add_argument('--it2me_manifest_file',
|
| + help='path to it2me host manifest file.')
|
| + parser.add_argument(
|
| + '-u', '--user_profile_dir',
|
| + help='path to user-profile-dir, used by connect-to-host tests.')
|
| + command_line_args = parser.parse_args()
|
| + try:
|
| + main(command_line_args)
|
| + finally:
|
| + # Stop host and cleanup user-profile-dir.
|
| + TestMachineCleanup(command_line_args.user_profile_dir)
|
|
|