def _process_args(raw_args): args = parse_args(raw_args) logging_util.setup( level=logging.DEBUG if args.output == 'verbose' else logging.WARNING) OPTIONS.parse_configure_file() # Limit to one job at a time when running a suite multiple times. Otherwise # suites start interfering with each others operations and bad things happen. if args.repeat_runs > 1: args.jobs = 1 if args.buildbot and OPTIONS.weird(): args.exclude_patterns.append('cts.*') # Fixup all patterns to at least be a prefix match for all tests. # This allows options like "-t cts.CtsHardwareTestCases" to work to select all # the tests in the suite. args.include_patterns = [(pattern if '*' in pattern else (pattern + '*')) for pattern in args.include_patterns] args.exclude_patterns = [(pattern if '*' in pattern else (pattern + '*')) for pattern in args.exclude_patterns] set_test_global_state(args) if (not args.remote and args.buildbot and not platform_util.is_running_on_cygwin()): print_chrome_version() if platform_util.is_running_on_remote_host(): args.run_ninja = False return args
def _process_args(raw_args): args = parse_args(raw_args) logging_util.setup( level=logging.DEBUG if args.output == 'verbose' else logging.WARNING) OPTIONS.parse_configure_file() # Limit to one job at a time when running a suite multiple times. Otherwise # suites start interfering with each others operations and bad things happen. if args.repeat_runs > 1: args.jobs = 1 if args.buildbot and OPTIONS.weird(): args.exclude_patterns.append('cts.*') # Fixup all patterns to at least be a prefix match for all tests. # This allows options like "-t cts.CtsHardwareTestCases" to work to select all # the tests in the suite. args.include_patterns = [(pattern if '*' in pattern else (pattern + '*')) for pattern in args.include_patterns] args.exclude_patterns = [(pattern if '*' in pattern else (pattern + '*')) for pattern in args.exclude_patterns] set_test_global_state(args) if (not args.remote and args.buildbot and not platform_util.is_running_on_cygwin()): print_chrome_version() if platform_util.is_running_on_remote_host(): args.run_ninja = False return args
def print_chrome_version(): assert not platform_util.is_running_on_cygwin(), ( 'Chrome on Windows does not support --version option.') chrome_path = remote_executor.get_chrome_exe_path() chrome_version = subprocess.check_output([chrome_path, '--version']).rstrip() print '@@@STEP_TEXT@%s<br/>@@@' % (chrome_version)
def resolve_path(path): if platform_util.is_running_on_cygwin(): # As relative path on cygwin, which is passed to Chrome via an environment # variable or a flag, is not resolved by Chrome on Windows, # it is necessary to resolve beforehand. return remote_windows_executor.resolve_cygpath(path) return path
def resolve_path(path): if platform_util.is_running_on_cygwin(): # As relative path on cygwin, which is passed to Chrome via an environment # variable or a flag, is not resolved by Chrome on Windows, # it is necessary to resolve beforehand. return remote_windows_executor.resolve_cygpath(path) return path
def __init__(self, args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=None, env=None, timeout=None): # To stabilize the Chrome flakiness problem handling, we use customized # Popen for Chrome. Note that we do not need to worry about the xvfb-run # as we do in concurrent_subprocess._XvfbPopen, because we are launching # Chrome process, here. if platform_util.is_running_on_cygwin(): # To launch on Cygwin, stdout and stderr for NaCl are not yet supported. # We instead use a customized Popen class. See its doc for the details. # TODO(crbug.com/171836): Remove this when stdout and stderr are # supported. subprocess_factory = _TailProxyChromePopen else: subprocess_factory = None super(ChromeProcess, self).__init__(args=args, stdout=stdout, stderr=stderr, cwd=cwd, env=env, timeout=timeout, subprocess_factory=subprocess_factory)
def _kill_process(process): if platform_util.is_running_on_cygwin(): kill_command = ['taskkill', '/F', '/IM', process] else: kill_command = ['killall', '-v', '-9', process] return subprocess.Popen(kill_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
def get_chrome_prebuilt_arch_bits(): # Use 32-bit version of Chrome on Windows regardless of the target bit size. if platform_util.is_running_on_cygwin(): return "32" elif OPTIONS.is_x86_64() or OPTIONS.is_bare_metal_i686(): return "64" else: return "32"
def _get_processes_to_kill(): if (platform_util.is_running_on_linux() and not platform_util.is_running_on_chromeos()): return _KILL_PROCESSES_LINUX elif platform_util.is_running_on_cygwin(): return _KILL_PROCESSES_CYGWIN # TODO(mazda): Add the case for Mac. return []
def get_chrome_prebuilt_arch_bits(): # Use 32-bit version of Chrome on Windows regardless of the target bit size. if platform_util.is_running_on_cygwin(): return '32' elif OPTIONS.is_x86_64() or OPTIONS.is_bare_metal_i686(): return '64' else: return '32'
def _kill_process(process): if platform_util.is_running_on_cygwin(): kill_command = ['taskkill', '/F', '/IM', process] else: kill_command = ['killall', '-v', '-9', process] return subprocess.Popen(kill_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
def _get_processes_to_kill(): if (platform_util.is_running_on_linux() and not platform_util.is_running_on_chromeos()): return _KILL_PROCESSES_LINUX elif platform_util.is_running_on_cygwin(): return _KILL_PROCESSES_CYGWIN # TODO(mazda): Add the case for Mac. return []
def _get_chrome_exe_path_on_remote_host(): """If this script is running on remote host, returns the path to Chrome.""" if platform_util.is_running_on_chromeos(): return remote_chromeos_executor.get_chrome_exe_path() if platform_util.is_running_on_cygwin(): return _get_win_chrome_exe_path() if platform_util.is_running_on_mac(): return _get_mac_chrome_exe_path() raise NotImplementedError( 'get_chrome_exe_path_on_remote_host is supported only for Chrome OS, ' 'Cygwin, and Mac.')
def _get_adb_path_for_localhost(): root = os.path.join(build_common.get_arc_root(), 'out/adb') if platform_util.is_running_on_mac(): return os.path.join(root, 'mac-x86_64/adb') elif platform_util.is_running_on_cygwin(): return os.path.join(root, 'win-x86_64/adb.exe') elif platform_util.is_running_on_chromeos(): return get_adb_path_for_chromeos(relative=False) else: # For Linux desktop. return 'third_party/android-sdk/platform-tools/adb'
def _get_adb_path_for_localhost(): root = os.path.join(build_common.get_arc_root(), 'out/adb') if platform_util.is_running_on_mac(): return os.path.join(root, 'mac-x86_64/adb') elif platform_util.is_running_on_cygwin(): return os.path.join(root, 'win-x86_64/adb.exe') elif platform_util.is_running_on_chromeos(): return get_adb_path_for_chromeos(relative=False) else: # For Linux desktop. return 'third_party/android-sdk/platform-tools/adb'
def _get_chrome_exe_path_on_remote_host(): """If this script is running on remote host, returns the path to Chrome.""" if platform_util.is_running_on_chromeos(): return remote_chromeos_executor.get_chrome_exe_path() if platform_util.is_running_on_cygwin(): return _get_win_chrome_exe_path() if platform_util.is_running_on_mac(): return _get_mac_chrome_exe_path() raise NotImplementedError( 'get_chrome_exe_path_on_remote_host is supported only for Chrome OS, ' 'Cygwin, and Mac.')
def __init__(self, args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=None, env=None, timeout=None): # To stabilize the Chrome flakiness problem handling, we use customized # Popen for Chrome. Note that we do not need to worry about the xvfb-run # as we do in concurrent_subprocess._XvfbPopen, because we are launching # Chrome process, here. if platform_util.is_running_on_cygwin(): # To launch on Cygwin, stdout and stderr for NaCl are not yet supported. # We instead use a customized Popen class. See its doc for the details. # TODO(crbug.com/171836): Remove this when stdout and stderr are # supported. subprocess_factory = _TailProxyChromePopen else: subprocess_factory = None super(ChromeProcess, self).__init__( args=args, stdout=stdout, stderr=stderr, cwd=cwd, env=env, timeout=timeout, subprocess_factory=subprocess_factory)
def maybe_detect_remote_host_type(parsed_args): """Sets remote_host_type if necessary. This function ensures that parsed_args has |remote_host_type| value, if it has |remote|. On remote execution, this function checks if remote_host_type is already set or not. If not, detects the remote host type by communicating with the remote machine by using |remote| and |ssh_key| values. Unfortunately, currently ArgumentParser does not support default values evaluated lazily (after actual parsing) with already parsed arguments. So, all parsers using add_remote_arguments() defined above need to call this function just after its parse_known_args() family. """ if platform_util.is_running_on_remote_host(): # On remote machine, we expect --remote flag is removed. assert parsed_args.remote is None, ( 'Found --remote flag, but the script runs on the remote machine.') # Detect the remote_host_type of the machine, and fix up or verify # the parsed flag. if platform_util.is_running_on_cygwin(): remote_host_type = 'cygwin' elif platform_util.is_running_on_mac(): remote_host_type = 'mac' elif platform_util.is_running_on_chromeos(): remote_host_type = 'chromeos' else: raise Exception('Unknown platform') if parsed_args.remote_host_type is None: parsed_args.remote_host_type = remote_host_type assert parsed_args.remote_host_type == remote_host_type, ( '--remote_host_type is mismatching: "%s" vs "%s"' % ( parsed_args.remote_host_type, remote_host_type)) return # Hereafter, this runs on the host machine. if parsed_args.remote_host_type or not parsed_args.remote: # If --remote-host-type is already set, or it is not --remote execution, # we do nothing. return parsed_args.remote_host_type = remote_executor_util.detect_remote_host_type( parsed_args.remote, parsed_args.ssh_key)
def maybe_detect_remote_host_type(parsed_args): """Sets remote_host_type if necessary. This function ensures that parsed_args has |remote_host_type| value, if it has |remote|. On remote execution, this function checks if remote_host_type is already set or not. If not, detects the remote host type by communicating with the remote machine by using |remote| and |ssh_key| values. Unfortunately, currently ArgumentParser does not support default values evaluated lazily (after actual parsing) with already parsed arguments. So, all parsers using add_remote_arguments() defined above need to call this function just after its parse_known_args() family. """ if platform_util.is_running_on_remote_host(): # On remote machine, we expect --remote flag is removed. assert parsed_args.remote is None, ( 'Found --remote flag, but the script runs on the remote machine.') # Detect the remote_host_type of the machine, and fix up or verify # the parsed flag. if platform_util.is_running_on_cygwin(): remote_host_type = 'cygwin' elif platform_util.is_running_on_mac(): remote_host_type = 'mac' elif platform_util.is_running_on_chromeos(): remote_host_type = 'chromeos' else: raise Exception('Unknown platform') if parsed_args.remote_host_type is None: parsed_args.remote_host_type = remote_host_type assert parsed_args.remote_host_type == remote_host_type, ( '--remote_host_type is mismatching: "%s" vs "%s"' % (parsed_args.remote_host_type, remote_host_type)) return # Hereafter, this runs on the host machine. if parsed_args.remote_host_type or not parsed_args.remote: # If --remote-host-type is already set, or it is not --remote execution, # we do nothing. return parsed_args.remote_host_type = remote_executor_util.detect_remote_host_type( parsed_args.remote, parsed_args.ssh_key)
def _list_child_process(*target_pid): """Returns a list of PIDs whose parent PID is |target_pid|.""" if platform_util.is_running_on_linux(): # On Linux Workstation or Chrome OS. try: output = subprocess.check_output([ 'ps', '-o', 'pid=', '--ppid', ','.join(str(p) for p in target_pid) ]) except subprocess.CalledProcessError: # If not found, ps returns status code 1. return [] return [int(child.strip()) for child in output.splitlines()] if platform_util.is_running_on_mac(): # On Mac. try: output = subprocess.check_output(['ps', 'x', '-o', 'pid=,ppid=']) except subprocess.CalledProcessError: return [] result = [] for line in output.splitlines(): pid, ppid = line.split() if int(ppid) in target_pid: result.append(int(pid)) return result if platform_util.is_running_on_cygwin(): # On Cygwin. try: output = subprocess.check_output(['ps', 'aux']) except subprocess.CalledProcessError: return [] result = [] for line in output.splitlines()[1:]: pid, ppid = line.split(None, 2)[:2] if int(ppid) in target_pid: result.append(int(pid)) return result raise NotImplementedError('Unknown platform: ' + sys.platform)
def _list_child_process(*target_pid): """Returns a list of PIDs whose parent PID is |target_pid|.""" if platform_util.is_running_on_linux(): # On Linux Workstation or Chrome OS. try: output = subprocess.check_output( ['ps', '-o', 'pid=', '--ppid', ','.join(str(p) for p in target_pid)]) except subprocess.CalledProcessError: # If not found, ps returns status code 1. return [] return [int(child.strip()) for child in output.splitlines()] if platform_util.is_running_on_mac(): # On Mac. try: output = subprocess.check_output(['ps', 'x', '-o', 'pid=,ppid=']) except subprocess.CalledProcessError: return [] result = [] for line in output.splitlines(): pid, ppid = line.split() if int(ppid) in target_pid: result.append(int(pid)) return result if platform_util.is_running_on_cygwin(): # On Cygwin. try: output = subprocess.check_output(['ps', 'aux']) except subprocess.CalledProcessError: return [] result = [] for line in output.splitlines()[1:]: pid, ppid = line.split(None, 2)[:2] if int(ppid) in target_pid: result.append(int(pid)) return result raise NotImplementedError('Unknown platform: ' + sys.platform)
def maybe_extend_remote_host_chrome_params(parsed_args, params): """Adds chrome flags for Chrome on remote host, if necessary.""" if platform_util.is_running_on_chromeos(): remote_chromeos_executor.extend_chrome_params(parsed_args, params) if platform_util.is_running_on_cygwin(): remote_windows_executor.extend_chrome_params(parsed_args, params)
def maybe_extend_remote_host_chrome_params(parsed_args, params): """Adds chrome flags for Chrome on remote host, if necessary.""" if platform_util.is_running_on_chromeos(): remote_chromeos_executor.extend_chrome_params(parsed_args, params) if platform_util.is_running_on_cygwin(): remote_windows_executor.extend_chrome_params(parsed_args, params)
def print_chrome_version(): assert not platform_util.is_running_on_cygwin(), ( 'Chrome on Windows does not support --version option.') chrome_path = remote_executor.get_chrome_exe_path() chrome_version = subprocess.check_output([chrome_path, '--version']).rstrip() print '@@@STEP_TEXT@%s<br/>@@@' % (chrome_version)