def test_run_and_wait_none_env(self): """Test RemoteProcessRunner.run_and_wait() with a None env.""" process_result = new_process.ProcessResult(['command', '123'], 0, b'output', 60.0, False) self.mock.stub().RunAndWait.return_value = ( untrusted_runner_pb2.RunAndWaitResponse( result=remote_process.process_result_to_proto(process_result))) runner = remote_process_host.RemoteProcessRunner( '/executable', ['-default_arg']) result = runner.run_and_wait() result = remote_process_host.process_result_from_proto(result) request = self.mock.stub().RunAndWait.call_args[0][0] self.assertEqual('/executable', request.executable_path) self.assertEqual(['-default_arg'], request.default_args) self.assertEqual([], request.additional_args) self.assertFalse(request.HasField('timeout')) self.assertFalse(request.terminate_before_kill) self.assertFalse(request.HasField('terminate_wait_time')) self.assertFalse(request.HasField('input_data')) self.assertFalse(request.popen_args.HasField('bufsize')) self.assertFalse(request.popen_args.HasField('executable')) self.assertFalse(request.popen_args.HasField('shell')) self.assertFalse(request.popen_args.HasField('cwd')) self.assertEqual({}, request.popen_args.env) self.assertFalse(request.popen_args.env_is_set) self.assertEqual(result.command, process_result.command) self.assertEqual(result.return_code, process_result.return_code) self.assertEqual(result.output, process_result.output) self.assertEqual(result.time_executed, process_result.time_executed) self.assertEqual(result.timed_out, process_result.timed_out)
def test_run_and_wait(self): """Test RemoteProcessRunner.run_and_wait().""" process_result = new_process.ProcessResult(['command', '123'], 0, b'output', 60.0, False) self.mock.stub().RunAndWait.return_value = ( untrusted_runner_pb2.RunAndWaitResponse( result=remote_process.process_result_to_proto(process_result))) runner = remote_process_host.RemoteProcessRunner( '/executable', ['-default_arg']) result = runner.run_and_wait(['-additional_arg'], 100.0, True, 10.0, b'input', shell=True, env={'ASAN_OPTIONS': 'asan_options'}, cwd='/', max_stdout_len=1337) result = remote_process_host.process_result_from_proto(result) request = self.mock.stub().RunAndWait.call_args[0][0] self.assertEqual('/executable', request.executable_path) self.assertEqual(['-default_arg'], request.default_args) self.assertEqual(['-additional_arg'], request.additional_args) self.assertEqual(100.0, request.timeout) self.assertTrue(request.terminate_before_kill) self.assertEqual(10.0, request.terminate_wait_time) self.assertEqual(b'input', request.input_data) self.assertFalse(request.popen_args.HasField('bufsize')) self.assertFalse(request.popen_args.HasField('executable')) self.assertTrue(request.popen_args.shell) self.assertEqual('/', request.popen_args.cwd) self.assertEqual({'ASAN_OPTIONS': 'asan_options'}, request.popen_args.env) self.assertTrue(request.popen_args.env_is_set) self.assertEqual(1337, request.max_stdout_len) self.assertEqual(result.command, process_result.command) self.assertEqual(result.return_code, process_result.return_code) self.assertEqual(result.output, process_result.output) self.assertEqual(result.time_executed, process_result.time_executed) self.assertEqual(result.timed_out, process_result.timed_out)
def test_run_and_wait(self, mock_run_and_wait): """Test remote_process.run_and_wait().""" process_result = new_process.ProcessResult(['command', '123'], 0, 'output', 60.0, False) mock_run_and_wait.return_value = process_result request = untrusted_runner_pb2.RunAndWaitRequest() request.executable_path = '/path' request.default_args.extend(['-default_arg']) request.additional_args.extend(['-additional_arg']) request.timeout = 100.0 request.terminate_before_kill = True request.terminate_wait_time = 10.0 request.input_data = 'input' request.max_stdout_len = 1337 request.popen_args.shell = True request.popen_args.env.update({'VAR': 'VAL'}) request.popen_args.env_is_set = True request.popen_args.cwd = '/' response = remote_process.run_and_wait(request, None) result = remote_process_host.process_result_from_proto(response.result) mock_run_and_wait.assert_called_with( additional_args=['-additional_arg'], timeout=100.0, terminate_before_kill=True, terminate_wait_time=10.0, input_data='input', max_stdout_len=1337, cwd='/', env={'VAR': 'VAL'}, shell=True) self.assertEqual(result.command, process_result.command) self.assertEqual(result.return_code, process_result.return_code) self.assertEqual(result.output, process_result.output) self.assertEqual(result.time_executed, process_result.time_executed) self.assertEqual(result.timed_out, process_result.timed_out)