mirror of
https://github.com/QingdaoU/JudgeServer.git
synced 2024-12-28 21:31:43 +00:00
增加自定义运行环境变量
This commit is contained in:
parent
3887c5f837
commit
bd40ce6f9f
@ -3,11 +3,10 @@ from __future__ import unicode_literals
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from languages import c_lang_config, cpp_lang_config, java_lang_config
|
||||
from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, c_lang_spj_compile
|
||||
|
||||
|
||||
class JudgeServerClientError(Exception):
|
||||
@ -95,7 +94,7 @@ if __name__ == "__main__":
|
||||
|
||||
client = JudgeServerClient(token="token", server_base_url="http://123.57.151.42:12358")
|
||||
print client.ping(), "\n\n"
|
||||
print client.compile_spj(src=c_spj_src, spj_version="1", spj_compile_config=c_lang_config["spj_compile"],
|
||||
print client.compile_spj(src=c_spj_src, spj_version="1", spj_compile_config=c_lang_spj_compile,
|
||||
test_case_id="spj"), "\n\n"
|
||||
|
||||
print client.judge(src=c_src, language_config=c_lang_config,
|
||||
@ -113,4 +112,4 @@ if __name__ == "__main__":
|
||||
print client.judge(src=c_src, language_config=c_lang_config,
|
||||
max_cpu_time=1000, max_memory=1024 * 1024 * 128,
|
||||
test_case_id="spj",
|
||||
spj_version="1", spj_config=c_lang_config["spj_config"]), "\n\n"
|
||||
spj_version="1", spj_config=c_lang_spj_config), "\n\n"
|
||||
|
@ -8,27 +8,28 @@ c_lang_config = {
|
||||
"max_cpu_time": 3000,
|
||||
"max_real_time": 5000,
|
||||
"max_memory": 128 * 1024 * 1024,
|
||||
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 -static {src_path} -lm -o {exe_path}",
|
||||
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 {src_path} -lm -o {exe_path}",
|
||||
},
|
||||
"run": {
|
||||
"command": "{exe_path}",
|
||||
"seccomp_rule": "c_cpp"
|
||||
},
|
||||
"spj_compile": {
|
||||
"src_name": "spj-{spj_version}.c",
|
||||
"exe_name": "spj-{spj_version}",
|
||||
"max_cpu_time": 3000,
|
||||
"max_real_time": 5000,
|
||||
"max_memory": 1024 * 1024 * 1024,
|
||||
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 {src_path} -lm -o {exe_path}"
|
||||
},
|
||||
"spj_config": {
|
||||
"exe_name": "spj-{spj_version}",
|
||||
"command": "{exe_path} {in_file_path} {user_out_file_path}",
|
||||
"seccomp_rule": "c_cpp"
|
||||
"seccomp_rule": "c_cpp",
|
||||
}
|
||||
}
|
||||
|
||||
c_lang_spj_compile = {
|
||||
"src_name": "spj-{spj_version}.c",
|
||||
"exe_name": "spj-{spj_version}",
|
||||
"max_cpu_time": 3000,
|
||||
"max_real_time": 5000,
|
||||
"max_memory": 1024 * 1024 * 1024,
|
||||
"compile_command": "/usr/bin/gcc -DONLINE_JUDGE -O2 -w -fmax-errors=3 -std=c99 {src_path} -lm -o {exe_path}"
|
||||
}
|
||||
|
||||
c_lang_spj_config = {
|
||||
"exe_name": "spj-{spj_version}",
|
||||
"command": "{exe_path} {in_file_path} {user_out_file_path}",
|
||||
"seccomp_rule": "c_cpp"
|
||||
}
|
||||
|
||||
cpp_lang_config = {
|
||||
"name": "cpp",
|
||||
@ -42,12 +43,10 @@ cpp_lang_config = {
|
||||
},
|
||||
"run": {
|
||||
"command": "{exe_path}",
|
||||
"seccomp_rule": "c_cpp",
|
||||
"max_process_number": -1
|
||||
"seccomp_rule": "c_cpp"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
java_lang_config = {
|
||||
"name": "java",
|
||||
"compile": {
|
||||
@ -61,6 +60,6 @@ java_lang_config = {
|
||||
"run": {
|
||||
"command": "/usr/bin/java -cp {exe_dir} -Xss1M -XX:MaxPermSize=16M -XX:PermSize=8M -Xms16M -Xmx{max_memory}k -Djava.security.manager -Djava.security.policy==/etc/java_policy -Djava.awt.headless=true Main",
|
||||
"seccomp_rule": None,
|
||||
"max_process_number": -1
|
||||
"env": ["MALLOC_ARENA_MAX=1"]
|
||||
}
|
||||
}
|
@ -95,6 +95,7 @@ class JudgeClient(object):
|
||||
command = self._run_config["command"].format(exe_path=self._exe_path, exe_dir=os.path.dirname(self._exe_path),
|
||||
max_memory=self._max_memory / 1024).split(" ")
|
||||
seccomp_rule_name = self._run_config["seccomp_rule"].encode("utf-8") if self._run_config["seccomp_rule"] else None
|
||||
env = [item.encode("utf-8") for item in ["PATH=" + os.environ.get("PATH", "")] + self._run_config.get("env", [])]
|
||||
|
||||
run_result = _judger.run(max_cpu_time=self._max_cpu_time,
|
||||
max_real_time=self._max_real_time,
|
||||
@ -106,7 +107,7 @@ class JudgeClient(object):
|
||||
output_path=out_file,
|
||||
error_path=out_file,
|
||||
args=[item.encode("utf-8") for item in command[1::]],
|
||||
env=[("PATH=" + os.getenv("PATH", "")).encode("utf-8")],
|
||||
env=env,
|
||||
log_path=JUDGER_RUN_LOG_PATH,
|
||||
seccomp_rule_name=seccomp_rule_name,
|
||||
uid=LOW_PRIVILEDGE_UID,
|
||||
|
Loading…
Reference in New Issue
Block a user