judge: allow runtimeErrorAnalysis hook

This commit is contained in:
undefined committed 2022-03-26 01:53:11 +08:00
1 parent cdc6ba8453
commit d225be35c9
5 files changed
+34 -1

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js",
"version": "2.14.10",
"version": "2.15.0",
"main": "package.json",
"author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git",
+16
View File
@@ -82,6 +82,22 @@ function judgeCase(c: Case, sid: string) {
} else if (status === STATUS.STATUS_RUNTIME_ERROR && code) {
if (code < 32) message = signals[code];
else message = { message: 'Your program returned {0}.', params: [code] };
const langConfig = ctx.getLang(ctx.lang);
if (langConfig.runtimeErrorAnalysis && !this.runtimeErrorAnalysis) {
this.runtimeErrorAnalysis = true;
run(langConfig.runtimeErrorAnalysis, {
copyIn: {
input: { src: stdin },
[langConfig.code_file || 'foo']: { content: ctx.code },
compile: { content: langConfig.compile },
execute: { content: langConfig.execute },
},
time: 5000,
memory: 256,
})
.then((r) => ctx.next({ compiler_text: r.stdout.toString().substring(0, 1024) }))
.catch((e) => console.error(e));
}
}
await Promise.all(
Object.values(res.fileIds).map((id) => del(id)),
@@ -6,6 +6,7 @@ export type Context = JudgeTaskInterface & RuntimeContext;
export interface JudgeTaskInterface {
next(arg0: {
compiler_text?: string;
status?: number;
message?: string;
progress?: number;
+15
View File
@@ -79,6 +79,21 @@ export const judge = async (ctx: Context) => {
status = STATUS.STATUS_RUNTIME_ERROR;
if (code < 32) message.push(`ExitCode: ${code} (${signals[code]})`);
else message.push(`ExitCode: ${code}`);
const langConfig = ctx.getLang(ctx.lang);
if (langConfig.runtimeErrorAnalysis) {
run(langConfig.runtimeErrorAnalysis, {
copyIn: {
input: { src: stdin },
[langConfig.code_file || 'foo']: { content: ctx.code },
compile: { content: langConfig.compile },
execute: { content: langConfig.execute },
},
time: 5000,
memory: 256,
})
.then((r) => ctx.next({ compiler_text: r.stdout.toString().substring(0, 1024) }))
.catch((e) => console.error(e));
}
}
message.push(fs.readFileSync(stdout).toString());
message.push(fs.readFileSync(stderr).toString());