コード例 #1
0
ファイル: test.py プロジェクト: RainboyOnlineJudge/ujudge
 def test_re2(self):
     config = self.base_config
     self._compile_c("re2.c")
     config["work_path"] = "/tmp/integration"
     config["argv"] = ['re2']
     result = _judger.run_program(**config)
     self.assertEqual(result["result"], _judger.RS_RE)
コード例 #2
0
ファイル: test.py プロジェクト: RainboyOnlineJudge/ujudge
    def test_stack_size(self):
        config = self.base_config
        config["ml"] = 256
        config["sl"] = 4
        self._compile_c("stack.c")
        config["out"] = config["err"] = self.output_path()
        config["work_path"] = "/tmp/integration"
        config["argv"] = ['stack']

        result = _judger.run_program(**config)
        self.assertEqual(result["result"], _judger.RS_RE)

        config["sl"] = 128
        result = _judger.run_program(**config)
        self.assertEqual(result["result"], _judger.RS_AC)
        self.assertEqual("big stack", self.output_content(config["out"]))
コード例 #3
0
ファイル: test.py プロジェクト: RainboyOnlineJudge/ujudge
 def test_memory2(self):
     config = self.base_config
     config["ml"] = 64
     self._compile_c("memory2.c")
     config["work_path"] = "/tmp/integration"
     config["argv"] = ['memory2']
     result = _judger.run_program(**config)
     self.assertEqual(result['result'], _judger.RS_MLE)
コード例 #4
0
ファイル: test.py プロジェクト: RainboyOnlineJudge/ujudge
 def test_re1(self):
     config = self.base_config
     self._compile_c("re1.c")
     config["work_path"] = "/tmp/integration"
     config["argv"] = ['re1']
     result = _judger.run_program(**config)
     # re1.c return 25
     self.assertEqual(result["exit_code"], 25)
コード例 #5
0
ファイル: test.py プロジェクト: RainboyOnlineJudge/ujudge
 def test_cpu_time(self):
     config = self.base_config
     self._compile_c("while1.c")
     config["work_path"] = "/tmp/integration"
     config["argv"] = ['while1']
     print(config)
     result = _judger.run_program(**config)
     self.assertEqual(result['result'], _judger.RS_TLE)
コード例 #6
0
ファイル: test.py プロジェクト: RainboyOnlineJudge/ujudge
 def test_memory3(self):
     config = self.base_config
     config["ml"] = 512
     self._compile_c("memory3.c")
     config["work_path"] = "/tmp/integration"
     config["argv"] = ['memory3']
     result = _judger.run_program(**config)
     print(result)
     self.assertEqual(result['result'], _judger.RS_AC)
     # self.assertEqual(result["result"], _judger.RESULT_SUCCESS)
     self.assertTrue(result["memory"] * 1024 >= 102400000 * 4)
コード例 #7
0
ファイル: test.py プロジェクト: RainboyOnlineJudge/ujudge
    def test_python3_aplusb(self):
        config = self.base_config
        config["_in"] = self.make_input("1 2")
        config["out"] = config["err"] = self.output_path()
        config["work_path"] = "/tmp/integration"
        _t = self._make_copy("aplusb.py")
        config["argv"] = ['aplusb.py']
        config["_type"] = 'python3.5'
        # config["unsafe"]= True
        config["show_trace_details"] = True

        result = _judger.run_program(**config)
        print(result)
コード例 #8
0
rundir = basedir + '/demo_judge_py'
exe_path = rundir + '/main.py'

if os.path.exists(rundir) == False:
    os.mkdir(rundir)

if os.system(" ".join(["python3", "-m", "py_compile", "aplusb.py"])) != 0:
    print('编译失败')
    os.exit(1)

os.system("cp in ./demo_judge_py")
os.system("cp aplusb.py ./demo_judge_py/main.py")

