Beispiel #1
0
    def init(self):
        code_path = f'{self.exe_dir}/code.py'
        with create_file_to_write(code_path) as code_file:
            code_file.write(self.code)

        exe_path = f'{self.exe_dir}/__pycache__/code.{self.magic}.pyc'
        self.exe_args = [self.interpreter, '-O', '-S', exe_path]

        log_path = f'{self.exe_dir}/compile.log'
        with open(log_path, 'w') as log_file:
            run_cfg = self.get_run_cfg(
                [
                    self.interpreter, '-O', '-m', 'compileall', '-q',
                    self.exe_dir
                ],
                0,
                0,
                log_file.fileno(),
                runner=-1,
            )
            result = lorun.run(run_cfg)

        if result['result'] != VerdictResult.AC:
            with open(log_path, 'r') as log_file:
                raise ExecutorInitException(
                    log_file.read())  # TODO check file size before read
Beispiel #2
0
def runone(p_path, in_path, out_path):
    fin = file(in_path)
    ftemp = file('temp.out', 'w')

    runcfg = {
        'args': ['cd', '/home/ma6174/111/', '&&', 'java', 'Main'],
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': 2000,  #in MS
        'memorylimit': 65536,  #in KB
    }
    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    if rst['result'] == 0:
        ftemp = file('temp.out')
        fout = file(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
        #        os.remove('temp.out')
        if crst != 0:
            return {'result': crst}

    return rst
Beispiel #3
0
def run(workPath, index, language, testdata_path, standout_path, limitTime,
        limitMemory, exec_file_name):
    language = language.lower()
    cmd = ''
    if language == 'java':
        cmd = 'java -classpath %s %s ' % (workPath, exec_file_name)
    elif language == 'python':
        cmd = 'python %s ' % (os.path.join(workPath, exec_file_name))
    else:
        cmd = '%s ' % (os.path.join(workPath, exec_file_name))
    fin = open(testdata_path)
    ftemppath = os.path.join(workPath, str(index) + ".out")
    ftemp = open(ftemppath, 'w')
    runcfg = {
        'args': shlex.split(cmd),
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': int(limitTime),
        'memorylimit': int(limitMemory)
    }
    res = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    if res['result'] == 0:
        ftemp = open(ftemppath)
        fout = open(standout_path)
        res['result'] = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
    return res
Beispiel #4
0
def runone(p_path, in_path, out_path):
    fin = open(in_path)
    ftemp = open("temp.out", "w")
    argsList = p_path.split(" ")

    runcfg = {
        "args": argsList,
        "fd_in": fin.fileno(),
        "fd_out": ftemp.fileno(),
        "timelimit": 2000,  # in MS
        "memorylimit": 200000,  # in KB
    }

    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()

    if rst["result"] == 0:
        ftemp = open("temp.out")
        fout = open(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
        os.remove("temp.out")
        if crst != 0:
            return {"result": crst}

    return rst
Beispiel #5
0
def judge_one_mem_time(solution_id, problem_id, item, time_limit, mem_limit, language):
	low_level()
	'''ce yi zu shu zu'''
	input_path = os.path.join(config.data_dir,str(problem_id),"%s" %item)
	try:
		input_data = file(input_path)
	except:
		return False
	out_path = os.path.join(config.work_dir,str(solution_id),'%s'%(item[:-2] + 'txt'))
	temp_out_data = open(out_path, 'w')
	if language == 'java':
		cmd = 'java -cp %s Main' % (os.path.join(config.work_dir, str(solution_id)))
		main_exe = shlex.split(cmd)
	elif language  == 'python2':
		cmd = 'python2 %s' (os.path.join(config.work_dir,str(solution_id), 'main.pyc'))
		main_exe = shlex.split(cmd)
	elif language == 'python3':
		cmd = 'python3 %s' % (os.path.join(config.work_dir, str(solution_id), '__pycache__/main,cpython-33.pyc'))
		main_exe = shlex.split(cmd)
	else:
		main_exe = [os.path.join(config.work_dir,str(solution_id), 'main')]
	runcfg = {
		'args': main_exe,
		'fd_in': input_data.fileno(),
		'fd_out': temp_out_data.fileno(),
		'timelimit': time_limit,#in MS
		'memorylimit': mem_limit,# in KB
	}
	#low_level()

	rst = lorun.run(runcfg)
	input_data.close()
	temp_out_data.close()
	#logging.debug(rst)
	return rst
Beispiel #6
0
def runone(p_path, in_path, out_path):
    fin = open(in_path)
    ftemp = open('temp.out', 'w')
    
    runcfg = {
        'args':['./m'],
        'fd_in':fin.fileno(),
        'fd_out':ftemp.fileno(),
        'timelimit':1000, #in MS
        'memorylimit':20000, #in KB
    }
    
    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    
    if rst['result'] == 0:
        ftemp = open('temp.out')
        fout = open(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
        os.remove('temp.out')
        if crst != 0:
            return {'result':crst}
    
    return rst
Beispiel #7
0
def judge(cmd, file_in, file_out, time_limit, memory_limit, kind, spj):
    fin = open(file_in)
    fout = open(file_out, 'w+')
    ferr = open('/bin/null')
    runcfg['args'] = cmd
    runcfg['fd_err'] = ferr.fileno()
    runcfg['fd_in'] = fin.fileno()
    runcfg['fd_out'] = fout.fileno()
    runcfg['timelimit'] = time_limit
    runcfg['memorylimit'] = memory_limit
    result = lorun.run(runcfg)
    fin.close()
    fout.close()
    if spj == 1:
        result = SPJudge(file_in, result)
    elif result['result'] == 0:
        file_ans = file_in.replace(".in", ".out")
        fans = open(file_ans)
        fout = open(file_out)
        flag = lorun.check(fans.fileno(), fout.fileno())
        fout.close()
        fans.close()
        result['result'] = flag
    #os.remove(file_out)
    return result
Beispiel #8
0
def runone(p_path, in_path, out_path):
    fin = file(in_path)
    ftemp = file('temp.out', 'w')
    
    runcfg = {
        'args':['cd','/home/ma6174/111/','&&','java','Main'],
        'fd_in':fin.fileno(),
        'fd_out':ftemp.fileno(),
        'timelimit':2000, #in MS
        'memorylimit':65536, #in KB
    }
    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    if rst['result'] == 0:
        ftemp = file('temp.out')
        fout = file(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
#        os.remove('temp.out')
        if crst != 0:
            return {'result':crst}
    
    return rst
Beispiel #9
0
Datei: tasks.py Projekt: zrt/XOJ
def runone(p_path, in_path, out_path, mem_limit, tim_limit):
    fin = open(in_path)
    ftemp = open('temp.out', 'w')
    
    runcfg = {
        'args':[p_path],
        'fd_in':fin.fileno(),
        'fd_out':ftemp.fileno(),
        'timelimit':tim_limit, #in MS
        'memorylimit':mem_limit*1024, #in KB
    }
    
    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    
    if rst['result'] == 0:
        ftemp = open('temp.out')
        fout = open(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
        os.remove('temp.out')
        if crst != 0:
            rst['result']=crst
            return rst
    
    return rst
Beispiel #10
0
def runone(p_path, in_path, out_path):
    fin = open(in_path)
    ftemp = open('temp.out', 'w')

    runcfg = {
        'args': ['./m'],
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': 1000,  # in MS
        'memorylimit': 20000,  # in KB
    }

    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    if rst['result'] == 0:
        ftemp = open('temp.out')
        fout = open(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
        os.remove('temp.out')
        if crst != 0:
            return {'result': crst}

    return rst
    def judge(self, judger, srcPath, outPath, inFile, ansFile, memlimit, timelimit):
        cmd = config.langRun[judger.lang] % {'src': srcPath, 'target': outPath}
        fout_path = "".join([sys.path[0], "/", "%s/%d.out" % (config.dataPath["tempPath"], random.randint(0, 65536))])
        
        if os.path.exists(fout_path):
            os.remove(fout_path)

        
        fin = open(inFile, 'rU')
        fout = open(fout_path, 'w')
        runcfg = {
            'args': [cmd],
            'fd_in': fin.fileno(),
            'fd_out': fout.fileno(),
            'timelimit': int(timelimit),
            'memorylimit': int(memlimit)
        }

        rst = lorun.run(runcfg)
        fin.close()
        fout.close()

        if rst['result'] == 0:
            fans = open(ansFile, 'rU')
            fout = open(fout_path, 'rU')
            crst = lorun.check(fans.fileno(), fout.fileno())
            fout.close()
            fans.close()
            return (RESULT_MAP[crst], int(rst['memoryused']), int(rst['timeused']))

        return (RESULT_MAP[rst['result']], 0, 0)
Beispiel #12
0
def judge(runid, pid, language):
    '''评测题目'''
    file_name = {
        'C': 'main.c',
        'C++': 'main.cpp',
        'Python2.7': 'main.py'
    }
    get_code(runid, file_name[language])
    input_file = file(os.path.join(DATA_FOLDER, ''.join([str(pid), '.in'])))
    output_file = file(os.path.join(DATA_FOLDER, ''.join([str(pid), '.out'])))
    tmp_file = file(os.path.join(TMP_FOLDER, str(runid)), 'w')
    time_limit = Problem.query.filter_by(pid = pid).first().time_limit
    memory_limit = Problem.query.filter_by(pid = pid).first().memory_limit

    if not compile(runid, language):
        return 'Compile Error', None

    if language == 'Python2.7':
        time_limit *= PYTHON_TIME_LIMIT_TIMES
        memory_limit *= PYTHON_MEMORY_LIMIT_TIMES
        cmd = 'python2.7 %s' % (os.path.join(TMP_FOLDER, 'main.pyc'))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [os.path.join(TMP_FOLDER, 'main'), ]

    runcfg = {
        'args': main_exe,
        'fd_in': input_file.fileno(),
        'fd_out': tmp_file.fileno(),
        'timelimit': time_limit,
        'memorylimit': memory_limit
    }
    rst = lorun.run(runcfg)
    tmp_file = file(os.path.join(TMP_FOLDER, str(runid)))
    return JUDGE_RESULT[lorun.check(output_file.fileno(), tmp_file.fileno())], rst
Beispiel #13
0
def debug(str_in, ques_info, cur_name, exec_path):
    os.chdir(exec_path)
    cin_name = cur_name + "in"
    fin = open(cin_name, "w")
    fin.write(str_in)
    fin.close()
    fin = open(cin_name, "r")

    temp_name = cur_name + ".out"
    ftemp = open(temp_name, "w")

    runcfg = {
        "args" : ["./" + cur_name],
        "fd_in" : fin.fileno(),
        "fd_out" : ftemp.fileno(),
        "timelimit" : ques_info["t_l"],
        "memorylimit": ques_info["m_l"]
    }
    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()

    rst["result"] = RESULT_STR[rst["result"]]
    ftemp = open(temp_name)
    _t = ftemp.read()
    i = len(_t) - 1
    while i >= 0 and (_t[i] == '\n' or _t[i] == ' '):
        i -= 1
    t = _t[0 : i + 1]
    rst["cout"] = t
    ftemp.close()
    os.remove(temp_name)
    os.remove(cin_name)
    print("debug:" , rst)
    return rst
Beispiel #14
0
    def init(self):
        try:
            tree = javalang.parse.parse(self.code)
            self.name = next(
                klass.name for klass in tree.types
                if isinstance(klass, javalang.tree.ClassDeclaration)
                for m in klass.methods if m.name == 'main'
                and m.modifiers.issuperset({'public', 'static'}))
        except javalang.parser.JavaSyntaxError:
            # if code illegal, you can't get a certain main class name, the code must ce ,you call it Solution is ok
            self.name = 'Solution'

        code_path = f'{self.exe_dir}/{self.name}.java'
        code_file = create_file_to_write(code_path)
        code_file.write(self.code)
        code_file.close()

        log_path = f'{self.exe_dir}/compile.log'
        self.exe_args = ['java', '-classpath', self.exe_dir,
                         self.name]  # overridden in `execute` method

        with open(log_path, 'w') as log_file:
            run_cfg = self.get_run_cfg(
                ['javac', code_path],
                0,
                0,
                log_file.fileno(),
                runner=-1,
            )
            result = lorun.run(run_cfg)

        if result['result'] != VerdictResult.AC:
            with open(log_path, 'r') as log_file:
                raise ExecutorInitException(log_file.read())
Beispiel #15
0
def run(language, testdata_path, standout_path, limitTime, limitMemory):
    language = language.lower()
    cmd = ''
    if language == 'java':
        cmd = 'java -classpath %s %s ' % (cfg.tempdata_path,
                                          cfg.java_file_name_no_ext)
    elif language == 'python':
        cmd = 'python %s ' % (os.path.join(
            cfg.source_path, cfg.python_file_name_no_ext + ".pyc"))
    else:
        cmd = './%s ' % (cfg.exec_name)
    fin = open(testdata_path)
    ftemp = open(cfg.temp_file_name, 'w')
    ftemp = open(os.path.join(cfg.tempdata_path, cfg.temp_file_name), 'w')
    runcfg = {
        'args': shlex.split(cmd),
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': int(limitTime),
        'memorylimit': int(limitMemory),
    }
    res = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    if res['result'] == 0:
        ftemp = open(os.path.join(cfg.tempdata_path, cfg.temp_file_name))
        fout = open(standout_path)
        res['result'] = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
    return res
Beispiel #16
0
def run_one(exe_id, lang, in_path, out_path, time, memory):
    out = exe_id + ".out"
    fin = open(in_path)
    ftemp = open(out, 'w')
    run_map = {1: "java -cp " + return_exe_path(exe_id) + " Main", 2: "./" + exe_id}
    main_exe = shlex.split(run_map[lang])
    print(main_exe)
    run_config = {
        'args': main_exe,
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': time,  # in MS
        'memorylimit': memory,  # in KB
    }

    rst = lorun.run(run_config)
    fin.close()
    ftemp.close()

    if rst['result'] == 0:
        ftemp = open(out)
        fout = open(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
        os.remove(out)
        if crst != 0:
            return {'result': crst}

    return rst
Beispiel #17
0
def run(exe_file, std_in, std_out, time_limit, memory_limit, file_io,
        file_io_input_name, file_io_output_name):
    result_str = ('Accepted', 'Presentation Error', 'Time Limit Exceed',
                  'Memory Limit Exceed', 'Wrong Answer', 'Runtime Error',
                  'Output Limit Exceed', 'Compile Error', 'System Error')

    user_out = "user_tmp.out"
    std_in_f = open(std_in)
    user_out_f = open(user_out, 'w')

    if file_io:
        os.system("cp " + std_in + " " + file_io_input_name)
        std_in_f = open("/dev/null")
    run_cfg = {
        'args': ['./' + exe_file],
        'fd_in': std_in_f.fileno(),
        'fd_out': user_out_f.fileno(),
        'timelimit': time_limit,
        'memorylimit': memory_limit * 1024,
    }

    res = lorun.run(run_cfg)
    std_in_f.close()
    user_out_f.close()

    if file_io:
        os.remove(user_out)
        user_out = file_io_output_name
    result = {}
    result['status'] = result_str[res['result']]
    if res['result'] == 0:
        if not os.path.isfile(user_out):
            result['status'] = 'Wrong Answer'
        elif not check_ans(std_out, user_out):
            print "zz"
            result['status'] = 'Wrong Answer'
    if not 'timeused' in res:
        result['time_used'] = 0
    else:
        result["time_used"] = res["timeused"]
    if not 'memoryused' in res:
        result['memory_used'] = 0
    else:
        result["memory_used"] = res["memoryused"]

    result["input"] = shorter_read(std_in, 120)
    result["answer"] = shorter_read(std_out, 120)

    if os.path.isfile(user_out):
        result["user_out"] = shorter_read(user_out, 120)
        os.remove(user_out)
    else:
        result["user_out"] = ""

    if file_io:
        os.system("rm -r " + file_io_input_name)
    return result
Beispiel #18
0
def judge_one_mem_time(solution_id, problem_id, data_num, time_limit,
                       mem_limit, language):
    low_level()
    '''评测一组数据'''
    input_path = os.path.join(config.data_dir, str(problem_id),
                              'data%s.in' % data_num)
    try:
        input_data = file(input_path)
    except:
        return False
    output_path = os.path.join(config.work_dir, str(solution_id),
                               'out%s.txt' % data_num)
    temp_out_data = file(output_path, 'w')
    if language == 'java':
        cmd = 'java -cp %s Main' % (os.path.join(config.work_dir,
                                                 str(solution_id)))
        main_exe = shlex.split(cmd)
        logging.info(main_exe)
    elif language == 'python2':
        cmd = 'python %s' % (os.path.join(config.work_dir, str(solution_id),
                                          'main.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'python3':
        cmd = 'python3 %s' % (os.path.join(config.work_dir, str(solution_id),
                                           '__pycache__/main.cpython-33.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'lua':
        cmd = "lua %s" % (os.path.join(config.work_dir, str(solution_id),
                                       "main"))
        main_exe = shlex.split(cmd)
    elif language == "ruby":
        cmd = "ruby %s" % (os.path.join(config.work_dir, str(solution_id),
                                        "main.rb"))
        main_exe = shlex.split(cmd)
    elif language == "perl":
        cmd = "perl %s" % (os.path.join(config.work_dir, str(solution_id),
                                        "main.pl"))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [
            os.path.join(config.work_dir, str(solution_id), 'main'),
        ]
    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': temp_out_data.fileno(),
        'timelimit': time_limit,  # in MS
        'memorylimit': mem_limit,  # in KB
    }
    low_level()
    rst = lorun.run(runcfg)
    logging.info("the lorun result is : " + str(rst))
    input_data.close()
    temp_out_data.close()
    logging.debug(rst)
    return rst
Beispiel #19
0
def judge(runid, pid, language):
    filename = {'C': 'main.c', 'C++': 'main.cpp', 'Python2.7': 'main.py'}
    #form the src into main.py/main.c
    get_code(runid, filename[language])

    input_file = open(os.path.join(UPLOAD_FOLDER, ''.join([str(pid), '.in'])))
    output_file = open(os.path.join(UPLOAD_FOLDER, ''.join([str(pid),
                                                            '.out'])))
    tmp_file = open(os.path.join(TMP_FOLDER, str(runid)), 'w')
    time_limit = Problem.query.get(pid).time_limit
    memory_limit = Problem.query.get(pid).memory_limit

    if not compile(runid, language):
        return ('Compile Error', None)

    if language == 'Python2.7':
        time_limit *= PYTHON_TIME_LIMIT_TIMES
        memory_limit *= PYTHON_MEMORY_LIMIT_TIMES
        cmd = 'python2.7 %s' % (os.path.join(TMP_FOLDER, 'main.pyc'))
        main_exe = shlex.split(cmd)

    else:
        main_exe = [
            os.path.join(TMP_FOLDER, 'main'),
        ]

    runcfg = {
        'args': main_exe,
        'fd_in': input_file.fileno(),
        'fd_out': tmp_file.fileno(),
        'timelimit': time_limit,
        'memorylimit': memory_limit
    }
    #lorun.run() returns a dict = {'memoryused': kb, 'timeused': ms, 'results': '0 if run properly'}
    #otherwise non-zero maybe Runtime Error
    rst = lorun.run(runcfg)
    print rst
    input_file.close()
    tmp_file.close()

    tmp_file = open(os.path.join(TMP_FOLDER, str(runid)))

    if rst['result'] == 0:
        #lorun.check() returns a number which means the final result
        crst = lorun.check(output_file.fileno(), tmp_file.fileno())
        output_file.close()
        tmp_file.close()
        rst['result'] = crst

        print crst

    return JUDGE_RESULT[rst['result']], rst
Beispiel #20
0
def runone(p_path, in_path, out_path, user_path, time_limit, memory_limit,
           lang):
    fin = open(in_path)
    ftemp = open(user_path, 'w')
    if type(p_path) == str:
        p_path = [p_path]

    runcfg = {
        'args': p_path,
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': int(time_limit * 1000),  #in MS
        'memorylimit': int(memory_limit * 2 / 1024 + 1024),  #in KB
    }
    if lang != 'Java':
        runcfg['trace'] = True
        runcfg['calls'] = [0, 1, 2, 3, 5, 9, 10, 11, 12, 21, 59, 158, 231]
        runcfg['files'] = {}
    else:
        runcfg['memorylimit'] = 0x3f3f3f3f3f3f3f3f
    # print('Runone Config:')
    # print(runcfg)
    rst = lorun.run(runcfg)
    # print('Runone Result:')
    # print(rst)
    fin.close()
    ftemp.close()

    if rst['result'] == 0:
        if rst['memoryused'] > memory_limit / 1024:
            rst['memoryused'] = memory_limit / 1024
            rst['result'] = 3  #MLE

    if rst['result'] == 0:
        ftemp = open(user_path, 'r')
        output = ftemp.read().strip()
        ftemp.close()
        output = output.replace(chr(13), '')

        fout = open(out_path, 'r')
        right = fout.read().strip()
        fout.close()
        right = right.replace(chr(13), '')

        if right != output:
            if ''.join(output.split()) == ''.join(right.split()):
                rst['result'] = 1  #PE
            else:
                rst['result'] = 4  #WA
    return rst
Beispiel #21
0
def run(exe_file, std_in, std_out, time_limit, memory_limit):
    result_str = (
        'Accepted',
        'Presentation Error',
        'Time Limit Exceed',
        'Memory Limit Exceed',
        'Wrong Answer',
        'Runtime Error',
        'Output Limit Exceed',
        'Compile Error',
        'System Error'
    )
    user_out = "user_tmp.out"

    std_in_f = open(std_in)
    user_out_f = open(user_out, 'w')

    run_cfg = {
        'args': ['./' + exe_file],
        'fd_in': std_in_f.fileno(),
        'fd_out': user_out_f.fileno(),
        'timelimit': time_limit,
        'memorylimit': memory_limit * 1024,
    }

    res = lorun.run(run_cfg)
    std_in_f.close()
    user_out_f.close()

    result = {}
    result['status'] = result_str[res['result']]
    if res['result'] == 0:
        if not check_ans(std_out, user_out):
            result['status'] = 'Wrong Answer'
    if not 'timeused' in res:
        result['time_used'] = 0
    else:
        result["time_used"] = res["timeused"]
    if not 'memoryused' in res:
        result['memory_used'] = 0
    else:
        result["memory_used"] = res["memoryused"]

    result["input"] = shorter_read(std_in, 120)
    result["answer"] = shorter_read(std_out, 120)
    result["user_out"] = shorter_read(user_out, 120)

    os.remove(user_out)
    return result
Beispiel #22
0
def judge_one_mem_time(submit_id, problem_id, data_num, time_limit, mem_limit, language):
    protect.low_level()
    '''评测一组数据'''
    lans = DBData.lans
    input_path = os.path.join(config.data_dir, str(problem_id), 'data%s.in' % data_num)  # 获取存放输入数据的文件的路径
    try:
        input_data = open(input_path)  # 尝试打开
    except:
        return False  # 无法打开
    # 创建一个供写入数据的txt文件(用于存放用户程序的运行结果)
    output_path = os.path.join(config.work_dir, str(submit_id), 'out%s.txt' % data_num)
    temp_out_data = open(output_path, 'w')  # 以写入方法创建打开上述文件
    if lans[language][0] == 'java':
        mem_limit += 1000000
        cmd = 'java -cp %s Main' % (os.path.join(config.work_dir, str(submit_id)))
        main_exe = shlex.split(cmd)  # 使用类似shell的语法分割cmd
    elif lans[language][0] == 'python2':
        cmd = 'python2 %s' % (os.path.join(config.work_dir, str(submit_id), 'main.pyc'))
        main_exe = shlex.split(cmd)
    elif lans[language][0] == 'python3':
        cmd = 'python3 %s' % (os.path.join(config.work_dir, str(submit_id), 'main.py'))
        main_exe = shlex.split(cmd)
    elif lans[language][0] == 'lua':
        cmd = "lua %s" % (os.path.join(config.work_dir, str(submit_id), "main"))
        main_exe = shlex.split(cmd)
    elif lans[language][0] == "ruby":
        cmd = "ruby %s" % (os.path.join(config.work_dir, str(submit_id), "main.rb"))
        main_exe = shlex.split(cmd)
    elif lans[language][0] == "perl":
        cmd = "perl %s" % (os.path.join(config.work_dir, str(submit_id), "main.pl"))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [os.path.join(config.work_dir, str(submit_id), 'main'), ]
    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),  # 一个整型的文件描述符(文件id)
        'fd_out': temp_out_data.fileno(),  # 同上
        'timelimit': time_limit,  # in MS
        'memorylimit': mem_limit,  # in KB
    }
    try:
        protect.low_level()
        rst = lorun.run(runcfg)  # 在lorun黑盒中运行程序
        input_data.close()
        temp_out_data.close()
        logging.debug(rst)
        return rst  # {result:int,timeused:int,memoryused:int}
    except:
        logging.error("lorun错误")
Beispiel #23
0
def runone(in_path, out_path, ques_info, cur_name):
    temp_name = cur_name + ".out" 
    fin = open(in_path)
    cin_text = fin.read()
    fin.close()
    fin = open(in_path)
    ftemp = open(temp_name, "w")

    runcfg = {
        "args" : ["./" + cur_name],
        "fd_in" : fin.fileno(),
        "fd_out" : ftemp.fileno(),
        "timelimit" : ques_info["t_l"],
        "memorylimit": ques_info["m_l"]
    }

    print("runone", runcfg["args"])
    
    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()

    if rst["result"] == 0:
        ftemp = open(temp_name)
        fout = open(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        
        ftemp.close()

        if crst != 0:
            ftemp = open(temp_name)
            _t = ftemp.read()
            out = fout.read()
            i = len(_t) - 1
            while i >= 0 and ( _t[i] == '\n' or _t[i] == ' '):
                i -= 1
            t = _t[0 : i + 1]
            if(t == out):
                crst == 0
            else:   
                rst["result"] = crst
                rst["cout"] = t
                rst["true_cout"] = out
                ftemp.close()
                fout.close()
    rst["cin_text"] = cin_text
    os.remove(temp_name)
    print("run_one:" , rst)
    return rst
Beispiel #24
0
def judge_one(solution_id, problem_id, data_num, time_limit, mem_limit,
              language):
    low_level()
    input_path = os.path.join(config.data_dir, str(problem_id),
                              'data%s.in' % data_num)
    try:
        input_data = open(input_path, 'r')
    except:
        return False

    output_path = os.path.join(config.work_dir, str(solution_id),
                               'out%s.txt' % data_num)
    temp_out_data = open(output_path, 'w')

    if language == 'java':
        cmd = 'java -cp %s Main' % (os.path.join(config.work_dir,
                                                 str(solution_id)))
        main_exe = shlex.split(cmd)

    elif language == 'python2':
        cmd = 'python2 %s' % (os.path.join(config.work_dir, str(solution_id),
                                           'main.pyc'))
        main_exe = shlex.split(cmd)

    elif language == 'python3':
        cmd = 'python3 %s' % (os.path.join(config.work_dir, str(solution_id),
                                           '__pycache__/main.cpython-33.pyc'))
        main_exe = shlex.split(cmd)

    else:
        main_exe = [
            os.path.join(config.work_dir, str(solution_id), 'main'),
        ]

    runfig = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': temp_out_data.fileno(),
        'timelimit': time_limit,
        'memorylimit': mem_limit,
    }

    low_level()
    rst = lorun.run(runfig)
    input_data.close()
    temp_out_data.close()
    logging.debug(rst)
    return rst
Beispiel #25
0
def runone(p_path, in_path, out_path):
    fin = open(in_path)
    fout = open(out_path)
    ftemp = open('temp.out', 'w')

    runcfg = {
        'args': p_path,
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': 5000,  #in MS
        'memorylimit': 200000,  #in KB
    }

    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    return rst
Beispiel #26
0
    def execute(self,
                input_path,
                output_path,
                log_path,
                time_limit,
                memory_limit,
                trace=False,
                runner=NOBODY_UID):
        input_file = open(input_path, 'r') if input_path else None
        output_file = create_file_to_write(
            output_path) if output_path else None
        log_file = create_file_to_write(log_path) if log_path else None

        result = {
            'result': VerdictResult.SE,
            'timeused': 0,
            'memoryused': 0,
            'desc': "lorun exited unexpectedly"
        }
        try:
            run_cfg = self.get_run_cfg(
                self.exe_args,
                input_file.fileno() if input_file else 0,
                output_file.fileno() if output_file else 0,
                log_file.fileno() if log_path else 0,
                time_limit,
                memory_limit,
                trace=trace,
                runner=runner,
            )
            result = lorun.run(run_cfg)
        except SystemError:
            return result
        finally:
            self.get_additional_info(result, output_path, log_path)
            if input_file:
                input_file.close()
            if output_file:
                output_file.close()
            if log_file:
                log_file.close()
            # do some cleanups in subclasses if necessary
            self.cleanup(log_path)

        return result
Beispiel #27
0
def judge_one(work_path, pid, language, input_data, output_data, time_limit,
              mem_limit):
    if language == 'c' or language == 'c++':
        main_exe = [
            os.path.join(work_path, 'main'),
        ]
    elif language == 'python2':
        cmd = 'python2 %s' % (os.path.join(work_path, 'main.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'python3':
        cmd = 'python3 %s' % (os.path.join(work_path,
                                           '__pycache__/main.cpython-34.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'java':
        cmd = 'java -cp %s main' % work_path
        main_exe = shlex.split(cmd)
    elif language == 'php':
        cmd = 'php %s' % (os.path.join(work_path, 'main.php'))
        main_exe = shlex.split(cmd)
    elif language == 'lua':
        cmd = "lua %s" % (os.path.join(work_path, "main"))
        main_exe = shlex.split(cmd)
    elif language == "ruby":
        cmd = "ruby %s" % (os.path.join(work_path, "main.rb"))
        main_exe = shlex.split(cmd)
    elif language == "perl":
        cmd = "perl %s" % (os.path.join(work_path, "main.pl"))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [
            os.path.join(work_path, 'main'),
        ]

    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': output_data.fileno(),
        'timelimit': time_limit,
        'memorylimit': mem_limit * 1024,
    }

    rst = lorun.run(runcfg)

    return rst
Beispiel #28
0
def judge_one_mem_time(solution_id, problem_id, item, time_limit, mem_limit,
                       language):
    low_level()
    input_path = os.path.join(config.data_dir, str(problem_id), "%s" % item)
    try:
        input_data = file(input_path)
    except:
        return False

    out_path = os.path.join(config.work_dir, str(solution_id),
                            '%s' % (item[:-2] + 'txt'))
    temp_out_data = open(out_path, 'w')

    if language == 'java':
        cmd = 'java -cp %s Main' % (os.path.join(config.work_dir,
                                                 str(solution_id)))
        main_exe = shlex.split(cmd)

    elif language == 'python2':
        cmd = 'python2 %s' % (os.path.join(config.work_dir, str(solution_id),
                                           'main.pyc'))
        main_exe = shlex.split(cmd)

    elif language == 'python3':
        cmd = 'python3 %s' % (os.path.join(config.work_dir, str(solution_id),
                                           '__pycache__/main,cpython-33.pyc'))
        main_exe = shlex.split(cmd)

    else:
        main_exe = [os.path.join(config.work_dir, str(solution_id), 'main')]

    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': temp_out_data.fileno(),
        'timelimit': time_limit,  #in MS
        'memorylimit': mem_limit,  # in KB
    }

    rst = lorun.run(runcfg)
    input_data.close()
    temp_out_data.close()
    return rst
Beispiel #29
0
def judge_one_mem_time(solution_id, problem_id, data_num, time_limit,
                       mem_limit, language):
    '''评测一组数据'''
    input_path = os.path.join(config.data_dir, str(problem_id), "test_data",
                              'data%s.in' % data_num)

    print("inputpath:", input_path)
    try:
        input_data = open(input_path, 'r')
    except:
        return False
    output_path = os.path.join(config.work_dir, str(solution_id),
                               'out%s.txt' % data_num)
    print("out_path", output_path)
    temp_out_data = open(output_path, 'w')
    print(temp_out_data)
    if language == 'python3':
        cmd = 'python3 %s' % (os.path.join(config.work_dir, str(solution_id),
                                           '__pycache__/main.cpython-38.pyc'))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [
            os.path.join(config.work_dir, str(solution_id), 'main'),
        ]
    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': temp_out_data.fileno(),
        'timelimit': time_limit,  # in MS
        'memorylimit': mem_limit,  # in KB
        'trace' : True,
        'calls': [1,3, 17, 12, 21, 257, 5, 9, 0, 10, 158, 11, 8, 218,\
            89,63,231], # system calls that could be used by testing programs
        'files' : {'/etc/ld.so.cache': 1} # open flag permitted (value is the flags of open)
    }
    rst = lorun.run(runcfg)
    print("lorn:", rst)
    input_data.close()
    temp_out_data.close()
    logging.debug(rst)
    return rst
Beispiel #30
0
def execRunOnce(session_path, handel, config, td_in_path):
    my_out_filename = "%s.outdata" % handel
    # 获取程序运行结果输出文件的绝对路径
    tMP_PATH = os.path.join(session_path, my_out_filename)
    # 只读打开测试数据输入样例文件
    fin = open(td_in_path)
    # 清理遗留文件
    if os.path.exists(tMP_PATH):
        os.remove(tMP_PATH)
    # 只写打开运行结果文件
    ftemp = open(tMP_PATH, 'w+')
    # 创建评测配置信息
    # java -classpath <session_path> Main
    if str(config.get('lang')) == 'java':
        args = [
            'java', '-client', '-Dfile.encoding=utf-8', '-classpath',
            session_path, "Main"
        ]

    else:
        args = [os.path.join(session_path, "m")]
    time_limit = config.get('time_limit', 1000)
    memory_limit = config.get('memory_limit', 32768)
    runcfg = {
        'args': args,  # 运行程序文件
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': time_limit,
        'memorylimit': memory_limit
    }
    Base.log('[TDMaker]运行源程序!(JUDGE_PROCESS_START)')
    # 执行Lorun模块,运行程序
    rst = lorun.run(runcfg)
    Base.log('[TDMaker]程序运行结束!(JUDGE_PROCESS_FINISHED)')
    # 释放文件
    fin.close()
    ftemp.close()

    # 返回运行结果
    return rst
Beispiel #31
0
def judge(cmd,file_in,file_out,time_limit,memory_limit):
    fin = open(file_in)
    fout = open(file_out,'w+')
    runcfg['args'] = cmd.split(' ')
    runcfg['fd_in'] = fin.fileno()
    runcfg['fd_out'] = fout.fileno()
    runcfg['timelimit'] = time_limit
    runcfg['memorylimit'] = memory_limit
    result = lorun.run(runcfg)
    fin.close()
    fout.close()
    if result['result'] == 0:
        file_ans = file_in.split('.')
        file_ans = file_ans[0] + '.out'
        fans = open(file_ans)
        fout = open(file_out)
        flag = lorun.check(fans.fileno(), fout.fileno())
        fout.close()
        fans.close()
        #os.remove(file_out)
        result['result'] = flag
    return result
Beispiel #32
0
def judge_one_mem_time(id, test_case_id, data_num, time_limit, mem_limit,
                       language):
    low_level()
    '''评测一组数据'''
    input_path = os.path.join(config.data_dir, str(test_case_id),
                              '%s.in' % data_num)
    try:
        input_data = open(input_path)
    except:
        return False
    output_path = os.path.join(config.work_dir, id, 'out%s.txt' % data_num)
    temp_out_data = open(output_path, 'w')
    if language == 'java':
        cmd = 'java -cp %s Main' % (os.path.join(config.work_dir, id))
        main_exe = shlex.split(cmd)
    elif language == 'python2':
        cmd = 'python2 %s' % (os.path.join(config.work_dir, id, 'main.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'python3':
        cmd = 'python3 %s' % (os.path.join(config.work_dir, id,
                                           config.python_exe_name))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [
            os.path.join(config.work_dir, id, 'main'),
        ]
    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': temp_out_data.fileno(),
        'timelimit': time_limit,  # in MS
        'memorylimit': mem_limit,  # in KB
    }
    low_level()
    rst = lorun.run(runcfg)
    input_data.close()
    temp_out_data.close()
    logging.debug(rst)
    return rst
def RunOne(runcfg, in_path, out_path, temp_path):
    fin = file(in_path)
    ftemp = file(temp_path, 'w')

    runcfg['fd_in'] = fin.fileno()
    runcfg['fd_out'] = ftemp.fileno()

    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()

    if rst['result'] == 0:
        ftemp = file(temp_path)
        fout = file(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
        os.remove(temp_path)
        if crst != 0:
            return {'result': crst}

    return rst
def run(work_path, language, input_data, output_data):
    if language == 'c' or language == 'c++':
        main_exe = [os.path.join(work_path, 'main'), ]
    elif language == 'python2':
        cmd = 'python2 %s' % (os.path.join(work_path,'main.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'python3':
        cmd = 'python3 %s' % (os.path.join(work_path,'__pycache__/main.cpython-34.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'java':
        cmd = 'java -cp %s main' % work_path
        main_exe = shlex.split(cmd)
    elif language == 'php':
        cmd = 'php %s' % (os.path.join(work_path,'main.php'))
        main_exe = shlex.split(cmd)
    elif language == 'lua':
        cmd = "lua %s" % (os.path.join(work_path,"main"))
        main_exe = shlex.split(cmd)
    elif language == "ruby":
        cmd = "ruby %s" % (os.path.join(work_path,"main.rb"))
        main_exe = shlex.split(cmd)
    elif language == "perl":
        cmd = "perl %s" % (os.path.join(work_path,"main.pl"))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [os.path.join(work_path, 'main'), ]

    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': output_data.fileno(),
        'timelimit': 1000,
        'memorylimit': 32*1024,
    }

    rst = lorun.run(runcfg)
    
    return rst
Beispiel #35
0
def run(cmd, stdIn, stdOut, userOut, timeLimit, memoryLimit):
    result, fileIn, fileOut = None, None, None
    try:
        fileIn = open(stdIn, 'r')
        fileOut = open(userOut, 'w')
        runcfg = {
            'args': shlex.split(cmd),
            'fd_in': fileIn.fileno(),
            'fd_out': fileOut.fileno(),
            'timelimit': timeLimit,
            'memorylimit': memoryLimit,
        }
        result = lorun.run(runcfg)
    except Exception as e:
        result = {'memoryused': 0, 'timeused': 0, 'result': 8,'errormessage': str(e)}
    finally:
        if fileIn is not None:
            fileIn.close()
        if fileOut is not None:
            fileOut.close()
    if result['result'] == 0:
        file1, file2 = None, None
        try:
            file1 = open(userOut, 'r')
            file2 = open(stdOut, 'r')
            rst = lorun.check(file2.fileno(), file1.fileno())
            if rst != 0:
                result = {'memoryused': 0, 'timeused': 0, 'result': rst}
        except Exception as e:
            result = {'memoryused': 0, 'timeused': 0, 'result': 8, 'errormessage': str(e)}
        finally:
            if file1 is not None:
                file1.close()
            if file2 is not None:
                file2.close()
    else:
        result['memoryused'], result['timeused'] = 0, 0
    return result
Beispiel #36
0
    def init(self):
        code_path = f'{self.exe_dir}/code.cpp'
        code_file = create_file_to_write(code_path)
        code_file.write(self.code)
        code_file.close()

        exe_path = f'{self.exe_dir}/executable'
        log_path = f'{self.exe_dir}/compile.log'
        self.exe_args = [exe_path]

        with open(log_path, 'w') as log_file:
            run_cfg = self.get_run_cfg(
                ['g++', code_path, '-DONLINE_JUDGE', '-o', exe_path, '-Wall', '-O2', '-std=c++17'],
                0,
                0,
                log_file.fileno(),
                runner=-1,
            )
            result = lorun.run(run_cfg)

        if result['result'] != VerdictResult.AC:
            with open(log_path, 'r') as log_file:
                raise ExecutorInitException(log_file.read())
Beispiel #37
0
def runone(process, in_path, out_path, user_path, time, memory):
    fin = open(in_path)
    tmp = os.path.join(user_path, 'temp.out')
    ftemp = open(tmp, 'w')
    runcfg = {
        'args': [process],
        'fd_in': fin.fileno(),
        'fd_out': ftemp.fileno(),
        'timelimit': time,  # in MS
        'memorylimit': memory,  # in KB
    }
    rst = lorun.run(runcfg)
    fin.close()
    ftemp.close()
    if rst['result'] == 0:
        ftemp = open(tmp)
        fout = open(out_path)
        crst = lorun.check(fout.fileno(), ftemp.fileno())
        fout.close()
        ftemp.close()
        os.remove(tmp)
        rst['result'] = crst
    return rst
Beispiel #38
0
        # 创建测试结果
        result = JudgeResultDetailItem()
        result.handle = case.handle
        # 获取时间限制
        tl, ml = self.__get_time_mem_limit()

        runcfg = {
            'args': run_args,  # 运行程序文件
            'fd_in': in_file.fileno(),
            'fd_out': target_out_file.fileno(),
            'fd_err': err_out_file.fileno(),
            'timelimit': tl,
            'memorylimit': ml
        }
        # 运行程序
        rst = lorun.run(runcfg)
        # 关闭文件
        in_file.close()
        target_out_file.close()
        err_out_file.close()
        _log("RUN FINISHED")
        # 获取运行数据
        result.re_signum = rst.get('re_signum', 0)
        result.re_call = rst.get('re_call', 0)
        result.re_file_flag = rst.get('re_file_flag', 0)
        result.re_file = rst.get('re_file', "")
        result.time_used = rst.get('timeused', 0)
        result.memory_used = rst.get('memoryused', 0)
        result.re_msg = ""
        err_out_file = self.output_storage.open_file("%s.err" % case.handle, "r")
        # 获取stderr的输出
Beispiel #39
0
             'memoryused': 0,
             'timeused': 0
         }))
     continue
 if 'fd_in' in runcfg:
     fd_in = file(runcfg['fd_in'])
     runcfg['fd_in'] = fd_in.fileno()
 if 'fd_out' in runcfg:
     fd_out = file(runcfg['fd_out'], 'w')
     runcfg['fd_out'] = fd_out.fileno()
 if 'fd_err' in runcfg:
     fd_err = file(runcfg['fd_err'], 'w')
     runcfg['fd_err'] = fd_err.fileno()
 gc.collect()
 try:
     ret = lorun.run(runcfg)
 except:
     connection.send(
         json.dumps({
             'result': 11,
             'memoryused': 0,
             'timeused': 0
         }))
     continue
 del runcfg
 fd_err.close()
 fd_out.close()
 fd_in.close()
 del fd_in
 del fd_out
 del fd_err
Beispiel #40
0
def judge_one_mem_time( solution_id, problem_id, data_num, time_limit, mem_limit, language):
    low_level()
    '''评测一组数据'''
    input_path = os.path.join(
        config.data_dir, str(problem_id), 'data%s.in' %
        data_num)
    try:
        input_data = file(input_path)
    except:
        return False
    output_path = os.path.join(
        config.work_dir, str(solution_id), 'out%s.txt' %
        data_num)
    temp_out_data = file(output_path, 'w')
    if language == 'java':
        cmd = 'java -cp %s Main' % (
            os.path.join(config.work_dir,
                         str(solution_id)))
        main_exe = shlex.split(cmd)
    elif language == 'python2':
        cmd = 'python2 %s' % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         'main.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'python3':
        cmd = 'python3 %s' % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         '__pycache__/main.cpython-33.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'lua':
        cmd = "lua %s" % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         "main"))
        main_exe = shlex.split(cmd)
    elif language == "ruby":
        cmd = "ruby %s" % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         "main.rb"))
        main_exe = shlex.split(cmd)
    elif language == "perl":
        cmd = "perl %s" % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         "main.pl"))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [os.path.join(config.work_dir, str(solution_id), 'main'), ]
    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': temp_out_data.fileno(),
        'timelimit': time_limit,  # in MS
        'memorylimit': mem_limit,  # in KB
    }
    low_level()
    rst = lorun.run(runcfg)
    input_data.close()
    temp_out_data.close()
    logging.debug(rst)
    return rst
Beispiel #41
0
def run(submission_id, time_limit, mem_limit, program_info, language_id):
    low_level()
    '''评测一组测试用例'''

    input_path = os.path.join(
        config.data_dir, str(submission_id), '%s.in' %
        str(submission_id))
    try:
        input_data = file(input_path)
    except:
        return False

    output_path = os.path.join(
		config.work_dir, str(submission_id), '%s.out' %
		str(submission_id))
    try:
    	out_data = file(output_path, 'w')
    except:
    	return False

    if language_id == 3: # Java
        cmd = 'java -cp %s Main' % (
            os.path.join(config.work_dir,
                         str(submission_id)))
        main_exe = shlex.split(cmd)
    elif language_id == 9: #Python 2
        cmd = 'python2 %s' % (
            os.path.join(config.work_dir,
                         str(submission_id),
                         'main.pyc'))
        main_exe = shlex.split(cmd)
    elif language_id == 10: #Python 3
        cmd = 'python3 %s' % (
            os.path.join(config.work_dir,
                         str(submission_id),
                         '__pycache__/main.cpython-33.pyc'))
        main_exe = shlex.split(cmd)
    elif language_id == 8:
        cmd = "lua %s" % (
            os.path.join(config.work_dir,
                         str(submission_id),
                         "main"))
        main_exe = shlex.split(cmd)
    elif language_id == 8:
        cmd = "ruby %s" % (
            os.path.join(config.work_dir,
                         str(submission_id),
                         "main.rb"))
        main_exe = shlex.split(cmd)
    elif language_id == 5:
        cmd = "perl %s" % (
            os.path.join(config.work_dir,
                         str(submission_id),
                         "main.pl"))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [os.path.join(config.work_dir, str(submission_id), 'main'), ]

    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': out_data.fileno(),
        'timelimit': time_limit,  # in MS
        'memorylimit': mem_limit,  # in KB
    }
    log.log_info('Runing, %d' % submission_id)
    low_level()
    rst = lorun.run(runcfg)
    input_data.close()
    out_data.close()
    
    return rst
Beispiel #42
0
    def raidtwo_simulate(self):

        fin = open('input.in', 'w')
        ftemp = open('output.out', 'w')
        
        EXEC_NAME = {
            'c': 'main',
            'cpp': 'main',
            # 'java': 'Main,java',
            'python2': 'main.py',
            'python3': 'main.py',
        }

        fin.write('Language:\n' +
                '%s\n' %(self.language) +
                'Executable:\n' +
                'main\n' +
                'Army R C and resource:\n' +
                '100\n' +
                '70\n' +
                '7500\n' +
                'Number of enemies:\n' +
                '5\n' +
                'Enemies R C and resource:\n' +
                '125\n' +
                '400\n' +
                '5000\n' +
                '120\n' +
                '667\n' +
                '5000\n' +
                '290 \n' +
                '675 \n' +
                '4000\n' +
                '375\n' +
                '485\n' +
                '4000\n' +
                '438\n' +
                '62\n' +
                '5000\n' +
                'Travel Cost Army Spy:\n' +
                '0.5\n' +
                '0.01\n' +
                'Spy Assign Cost:\n' +
                '10\n')
        fin.close
        fin = open('input.in')

        runcfg = {
            'args':['python','raidtwo.py'],
            'fd_in':fin.fileno(),
            'fd_out':ftemp.fileno(),
            'timelimit':10000, #in MS
            'memorylimit':200000, #in KB
        }
        
        JUDGE_RESULT ={
            '0': 'Accepted',   
            '1': 'Presentation Error',
            '2': 'Time Limit Exceeded',
            '3': 'Memory Limit Exceeded',
            '4': 'Wrong Answer',
            '5': 'Runtime Error',
            '6': 'Output Limit Exceeded',
            '7': 'Compile Error',
            '8': 'System Error',
        }
        
        rst = lorun.run(runcfg)

        print rst 
        
        fin.close()
        ftemp.close()
        ftemp = open('output.out')

        if rst['result'] == 0:
            self.stat = ftemp.readline()
            self.cpu = Decimal(float(rst['timeused'])/1000).quantize(Decimal('.001'), rounding=ROUND_UP)
            self.memory = Decimal(float(rst['memoryused'])/1000).quantize(Decimal('.01'), rounding=ROUND_UP)
            if self.stat.find('Yay!')>=0:
                self.queries = int(ftemp.readline())
            else:
                self.queries = 9999
            self.save()
            ftemp.close()
        else:
            self.queries = 0
            self.cpu = 99.999
            self.memory = 999.99
            self.stat = JUDGE_RESULT[str(rst['result'])]
            self.save()
            ftemp.close()
Beispiel #43
0
    def _judge_one_mem_time(self, data_num):
        """
        评测一组数据
        :param data_num:
        :return:
        """
        self._low_level()
        input_path = os.path.join(
            configs.oj.data_dir, str(self.problem_id), 'data%s.in' %
            data_num)
        try:
            input_data = file(input_path)
        except Exception as e:
            logging.error(e)
            return False
        output_path = os.path.join(
            configs.oj.work_dir, str(self.solution_id), 'out%s.txt' %
            data_num)
        temp_out_data = file(output_path, 'w')
        if self.language == 'java':
            cmd = 'java -cp %s Main' % (
                os.path.join(configs.oj.work_dir,
                             str(self.solution_id)))
            main_exe = shlex.split(cmd)
        elif self.language == 'python2':
            cmd = 'python2 %s' % (
                os.path.join(configs.oj.work_dir,
                             str(self.solution_id),
                             'main.pyc'))
            main_exe = shlex.split(cmd)
        elif self.language == 'python3':
            cmd = 'python3 %s' % (
                os.path.join(configs.oj.work_dir,
                             str(self.solution_id),
                             '__pycache__/main.cpython-33.pyc'))
            main_exe = shlex.split(cmd)
        elif self.language == 'lua':
            cmd = "lua %s" % (
                os.path.join(configs.oj.work_dir,
                             str(self.solution_id),
                             "main"))
            main_exe = shlex.split(cmd)
        elif self.language == "ruby":
            cmd = "ruby %s" % (
                os.path.join(configs.oj.work_dir,
                             str(self.solution_id),
                             "main.rb"))
            main_exe = shlex.split(cmd)
        elif self.language == "perl":
            cmd = "perl %s" % (
                os.path.join(configs.oj.work_dir,
                             str(self.solution_id),
                             "main.pl"))
            main_exe = shlex.split(cmd)
        else:
            main_exe = [os.path.join(configs.oj.work_dir, str(self.solution_id), 'main'), ]
        runcfg = {
            'args': main_exe,
            'fd_in': input_data.fileno(),
            'fd_out': temp_out_data.fileno(),
            'timelimit': self.time_limit,  # in MS
            'memorylimit': self.memory_limit,  # in KB

            #'trace': True,
            #'calls': [3, 4, 5, 6, 11, 33, 45, 85, 91, 122, 125, 162, 174, 175, 192, 197, 243, 252, ],    # system calls that could be used by testing programs
            #'files': {'/etc/ld.so.nohwcap': 0},
        }

        self._low_level()
        rst = lorun.run(runcfg)
        input_data.close()
        temp_out_data.close()
        logging.debug(rst)
        '''
        if rst['result'] == 0:
            correct_result = os.path.join(
                configs.oj.data_dir, str(self.problem_id), 'data%s.out' %
                data_num)
            corr_out_data = file(correct_result, 'r')
            temp_out_data = file(output_path, 'r')
            rst['result'] = lorun.check(corr_out_data.fileno(), temp_out_data.fileno())
        logging.info(rst)
        '''
        return rst
Beispiel #44
0
def judge_one_mem_time(solution_id, problem_id, data_num, time_limit, mem_limit, language):
    low_level()
    '''评测一组数据'''
    logging.info("评测一组数据")  # <==>
    input_path = os.path.join(config.data_dir, str(problem_id), 'data%s.in' % data_num)
    try:
        input_data = file(input_path)
        logging.info("judge_one_mem_time.input_data")  # <==>
    except Exception as e:
        logging.info(e)  # <==>System Error==>find error is that the 'X' of the 'dataX.in' is from 0,not 1
        return False
    output_path = os.path.join(config.work_dir, str(solution_id), 'out%s.txt' % data_num)
    temp_out_data = file(output_path, 'w')
    logging.info("finish temp_out_data")  # <==>
    if language == 'java':
        cmd = 'java -cp %s Main' % (
            os.path.join(config.work_dir,
                         str(solution_id)))
        main_exe = shlex.split(cmd)
    elif language == 'python2':
        cmd = 'python2 %s' % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         'main.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'python3':
        cmd = 'python3 %s' % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         '__pycache__/main.cpython-33.pyc'))
        main_exe = shlex.split(cmd)
    elif language == 'lua':
        cmd = "lua %s" % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         "main"))
        main_exe = shlex.split(cmd)
    elif language == "ruby":
        cmd = "ruby %s" % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         "main.rb"))
        main_exe = shlex.split(cmd)
    elif language == "perl":
        cmd = "perl %s" % (
            os.path.join(config.work_dir,
                         str(solution_id),
                         "main.pl"))
        main_exe = shlex.split(cmd)
    else:
        main_exe = [os.path.join(config.work_dir, str(solution_id), 'main'), ]
    runcfg = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': temp_out_data.fileno(),
        'timelimit': time_limit,  # in MS
        'memorylimit': mem_limit,  # in KB
    }
    low_level()
    rst = lorun.run(runcfg)  # 调用lorun插件
    input_data.close()
    temp_out_data.close()
    logging.debug(rst)
    return rst
