judge: configurable limits (#31)

This commit is contained in:
undefined committed 2020-11-28 17:33:01 +08:00
1 parent 55352ab27b
commit de40219a88
7 files changed
+12 -11

No files matched your search

+5 -2
View File
@@ -2,6 +2,7 @@ import fs from 'fs-extra';
import path from 'path';
import yaml from 'js-yaml';
import { Dictionary } from 'lodash';
import { argv } from 'yargs';
import { FormatError, SystemError } from './error';
import { parseTimeMS, parseMemoryMB, ensureFile } from './utils';
@@ -284,12 +285,14 @@ function convertIniConfig(ini: string) {
}
function isValidConfig(config) {
if (config.count > 100) throw new FormatError('Too many testcases. Cancelled.');
if (config.count > (argv.max_testcases_count as string || 100)) throw new FormatError('Too many testcases. Cancelled.');
let total_time = 0;
for (const subtask of config.subtasks) {
total_time += subtask.time_limit_ms * subtask.cases.length;
}
if (total_time > 60 * 1000) throw new FormatError('Total time limit longer than 60s. Cancelled.');
if (total_time > (+argv.max_time_limit || 60) * 1000) {
throw new FormatError('Total time limit longer than {0}s. Cancelled.', [+argv.max_time_limit || 60]);
}
}
export default async function readCases(folder: string, cfg: Record<string, any> = {}, args) {
+1 -1
View File
@@ -153,7 +153,7 @@ const checkers: Record<string, Checker> = {
...config.copyIn,
},
});
if (status !== STATUS.STATUS_ACCEPTED) throw new SystemError('Checker returned a non-zero value', [status]);
if (status !== STATUS.STATUS_ACCEPTED) throw new SystemError('Checker returned {0}.', [status]);
const score = parseInt(stdout, 10);
status = score === config.score ? STATUS.STATUS_ACCEPTED : STATUS.STATUS_WRONG_ANSWER;
return { status, score, message: stderr };
-3
View File
@@ -10,9 +10,6 @@ import log from './log';
export let CONFIG_FILE = path.resolve(os.homedir(), '.config', 'hydro', 'judge.yaml');
export let CACHE_DIR = path.resolve(os.homedir(), '.cache', 'hydro', 'judge');
export let FILES_DIR = path.resolve(os.homedir(), '.cache', 'hydro', 'files', 'judge');
export let SYSTEM_MEMORY_LIMIT_MB = 1024;
export let SYSTEM_TIME_LIMIT_MS = 16000;
export let SYSTEM_PROCESS_LIMIT = 32;
export let RETRY_DELAY_SEC = 15;
export let TEMP_DIR = path.resolve(os.tmpdir(), 'hydro', 'judge');
export let EXECUTION_HOST = 'http://localhost:5050';
+2 -1
View File
@@ -1,11 +1,12 @@
import Axios from 'axios';
import fs from 'fs-extra';
import { argv } from 'yargs';
import * as STATUS from './status';
import { SystemError } from './error';
import { cmd } from './utils';
const env = ['PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', 'HOME=/w'];
const axios = Axios.create({ baseURL: 'http://localhost:5050' });
const axios = Axios.create({ baseURL: argv.sandbox as string || 'http://localhost:5050' });
const statusMap = {
'Time Limit Exceeded': STATUS.STATUS_TIME_LIMIT_EXCEEDED,