You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/hydrojudge/src/sysinfo.ts

70 lines
1.9 KiB
TypeScript

import path from 'path';
import fs from 'fs-extra';
import { noop } from 'lodash';
import { get as _get } from '@hydrooj/utils/lib/sysinfo';
import { getConfig } from './config';
import { Context } from './judge/interface';
import { judge } from './judge/run';
import * as tmpfs from './tmpfs';
export { update } from '@hydrooj/utils/lib/sysinfo';
async function stackSize() {
let output = '';
try {
const context: Context = {
lang: 'cc',
code: `#include <iostream>
using namespace std;
int i=1;
int main(){
char a[1048576]={'1'};
cout<<" "<<i<<flush;
i++;
if (i>256) return 0;
main();
}`,
config: {
time: '3s',
memory: '256m',
},
stat: {},
clean: [],
next: (data) => {
if (data.case) output = data.case.message;
},
end: () => { },
getLang: () => ({
compile: '/usr/bin/g++ -Wall -std=c++14 -o foo foo.cc -lm',
execute: '/w/foo',
code_file: 'foo.cc',
highlight: 'cpp',
monaco: 'cpp',
display: 'C++',
time_limit_rate: 1,
domain: [],
key: '',
}),
tmpdir: path.resolve(getConfig('tmp_dir'), 'sysinfo'),
};
fs.ensureDirSync(context.tmpdir);
tmpfs.mount(context.tmpdir, '32m');
await judge(context).catch((e) => console.error(e));
// eslint-disable-next-line no-await-in-loop
for (const clean of context.clean) await clean().catch(noop);
tmpfs.umount(context.tmpdir);
fs.removeSync(context.tmpdir);
} catch (e) {
return -1;
}
const a = output.split(' ');
return parseInt(a[a.length - 2], 10);
}
export async function get() {
const info = await _get();
// @ts-ignore
info.stack = await stackSize();
return info;
}