judge: 修复 time&mem limit 在自动模式不生效的问题

This commit is contained in:
undefined committed 2021-03-02 23:42:28 +08:00
1 parent 8e90f24d01
commit d6349a70cf
4 files changed
+20 -20

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.4.0", "version": "2.4.1",
"main": "package.json", "main": "package.json",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
+16 -16
View File
@@ -67,7 +67,7 @@ const RE1: Re1[] = [
}, },
]; ];
async function read0(folder: string, files: string[], checkFile) { async function read0(folder: string, files: string[], checkFile, cfg) {
const cases = []; const cases = [];
for (const file of files) { for (const file of files) {
for (const REG of RE0) { for (const REG of RE0) {
@@ -86,8 +86,8 @@ async function read0(folder: string, files: string[], checkFile) {
const config = { const config = {
count: 0, count: 0,
subtasks: [{ subtasks: [{
time_limit_ms: 1000, time_limit_ms: parseTimeMS(cfg.time || '1s'),
memory_limit_mb: 512, memory_limit_mb: parseMemoryMB(cfg.memory || '256m'),
type: 'sum', type: 'sum',
cases: [], cases: [],
score: Math.floor(100 / cases.length), score: Math.floor(100 / cases.length),
@@ -103,8 +103,8 @@ async function read0(folder: string, files: string[], checkFile) {
} }
if (extra < cases.length) { if (extra < cases.length) {
config.subtasks.push({ config.subtasks.push({
time_limit_ms: 1000, time_limit_ms: parseTimeMS(cfg.time || '1s'),
memory_limit_mb: 512, memory_limit_mb: parseMemoryMB(cfg.memory || '256m'),
type: 'sum', type: 'sum',
cases: [], cases: [],
score: Math.floor(100 / cases.length) + 1, score: Math.floor(100 / cases.length) + 1,
@@ -121,7 +121,7 @@ async function read0(folder: string, files: string[], checkFile) {
return config; return config;
} }
async function read1(folder: string, files: string[], checkFile) { async function read1(folder: string, files: string[], checkFile, cfg) {
const subtask = {}; const subtask = {};
const subtasks = []; const subtasks = [];
for (const file of files) { for (const file of files) {
@@ -132,8 +132,8 @@ async function read1(folder: string, files: string[], checkFile) {
if (fs.existsSync(path.resolve(folder, c.output))) { if (fs.existsSync(path.resolve(folder, c.output))) {
if (!subtask[REG.subtask(data)]) { if (!subtask[REG.subtask(data)]) {
subtask[REG.subtask(data)] = [{ subtask[REG.subtask(data)] = [{
time_limit_ms: 1000, time_limit_ms: parseTimeMS(cfg.time || '1s'),
memory_limit_mb: 512, memory_limit_mb: parseMemoryMB(cfg.memory || '256m'),
type: 'min', type: 'min',
cases: [c], cases: [c],
}]; }];
@@ -164,7 +164,7 @@ async function read1(folder: string, files: string[], checkFile) {
return config; return config;
} }
async function readAutoCases(folder, { next }) { async function readAutoCases(folder, { next }, cfg) {
const config = { const config = {
checker_type: 'default', checker_type: 'default',
count: 0, count: 0,
@@ -183,8 +183,8 @@ async function readAutoCases(folder, { next }) {
const outputs = await fs.readdir(path.resolve(folder, 'output')); const outputs = await fs.readdir(path.resolve(folder, 'output'));
files.push(...outputs.map((i) => `output/${i}`)); files.push(...outputs.map((i) => `output/${i}`));
} }
let result = await read0(folder, files, checkFile); let result = await read0(folder, files, checkFile, cfg);
if (!result.count) result = await read1(folder, files, checkFile); if (!result.count) result = await read1(folder, files, checkFile, cfg);
Object.assign(config, result); Object.assign(config, result);
next({ message: { message: 'Found {0} testcases.', params: [config.count] } }); next({ message: { message: 'Found {0} testcases.', params: [config.count] } });
} catch (e) { } catch (e) {
@@ -235,8 +235,8 @@ export async function readYamlCases(folder: string, cfg: Dictionary<any> = {}, a
for (const c of cfg.cases) { for (const c of cfg.cases) {
config.count++; config.count++;
config.subtasks[0].cases.push({ config.subtasks[0].cases.push({
input: checkFile(c.input, 'Cannot find input file {0}.'), input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : null,
output: checkFile(c.output, 'Cannot find output file {0}.'), output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : null,
id: config.count, id: config.count,
}); });
} }
@@ -246,8 +246,8 @@ export async function readYamlCases(folder: string, cfg: Dictionary<any> = {}, a
for (const c of subtask.cases) { for (const c of subtask.cases) {
config.count++; config.count++;
cases.push({ cases.push({
input: checkFile(c.input, 'Cannot find input file {0}.'), input: c.input ? checkFile(c.input, 'Cannot find input file {0}.') : null,
output: checkFile(c.output, 'Cannot find output file {0}.'), output: c.output ? checkFile(c.output, 'Cannot find output file {0}.') : null,
id: config.count, id: config.count,
}); });
} }
@@ -260,7 +260,7 @@ export async function readYamlCases(folder: string, cfg: Dictionary<any> = {}, a
}); });
} }
} else { } else {
const c = await readAutoCases(folder, { next }); const c = await readAutoCases(folder, { next }, cfg);
config.subtasks = c.subtasks; config.subtasks = c.subtasks;
config.count = c.count; config.count = c.count;
} }
+1 -1
View File
@@ -36,7 +36,7 @@ function judgeCase(c, sid) {
} }
const { filename } = ctx.config; const { filename } = ctx.config;
const copyIn = { ...ctx.execute.copyIn }; const copyIn = { ...ctx.execute.copyIn };
if (filename) copyIn[`${filename}.in`] = { src: c.input }; if (filename) copyIn[`${filename}.in`] = c.input ? { src: c.input } : { content: '' };
const copyOut = filename ? [`${filename}.out`] : []; const copyOut = filename ? [`${filename}.out`] : [];
const stdin = filename ? null : c.input; const stdin = filename ? null : c.input;
const stdout = path.resolve(ctx.tmpdir, `${c.id}.out`); const stdout = path.resolve(ctx.tmpdir, `${c.id}.out`);
+2 -2
View File
@@ -17,8 +17,8 @@ const Score = {
function judgeCase(c) { function judgeCase(c) {
return async (ctx, ctxSubtask) => { return async (ctx, ctxSubtask) => {
ctx.executeInteractor.copyIn.in = { src: c.input }; ctx.executeInteractor.copyIn.in = c.input ? { src: c.input } : { content: '' };
ctx.executeInteractor.copyIn.out = { src: c.output }; ctx.executeInteractor.copyIn.out = c.output ? { src: c.output } : { content: '' };
ctx.executeInteractor.copyIn['testlib.h'] = { src: resolve(__dirname, '../../files/testlib.h') }; ctx.executeInteractor.copyIn['testlib.h'] = { src: resolve(__dirname, '../../files/testlib.h') };
const [{ code, time_usage_ms, memory_usage_kb }, resInteractor] = await run([ const [{ code, time_usage_ms, memory_usage_kb }, resInteractor] = await run([
{ {