mirror of
https://github.com/QingdaoU/Judger.git
synced 2024-12-29 08:21:41 +00:00
update demo
This commit is contained in:
parent
018d2b2d73
commit
6eba6a912d
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ limit
|
||||
runner
|
||||
CMakeLists.txt
|
||||
main
|
||||
demo/out
|
||||
|
10
README.md
10
README.md
@ -1,9 +1,13 @@
|
||||
|
||||
#Judger
|
||||
|
||||
[![Build Status](https://travis-ci.org/QingdaoU/Judger.svg?branch=master)](https://travis-ci.org/QingdaoU/Judger)
|
||||
|
||||
|
||||
OnlineJudge 判题沙箱
|
||||
|
||||
demo:
|
||||
```
|
||||
sudo python setup.py install
|
||||
touch in out
|
||||
gcc test.c -o test
|
||||
sudo python demo.py
|
||||
cd demo && sudo python demo.py
|
||||
```
|
||||
|
17
demo.py
17
demo.py
@ -1,17 +0,0 @@
|
||||
# coding=utf-8
|
||||
import os
|
||||
import judger
|
||||
|
||||
|
||||
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
print judger.run(path=os.path.join(base_path, "test"),
|
||||
in_file=os.path.join(base_path, "in"),
|
||||
out_file=os.path.join(base_path, "out"),
|
||||
max_cpu_time=2000,
|
||||
max_memory=200000000,
|
||||
args=["1", "2", "####"],
|
||||
env=[],
|
||||
use_sandbox=True)
|
||||
|
32
demo/demo.c
Normal file
32
demo/demo.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int *p = NULL;
|
||||
int j;
|
||||
char input[100];
|
||||
// 150M
|
||||
int v = 150000000;
|
||||
|
||||
printf("start\n");
|
||||
|
||||
for (j = 0; j < argc; j++)
|
||||
printf("argv[%d]: %s\n", j, argv[j]);
|
||||
|
||||
scanf("%s", input);
|
||||
printf("%s\n", input);
|
||||
|
||||
p = (int *) malloc(v);
|
||||
if (p == NULL) {
|
||||
printf("malloc failed\n");
|
||||
}
|
||||
else {
|
||||
memset(p, 0, v);
|
||||
printf("malloc succeeded\n");
|
||||
}
|
||||
printf("begin to execute command\n");
|
||||
system("/bin/ls /tmp");
|
||||
return 0;
|
||||
}
|
28
demo/demo.py
Normal file
28
demo/demo.py
Normal file
@ -0,0 +1,28 @@
|
||||
# coding=utf-8
|
||||
import os
|
||||
import judger
|
||||
|
||||
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def run(use_sandbox):
|
||||
os.system("gcc demo.c -o demo")
|
||||
path = os.path.join(base_path, "demo")
|
||||
return judger.run(path=path,
|
||||
in_file=os.path.join(base_path, "in"),
|
||||
out_file=os.path.join(base_path, "out"),
|
||||
# ms
|
||||
max_cpu_time=2000,
|
||||
# Byte
|
||||
max_memory=200000000,
|
||||
# args and env are optional
|
||||
args=["1", "2", "####"],
|
||||
env=["aaa=123"],
|
||||
# default is True
|
||||
use_sandbox=use_sandbox)
|
||||
|
||||
|
||||
print "With sandbox"
|
||||
print run(use_sandbox=True)
|
||||
print 'Without sandbox'
|
||||
print run(use_sandbox=False)
|
1
judger.c
1
judger.c
@ -33,6 +33,7 @@ static PyObject *judger_run(PyObject *self, PyObject *args, PyObject *kwargs) {
|
||||
PyErr_SetString(PyExc_ValueError, "Input file does not exist");
|
||||
return NULL;
|
||||
}
|
||||
config.args[count++] = config.path;
|
||||
if (args_list != NULL) {
|
||||
if (!PyList_Check(args_list)) {
|
||||
PyErr_SetString(PyExc_ValueError, "args must be a list");
|
||||
|
28
test.c
28
test.c
@ -1,28 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
int main(int argc, char *argv[]) {
|
||||
int *a = NULL;
|
||||
int j;
|
||||
char *newargv[] = {"/", NULL};
|
||||
char *env[] = {NULL};
|
||||
printf("start\n");
|
||||
// 150M
|
||||
int v = 150000000;
|
||||
//fork();
|
||||
// printf("%s\n", getenv("LD_PRELOAD"));
|
||||
for (j = 0; j < argc; j++)
|
||||
printf("argv[%d]: %s\n", j, argv[j]);
|
||||
//execve("/bin/echo", newargv, env);
|
||||
a = (int *) malloc(v);
|
||||
if (a == NULL) {
|
||||
printf("error\n");
|
||||
}
|
||||
else {
|
||||
memset(a, 0, v);
|
||||
printf("success\n");
|
||||
}
|
||||
printf("end\n");
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user