Skip to content

Commit 44a2961

Browse files
committed
add: submission result method
1 parent 42b86c5 commit 44a2961

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

src/tasks/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export const executor = <J, R>(scenario: Scenario) => async (job: Job & J): Prom
2626
--memory="${LANG_CONFIG.MEM_LIMIT}" \\
2727
--ulimit nofile=64:64 \\
2828
--rm \\
29-
--read-only \\
3029
-v "${currentJobDir}":/usr/src/runbox \\
3130
-w /usr/src/runbox \\
3231
codingblocks/judge-worker-${job.lang} \\

src/tasks/submission.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import config = require('../../config.js')
2-
import { cat, exec, mkdir, rm } from 'shelljs'
2+
import { cat, ls, mkdir, exec } from 'shelljs'
33
import { SubmissionJob } from 'types/job'
44
import { SubmissionResult } from 'types/result'
55
import * as path from 'path'
@@ -40,13 +40,52 @@ class SubmissionScenario implements Scenario {
4040
}))
4141
}
4242

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+
}
4982
})
83+
84+
return {
85+
id: jobId,
86+
stderr: compile_stderr,
87+
testcases
88+
}
5089
}
5190
}
5291

test/submissionScenario.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ describe('Submission Scenario', () => {
2525
source: (new Buffer(source)).toString('base64'),
2626
lang: 'py3',
2727
timelimit: 5,
28-
testcases: [{ id: 122, input: 'https://minio.cb.lk/public/input', output: 'https://minio.cb.lk/public/output' }]
28+
testcases: [{
29+
id: 122,
30+
input: 'https://minio.cb.lk/public/input',
31+
output: 'https://minio.cb.lk/public/output'
32+
}]
2933
}
3034

3135
rm('-rf', config.RUNBOX.DIR)

0 commit comments

Comments
 (0)