Beispiel #45
0
    def raidone_simulate(self):

        fin = open('input.in', 'w')
        ftemp = open('output.out', 'w')
        
        EXEC_NAME = {
            'c': 'main',
            'cpp': 'main',
            # 'java': 'Main,java',
            'python2': 'main.py',
            'python3': 'main.py',
        }
        fin.write('%s\n%s\n' %(self.language, EXEC_NAME[self.language]))
        fin.close
        fin = open('input.in')

        runcfg = {
            'args':['python','raidone.py'],
            'fd_in':fin.fileno(),
            'fd_out':ftemp.fileno(),
            'timelimit':10000, #in MS
            'memorylimit':200000, #in KB
        }
        
        JUDGE_RESULT ={
            '0': 'Accepted',   
            '1': 'Presentation Error',
            '2': 'Time Limit Exceeded',
            '3': 'Memory Limit Exceeded',
            '4': 'Wrong Answer',
            '5': 'Runtime Error',
            '6': 'Output Limit Exceeded',
            '7': 'Compile Error',
            '8': 'System Error',
        }
        
        rst = lorun.run(runcfg)

        print rst
        
        fin.close()
        ftemp.close()
        ftemp = open('output.out')

        if rst['result'] == 0:
            self.stat = ftemp.readline()
            self.cpu = Decimal(float(rst['timeused'])/1000).quantize(Decimal('.001'), rounding=ROUND_UP)
            self.memory = Decimal(float(rst['memoryused'])/1000).quantize(Decimal('.01'), rounding=ROUND_UP)
            if self.stat.find('Yay!')>=0:
                self.queries = int(ftemp.readline())
            else:
                self.queries = 9999
            self.save()
            ftemp.close()
        else:
            self.queries = 9999
            self.cpu = 99.999
            self.memory = 999.99
            self.stat = JUDGE_RESULT[str(rst['result'])]
            self.save()
            ftemp.close()