res = judge.run_program(
    tl=1,  # time_limit 单位s 
    ml=128,  # memory_limit 单位 mb
    ol=128,  # output_limit 单位 mb
    sl=1024,  # stack limit 单位 mb
    _in="in",  # 输入文件
    out="out",  # 输出文件
    err="stderr",  # 错误输出
    work_path=rundir,  # 工作目录
    _type="python3.5",  # type default or python3.5
    show_trace_details=False,  # 显示详细的信息
    allow_proc=False,  #  允许 fork exec
    unsafe=False,  #  不安全模式
    argv=["main.py"],  # 运行的程序名
    add_readable_raw="")
print(res)
コード例 #9
0
exe_path = rundir + '/main.pas'

if os.path.exists(rundir) == False:
    os.mkdir(rundir)

os.system("cp in ./demo_judge_pas")
os.system("cp aplusb.pas ./demo_judge_pas/main.pas")

res = judge.run_program(
    tl=10,  # time_limit 单位s 
    ml=512,  # memory_limit 单位 mb
    ol=128,  # output_limit 单位 mb
    sl=1024,  # stack limit 单位 mb
    _in="/dev/null",  # 输入文件
    out="compile_out",  # 输出文件
    err="compile_err",  # 错误输出
    work_path=rundir,  # 工作目录
    _type="default",  # type default or python3.5
    show_trace_details=False,  # 显示详细的信息
    allow_proc=False,  #  允许 fork exec
    unsafe=True,  #  不安全模式
    argv=["/usr/bin/fpc", "main.pas"],  # 运行的程序名
    add_readable_raw="")
print(res)

# res = judge.run_program(
# tl=1,   # time_limit 单位s
# ml=128, # memory_limit 单位 mb
# ol=128, # output_limit 单位 mb
# sl=1024, # stack limit 单位 mb
# _in="in",  # 输入文件
コード例 #10
0
def run_judge(config_data, infile, ansfile, count):

    in_path = os.path.join(config_data["data_dir"], infile)
    out_path = os.path.join(config_data["round_dir"], random_string(32))
    ans_path = os.path.join(config_data["data_dir"], ansfile)
    log_path = os.path.join(config_data["round_dir"], random_string(32))
    spj_path = os.path.join(config_data["round_dir"], "spj")
    ans_checker = {"details": "", "exit_code": 0}

    # Prevent input errors
    if not os.path.exists(in_path):
        open(in_path, "w").close()

    ## 得到
    run_args = _run_args(config_data, in_path, out_path, log_path)
    # 选择使用的评测机
    result = {}
    if config_data['judger'] == 'ujudge':
        result = judge.run_program(**run_args)
    else:  # 默认使用 qjudge
        result = _judger.run(**run_args)

    # 结果码转换
    if config_data['judger'] == 'ujudge':
        trans = [0, -1, 3, 1, 5, 5, 5]
        result["result"] = trans[result["result"]]
        result["cpu_time"] = result["time"]
        result["real_time"] = result["time"]

    if config_data['judger'] == 'qjudge':
        result["memory"] = result["memory"] // 1024  #转成kb

    if ((result["result"] == 0 or result["result"] == RUNTIME_ERROR)
            and result["memory"] > config_data["memory"] * 1024):
        result["result"] = MEMORY_LIMIT_EXCEEDED
    # A fake time limit / memory limit exceeded
    elif result['cpu_time'] > config_data["time"]*1000 or result['result'] == CPU_TIME_LIMIT_EXCEEDED \
            or result['result'] == REAL_TIME_LIMIT_EXCEEDED:
        # result['cpu_time'] = config_data["time"]*1000 ?
        result['result'] = CPU_TIME_LIMIT_EXCEEDED
    # elif result['result'] == MEMORY_LIMIT_EXCEEDED:
    # result['memory'] = config_data["max_memory"]

    elif result['result'] == 0:
        ans_checker = _result_checker(spj_path, in_path, out_path, ans_path)
        # print("res_judge %d" % res_judge)
        if (ans_checker["exit_code"] != 0):
            result['result'] = WRONG_ANSWER

    verdict = result['result']

    judge_ans = dict(
        status=0,
        count=count,
        mid=JUDGING,
        time=result['cpu_time'],
        memory=result['memory'],
        result=verdict,
        details=ans_checker['details']  # 答案错误细节
    )

    #del judge_ans["revert"]
    return judge_ans