def ChromeOSTelemetryRemote(test_config):
  """Substitutes the correct CrOS remote Telemetry arguments.

  VMs use a hard-coded remote address and port, while physical hardware use
  a magic hostname.

  Args:
    test_config: A dict containing a configuration for a specific test on a
        specific builder.
  """
  def StringContainsSubstring(s, sub_strs):
    for sub_str in sub_strs:
      if sub_str in s:
        return True
    return False
  VM_POOLS = [
    'chromium.tests.cros.vm',
    'chrome.tests.cros-vm',
  ]
  HW_POOLS = [
    'chrome-cros-dut',
    'chrome.cros-dut',
  ]
  dimensions = test_config.get('swarming', {}).get('dimension_sets', [])
  assert len(dimensions)
  pool = dimensions[0].get('pool')
  if not pool:
    raise RuntimeError(
        'No pool set for CrOS test, unable to determine whether running on '
        'a VM or physical hardware.')

  if StringContainsSubstring(pool, VM_POOLS):
    return [
      '--remote=127.0.0.1',
      # By default, CrOS VMs' ssh servers listen on local port 9222.
      '--remote-ssh-port=9222',
    ]
  if StringContainsSubstring(pool, HW_POOLS):
    return [
      # Magic hostname that resolves to a CrOS device in the test lab.
      '--remote=variable_chromeos_device_hostname',
    ]
  raise RuntimeError('Unknown CrOS pool %s' % pool)