Beispiel #46
0
def runone(p_path, in_path, out_path, user_path, time_limit, memory_limit, lang):
    fin = open(in_path)
    ftemp = open(user_path, 'w')
    if type(p_path)==str:
        p_path=[p_path]
#    print('p_path:')
#    print(p_path)
#    print('in_path:')
#    print(in_path)
#    print('user_path:')
#    print(user_path)
#    print('memolimit')
#    print(memory_limit)
    
    runcfg = {
        'args':p_path,
        'fd_in':fin.fileno(),
        'fd_out':ftemp.fileno(),
        'timelimit':int(time_limit*1000), #in MS
        'memorylimit':int(memory_limit*2/1024+1024), #in KB
    }
    if lang!='Java':
        runcfg['trace'] = True
        runcfg['calls'] = [0,1,2,3,5,9,10,11,12,21,59,158,231]
        runcfg['files'] = {}
    else:
        runcfg['memorylimit']=0x3f3f3f3f3f3f3f3f
#    print('runcfg')
#    print(runcfg)
    rst = lorun.run(runcfg)
    print('result')
    print(rst)
    fin.close()
    ftemp.close()
    
    if rst['result'] == 0:
        if rst['memoryused']>memory_limit/1024:
            rst['memoryused']=memory_limit/1024
            rst['result']=3


    if rst['result'] == 0:
        ftemp = open(user_path, 'r')
        output = ftemp.read().strip()
        ftemp.close()
        output = output.replace(chr(13),'')

        fout = open(out_path,'r')
        right = fout.read().strip()
        fout.close()
        right = right.replace(chr(13),'')
        
        #print('right:')
        #print(right)
        #print('output:')
        #print(output)
        #os.remove('temp.out')
        if right != output:
            if ''.join(output.split()) == ''.join(right.split()):
                #print('PE')
                rst['result'] = 1
            else:
                rst['result'] = 4
    return rst
