def _TestSolutionWithChallengeCasesOne(self, solution, testcase, result, ui): """Test a wrong solution which has specified challenge cases.""" case_result = yield self._TestOneCase(solution, testcase, ui) result.results[testcase] = case_result if case_result.verdict == test.TestCaseResult.AC: result.Finalize(False, '%s: Unexpectedly accepted' % os.path.basename(testcase.infile), notable_testcase=testcase) ui.errors.Error(solution, result.detail) if ui.options.keep_going: yield False else: raise taskgraph.Bailout([False]) elif case_result.verdict not in (test.TestCaseResult.WA, test.TestCaseResult.TLE, test.TestCaseResult.RE): result.Finalize(False, '%s: Judge Error' % os.path.basename(testcase.infile), notable_testcase=testcase) ui.errors.Error(solution, result.detail) if ui.options.keep_going: yield False else: raise taskgraph.Bailout([False]) ui.console.PrintAction('TEST', solution, '%s: PASSED' % os.path.basename(testcase.infile), progress=True) yield True
def _RunValidatorOne(self, validator, testcase, ui): """Run an input validator against a single input file.""" validationfile = (os.path.splitext(testcase.infile)[0] + consts.VALIDATION_EXT) res = yield validator.Run(args=(), cwd=self.out_dir, input=testcase.infile, output=validationfile, timeout=None, precise=False, redirect_error=True) if res.status == core_codes.RunResult.NG: ui.errors.Error( self, '%s: Validation Failed' % os.path.basename(testcase.infile)) log = files.ReadFile(validationfile) ui.console.PrintLog(log) raise taskgraph.Bailout([False]) elif res.status != core_codes.RunResult.OK: ui.errors.Error( self, '%s: Validator Failed: %s' % (os.path.basename(testcase.infile), res.status)) raise taskgraph.Bailout([False]) ui.console.PrintAction('VALIDATE', self, '%s: PASSED' % os.path.basename(testcase.infile), progress=True) yield True
def _TestSolutionWithAllCasesOne(self, solution, testcase, result, ui): """Test a solution without challenge cases. The solution can be marked as wrong but without challenge cases. """ case_result = yield self._TestOneCase(solution, testcase, ui) result.results[testcase] = case_result if case_result.verdict not in (test.TestCaseResult.AC, test.TestCaseResult.WA, test.TestCaseResult.TLE, test.TestCaseResult.RE): result.Finalize(False, '%s: Judge Error' % os.path.basename(testcase.infile), notable_testcase=testcase) ui.errors.Error(solution, result.detail) if ui.options.keep_going: yield False else: raise taskgraph.Bailout([False]) elif case_result.verdict != test.TestCaseResult.AC: expected = not solution.IsCorrect() result.Finalize( expected, '%s: %s' % (os.path.basename(testcase.infile), case_result.verdict), notable_testcase=testcase) if solution.IsCorrect(): if case_result.verdict == test.TestCaseResult.WA: judgefile = os.path.join( solution.out_dir, os.path.splitext(os.path.basename(testcase.infile))[0] + consts.JUDGE_EXT) ui.errors.Error( solution, '%s\n judge log: %s' % (result.detail, judgefile)) else: ui.errors.Error(solution, result.detail) if ui.options.keep_going: yield False else: raise taskgraph.Bailout([False]) ui.console.PrintAction('TEST', solution, '%s: PASSED' % os.path.basename(testcase.infile), progress=True) yield True
def _RunReferenceSolutionOne(self, reference_solution, testcase, ui): """Run the reference solution against a single input file.""" if os.path.isfile(testcase.difffile): yield True # reactive if self.reactives: if len(self.reactives) > 1: ui.errors.Error(self, "Multiple reactive checkers registered.") yield None reactive = self.reactives[0] if not reactive.variant: reactive.variant = KUPCReactiveRunner() res = yield reactive.variant.Run( reactive=reactive, args=reference_solution.code.run_args, cwd=reference_solution.out_dir, input=testcase.infile, output=testcase.difffile, timeout=None, precise=False) else: res = yield reference_solution.Run(args=(), cwd=reference_solution.out_dir, input=testcase.infile, output=testcase.difffile, timeout=None, precise=False) if res.status != core_codes.RunResult.OK: ui.errors.Error(reference_solution, res.status) raise taskgraph.Bailout([False]) ui.console.PrintAction('REFRUN', reference_solution, '%s: DONE' % os.path.basename(testcase.infile), progress=True) yield True
def _CompileValidatorOne(self, validator, ui): """Compile a single input validator.""" if not validator.QUIET_COMPILE: ui.console.PrintAction('COMPILE', self, validator.src_name) res = yield validator.Compile() if res.status != core_codes.RunResult.OK: ui.errors.Error( self, '%s: Compile Error (%s)' % (validator.src_name, res.status)) ui.console.PrintLog(validator.ReadCompileLog()) raise taskgraph.Bailout([False]) yield True
def _RunGeneratorOne(self, generator, ui): """Run a single input generator.""" ui.console.PrintAction('GENERATE', self, generator.src_name) res = yield generator.Run(args=(), cwd=self.out_dir, input=os.devnull, output=os.devnull, timeout=None, precise=False) if res.status != core_codes.RunResult.OK: ui.errors.Error(self, '%s: %s' % (generator.src_name, res.status)) raise taskgraph.Bailout([False]) yield True
def _RunReferenceSolutionOne(self, reference_solution, testcase, ui): """Run the reference solution against a single input file.""" if os.path.isfile(testcase.difffile): yield True # ui.console.PrintAction('REFRUN', reference_solution, # testcase.infile, progress=True) res = yield reference_solution.Run(args=(), cwd=self.out_dir, input=testcase.infile, output=testcase.difffile, timeout=None, precise=False) if res.status != core_codes.RunResult.OK: ui.errors.Error(reference_solution, res.status) raise taskgraph.Bailout([False]) ui.console.PrintAction('REFRUN', reference_solution, '%s: DONE' % os.path.basename(testcase.infile), progress=True) yield True
def _RunValidatorForInvalidCasesOne(self, validator, testcase, ui): """Run an input validator against a single input file.""" validationfile = (os.path.splitext(testcase.infile)[0] + consts.VALIDATION_EXT) res = yield validator.Run(args=(), cwd=self.out_dir, input=testcase.infile, output=validationfile, timeout=None, precise=False, redirect_error=True) if res.status == codes.RunResult.OK: ui.errors.Error( self, '%s: Unexpectedly Validator Accepted: %s' % (os.path.basename(testcase.infile), res.status)) raise taskgraph.Bailout([False]) ui.console.PrintAction('VALIDATE', self, '%s: Expectedly Failed' % os.path.basename(testcase.infile), progress=True) yield True