Skip to content

Commit

Permalink
add javascript and php
Browse files Browse the repository at this point in the history
(cherry picked from commit 9a9fd10942f7e30bb27cd7e7dec980e4fef2d7ca)
  • Loading branch information
happystraw authored and virusdefender committed Sep 27, 2021
1 parent 54a2758 commit ed605d1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 10 deletions.
9 changes: 7 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ FROM ubuntu:18.04

COPY build/java_policy /etc
#RUN sed -E -i -e 's/(archive|ports).ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' -e '/security.ubuntu.com/d' /etc/apt/sources.list
RUN buildDeps='software-properties-common git libtool cmake python-dev python3-pip python-pip libseccomp-dev' && \
ENV DEBIAN_FRONTEND=noninteractive
RUN buildDeps='software-properties-common git libtool cmake python-dev python3-pip python-pip libseccomp-dev curl' && \
apt-get update && apt-get install -y python python3 python-pkg-resources python3-pkg-resources $buildDeps && \
add-apt-repository ppa:openjdk-r/ppa && add-apt-repository ppa:longsleep/golang-backports && \
add-apt-repository ppa:ubuntu-toolchain-r/test && \
apt-get update && apt-get install -y golang-go openjdk-11-jdk gcc-9 g++-9 && \
add-apt-repository ppa:ondrej/php && \
curl -fsSL https://deb.nodesource.com/setup_14.x | bash - && \
apt-get update && apt-get install -y golang-go openjdk-11-jdk php-cli nodejs gcc-9 g++-9 && \
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 40 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 40 && \
phpJitOption='opcache.enable=1\nopcache.enable_cli=1\nopcache.jit=1205\nopcache.jit_buffer_size=64M' && \
echo $phpJitOption > /etc/php/8.0/cli/conf.d/10-opcache-jit.ini && \
pip3 install -I --no-cache-dir psutil gunicorn flask requests idna && \
cd /tmp && git clone -b newnew --depth 1 https://github.com/QingdaoU/Judger && cd Judger && \
mkdir build && cd build && cmake .. && make && make install && cd ../bindings/Python && python3 setup.py install && \
Expand Down
28 changes: 25 additions & 3 deletions client/Python/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

import requests

from languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, \
c_lang_spj_compile, py2_lang_config, py3_lang_config, go_lang_config
from .languages import c_lang_config, cpp_lang_config, java_lang_config, c_lang_spj_config, c_lang_spj_compile, py2_lang_config, py3_lang_config, go_lang_config, php_lang_config, js_lang_config


class JudgeServerClientError(Exception):
Expand Down Expand Up @@ -117,6 +116,20 @@ def compile_spj(self, src, spj_version, spj_compile_config):
fmt.Printf("%d", a + b)
}"""

php_src = """<?php
fscanf(STDIN, "%d %d", $a, $b);
print($a + $b);"""

js_src = """const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin });
rl.on('line', (input) => {
if (input === '') {
return rl.close();
}
const [a, b] = input.split(' ').map(Number)
console.log(a + b);
});"""

client = JudgeServerClient(token=token, server_base_url="http://127.0.0.1:12358")
print("ping")
print(client.ping(), "\n\n")
Expand Down Expand Up @@ -147,7 +160,6 @@ def compile_spj(self, src, spj_version, spj_compile_config):
spj_version="3", spj_config=c_lang_spj_config,
spj_compile_config=c_lang_spj_compile, spj_src=c_spj_src), "\n\n")


print("py2_judge")
print(client.judge(src=py2_src, language_config=py2_lang_config,
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
Expand All @@ -163,6 +175,16 @@ def compile_spj(self, src, spj_version, spj_compile_config):
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
test_case_id="normal", output=True), "\n\n")

print("php_judge")
print(client.judge(src=php_src, language_config=php_lang_config,
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
test_case_id="normal", output=True), "\n\n")

print("js_judge")
print(client.judge(src=js_src, language_config=js_lang_config,
max_cpu_time=1000, max_memory=128 * 1024 * 1024,
test_case_id="normal", output=True), "\n\n")

print("c_dynamic_input_judge")
print(client.judge(src=c_src, language_config=c_lang_config,
max_cpu_time=1000, max_memory=1024 * 1024 * 128,
Expand Down
24 changes: 22 additions & 2 deletions client/Python/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
"max_real_time": 5000,
"max_memory": 1024 * 1024 * 1024,
"compile_command": "/usr/bin/go build -o {exe_path} {src_path}",
"env": ["GOCACHE=/tmp"]
"env": ["GOCACHE=/tmp", "GOPATH=/tmp/go"]
},
"run": {
"command": "{exe_path}",
Expand All @@ -119,4 +119,24 @@
"env": ["GODEBUG=madvdontneed=1", "GOCACHE=off"] + default_env,
"memory_limit_check_only": 1
}
}
}

php_lang_config = {
"run": {
"exe_name": "solution.php",
"command": "/usr/bin/php {exe_path}",
"seccomp_rule": "",
"env": default_env,
"memory_limit_check_only": 1
}
}

js_lang_config = {
"run": {
"exe_name": "solution.js",
"command": "/usr/bin/node {exe_path}",
"seccomp_rule": "",
"env": ["NO_COLOR=true"] + default_env,
"memory_limit_check_only": 1
}
}
3 changes: 2 additions & 1 deletion server/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from config import COMPILER_LOG_PATH, COMPILER_USER_UID, COMPILER_GROUP_GID
from exception import CompileError
import shlex


class Compiler(object):
Expand All @@ -12,7 +13,7 @@ def compile(self, compile_config, src_path, output_dir):
exe_path = os.path.join(output_dir, compile_config["exe_name"])
command = command.format(src_path=src_path, exe_dir=output_dir, exe_path=exe_path)
compiler_out = os.path.join(output_dir, "compiler.out")
_command = command.split(" ")
_command = shlex.split(command)

os.chdir(output_dir)
env = compile_config.get("env", [])
Expand Down
7 changes: 5 additions & 2 deletions server/judge_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import shutil
from multiprocessing import Pool
import shlex

import psutil

Expand Down Expand Up @@ -70,7 +71,8 @@ def _spj(self, in_file_path, user_out_file_path):
os.chmod(user_out_file_path, 0o740)
command = self._spj_config["command"].format(exe_path=self._spj_exe,
in_file_path=in_file_path,
user_out_file_path=user_out_file_path).split(" ")
user_out_file_path=user_out_file_path)
command = shlex.split(command)
seccomp_rule_name = self._spj_config["seccomp_rule"]
result = _judger.run(max_cpu_time=self._max_cpu_time * 3,
max_real_time=self._max_cpu_time * 9,
Expand Down Expand Up @@ -116,7 +118,8 @@ def _judge_one(self, test_case_file_id):
kwargs = {"input_path": in_file, "output_path": real_user_output_file, "error_path": real_user_output_file}

command = self._run_config["command"].format(exe_path=self._exe_path, exe_dir=os.path.dirname(self._exe_path),
max_memory=int(self._max_memory / 1024)).split(" ")
max_memory=int(self._max_memory / 1024))
command = shlex.split(command)
env = ["PATH=" + os.environ.get("PATH", "")] + self._run_config.get("env", [])

seccomp_rule = self._run_config["seccomp_rule"]
Expand Down

0 comments on commit ed605d1

Please sign in to comment.