运行交互评测
(ctx context.Context, session *JudgeSession, rst *commonStructs.TestCaseResult)
| 133 | |
| 134 | // 运行交互评测 |
| 135 | func runInteractiveAsync(ctx context.Context, session *JudgeSession, rst *commonStructs.TestCaseResult) (*ProcessInfo, *ProcessInfo, error) { |
| 136 | var answerErr, checkerErr, gErr error |
| 137 | |
| 138 | fdChecker, err := forkexec.GetPipe() |
| 139 | if err != nil { |
| 140 | return nil, nil, errors.Errorf("create pipe error: %s", err.Error()) |
| 141 | } |
| 142 | |
| 143 | fdAnswer, err := forkexec.GetPipe() |
| 144 | if err != nil { |
| 145 | return nil, nil, errors.Errorf("create pipe error: %s", err.Error()) |
| 146 | } |
| 147 | |
| 148 | answer := ProcessInfo{} |
| 149 | checker := ProcessInfo{} |
| 150 | answerSuccess := make(chan bool, 1) |
| 151 | checkerSuccess := make(chan bool, 1) |
| 152 | answerPid := 0 |
| 153 | checkerPid := 0 |
| 154 | exitCounter := 0 |
| 155 | |
| 156 | go func() { |
| 157 | var pstate *cmd.ProcessState |
| 158 | var pArgs *PArgs |
| 159 | var proc *cmd.Process |
| 160 | // Get process options |
| 161 | pArgs, answerErr = getProcessOptions(session, rst, false, true, []uintptr{fdAnswer[0], fdChecker[1]}) |
| 162 | if answerErr != nil { |
| 163 | answerSuccess <- false |
| 164 | return |
| 165 | } |
| 166 | // Start process |
| 167 | proc, answerErr = cmd.StartProcess(pArgs.Name, pArgs.Args, pArgs.Attr) |
| 168 | if answerErr != nil { |
| 169 | answerSuccess <- false |
| 170 | return |
| 171 | } |
| 172 | // Collect process info |
| 173 | answer.Process = proc |
| 174 | answer.Pid = proc.Pid |
| 175 | answerPid = proc.Pid |
| 176 | log.Printf("[Interactive]Start answer process (%d)...\n", answer.Pid) |
| 177 | // Wait for exit. |
| 178 | pstate, answerErr = answer.Process.Wait() |
| 179 | if answerErr != nil { |
| 180 | answerSuccess <- false |
| 181 | return |
| 182 | } |
| 183 | log.Printf("Process (%d) exited.\n", answer.Pid) |
| 184 | answer.Status = pstate.Sys().(syscall.WaitStatus) |
| 185 | answer.Rusage = pstate.SysUsage().(*syscall.Rusage) |
| 186 | if answer.Rusage == nil { |
| 187 | answerErr = errors.Errorf("get rusage failed") |
| 188 | answerSuccess <- false |
| 189 | return |
| 190 | } |
| 191 | closeFiles(pArgs.Attr.Files) |
| 192 | answerSuccess <- true |
no test coverage detected