From d9b448a50817061f5cc9f4a33cc4aabde89b4004 Mon Sep 17 00:00:00 2001 From: LiYang Date: Fri, 26 Aug 2016 22:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bindings/Python/_judger.c | 12 ++++++------ tests/test.py | 2 +- tests/testcase/integration/test.py | 30 +++++++++++++++--------------- tests/testcase/seccomp/test.py | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bindings/Python/_judger.c b/bindings/Python/_judger.c index 9c97935..dfc3337 100644 --- a/bindings/Python/_judger.c +++ b/bindings/Python/_judger.c @@ -111,10 +111,10 @@ PyMODINIT_FUNC init_judger(void) { PyObject *module = Py_InitModule3("_judger", judger_methods, NULL); PyModule_AddIntConstant(module, "VERSION", VERSION); PyModule_AddIntConstant(module, "UNLIMITED", UNLIMITED); - PyModule_AddIntConstant(module, "SUCCESS", SUCCESS); - PyModule_AddIntConstant(module, "CPU_TIME_LIMIT_EXCEEDED", CPU_TIME_LIMITED); - PyModule_AddIntConstant(module, "REAL_TIME_LIMIT_EXCEEDED", REAL_TIME_LIMIT_EXCEEDED); - PyModule_AddIntConstant(module, "MEMORY_LIMIT_EXCEEDED", MEMORY_LIMIT_EXCEEDED); - PyModule_AddIntConstant(module, "RUNTIME_ERROR", RUNTIME_ERROR); - PyModule_AddIntConstant(module, "SYSTEM_ERROR", SYSTEM_ERROR); + PyModule_AddIntConstant(module, "RESULT_SUCCESS", SUCCESS); + PyModule_AddIntConstant(module, "RESULT_CPU_TIME_LIMIT_EXCEEDED", CPU_TIME_LIMITED); + PyModule_AddIntConstant(module, "RESULT_REAL_TIME_LIMIT_EXCEEDED", REAL_TIME_LIMIT_EXCEEDED); + PyModule_AddIntConstant(module, "RESULT_MEMORY_LIMIT_EXCEEDED", MEMORY_LIMIT_EXCEEDED); + PyModule_AddIntConstant(module, "RESULT_RUNTIME_ERROR", RUNTIME_ERROR); + PyModule_AddIntConstant(module, "RESULT_SYSTEM_ERROR", SYSTEM_ERROR); } diff --git a/tests/test.py b/tests/test.py index 1335900..7ac617f 100644 --- a/tests/test.py +++ b/tests/test.py @@ -7,5 +7,5 @@ from testcase.c_cpp.test import C_CPPJudgeTestCase from testcase.seccomp.test import SeccompTest ver = _judger.VERSION -print "Judger version", (ver >> 16) & 0xff, (ver >> 8) & 0xff, ver & 0xff +print "Judger version %d.%d.%d" % ((ver >> 16) & 0xff, (ver >> 8) & 0xff, ver & 0xff) main() \ No newline at end of file diff --git a/tests/testcase/integration/test.py b/tests/testcase/integration/test.py index 8ec8312..01537d1 100644 --- a/tests/testcase/integration/test.py +++ b/tests/testcase/integration/test.py @@ -131,7 +131,7 @@ class IntegrationTest(base.BaseTestCase): config["output_path"] = config["error_path"] = self.output_path() result = _judger.run(**config) output = "judger_test\nHello world" - self.assertEqual(result["result"], _judger.SUCCESS) + self.assertEqual(result["result"], _judger.RESULT_SUCCESS) self.assertEqual(output, self.output_content(config["output_path"])) def test_args(self): @@ -141,7 +141,7 @@ class IntegrationTest(base.BaseTestCase): config["output_path"] = config["error_path"] = self.output_path() result = _judger.run(**config) output = "argv[0]: /tmp/integration/args\nargv[1]: test\nargv[2]: hehe\nargv[3]: 000\n" - self.assertEqual(result["result"], _judger.SUCCESS) + self.assertEqual(result["result"], _judger.RESULT_SUCCESS) self.assertEqual(output, self.output_content(config["output_path"])) def test_env(self): @@ -150,14 +150,14 @@ class IntegrationTest(base.BaseTestCase): config["output_path"] = config["error_path"] = self.output_path() result = _judger.run(**config) output = "judger_test\njudger\n" - self.assertEqual(result["result"], _judger.SUCCESS) + self.assertEqual(result["result"], _judger.RESULT_SUCCESS) self.assertEqual(output, self.output_content(config["output_path"])) def test_real_time(self): config = self.config config["exe_path"] = self._compile_c("sleep.c") result = _judger.run(**config) - self.assertEqual(result["result"], _judger.REAL_TIME_LIMIT_EXCEEDED) + self.assertEqual(result["result"], _judger.RESULT_REAL_TIME_LIMIT_EXCEEDED) self.assertEqual(result["signal"], signal.SIGKILL) self.assertTrue(result["real_time"] >= config["max_real_time"]) @@ -165,7 +165,7 @@ class IntegrationTest(base.BaseTestCase): config = self.config config["exe_path"] = self._compile_c("while1.c") result = _judger.run(**config) - self.assertEqual(result["result"], _judger.CPU_TIME_LIMIT_EXCEEDED) + self.assertEqual(result["result"], _judger.RESULT_CPU_TIME_LIMIT_EXCEEDED) self.assertEqual(result["signal"], signal.SIGKILL) self.assertTrue(result["cpu_time"] >= config["max_cpu_time"]) @@ -176,7 +176,7 @@ class IntegrationTest(base.BaseTestCase): result = _judger.run(**config) # malloc succeeded self.assertTrue(result["memory"] > 80 * 1024 * 1024) - self.assertEqual(result["result"], _judger.MEMORY_LIMIT_EXCEEDED) + self.assertEqual(result["result"], _judger.RESULT_MEMORY_LIMIT_EXCEEDED) def test_memory2(self): config = self.config @@ -187,14 +187,14 @@ class IntegrationTest(base.BaseTestCase): self.assertEqual(result["exit_code"], 1) # malloc failed, so it should use a little memory self.assertTrue(result["memory"] < 12 * 1024 * 1024) - self.assertEqual(result["result"], _judger.RUNTIME_ERROR) + self.assertEqual(result["result"], _judger.RESULT_RUNTIME_ERROR) def test_memory3(self): config = self.config config["max_memory"] = 512 * 1024 * 1024 config["exe_path"] = self._compile_c("memory3.c") result = _judger.run(**config) - self.assertEqual(result["result"], _judger.SUCCESS) + self.assertEqual(result["result"], _judger.RESULT_SUCCESS) self.assertTrue(result["memory"] >= 102400000 * 4) def test_re1(self): @@ -208,20 +208,20 @@ class IntegrationTest(base.BaseTestCase): config = self.config config["exe_path"] = self._compile_c("re2.c") result = _judger.run(**config) - self.assertEqual(result["result"], _judger.RUNTIME_ERROR) + self.assertEqual(result["result"], _judger.RESULT_RUNTIME_ERROR) self.assertEqual(result["signal"], signal.SIGSEGV) def test_child_proc_cpu_time_limit(self): config = self.config config["exe_path"] = self._compile_c("child_proc_cpu_time_limit.c") result = _judger.run(**config) - self.assertEqual(result["result"], _judger.CPU_TIME_LIMIT_EXCEEDED) + self.assertEqual(result["result"], _judger.RESULT_CPU_TIME_LIMIT_EXCEEDED) def test_child_proc_real_time_limit(self): config = self.config config["exe_path"] = self._compile_c("child_proc_real_time_limit.c") result = _judger.run(**config) - self.assertEqual(result["result"], _judger.REAL_TIME_LIMIT_EXCEEDED) + self.assertEqual(result["result"], _judger.RESULT_REAL_TIME_LIMIT_EXCEEDED) self.assertEqual(result["signal"], signal.SIGKILL) def test_stdout_and_stderr(self): @@ -229,7 +229,7 @@ class IntegrationTest(base.BaseTestCase): config["exe_path"] = self._compile_c("stdout_stderr.c") config["output_path"] = config["error_path"] = self.output_path() result = _judger.run(**config) - self.assertEqual(result["result"], _judger.SUCCESS) + self.assertEqual(result["result"], _judger.RESULT_SUCCESS) output = "stderr\n+++++++++++++++\n--------------\nstdout\n" self.assertEqual(output, self.output_content(config["output_path"])) @@ -240,7 +240,7 @@ class IntegrationTest(base.BaseTestCase): config["uid"] = 65534 config["gid"] = 65534 result = _judger.run(**config) - self.assertEqual(result["result"], _judger.SUCCESS) + self.assertEqual(result["result"], _judger.RESULT_SUCCESS) output = "uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)\nuid 65534\ngid 65534\n" self.assertEqual(output, self.output_content(config["output_path"])) @@ -250,7 +250,7 @@ class IntegrationTest(base.BaseTestCase): config["args"] = [os.path.join(os.path.dirname(os.path.abspath(__file__)), "gcc_random.c"), "-o", os.path.join(self.workspace, "gcc_random")] result = _judger.run(**config) - self.assertEqual(result["result"], _judger.CPU_TIME_LIMIT_EXCEEDED) + self.assertEqual(result["result"], _judger.RESULT_CPU_TIME_LIMIT_EXCEEDED) self.assertTrue(result["cpu_time"] >= 1950) self.assertTrue(result["real_time"] >= 1950) @@ -260,6 +260,6 @@ class IntegrationTest(base.BaseTestCase): config["args"] = [os.path.join(os.path.dirname(os.path.abspath(__file__)), "cpp_meta.cpp"), "-o", os.path.join(self.workspace, "cpp_meta")] result = _judger.run(**config) - self.assertEqual(result["result"], _judger.CPU_TIME_LIMIT_EXCEEDED) + self.assertEqual(result["result"], _judger.RESULT_CPU_TIME_LIMIT_EXCEEDED) self.assertTrue(result["cpu_time"] >= 1950) self.assertTrue(result["real_time"] >= 1950) diff --git a/tests/testcase/seccomp/test.py b/tests/testcase/seccomp/test.py index ba4c19f..ccdde6e 100644 --- a/tests/testcase/seccomp/test.py +++ b/tests/testcase/seccomp/test.py @@ -34,5 +34,5 @@ class SeccompTest(base.BaseTestCase): config["exe_path"] = self._compile_c("mmap.c") config["seccomp_rule_so_path"] = "/usr/lib/judger/librule_c_cpp.so" result = _judger.run(**config) - self.assertEqual(result["result"], _judger.RUNTIME_ERROR) + self.assertEqual(result["result"], _judger.RESULT_RUNTIME_ERROR) self.assertEqual(result["signal"], 31)