Exemple #1
0
 def parse_return_code(cls, proc, executor, point_value, time_limit,
                       memory_limit, feedback, name, stderr):
     if proc.returncode == cls.AC:
         return CheckerResult(True, point_value, feedback=feedback)
     elif proc.returncode == cls.PARTIAL:
         match = cls.repartial.search(stderr)
         if not match:
             raise InternalError('Invalid stderr for partial points: %r' %
                                 stderr)
         points = int(match.group(1))
         if not 0 <= points <= point_value:
             raise InternalError('Invalid partial points: %d' % points)
         return CheckerResult(True, points, feedback=feedback)
     elif proc.returncode == cls.WA:
         return CheckerResult(False, 0, feedback=feedback)
     elif proc.returncode == cls.PE:
         return CheckerResult(False,
                              0,
                              feedback=feedback or 'Presentation Error')
     elif proc.returncode == cls.IE:
         raise InternalError('%s failed assertion with message %s' %
                             (name, feedback))
     else:
         parse_helper_file_error(proc, executor, name, stderr, time_limit,
                                 memory_limit)
Exemple #2
0
 def parse_return_code(cls, proc, executor, point_value, time_limit,
                       memory_limit, feedback, name, stderr):
     if proc.returncode == cls.AC:
         return CheckerResult(True, point_value, feedback=feedback)
     elif proc.returncode == cls.WA:
         return CheckerResult(False, 0, feedback=feedback)
     else:
         parse_helper_file_error(proc, executor, name, stderr, time_limit,
                                 memory_limit)
Exemple #3
0
 def parse_return_code(cls, proc, executor, point_value, time_limit,
                       memory_limit, feedback, name, stderr):
     if proc.returncode == cls.AC:
         return CheckerResult(True, point_value, feedback=feedback)
     elif proc.returncode == cls.WA:
         return CheckerResult(False, 0, feedback=feedback)
     elif proc.returncode == cls.PE:
         return CheckerResult(False,
                              0,
                              feedback=feedback or 'Presentation Error')
     elif proc.returncode == cls.IE:
         raise InternalError('%s failed assertion with message %s' %
                             (name, feedback))
     else:
         parse_helper_file_error(proc, executor, name, stderr, time_limit,
                                 memory_limit)
Exemple #4
0
 def parse_return_code(cls, proc, executor, point_value, time_limit, memory_limit, feedback, name, stderr):
     if proc.returncode == cls.AC:
         return True
     elif proc.returncode == cls.WA:
         # PEG allows for a ratio of floating points
         # Scanning for floating points with a regex is impractical, so we loop all lines
         feedback_lines = feedback.split('\n')
         for line1, line2 in zip(feedback_lines, feedback_lines[1:]):
             try:
                 percentage = float(line1) / float(line2)
             except (ValueError, ZeroDivisionError):
                 pass
             else:
                 if percentage > 0:
                     # We like to return _AC for partials, vs PEG and WA
                     return CheckerResult(True, point_value * percentage)
         return False
     else:
         parse_helper_file_error(proc, executor, name, stderr, time_limit, memory_limit)
Exemple #5
0
    def parse_return_code(cls, proc, executor, point_value, time_limit,
                          memory_limit, feedback, name, stderr):
        if proc.returncode == cls.AC:
            return CheckerResult(True, point_value, feedback=feedback)
        elif proc.returncode == cls.PARTIAL:
            match = cls.repartial.search(stderr)
            if not match:
                raise InternalError('Invalid stderr for partial points: %r' %
                                    stderr)
            points = float(match.group(0))
            if not 0 <= points <= 1:
                raise InternalError('Invalid partial points: %d' % points)

            ac = (points == 1)
            return CheckerResult(ac, points * point_value, feedback=feedback)
        elif proc.returncode == cls.WA:
            return CheckerResult(False, 0, feedback=feedback)
        else:
            parse_helper_file_error(proc, executor, name, stderr, time_limit,
                                    memory_limit)
Exemple #6
0
    def _run_generator(self, gen, args=None):
        flags = []
        args = args or []

        # resource limits on how to run the generator
        time_limit = env.generator_time_limit
        memory_limit = env.generator_memory_limit
        compiler_time_limit = env.generator_compiler_time_limit
        lang = None  # Default to C/C++

        base = get_problem_root(self.problem.id)
        if isinstance(gen, str):
            filenames = gen
        elif isinstance(gen.unwrap(), list):
            filenames = list(gen.unwrap())
        else:
            if isinstance(gen.source, str):
                filenames = gen.source
            elif isinstance(gen.source.unwrap(), list):
                filenames = list(gen.source.unwrap())
            else:
                raise InvalidInitException('invalid generator declaration')

            if gen.flags:
                flags += gen.flags
            if not args and gen.args:
                args += gen.args

            time_limit = gen.time_limit or time_limit
            memory_limit = gen.memory_limit or memory_limit
            compiler_time_limit = gen.compiler_time_limit or compiler_time_limit
            lang = gen.language

        if not isinstance(filenames, list):
            filenames = [filenames]

        filenames = [
            os.path.abspath(os.path.join(base, name)) for name in filenames
        ]
        executor = compile_with_auxiliary_files(filenames, flags, lang,
                                                compiler_time_limit)

        # convert all args to str before launching; allows for smoother int passing
        args = map(str, args)

        # setting large buffers is really important, because otherwise stderr is unbuffered
        # and the generator begins calling into cptbox Python code really frequently
        proc = executor.launch(*args,
                               time=time_limit,
                               memory=memory_limit,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               stderr_buffer_size=65536,
                               stdout_buffer_size=65536)

        try:
            input = self.problem.problem_data[
                self.config['in']] if self.config['in'] else None
        except KeyError:
            input = None

        stdout, stderr = proc.unsafe_communicate(input)
        self._generated = list(map(self._normalize, (stdout, stderr)))

        parse_helper_file_error(proc, executor, 'generator', stderr,
                                time_limit, memory_limit)