"""Utility script to launch browser-tests on the Chromoting bot."""
from __future__ import print_function
import argparse
import time
from chromoting_test_utilities import CleanupUserProfileDir
from chromoting_test_utilities import GetJidFromHostLog
from chromoting_test_utilities import GetJidListFromTestResults
from chromoting_test_utilities import InitialiseTestMachineForLinux
from chromoting_test_utilities import MAX_RETRIES
from chromoting_test_utilities import PrintHostLogContents
from chromoting_test_utilities import PROD_DIR_ID
from chromoting_test_utilities import RunCommandInSubProcess
from chromoting_test_utilities import TestCaseSetup
from chromoting_test_utilities import TestMachineCleanup
SUCCESS_INDICATOR = 'SUCCESS: all tests passed.'
TEST_FAILURE = False
FAILING_TESTS = ''
BROWSER_NOT_STARTED_ERROR = (
'Still waiting for the following processes to finish')
TIME_OUT_INDICATOR = '(TIMED OUT)'
def LaunchBTCommand(args, command):
"""Launches the specified browser-test command.
Retry if the execution failed because a browser-instance was not launched or
because the JID used did not match the host-JID.
Args:
args: Command line args, used for test-case startup tasks.
command: Browser-test command line.
Returns:
host_log_file_names: Array of host logs created for this command, including
retries.
"""
global TEST_FAILURE, FAILING_TESTS
host_log_file_names = []
retries = 0
host_jid_mismatch = False
host_jid = None
while retries <= MAX_RETRIES:
if host_jid_mismatch:
CleanupUserProfileDir(args)
else:
host_log_file_names.append(TestCaseSetup(args))
host_jid = GetJidFromHostLog(host_log_file_names[retries])
results = RunCommandInSubProcess(command)
jids_used = GetJidListFromTestResults(results)
if jids_used and host_jid.rstrip() not in jids_used:
host_jid_mismatch = True
print('Host JID mismatch. JID in host log = %s.' % host_jid.rstrip())
print('Host JIDs used by test:')
for jid in jids_used:
print(jid)
if host_jid_mismatch:
retries += 1
time.sleep(30)
continue
if jids_used:
print('JID used by test matched me2me host JID: %s' % host_jid)
else:
pass
if SUCCESS_INDICATOR in results:
break
if BROWSER_NOT_STARTED_ERROR in results and TIME_OUT_INDICATOR in results:
print('Browser-instance not started (http://crbug/480025). Retrying.')
else:
print('Test failed for unknown reason. Retrying.')
retries += 1
if SUCCESS_INDICATOR not in results:
TEST_FAILURE = True
FAILING_TESTS += command
return host_log_file_names
def main(args):
InitialiseTestMachineForLinux(args.cfg_file)
host_log_files = []
with open(args.commands_file) as f:
for line in f:
line = line.replace(PROD_DIR_ID, args.prod_dir)
host_log_files.extend(LaunchBTCommand(args, line))
PrintHostLogContents(host_log_files)
return host_log_files
if __name__ == '__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()
host_logs = ''
try:
host_logs = main(command_line_args)
if TEST_FAILURE:
print('++++++++++AT LEAST 1 TEST FAILED++++++++++')
print(FAILING_TESTS.rstrip('\n'))
print('++++++++++++++++++++++++++++++++++++++++++')
raise Exception('At least one test failed.')
finally:
TestMachineCleanup(command_line_args.user_profile_dir, host_logs)