This repository has been archived by the owner on Nov 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
runner.js
105 lines (90 loc) · 2.79 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
let randomstring = require("randomstring");
let Sandbox = require('chroot-sandbox');
let sb = new Sandbox(parseInt(process.argv[2]) || 2333, [
['/usr/bin', '/usr/bin', true],
['/usr/share', '/usr/share', true],
['/usr/lib', '/usr/lib', true],
['/lib', '/lib', true],
['/lib64', '/lib64', true],
['/etc/alternatives/', '/etc/alternatives/', true],
['/dev', '/dev', true],
['/proc', '/proc', true],
]);
function runTestcase(task, language, execFile, extraFiles, testcase) {
sb.reset();
if (!task.file_io_input_name) task.file_io_input_name = 'data.in'
if (!task.file_io_output_name) task.file_io_output_name = 'data.out'
if (extraFiles) {
for (let file of extraFiles) {
if (typeof file === 'string') sb.put(file);
else sb.put(file.filename, file.mask, file.targetFilename);
}
}
sb.put(testcase.input, 777, task.file_io_input_name);
let program = sb.put(execFile);
let stderr = randomstring.generate(10);
let runOptions = {
program: program,
file_stdin: '',
file_stdout: '',
file_stderr: stderr,
time_limit: Math.ceil(task.time_limit / 1000),
time_limit_reserve: 1,
memory_limit: task.memory_limit * 1024,
memory_limit_reserve: language.minMemory + 32 * 1024,
large_stack: language.largeStack,
output_limit: Math.max(config.output_limit, language.minOutputLimit),
process_limit: language.minProcessLimit,
network: false
};
if (!task.file_io) {
runOptions.file_stdin = task.file_io_input_name;
runOptions.file_stdout = task.file_io_output_name;
}
let result = sb.run(runOptions);
return {
result: result,
getOutputFile: () => {
return sb.get(task.file_io_output_name);
},
getStderrFile: () => {
return sb.get(stderr);
}
};
}
function runForSpecialJudge (execFile, extraFiles, language) {
sb.reset();
// console.log(arguments);
let program = sb.put(execFile);
if (extraFiles) {
for (let file of extraFiles) {
if (typeof file === 'string') sb.put(file);
else {
if (typeof file.data !== 'undefined') {
sb.put(Buffer.from(file.data), file.mask, file.targetFilename);
} else {
sb.put(file.filename, file.mask, file.targetFilename);
}
}
}
}
let runOptions = {
program: program,
file_stdout: 'stdout',
file_stderr: 'stderr',
time_limit: Math.ceil(config.spj_time_limit / 1000),
time_limit_reserve: 1,
memory_limit: config.spj_time_limit * 1024,
memory_limit_reserve: language.minMemory + 32 * 1024,
large_stack: language.largeStack,
output_limit: Math.max(config.spj_message_limit * 2, language.minOutputLimit),
process_limit: language.minProcessLimit,
network: false
};
return sb.run(runOptions);
}
module.exports = [
sb,
runTestcase,
runForSpecialJudge
];