Пример #1
0
def _run_ingen(environ, use_sandboxes=False):
    command = [tempcwd('ingen')]
    if use_sandboxes:
        executor = PRootExecutor('null-sandbox')
    else:
        executor = UnprotectedExecutor()
    return _run_in_executor(environ, command, executor, ignore_errors=True)
Пример #2
0
def _run_diff(env):
    renv = _run_in_executor(
        env,
        ['diff', '-b', '-q', 'out', 'hint'],
        UnprotectedExecutor(),
        extra_ignore_errors=(1, ),
    )
    return renv['return_code'] and ['WA'] or ['OK']
Пример #3
0
def execute(command, **kwargs):
    """Wrapper for :class:`sio.workers.executors.UnprotectedExecutor` returning stdout.

       Returns tuple (return_code, stdout)
    """
    kwargs['capture_output'] = True
    with UnprotectedExecutor() as e:
        env = e(command, **kwargs)

    return env['return_code'], env['stdout']
Пример #4
0
    def __init__(self, sandbox=None):
        """
        :param sandbox: If specified, commands will be executed in an isolated
                        environment with the sandbox as root directory.
        """
        if sandbox is not None:
            self.sandbox = sandbox

        if self.sandbox is None:
            self.executor = UnprotectedExecutor()
        else:
            self.executor = PRootExecutor('compiler-' + self.sandbox)
Пример #5
0
 def execute_checker(with_stderr=False):
     if env.get('untrusted_checker', False) and use_sandboxes:
         return _run_in_executor(env,
                                 command,
                                 PRootExecutor('null-sandbox'),
                                 ignore_return=True,
                                 forward_stderr=with_stderr)
     else:
         return _run_in_executor(env,
                                 command,
                                 UnprotectedExecutor(),
                                 ignore_errors=True,
                                 forward_stderr=with_stderr)
Пример #6
0
def compile_and_run(compiler_env, expected_output, program_args=None):
    """Helper function for compiling, launching and
       testing the result of a program.
    """

    # Dummy sandbox doesn't support asking for versioned filename
    out_file = compiler_env['out_file']
    if compiler_env.get('compiler', '').endswith('-java'):
        compiler_env['compilation_time_limit'] = 180000
    with TemporaryCwd('compile'):
        result_env = run(compiler_env)
    print_env(result_env)

    eq_(result_env['result_code'], 'OK')
    binary = ft.download({'path': out_file}, 'path')

    os.chmod(binary, stat.S_IXUSR | os.stat(binary).st_mode)

    if not program_args:
        program_args = []

    executor = UnprotectedExecutor()
    frkwargs = {}

    # Hack for java
    if compiler_env.get('compiler') == 'default-java':
        executor = PRootExecutor('compiler-java.1_8')
        frkwargs['proot_options'] = ['-b', '/proc']

    frunner = get_file_runner(executor, result_env)
    with frunner:
        renv = frunner(binary,
                       program_args,
                       stderr=sys.__stderr__,
                       capture_output=True,
                       **frkwargs)
    eq_(renv['return_code'], 0)
    eq_(renv['stdout'].decode().strip(), expected_output)

    os.remove(binary)