def _default_number_of_jobs(): if platform_util.is_running_on_chromeos(): # Newer builds of Chrome OS use the Freon display manager, which does not # support concurrent invocations of Chrome. return 1 else: return min(10, multiprocessing.cpu_count())
def handle_stderr(self, line): super(BareMetalGdbHandlerAdapter, self).handle_stderr(line) match = BareMetalGdbHandlerAdapter._WAITING_GDB_PATTERN.search(line) if not match: return plugin_pid = int(match.group(1)) # Note that, for remote debugging, BareMetalGdbHandlerAdapter will run in # both local and remote machine. if platform_util.is_running_on_chromeos(): _launch_bare_metal_gdbserver(plugin_pid, self._next_is_child_plugin) else: logging.info('Found new %s plugin process %d', 'child' if self._next_is_child_plugin else 'main', plugin_pid) if self._remote_executor: self._remote_executor.port_forward(_get_bare_metal_gdb_port(plugin_pid)) else: _launch_bare_metal_gdbserver(plugin_pid, self._next_is_child_plugin) _attach_bare_metal_gdb( self._host, plugin_pid, self._ssh_options, self._nacl_helper_nonsfi_path, self._gdb_type) self._next_is_child_plugin = True
def handle_stderr(self, line): super(BareMetalGdbHandlerAdapter, self).handle_stderr(line) match = BareMetalGdbHandlerAdapter._WAITING_GDB_PATTERN.search(line) if not match: return plugin_pid = int(match.group(1)) # Note that, for remote debugging, BareMetalGdbHandlerAdapter will run in # both local and remote machine. if platform_util.is_running_on_chromeos(): _launch_bare_metal_gdbserver(plugin_pid, self._next_is_child_plugin) else: logging.info('Found new %s plugin process %d', 'child' if self._next_is_child_plugin else 'main', plugin_pid) if self._remote_executor: self._remote_executor.port_forward( _get_bare_metal_gdb_port(plugin_pid)) else: _launch_bare_metal_gdbserver(plugin_pid, self._next_is_child_plugin) _attach_bare_metal_gdb(self._host, plugin_pid, self._ssh_options, self._nacl_helper_nonsfi_path, self._gdb_type) self._next_is_child_plugin = True
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 _compute_chrome_params(parsed_args): chrome_path = _get_chrome_path(parsed_args) params = [chrome_path] if parsed_args.mode in ('perftest', 'atftest'): # Do not show the New Tab Page because showing NTP during perftest makes the # benchmark score look unnecessarily bad. # TODO(crbug.com/315356): Remove the IF once 315356 is fixed. params.append('about:blank') # Append flags for performance measurement in test modes to stabilize # integration tests and perf score. Do not append these flags in run mode # because apps that depend on component extensions (e.g. Files.app) will not # work with these flags. params.extend(_compute_chrome_performance_test_params(parsed_args)) # Make the window size small on Goobuntu so that it does not cover the whole # desktop during perftest/integration_test. params.append('--window-size=500,500') if parsed_args.lang: params.append('--lang=' + parsed_args.lang) # LANGUAGE takes priority over --lang option in Linux. os.environ['LANGUAGE'] = parsed_args.lang # In Mac, there is no handy way to change the locale. if platform_util.is_running_on_mac(): print '\nWARNING: --lang is not supported in Mac.' if (parsed_args.mode == 'atftest' and not platform_util.is_running_on_chromeos() and not platform_util.is_running_on_mac()): # This launches ARC without creating a browser window. We only do it for # automated tests, in case the user wants to do something like examine the # Chromium settings ("about:flags" for example), which requires using the # browser window. Note that this does not work on Mac, and should be # unnecessary on a remote Chromebook target. params.append('--silent-launch') params.extend(_compute_chrome_plugin_params(parsed_args)) params.extend(_compute_chrome_sandbox_params(parsed_args)) params.extend(_compute_chrome_graphics_params(parsed_args)) params.extend(_compute_chrome_debugging_params(parsed_args)) diagnostic_params, diagnostic_params_startwith = ( _compute_chrome_diagnostic_params(parsed_args)) params.extend(diagnostic_params) params = diagnostic_params_startwith + params remote_executor.maybe_extend_remote_host_chrome_params(parsed_args, params) params.append( '--load-and-launch-app=' + remote_executor.resolve_path(parsed_args.arc_data_dir)) # This prevents Chrome to add icon to Gnome panel, which current leaks memory. # See http://crbug.com/341724 for details. params.append('--disable-background-mode') if parsed_args.chrome_args: params.extend(parsed_args.chrome_args) return params
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 _launch_bare_metal_gdbserver(plugin_pid, is_child_plugin): gdb_port = _get_bare_metal_gdb_port(plugin_pid) command = ['gdbserver', '--attach', ':%d' % gdb_port, str(plugin_pid)] if platform_util.is_running_on_chromeos(): gdb_process = _popen_with_sudo_on_chromeos(command) else: gdb_process = subprocess.Popen(command) if not is_child_plugin: _run_gdb_watch_thread(gdb_process)
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 handle_stderr(self, line): super(NaClGdbHandlerAdapter, self).handle_stderr(line) match = NaClGdbHandlerAdapter._START_DEBUG_STUB_PATTERN.search(line) if not match: return port = int(match.group(1)) # Note that, for remote debugging, NaClGdbHandlerAdapter will run in # both local and remote machine. if not platform_util.is_running_on_chromeos(): logging.info('Found debug stub on port (%d)' % port) if self._remote_executor: self._remote_executor.port_forward(port) _launch_nacl_gdb(self._gdb_type, self._nacl_irt_path, port)
def get_adb_path_for_chromeos(relative=True): """Returns the directory that contains the adb executable for Chrome OS.""" if platform_util.is_running_on_chromeos(): # The adb binary is copied to a directory whose filesystem is mounted # without noexec mount options on Chrome OS. root = build_common.get_chromeos_arc_root_without_noexec() else: root = build_common.get_arc_root() # Chrome OS based on linux-i686 is not supported. target = 'linux-arm' if OPTIONS.is_arm() else 'linux-x86_64' path = os.path.join('out/adb', target, 'adb') if relative: return path return os.path.join(root, path)
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 _compute_chrome_plugin_params(parsed_args): params = [] params.append( '--load-extension=' + remote_executor.resolve_path(build_common.get_runtime_out_dir())) # Do not use user defined data directory if user name for remote host is # provided. The mounted cryptohome directory is used instead. if not parsed_args.login_user: params.append( '--user-data-dir=' + remote_executor.resolve_path(_USER_DATA_DIR)) # Force-enable nonsfi mode on targets that do not allow it by default # (for example, non-ChromeOS Linux) for testing purposes. if (OPTIONS.is_bare_metal_build() and not platform_util.is_running_on_chromeos()): params.append('--enable-nacl-nonsfi-mode') return params
def _construct_command(test_info, gtest_filter, gtest_list_tests): variables = test_info['variables'].copy() variables.setdefault('argv', '') variables.setdefault('qemu_arm', '') if platform_util.is_running_on_chromeos(): # On ChromeOS, binaries in directories mounted with noexec options are # copied to the corresponding directories mounted with exec option. # Change runner to use the binaries under the directory mounted with exec # option. # Also do not use qemu_arm when running on ARM Chromebook. arc_root_without_noexec = \ build_common.get_chromeos_arc_root_without_noexec() if build_options.OPTIONS.is_bare_metal_build(): variables['runner'] = ' '.join( toolchain.get_bare_metal_runner(bin_dir=arc_root_without_noexec)) variables['runner_without_test_library'] = ' '.join( toolchain.get_bare_metal_runner(bin_dir=arc_root_without_noexec, use_test_library=False)) if build_options.OPTIONS.is_arm(): variables['qemu_arm'] = '' # Update --gtest_filter to re-enable the tests disabled only on qemu. if variables.get('qemu_disabled_tests'): variables['gtest_options'] = unittest_util.build_gtest_options( variables.get('enabled_tests'), variables.get('disabled_tests')) else: variables['runner'] = ' '.join( toolchain.get_nacl_runner( build_options.OPTIONS.get_target_bitsize(), bin_dir=arc_root_without_noexec)) variables['runner_without_test_library'] = ' '.join( toolchain.get_nacl_runner( build_options.OPTIONS.get_target_bitsize(), bin_dir=arc_root_without_noexec, use_test_library=False)) build_dir = build_common.get_build_dir() # Use test binary in the directory mounted without noexec. variables['in'] = variables['in'].replace( build_dir, os.path.join(arc_root_without_noexec, build_dir)) else: if build_options.OPTIONS.is_arm(): # Pass environment variables by -E flag for qemu-arm instead of # "env" command. # TODO(hamaji): This and the is_running_on_chromeos() case above # are both hacky. We probably want to construct the command to # run a unittest here based on the info in variables, and remove # test_info['command']. qemu_arm = variables['qemu_arm'].split(' ') if '$qemu_arm' in test_info['command']: runner = variables['runner'].split(' ') assert runner[0] == 'env' runner.pop(0) qemu_arm.append('-E') while '=' in runner[0]: qemu_arm.append(runner[0]) runner.pop(0) variables['qemu_arm'] = ' '.join(qemu_arm) variables['runner'] = ' '.join(runner) if gtest_filter: variables['gtest_options'] = '--gtest_filter=' + gtest_filter if gtest_list_tests: variables['gtest_options'] = '--gtest_list_tests' # Test is run as a command to build a test results file. command_template = string.Template(test_info['command']) return command_template.substitute(variables)
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 _construct_command(test_info, gtest_filter, gtest_list_tests): variables = test_info['variables'].copy() variables.setdefault('argv', '') variables.setdefault('qemu_arm', '') if platform_util.is_running_on_chromeos(): # On ChromeOS, binaries in directories mounted with noexec options are # copied to the corresponding directories mounted with exec option. # Change runner to use the binaries under the directory mounted with exec # option. # Also do not use qemu_arm when running on ARM Chromebook. arc_root_without_noexec = \ build_common.get_chromeos_arc_root_without_noexec() if build_options.OPTIONS.is_bare_metal_build(): variables['runner'] = ' '.join( toolchain.get_bare_metal_runner( bin_dir=arc_root_without_noexec)) variables['runner_without_test_library'] = ' '.join( toolchain.get_bare_metal_runner( bin_dir=arc_root_without_noexec, use_test_library=False)) if build_options.OPTIONS.is_arm(): variables['qemu_arm'] = '' # Update --gtest_filter to re-enable the tests disabled only on qemu. if variables.get('qemu_disabled_tests'): variables[ 'gtest_options'] = unittest_util.build_gtest_options( variables.get('enabled_tests'), variables.get('disabled_tests')) else: variables['runner'] = ' '.join( toolchain.get_nacl_runner( build_options.OPTIONS.get_target_bitsize(), bin_dir=arc_root_without_noexec)) variables['runner_without_test_library'] = ' '.join( toolchain.get_nacl_runner( build_options.OPTIONS.get_target_bitsize(), bin_dir=arc_root_without_noexec, use_test_library=False)) build_dir = build_common.get_build_dir() # Use test binary in the directory mounted without noexec. variables['in'] = variables['in'].replace( build_dir, os.path.join(arc_root_without_noexec, build_dir)) else: if build_options.OPTIONS.is_arm(): # Pass environment variables by -E flag for qemu-arm instead of # "env" command. # TODO(hamaji): This and the is_running_on_chromeos() case above # are both hacky. We probably want to construct the command to # run a unittest here based on the info in variables, and remove # test_info['command']. qemu_arm = variables['qemu_arm'].split(' ') if '$qemu_arm' in test_info['command']: runner = variables['runner'].split(' ') assert runner[0] == 'env' runner.pop(0) qemu_arm.append('-E') while '=' in runner[0]: qemu_arm.append(runner[0]) runner.pop(0) variables['qemu_arm'] = ' '.join(qemu_arm) variables['runner'] = ' '.join(runner) if gtest_filter: variables['gtest_options'] = '--gtest_filter=' + gtest_filter if gtest_list_tests: variables['gtest_options'] = '--gtest_list_tests' # Test is run as a command to build a test results file. command_template = string.Template(test_info['command']) return command_template.substitute(variables)