Exemple #1
0
    def run(self, *, interaction=None, submission_args=None):
        if self.problem.interactive:
            result = interactive.run_interactive_testcase(
                self, interaction=interaction, submission_args=submission_args)
        else:
            result = self.submission.run(self.testcase.in_path, self.out_path)
            if result.duration > self.problem.settings.timelimit:
                result.verdict = 'TIME_LIMIT_EXCEEDED'
                if result.duration >= self.problem.settings.timeout:
                    result.print_verdict_ = 'TLE (aborted)'
            elif result.ok is not True:
                result.verdict = 'RUN_TIME_ERROR'
                if config.args.error:
                    result.err = 'Exited with code ' + str(
                        result.ok) + ':\n' + result.err
                else:
                    result.err = 'Exited with code ' + str(result.ok)
            else:
                # Overwrite the result with validator returncode and stdout/stderr, but keep the original duration.
                duration = result.duration
                result = self._validate_output()
                if result is False:
                    error(
                        f'No output validators found for testcase {self.testcase.name}'
                    )
                    result = ExecResult(-1, 0, None, None)
                    result.verdict = 'VALIDATOR_CRASH'
                else:
                    result.duration = duration

                    if result.ok is True:
                        result.verdict = 'ACCEPTED'
                    elif result.ok is False:
                        result.verdict = 'WRONG_ANSWER'
                    else:
                        config.n_error += 1
                        result.verdict = 'VALIDATOR_CRASH'

            # Delete .out files larger than 1MB.
            if (not config.args.error and self.out_path.is_file()
                    and self.out_path.stat().st_size > 1_000_000_000):
                self.out_path.unlink()

        self.result = result
        return result
Exemple #2
0
    def test(self):
        print(ProgressBar.action('Running', str(self.name)), file=sys.stderr)

        testcases = self.problem.testcases(needans=False)

        if self.problem.interactive:
            output_validators = self.problem.validators('output')
            if output_validators is False:
                return

        for testcase in testcases:
            header = ProgressBar.action('Running ' + str(self.name),
                                        testcase.name)
            print(header, file=sys.stderr)

            if not self.problem.interactive:
                assert self.run_command is not None
                with testcase.in_path.open('rb') as inf:
                    result = exec_command(
                        self.run_command,
                        crop=False,
                        stdin=inf,
                        stdout=None,
                        stderr=None,
                        timeout=self.problem.settings.timeout,
                    )

                assert result.err is None and result.out is None
                if result.duration > self.problem.settings.timeout:
                    status = f'{Fore.RED}Aborted!'
                    config.n_error += 1
                elif result.ok is not True and result.ok != -9:
                    config.n_error += 1
                    status = None
                    print(
                        f'{Fore.RED}Run time error!{Style.RESET_ALL} exit code {result.ok} {Style.BRIGHT}{result.duration:6.3f}s{Style.RESET_ALL}',
                        file=sys.stderr,
                    )
                elif result.duration > self.problem.settings.timelimit:
                    status = f'{Fore.YELLOW}Done (TLE):'
                    config.n_warn += 1
                else:
                    status = f'{Fore.GREEN}Done:'

                if status:
                    print(
                        f'{status}{Style.RESET_ALL} {Style.BRIGHT}{result.duration:6.3f}s{Style.RESET_ALL}',
                        file=sys.stderr,
                    )
                print(file=sys.stderr)

            else:
                # Interactive problem.
                run = Run(self.problem, self, testcase)
                result = interactive.run_interactive_testcase(
                    run,
                    interaction=True,
                    validator_error=None,
                    team_error=None)
                if result.verdict != 'ACCEPTED':
                    config.n_error += 1
                    print(
                        f'{Fore.RED}{result.verdict}{Style.RESET_ALL} {Style.BRIGHT}{result.duration:6.3f}s{Style.RESET_ALL}',
                        file=sys.stderr,
                    )
                else:
                    print(
                        f'{Fore.GREEN}{result.verdict}{Style.RESET_ALL} {Style.BRIGHT}{result.duration:6.3f}s{Style.RESET_ALL}',
                        file=sys.stderr,
                    )