From c582bc87579a88d2020e4feabc257596caab1eef Mon Sep 17 00:00:00 2001 From: MeiK Date: Wed, 4 Nov 2020 19:23:13 +0800 Subject: [PATCH] add language python3.8 --- example/main.py | 7 +++++++ example/py/1000/in.txt | 0 example/py/1000/main.py | 1 + example/py/1000/out.txt | 1 + example/py/1001/in.txt | 1 + example/py/1001/main.py | 2 ++ example/py/1001/out.txt | 1 + example/river_pb2.py | 32 ++++++++++++++++++++++---------- src/allow.rs | 3 +++ src/judger.rs | 3 +++ 10 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 example/py/1000/in.txt create mode 100644 example/py/1000/main.py create mode 100644 example/py/1000/out.txt create mode 100644 example/py/1001/in.txt create mode 100644 example/py/1001/main.py create mode 100644 example/py/1001/out.txt diff --git a/example/main.py b/example/main.py index 74004d8..62f184a 100644 --- a/example/main.py +++ b/example/main.py @@ -11,6 +11,8 @@ def judge(path, language): filename = "main.c" elif language == river_pb2.Cpp: filename = "main.cpp" + elif language == river_pb2.Python: + filename = "main.py" with open(path.joinpath(filename), "rb") as fr: code = fr.read() with open(path.joinpath("in.txt"), "rb") as fr: @@ -46,6 +48,11 @@ def run(): for item in stub.Judge(judge(path, river_pb2.Cpp)): print(item) print(f"{path} 评测完成") + for path in Path("py").iterdir(): + print(f"开始评测 {path}") + for item in stub.Judge(judge(path, river_pb2.Python)): + print(item) + print(f"{path} 评测完成") if __name__ == "__main__": diff --git a/example/py/1000/in.txt b/example/py/1000/in.txt new file mode 100644 index 0000000..e69de29 diff --git a/example/py/1000/main.py b/example/py/1000/main.py new file mode 100644 index 0000000..f301245 --- /dev/null +++ b/example/py/1000/main.py @@ -0,0 +1 @@ +print("Hello World!") diff --git a/example/py/1000/out.txt b/example/py/1000/out.txt new file mode 100644 index 0000000..c57eff5 --- /dev/null +++ b/example/py/1000/out.txt @@ -0,0 +1 @@ +Hello World! \ No newline at end of file diff --git a/example/py/1001/in.txt b/example/py/1001/in.txt new file mode 100644 index 0000000..1ed0fb7 --- /dev/null +++ b/example/py/1001/in.txt @@ -0,0 +1 @@ +2 3 \ No newline at end of file diff --git a/example/py/1001/main.py b/example/py/1001/main.py new file mode 100644 index 0000000..19ac7e3 --- /dev/null +++ b/example/py/1001/main.py @@ -0,0 +1,2 @@ +a, b = input().split() +print(int(a) + int(b)) diff --git a/example/py/1001/out.txt b/example/py/1001/out.txt new file mode 100644 index 0000000..7813681 --- /dev/null +++ b/example/py/1001/out.txt @@ -0,0 +1 @@ +5 \ No newline at end of file diff --git a/example/river_pb2.py b/example/river_pb2.py index b731130..0b8205c 100644 --- a/example/river_pb2.py +++ b/example/river_pb2.py @@ -20,7 +20,7 @@ DESCRIPTOR = _descriptor.FileDescriptor( syntax='proto3', serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_pb=b'\n\x0briver.proto\x12\x05river\"\x1b\n\x0b\x43ompileData\x12\x0c\n\x04\x63ode\x18\x01 \x01(\x0c\"X\n\tJudgeData\x12\x0f\n\x07in_data\x18\x01 \x01(\x0c\x12\x10\n\x08out_data\x18\x02 \x01(\x0c\x12\x12\n\ntime_limit\x18\x03 \x01(\x05\x12\x14\n\x0cmemory_limit\x18\x04 \x01(\x05\"\xb3\x01\n\x0cJudgeRequest\x12!\n\x08language\x18\x01 \x01(\x0e\x32\x0f.river.Language\x12$\n\njudge_type\x18\x02 \x01(\x0e\x32\x10.river.JudgeType\x12*\n\x0c\x63ompile_data\x18\x03 \x01(\x0b\x32\x12.river.CompileDataH\x00\x12&\n\njudge_data\x18\x04 \x01(\x0b\x32\x10.river.JudgeDataH\x00\x42\x06\n\x04\x64\x61ta\"\xbc\x01\n\rJudgeResponse\x12\x11\n\ttime_used\x18\x01 \x01(\x03\x12\x13\n\x0bmemory_used\x18\x02 \x01(\x03\x12$\n\x06result\x18\x03 \x01(\x0e\x32\x12.river.JudgeResultH\x00\x12$\n\x06status\x18\t \x01(\x0e\x32\x12.river.JudgeStatusH\x00\x12\x0e\n\x06stdout\x18\x06 \x01(\t\x12\x0e\n\x06stderr\x18\x07 \x01(\t\x12\x0e\n\x06\x65rrmsg\x18\x08 \x01(\tB\x07\n\x05state*R\n\x08Language\x12\x05\n\x01\x43\x10\x00\x12\x07\n\x03\x43pp\x10\x01\x12\n\n\x06Python\x10\x02\x12\x08\n\x04Rust\x10\x03\x12\x08\n\x04Node\x10\x04\x12\x0e\n\nTypeScript\x10\x05\x12\x06\n\x02Go\x10\x06*\x19\n\tJudgeType\x12\x0c\n\x08Standard\x10\x00*\xc1\x01\n\x0bJudgeResult\x12\x0c\n\x08\x41\x63\x63\x65pted\x10\x00\x12\x0f\n\x0bWrongAnswer\x10\x01\x12\x15\n\x11TimeLimitExceeded\x10\x02\x12\x17\n\x13MemoryLimitExceeded\x10\x03\x12\x10\n\x0cRuntimeError\x10\x04\x12\x17\n\x13OutputLimitExceeded\x10\x05\x12\x10\n\x0c\x43ompileError\x10\x06\x12\x15\n\x11PresentationError\x10\x07\x12\x0f\n\x0bSystemError\x10\x08*2\n\x0bJudgeStatus\x12\x0b\n\x07Pending\x10\x00\x12\x0b\n\x07Running\x10\x01\x12\t\n\x05\x45nded\x10\x02\x32\x41\n\x05River\x12\x38\n\x05Judge\x12\x13.river.JudgeRequest\x1a\x14.river.JudgeResponse\"\x00(\x01\x30\x01\x62\x06proto3' + serialized_pb=b'\n\x0briver.proto\x12\x05river\"\x1b\n\x0b\x43ompileData\x12\x0c\n\x04\x63ode\x18\x01 \x01(\x0c\"X\n\tJudgeData\x12\x0f\n\x07in_data\x18\x01 \x01(\x0c\x12\x10\n\x08out_data\x18\x02 \x01(\x0c\x12\x12\n\ntime_limit\x18\x03 \x01(\x05\x12\x14\n\x0cmemory_limit\x18\x04 \x01(\x05\"\xb3\x01\n\x0cJudgeRequest\x12!\n\x08language\x18\x01 \x01(\x0e\x32\x0f.river.Language\x12$\n\njudge_type\x18\x02 \x01(\x0e\x32\x10.river.JudgeType\x12*\n\x0c\x63ompile_data\x18\x03 \x01(\x0b\x32\x12.river.CompileDataH\x00\x12&\n\njudge_data\x18\x04 \x01(\x0b\x32\x10.river.JudgeDataH\x00\x42\x06\n\x04\x64\x61ta\"\xbc\x01\n\rJudgeResponse\x12\x11\n\ttime_used\x18\x01 \x01(\x03\x12\x13\n\x0bmemory_used\x18\x02 \x01(\x03\x12$\n\x06result\x18\x03 \x01(\x0e\x32\x12.river.JudgeResultH\x00\x12$\n\x06status\x18\t \x01(\x0e\x32\x12.river.JudgeStatusH\x00\x12\x0e\n\x06stdout\x18\x06 \x01(\t\x12\x0e\n\x06stderr\x18\x07 \x01(\t\x12\x0e\n\x06\x65rrmsg\x18\x08 \x01(\tB\x07\n\x05state*\\\n\x08Language\x12\x05\n\x01\x43\x10\x00\x12\x07\n\x03\x43pp\x10\x01\x12\n\n\x06Python\x10\x02\x12\x08\n\x04Rust\x10\x03\x12\x08\n\x04Node\x10\x04\x12\x0e\n\nTypeScript\x10\x05\x12\x06\n\x02Go\x10\x06\x12\x08\n\x04Java\x10\x07*\x19\n\tJudgeType\x12\x0c\n\x08Standard\x10\x00*\xd5\x01\n\x0bJudgeResult\x12\x0c\n\x08\x41\x63\x63\x65pted\x10\x00\x12\x0f\n\x0bWrongAnswer\x10\x01\x12\x15\n\x11TimeLimitExceeded\x10\x02\x12\x17\n\x13MemoryLimitExceeded\x10\x03\x12\x10\n\x0cRuntimeError\x10\x04\x12\x17\n\x13OutputLimitExceeded\x10\x05\x12\x10\n\x0c\x43ompileError\x10\x06\x12\x15\n\x11PresentationError\x10\x07\x12\x0f\n\x0bSystemError\x10\x08\x12\x12\n\x0e\x43ompileSuccess\x10\t*2\n\x0bJudgeStatus\x12\x0b\n\x07Pending\x10\x00\x12\x0b\n\x07Running\x10\x01\x12\t\n\x05\x45nded\x10\x02\x32\x41\n\x05River\x12\x38\n\x05Judge\x12\x13.river.JudgeRequest\x1a\x14.river.JudgeResponse\"\x00(\x01\x30\x01\x62\x06proto3' ) _LANGUAGE = _descriptor.EnumDescriptor( @@ -65,11 +65,16 @@ _LANGUAGE = _descriptor.EnumDescriptor( serialized_options=None, type=None, create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='Java', index=7, number=7, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), ], containing_type=None, serialized_options=None, serialized_start=514, - serialized_end=596, + serialized_end=606, ) _sym_db.RegisterEnumDescriptor(_LANGUAGE) @@ -89,8 +94,8 @@ _JUDGETYPE = _descriptor.EnumDescriptor( ], containing_type=None, serialized_options=None, - serialized_start=598, - serialized_end=623, + serialized_start=608, + serialized_end=633, ) _sym_db.RegisterEnumDescriptor(_JUDGETYPE) @@ -147,11 +152,16 @@ _JUDGERESULT = _descriptor.EnumDescriptor( serialized_options=None, type=None, create_key=_descriptor._internal_create_key), + _descriptor.EnumValueDescriptor( + name='CompileSuccess', index=9, number=9, + serialized_options=None, + type=None, + create_key=_descriptor._internal_create_key), ], containing_type=None, serialized_options=None, - serialized_start=626, - serialized_end=819, + serialized_start=636, + serialized_end=849, ) _sym_db.RegisterEnumDescriptor(_JUDGERESULT) @@ -181,8 +191,8 @@ _JUDGESTATUS = _descriptor.EnumDescriptor( ], containing_type=None, serialized_options=None, - serialized_start=821, - serialized_end=871, + serialized_start=851, + serialized_end=901, ) _sym_db.RegisterEnumDescriptor(_JUDGESTATUS) @@ -194,6 +204,7 @@ Rust = 3 Node = 4 TypeScript = 5 Go = 6 +Java = 7 Standard = 0 Accepted = 0 WrongAnswer = 1 @@ -204,6 +215,7 @@ OutputLimitExceeded = 5 CompileError = 6 PresentationError = 7 SystemError = 8 +CompileSuccess = 9 Pending = 0 Running = 1 Ended = 2 @@ -496,8 +508,8 @@ _RIVER = _descriptor.ServiceDescriptor( index=0, serialized_options=None, create_key=_descriptor._internal_create_key, - serialized_start=873, - serialized_end=938, + serialized_start=903, + serialized_end=968, methods=[ _descriptor.MethodDescriptor( name='Judge', diff --git a/src/allow.rs b/src/allow.rs index b8578bb..c9896d2 100644 --- a/src/allow.rs +++ b/src/allow.rs @@ -25,6 +25,7 @@ pub fn gen_rules() -> Vec { allow_syscall(libc::SYS_geteuid), allow_syscall(libc::SYS_getgid), allow_syscall(libc::SYS_getpid), + allow_syscall(libc::SYS_gettid), allow_syscall(libc::SYS_getrandom), allow_syscall(libc::SYS_getrlimit), allow_syscall(libc::SYS_getrusage), @@ -33,6 +34,7 @@ pub fn gen_rules() -> Vec { allow_syscall(libc::SYS_lseek), allow_syscall(libc::SYS_lstat), // allow_syscall(libc::SYS_mmap), + allow_syscall(libc::SYS_mkdir), allow_syscall(libc::SYS_mprotect), // allow_syscall(libc::SYS_munmap), allow_syscall(libc::SYS_open), @@ -40,6 +42,7 @@ pub fn gen_rules() -> Vec { allow_syscall(libc::SYS_prlimit64), allow_syscall(libc::SYS_read), allow_syscall(libc::SYS_readlink), + allow_syscall(libc::SYS_rename), allow_syscall(libc::SYS_rt_sigaction), allow_syscall(libc::SYS_rt_sigprocmask), allow_syscall(libc::SYS_rt_sigreturn), diff --git a/src/judger.rs b/src/judger.rs index efb49a8..5706824 100644 --- a/src/judger.rs +++ b/src/judger.rs @@ -156,6 +156,9 @@ pub async fn compile( Ok(val) => val, Err(e) => return Err(Error::FileReadError(e)), }; + debug!("stdout: {}", resp.stdout); + debug!("stderr: {}", resp.stderr); + debug!("errmsg: {}", status.errmsg); resp.state = Some(State::Result(JudgeResult::CompileError as i32)); } else { resp.state = Some(State::Result(JudgeResult::CompileSuccess as i32));