def eval_submission(self, submission, test_set, run_template): """Takes submission and test_set and returns result_set""" self._set_submission_inputs(submission, test_set) self._set_submission_references(submission, test_set) run_command = self._get_run_cmd(submission, run_template) tlimit = test_set["time_limit"] mlimit = test_set["memory_limit"] max_file_size = 32 #Assumption: each infile would be of the form submission_id.in effective_user_id = 10000 + long(submission["id"]) % 10000 for (index, input_file) in enumerate(test_set["inputs"]): abs_index_file_base = os.path.join(self.config.abs_path, str(submission["id"]), str(index)) runs_index_file_base = os.path.join(self.config.run_path, str(submission["id"]), str(index)) abs_input_file = abs_index_file_base + '.in' abs_out_file = abs_index_file_base + '.out' abs_error_file = abs_index_file_base + '.err' os.system('touch %s' % abs_out_file) os.system('touch %s' % abs_error_file) os.system('chown -R %d %s' % (effective_user_id, os.path.join(self.config.abs_path, str(submission["id"])))) os.chmod(abs_input_file, stat.S_IRUSR | stat.S_IROTH) os.chmod(abs_out_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IWOTH | stat.S_IROTH) os.chmod(abs_error_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IWOTH | stat.S_IROTH) executable_file = os.path.join(self.config.abs_path, str(submission['id']), 'solution.exe') executable_file = self._get_executable(submission) os.system('chown %d %s' % (effective_user_id, executable_file)) os.chmod(executable_file, stat.S_IRUSR | stat.S_IXUSR) reference_file = os.path.join(self.reference_outputs_base, str(submission["id"]), str(index) + '.ref') args = ["--infile=%s" % abs_input_file, "--outfile=%s" % abs_out_file, "--errfile=%s" % abs_error_file, "--memlimit=%d" % mlimit, "--timelimit=%d" % tlimit, "--maxfilesz=%d" % max_file_size, "--executable=%s" % run_command, "--euid=%d" % effective_user_id, #TODO: someone needs to send the euid to use here "--jailroot=%s" % self.config.jail_root] ret_code = secexec.secure_spawn(args) response = [] return response
def eval_submission(self, submission, test_grp, submission_exec): """Takes submission and test_grp and returns result_set""" tlimit = test_grp["timelimit"] mlimit = test_grp["memlimit"] maxfilesz = 32 #TODO: for now we fix it at 32M jailroot = self.config.abs_path #Assumption: each infile would be of the form submission_id.in for infile in test_grp["input_files"]: #First run submission_exec and then validate output outfile = splitext(infile)[0] + ".out" errfile = splitext(infile)[0] + ".err" args = [ "--infile=%s" % infile, "--outfile=%s" % outfile, "--errfile=%s" % errfile, "--memlimit=%d" % mlimit, "--timelimit=%d" % tlimit, "--maxfilesz=%d" % maxfilesz, "--executable=%s" % submission_exec, "--euid=%d" % 1002, #TODO: someone needs #to send the euid to use here "--jailroot=%s" % jailroot ] args.insert(0, curdir + "/secexec") ret_code = secexec.secure_spawn(args) #End of executing the submission_exec if test_grp["is_cust_scored"] == True: #TODO: run cust_execute via secure_spawn #with appropriate infile and outfile pass else: check = subprocess.Popen('diff -Bb ' + outfile + ' ' + test_grp["input_file"], shell=True, stdout=subprocess.PIPE) diff_op = check.communicate()[0] if diff_op == '': #testcase passed pass else: #testcase failed pass pass pass
def eval_submission(self, submission, test_grp, submission_exec): """Takes submission and test_grp and returns result_set""" tlimit = test_grp["timelimit"] mlimit = test_grp["memlimit"] maxfilesz = 32 # TODO: for now we fix it at 32M jailroot = self.config.abs_path # Assumption: each infile would be of the form submission_id.in for infile in test_grp["input_files"]: # First run submission_exec and then validate output outfile = splitext(infile)[0] + ".out" errfile = splitext(infile)[0] + ".err" args = [ "--infile=%s" % infile, "--outfile=%s" % outfile, "--errfile=%s" % errfile, "--memlimit=%d" % mlimit, "--timelimit=%d" % tlimit, "--maxfilesz=%d" % maxfilesz, "--executable=%s" % submission_exec, "--euid=%d" % 1002, # TODO: someone needs # to send the euid to use here "--jailroot=%s" % jailroot, ] args.insert(0, curdir + "/secexec") ret_code = secexec.secure_spawn(args) # End of executing the submission_exec if test_grp["is_cust_scored"] == True: # TODO: run cust_execute via secure_spawn # with appropriate infile and outfile pass else: check = subprocess.Popen( "diff -Bb " + outfile + " " + test_grp["input_file"], shell=True, stdout=subprocess.PIPE ) diff_op = check.communicate()[0] if diff_op == "": # testcase passed pass else: # testcase failed pass pass pass