|
1 | 1 | import config = require('../../config.js') |
2 | | -import { cat, exec, mkdir, rm } from 'shelljs' |
| 2 | +import { cat, ls, mkdir, exec } from 'shelljs' |
3 | 3 | import { SubmissionJob } from 'types/job' |
4 | 4 | import { SubmissionResult } from 'types/result' |
5 | 5 | import * as path from 'path' |
@@ -40,13 +40,52 @@ class SubmissionScenario implements Scenario { |
40 | 40 | })) |
41 | 41 | } |
42 | 42 |
|
43 | | - async result(currentJobDir: string): Promise<SubmissionResult> { |
44 | | - // TODO |
45 | | - return Promise.resolve({ |
46 | | - id: 1, |
47 | | - stderr: '', |
48 | | - testcases: [] |
| 43 | + async result(currentJobDir: string, jobId: number): Promise<SubmissionResult> { |
| 44 | + // Check for compile_stderr if can't find a stdout file ; stdout can be '' |
| 45 | + const compile_stderr = cat(path.join(currentJobDir, 'compile.stderr')).toString() |
| 46 | + |
| 47 | + if (compile_stderr) { |
| 48 | + return { |
| 49 | + id: jobId, |
| 50 | + stderr: compile_stderr, |
| 51 | + testcases: [] |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + const testcases = ls(path.join(currentJobDir, 'testcases')).map(testcase => { |
| 56 | + const currentTestcasePath = path.join(currentJobDir, 'testcases', testcase) |
| 57 | + |
| 58 | + const stderr = cat(path.join(currentTestcasePath, 'run.stderr')).toString() |
| 59 | + const time = cat(path.join(currentTestcasePath, 'runguard.time')).toString().trim() |
| 60 | + const code = cat(path.join(currentTestcasePath, 'runguard.code')).toString() |
| 61 | + |
| 62 | + const runOutputFile = path.join(currentTestcasePath, 'run.stdout') |
| 63 | + const expectedOutputFile = path.join(currentTestcasePath, 'stdout') |
| 64 | + |
| 65 | + const result = new Array( |
| 66 | + +code === 143 && "TLE", |
| 67 | + +code === 137 && "MLE", |
| 68 | + +code !== 0 && "Run Error", |
| 69 | + +code === 0 && "Success" |
| 70 | + ).reduce((acc, cur) => acc || cur) |
| 71 | + |
| 72 | + const diff = exec(` |
| 73 | + diff -b -a ${runOutputFile} ${expectedOutputFile} |
| 74 | + `) |
| 75 | + |
| 76 | + return { |
| 77 | + id: +testcase, |
| 78 | + time, |
| 79 | + result, |
| 80 | + score: diff.code === 0 ? 100 : 0 |
| 81 | + } |
49 | 82 | }) |
| 83 | + |
| 84 | + return { |
| 85 | + id: jobId, |
| 86 | + stderr: compile_stderr, |
| 87 | + testcases |
| 88 | + } |
50 | 89 | } |
51 | 90 | } |
52 | 91 |
|
|
0 commit comments