def compile(self): write_to_disk(self.submission.code, self.config.abs_path + "Main.java") self.compile_cmd = self.config.config.get("CompileCommands", "Java_compile" ).replace("%s", self.config.abs_path + "Main.java") self.exec_string = self.exec_string.replace("%c", "Main" ).replace("%l", self.config.heapsize+"m" ).replace("%p", self.config.runpath) #compiling the submission return Compile.compile(self)
def compile(self): write_to_disk(self.submission.code, self.config.abs_path + "Main.java") self.compile_cmd = self.config.config.get( "CompileCommands", "Java_compile").replace("%s", self.config.abs_path + "Main.java") self.exec_string = self.exec_string.replace("%c", "Main").replace( "%l", self.config.heapsize + "m").replace("%p", self.config.runpath) #compiling the submission return Compile.compile(self)
def __init__(self, config, submission): self.config = config self.submission = submission #set compile command and exec command to None, they will be set by the, self.compile_cmd = None self.exec_string = None #get the basename self.basename = os.path.join(self.config.abs_path , str(submission.pk)) #write the code to the file #the java submission file will also be created here but only Main.java #created in Java_Compile would be compiled and run. write_to_disk(submission.code, self.basename + '.' + str(submission.language))
def __init__(self, config, submission): self.config = config self.submission = submission #set compile command and exec command to None, they will be set by the, self.compile_cmd = None self.exec_string = None #get the basename self.basename = os.path.join(self.config.abs_path, str(submission.pk)) #write the code to the file #the java submission file will also be created here but only Main.java #created in Java_Compile would be compiled and run. write_to_disk(submission.code, self.basename + '.' + str(submission.language))
def evaluate(self, testcase, test_result=None): #Decide how to evaluate based on if a setter binary is #given for this problem: prob = Problem.objects.get(id=self.submission.problem_id) ret_status = {} if prob.cust_eval != "": print "APPROX PROBLEM" #Is an approximate problem. Evaluate using cust_eval #TODO: Complete this stub. pass else: #not approximate, use default diff method. print "NON-APPROX PROBLEM" # create reference output file self.chkfile = self.config.abs_path + str( self.submission.pk) + '.ref' write_to_disk( testcase.output.replace('\r\n', '\n'), # Replace windows # newline with linux # newline self.chkfile) # make sure that only this process can read the ref output file. os.chmod(self.outfile, stat.S_IRUSR | stat.S_IWUSR) check = subprocess.Popen('diff -Bb ' + self.outfile + ' ' + self.chkfile, shell=True, stdout=subprocess.PIPE) diff_op = check.communicate()[0] if diff_op == '': self.log("Testcase #%s was CORRECTLY answered!" % testcase.id, Logger.DEBUG) print "Testcase #%s was CORRECTLY answered!" % testcase.id ret_status["STATUS"] = "PASSED" else: #self.submission.result = 'WA' #self.submission.save() ret_status["STATUS"] = "FAILED" return ret_status
def evaluate(self, testcase, test_result = None): #Decide how to evaluate based on if a setter binary is #given for this problem: prob = Problem.objects.get(id = self.submission.problem_id) ret_status = {} if prob.cust_eval != "": print "APPROX PROBLEM" #Is an approximate problem. Evaluate using cust_eval #TODO: Complete this stub. pass else: #not approximate, use default diff method. print "NON-APPROX PROBLEM" # create reference output file self.chkfile = self.config.abs_path + str(self.submission.pk) + '.ref' write_to_disk(testcase.output. replace('\r\n','\n'), # Replace windows # newline with linux # newline self.chkfile) # make sure that only this process can read the ref output file. os.chmod(self.outfile, stat.S_IRUSR | stat.S_IWUSR) check = subprocess.Popen('diff -Bb ' + self.outfile + ' ' + self.chkfile, shell=True, stdout=subprocess.PIPE) diff_op = check.communicate()[0] if diff_op == '': self.log("Testcase #%s was CORRECTLY answered!" % testcase.id, Logger.DEBUG) print "Testcase #%s was CORRECTLY answered!" % testcase.id ret_status["STATUS"] = "PASSED" else: #self.submission.result = 'WA' #self.submission.save() ret_status["STATUS"] = "FAILED" return ret_status
def test(self, testcase): # create input file self.infile = self.config.abs_path + str(self.submission.pk) + ".in" write_to_disk(testcase.input, self.infile) # create output and error files and allow "others" to write self.outfile = self.config.abs_path + str(self.submission.pk) + ".out" write_to_disk("", self.outfile) self.errfile = self.config.abs_path + str(self.submission.pk) + ".err" write_to_disk("", self.errfile) os.chmod(self.outfile, stat.S_IRUSR | stat.S_IWUSR | stat.S_IWOTH | stat.S_IROTH) os.chmod(self.errfile, stat.S_IRUSR | stat.S_IWUSR | stat.S_IWOTH | stat.S_IROTH) # Get problem specific limits prob = Problem.objects.get(id=self.submission.problem_id) tlimit = prob.tlimit mlimit = prob.mlimit self.log( 'Running executable %s with input file as %s' % (self.compile.exec_string, self.infile), Logger.DEBUG) # Call setuid_helper to execute the child helper_child = subprocess.Popen([ self.config.shPath, "--debug=%s" % str(Logger.DEBUG), "--infile=%s" % self.infile, "--outfile=%s" % self.outfile, "--errfile=%s" % self.errfile, "--memlimit=%d" % mlimit, "--timelimit=%d" % tlimit, "--maxfilesz=%d" % self.config.outputLimit, "--executable=%s" % self.compile.exec_string, "--jail=%s" % self.config.jail_root ]) try: helper_child.communicate() retval = self.process_returncode(helper_child.returncode) return retval except: self.log( 'Unknown exception. setuid_helper died on us! Comments : \n' + str(sys.exc_info()[0]) + str(sys.exc_info()[1]), Logger.DEBUG) sys.exit(1)
def test(self, testcase): # create input file self.infile = self.config.abs_path + str(self.submission.pk) + ".in" write_to_disk(testcase.input, self.infile) # create output and error files and allow "others" to write self.outfile = self.config.abs_path + str(self.submission.pk) + ".out" write_to_disk("", self.outfile) self.errfile = self.config.abs_path + str(self.submission.pk) + ".err" write_to_disk("", self.errfile) os.chmod(self.outfile, stat.S_IRUSR | stat.S_IWUSR | stat.S_IWOTH | stat.S_IROTH) os.chmod(self.errfile, stat.S_IRUSR | stat.S_IWUSR | stat.S_IWOTH | stat.S_IROTH) # Get problem specific limits prob = Problem.objects.get(id = self.submission.problem_id) tlimit = prob.tlimit mlimit = prob.mlimit self.log('Running executable %s with input file as %s' % (self.compile.exec_string, self.infile), Logger.DEBUG) # Call setuid_helper to execute the child helper_child = subprocess.Popen([self.config.shPath, "--debug=%s" % str(Logger.DEBUG), "--infile=%s" % self.infile, "--outfile=%s" % self.outfile, "--errfile=%s" % self.errfile, "--memlimit=%d" % mlimit, "--timelimit=%d" % tlimit, "--maxfilesz=%d" % self.config.outputLimit, "--executable=%s" % self.compile.exec_string, "--jail=%s" % self.config.jail_root]) try: helper_child.communicate() retval = self.process_returncode(helper_child.returncode) return retval except : self.log('Unknown exception. setuid_helper died on us! Comments : \n' + str(sys.exc_info()[0]) + str(sys.exc_info()[1]), Logger.DEBUG) sys.exit(1)