diff --git a/.gitignore b/.gitignore index 68169da..01ab412 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ limit runner CMakeLists.txt main +demo/out diff --git a/README.md b/README.md index ee45727..97f72b4 100644 --- a/README.md +++ b/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 ``` diff --git a/demo.py b/demo.py deleted file mode 100644 index 0049b46..0000000 --- a/demo.py +++ /dev/null @@ -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) - diff --git a/demo/demo.c b/demo/demo.c new file mode 100644 index 0000000..13c4fcb --- /dev/null +++ b/demo/demo.c @@ -0,0 +1,32 @@ +#include +#include +#include + + +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; +} diff --git a/demo/demo.py b/demo/demo.py new file mode 100644 index 0000000..cd32ac2 --- /dev/null +++ b/demo/demo.py @@ -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) diff --git a/demo/in b/demo/in new file mode 100644 index 0000000..70c379b --- /dev/null +++ b/demo/in @@ -0,0 +1 @@ +Hello world \ No newline at end of file diff --git a/judger.c b/judger.c index aa5e414..9a679a2 100644 --- a/judger.c +++ b/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"); diff --git a/test.c b/test.c deleted file mode 100644 index 6b93fd0..0000000 --- a/test.c +++ /dev/null @@ -1,28 +0,0 @@ -#include -#include -#include -#include -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; -}