(session *executor.JudgeSession, caseIndex int)
| 18 | ) |
| 19 | |
| 20 | func runCheckerCase(session *executor.JudgeSession, caseIndex int) error { |
| 21 | iCase := &session.JudgeConfig.SpecialJudge.CheckerCases[caseIndex] |
| 22 | tInput := path.Join(session.SessionDir, fmt.Sprintf("%d_problem.in", caseIndex)) |
| 23 | tOutput := path.Join(session.SessionDir, fmt.Sprintf("%d_problem.out", caseIndex)) |
| 24 | tAnswer := path.Join(session.SessionDir, fmt.Sprintf("%d_problem.ans", caseIndex)) |
| 25 | |
| 26 | // 写入数据 |
| 27 | err := ioutil.WriteFile(tInput, []byte(iCase.Input), 0666) |
| 28 | if err != nil { |
| 29 | return err |
| 30 | } |
| 31 | err = ioutil.WriteFile(tOutput, []byte(iCase.Output), 0666) |
| 32 | if err != nil { |
| 33 | return err |
| 34 | } |
| 35 | err = ioutil.WriteFile(tAnswer, []byte(iCase.Answer), 0666) |
| 36 | if err != nil { |
| 37 | return err |
| 38 | } |
| 39 | |
| 40 | config := session.JudgeConfig |
| 41 | |
| 42 | cPath, err := utils.GetCompiledBinaryFileAbsPath("checker", config.SpecialJudge.Name, session.ConfigDir) |
| 43 | if err != nil { |
| 44 | return err |
| 45 | } |
| 46 | // 运行checker程序 |
| 47 | ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) |
| 48 | // <input-file> <output-file> <answer-file> [<report-file>] |
| 49 | ret, err := utils.RunUnixShell(&structs.ShellOptions{ |
| 50 | Context: ctx, |
| 51 | Name: cPath, |
| 52 | Args: []string{ |
| 53 | tInput, |
| 54 | tOutput, |
| 55 | tAnswer, |
| 56 | }, |
| 57 | StdWriter: nil, |
| 58 | OnStart: nil, |
| 59 | }) |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | |
| 64 | judgeResult := -1 |
| 65 | for _, item := range constants.TestlibExitMsgMapping { |
| 66 | if strings.HasPrefix(ret.Stderr, item.ErrName) { |
| 67 | judgeResult = item.JudgeResult |
| 68 | } |
| 69 | } |
| 70 | if judgeResult == -1 { |
| 71 | judgeResult = constants.JudgeFlagSpecialJudgeError |
| 72 | } |
| 73 | iCase.CheckerVerdict = judgeResult |
| 74 | iCase.CheckerComment = ret.Stderr |
| 75 | iCase.Verdict = iCase.CheckerVerdict == iCase.ExpectedVerdict |
| 76 | return nil |
| 77 | } |
no test coverage detected