Example #1
0
def run_process(cmdline,
                current_working_directory=None,
                timeout=process_handler.DEFAULT_TEST_TIMEOUT,
                need_shell=False,
                gestures=None,
                env_copy=None,
                testcase_run=True,
                ignore_children=True):
  """Remote version of process_handler.run_process."""
  request = untrusted_runner_pb2.RunProcessRequest(
      cmdline=cmdline,
      current_working_directory=current_working_directory,
      timeout=timeout,
      need_shell=need_shell,
      testcase_run=testcase_run,
      ignore_children=ignore_children)

  if gestures:
    request.gestures.extend(gestures)

  env = {}
  # run_process's local behaviour is to apply the passed |env_copy| on top of
  # the current environment instead of replacing it completely (like with
  # subprocess).
  environment.set_environment_vars(env, os.environ)
  environment.set_environment_vars(env, env_copy)
  request.env_copy.update(env)

  response = host.stub().RunProcess(request)
  return response.return_code, response.execution_time, response.output
    def test_run_process(self):
        """Test remote_process.run_process."""
        request = untrusted_runner_pb2.RunProcessRequest()
        request.cmdline = 'cmd arg'
        request.timeout = 20
        request.testcase_run = True
        request.gestures.extend(['gesture', 'gesture2'])
        request.env_copy.update({'VAR': 'VAL'})

        self.mock.run_process.return_value = (0, 10.0, 'output')

        response = remote_process.run_process(request, None)
        self.assertEqual(response.return_code, 0)
        self.assertEqual(response.execution_time, 10.0)
        self.assertEqual(response.output, 'output')

        self.mock.run_process.assert_called_with(
            cmdline='cmd arg',
            env_copy={'VAR': 'VAL'},
            gestures=['gesture', 'gesture2'],
            testcase_run=True,
            timeout=20)