|
@@ -14,3 +14,93 @@ RESULT_STR = [
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def compile_c(src_path):
|
|
|
|
|
+ if os.system('gcc %s -o main' % src_path) != 0:
|
|
|
|
|
+ return False
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def compile_cpp(src_path):
|
|
|
|
|
+ if os.system('g++ %s -o main' % src_path) != 0:
|
|
|
|
|
+ return False
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def compile_java(src_path):
|
|
|
|
|
+ if os.system('javac %s' % src_path) != 0:
|
|
|
|
|
+ return False
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def compile_python(src_path):
|
|
|
|
|
+ if os.system('python -m py_compile %s' % src_path) != 0:
|
|
|
|
|
+ return False
|
|
|
|
|
+ return True
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def run(args, in_path, out_path, time_limit, memory_limit):
|
|
|
|
|
+ fin = open(in_path)
|
|
|
|
|
+ ftemp = open('temp.out', 'w')
|
|
|
|
|
+
|
|
|
|
|
+ runcfg = {
|
|
|
|
|
+ 'args': args,
|
|
|
|
|
+ 'fd_in': fin.fileno(),
|
|
|
|
|
+ 'fd_out': ftemp.fileno(),
|
|
|
|
|
+ 'timelimit': time_limit, # in MS
|
|
|
|
|
+ 'memorylimit': memory_limit, # 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(src_path, td_path, td_total, time_limit, memory_limit, language):
|
|
|
|
|
+ args = []
|
|
|
|
|
+ src_file = ''
|
|
|
|
|
+ rst_list = []
|
|
|
|
|
+ if language == 'c':
|
|
|
|
|
+ if not compile_c(src_path):
|
|
|
|
|
+ return {'result': RESULT_STR[7]}
|
|
|
|
|
+ args = ['./main']
|
|
|
|
|
+ src_file = 'main'
|
|
|
|
|
+ elif language == 'cpp':
|
|
|
|
|
+ if not compile_cpp(src_path):
|
|
|
|
|
+ return {'result': RESULT_STR[7]}
|
|
|
|
|
+ args = ['./main']
|
|
|
|
|
+ src_file = 'main'
|
|
|
|
|
+ elif language == 'java':
|
|
|
|
|
+ if not compile_java(src_path):
|
|
|
|
|
+ return {'result': RESULT_STR[7]}
|
|
|
|
|
+ args = ['java Main']
|
|
|
|
|
+ src_file = 'Main.class'
|
|
|
|
|
+ elif language == 'python':
|
|
|
|
|
+ if not compile_python(src_path):
|
|
|
|
|
+ return {'result': RESULT_STR[7]}
|
|
|
|
|
+ args = ['python main.py']
|
|
|
|
|
+ src_file = 'main.py'
|
|
|
|
|
+ for i in range(td_total):
|
|
|
|
|
+ in_path = os.path.join(td_path, '%d.in' % i)
|
|
|
|
|
+ out_path = os.path.join(td_path, '%d.out' % i)
|
|
|
|
|
+ if os.path.isfile(in_path) and os.path.isfile(out_path):
|
|
|
|
|
+ rst = run(args, in_path, out_path, time_limit, memory_limit)
|
|
|
|
|
+ rst['result'] = RESULT_STR[rst['result']]
|
|
|
|
|
+ rst_list.append(rst)
|
|
|
|
|
+ else:
|
|
|
|
|
+ os.remove(src_file)
|
|
|
|
|
+ return {'result': RESULT_STR[8],
|
|
|
|
|
+ 'message': 'test data:%d incompleted' % i}
|
|
|
|
|
+ os.remove(src_file)
|
|
|
|
|
+ return rst_list
|