Beispiel #47
0
     runcfg = json.loads(connection.recv(4096))
 except:
     connection.send(json.dumps({'result':11, 'memoryused':0,'timeused':0}))
     continue
 if 'fd_in' in runcfg:
     fd_in = file(runcfg['fd_in'])
     runcfg['fd_in'] = fd_in.fileno()
 if 'fd_out' in runcfg:
     fd_out = file(runcfg['fd_out'], 'w')
     runcfg['fd_out'] = fd_out.fileno()
 if 'fd_err' in runcfg:
     fd_err = file(runcfg['fd_err'], 'w')
     runcfg['fd_err'] = fd_err.fileno()
 gc.collect()
 try:
     ret = lorun.run(runcfg)
 except:
     connection.send(json.dumps({'result':11, 'memoryused':0,'timeused':0}))
     continue
 del runcfg
 fd_err.close()
 fd_out.close()
 fd_in.close()
 del fd_in
 del fd_out
 del fd_err
 try:
     connection.send(json.dumps(ret))
 except:
     connection.send(json.dumps({'result':11, 'memoryused':0,'timeused':0}))
 connection.close()
import lorun
import time
a = time.time()
fin = file('1.in')
fout = file('ptrace.out', "w")
runcfg = {
    'args': ['./demo'],
    'fd_in': fin.fileno(),
    'fd_out': fout.fileno(),
    'timelimit': 5000000, #in MS
    'memorylimit': 2000000, #in KB
    'trace': True,
    'calls': [0 ,1 ,2 ,3 ,5 ,9 ,10 ,11 ,12 ,21 ,158 ,231],
    'files': {'/lib/x86_64-linux-gnu/libc.so.6': 524288, '/lib/x86_64-linux-gnu/libm.so.6': 524288, '/etc/ld.so.cache': 524288, '/usr/lib/x86_64-linux-gnu/libstdc++.so.6': 524288, '/lib/x86_64-linux-gnu/libgcc_s.so.1': 524288}
}
print lorun.run(runcfg)
fin.close()
fout.close()
print time.time() - a