Пример #1
0
def check(
    process_output,
    judge_output,
    judge_input,
    problem_id,
    files,
    lang,
    time_limit=env['generator_time_limit'],
    memory_limit=env['generator_memory_limit'],
    compiler_time_limit=env['generator_compiler_limit'],
    feedback=True,
    flags=[],
    type='default',
    args_format_string=None,
    point_value=None,
    **kwargs,
) -> CheckerResult:
    executor = get_executor(problem_id, files, flags, lang,
                            compiler_time_limit)

    if type not in contrib_modules:
        raise InternalError('%s is not a valid contrib module' % type)

    args_format_string = args_format_string or contrib_modules[
        type].ContribModule.get_checker_args_format_string()

    with mktemp(judge_input) as input_file, mktemp(
            process_output) as output_file, mktemp(
                judge_output) as answer_file:
        checker_args = shlex.split(
            args_format_string.format(
                input_file=shlex.quote(input_file.name),
                output_file=shlex.quote(output_file.name),
                answer_file=shlex.quote(answer_file.name),
            ))
        process = executor.launch(
            *checker_args,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            memory=memory_limit,
            time=time_limit,
        )

        proc_output, error = process.communicate()
        proc_output = utf8text(proc_output)

        return contrib_modules[type].ContribModule.parse_return_code(
            process,
            executor,
            point_value,
            time_limit,
            memory_limit,
            feedback=utf8text(proc_output) if feedback else '',
            name='checker',
            stderr=error,
        )
Пример #2
0
def check(process_output,
          judge_output,
          judge_input,
          problem_id,
          files,
          lang,
          time_limit=env['generator_time_limit'],
          memory_limit=env['generator_memory_limit'],
          compiler_time_limit=env['generator_compiler_limit'],
          feedback=True,
          flags=[],
          cached=True,
          type='default',
          point_value=None,
          **kwargs) -> CheckerResult:
    executor = get_executor(problem_id, files, flags, lang,
                            compiler_time_limit, cached)

    if type not in contrib_modules:
        raise InternalError('%s is not a valid return code parser' % type)

    with mktemp(judge_input) as input_file, mktemp(
            process_output) as output_file, mktemp(judge_output) as judge_file:
        process = executor.launch(
            input_file.name,
            output_file.name,
            judge_file.name,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            memory=memory_limit,
            time=time_limit,
        )

        proc_output, error = process.communicate()
        proc_output = utf8text(proc_output)

        return contrib_modules[type].ContribModule.parse_return_code(
            process,
            executor,
            point_value,
            time_limit,
            memory_limit,
            feedback=utf8text(proc_output) if feedback else None,
            name='checker',
            stderr=error,
        )
Пример #3
0
def check(process_output,
          judge_output,
          judge_input,
          problem_id={{problemid}},
          files={{filecpp}},
          lang='CPP14',
          time_limit=10,
          memory_limit=1024 * 512,
          compiler_time_limit=30,
          feedback=True,
          point_value=None,
          **kwargs) -> CheckerResult:
    executor = get_executor(files, lang, compiler_time_limit, problem_id)

    with mktemp(judge_input) as input_file, mktemp(
            process_output) as output_file, mktemp(judge_output) as judge_file:
        try:
            process = executor.launch(input_file.name,
                                      output_file.name,
                                      judge_file.name,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE,
                                      memory=memory_limit,
                                      time=time_limit)
            proc_output, error = map(utf8text, process.communicate())
        except Exception as err:
            raise InternalError('Error while running checker: %r', err)

        return Module.parse_return_code(
            process,
            executor,
            point_value,
            time_limit,
            memory_limit,
            feedback=utf8text(proc_output) if feedback else None,
            name='checker',
            stderr=error)
Пример #4
0
        )
        os.close(submission_stdin_pipe)
        os.close(submission_stdout_pipe)

    def _interact_with_process(self, case, result, input):
        judge_output = case.output_data()
        # Give TL + 1s by default, so we do not race (and incorrectly throw IE) if submission gets TLE
        self._interactor_time_limit = (self.handler_data.preprocessing_time
                                       or 1) + self.problem.time_limit
        self._interactor_memory_limit = self.handler_data.memory_limit or env[
            'generator_memory_limit']
        args_format_string = (self.handler_data.args_format_string or
                              contrib_modules[self.contrib_type].ContribModule.
                              get_interactor_args_format_string())

        with mktemp(input) as input_file, mktemp(judge_output) as answer_file:
            # TODO(@kirito): testlib.h expects a file they can write to,
            # but we currently don't have a sane way to allow this.
            # Thus we pass /dev/null for now so testlib interactors will still
            # work, albeit with diminished capabilities
            interactor_args = shlex.split(
                args_format_string.format(
                    input_file=shlex.quote(input_file.name),
                    output_file=shlex.quote(os.devnull),
                    answer_file=shlex.quote(answer_file.name),
                ))
            self._interactor = self.interactor_binary.launch(
                *interactor_args,
                time=self._interactor_time_limit,
                memory=self._interactor_memory_limit,
                stdin=self._interactor_stdin_pipe,
Пример #5
0
            stdin=submission_stdin,
            stdout=submission_stdout,
            stderr=subprocess.PIPE,
            wall_time=case.config.wall_time_factor * self.problem.time_limit,
        )
        os.close(submission_stdin)
        os.close(submission_stdout)

    def _interact_with_process(self, case, result, input):
        output = case.output_data()
        self._interactor_time_limit = (self.handler_data.preprocessing_time
                                       or 0) + self.problem.time_limit
        self._interactor_memory_limit = self.handler_data.memory_limit or env[
            'generator_memory_limit']

        with mktemp(input) as input_file, mktemp(output) as output_file:
            self._interactor = self.interactor_binary.launch(
                input_file.name,
                output_file.name,
                time=self._interactor_time_limit,
                memory=self._interactor_memory_limit,
                stdin=self._stdin_pipe,
                stdout=self._stdout_pipe,
                stderr=subprocess.PIPE,
            )

            os.close(self._stdin_pipe)
            os.close(self._stdout_pipe)

            self._current_proc.wait()
            self._interactor.wait()