示例#1
0
 private void createSrcFile() throws ServerException {
   try {
     exec("touch " + srcFileName, "", 1, 10);
     exec("chmod 666 " + srcFileName, "", 1, 10);
   } catch (Exception e) {
     UtilSrv.se("Can't save submission.", e);
   }
 }
示例#2
0
 public boolean compile(String sol) throws ServerException {
   try {
     createSrcFile();
     File f = new File(workDir, srcFileName);
     FileWriter fw = new FileWriter(f);
     fw.write(sol);
     fw.close();
     exec(compileCmd, "", 2, 2048);
     File ef = new File(workDir, executableName);
     return ef.exists();
   } catch (Exception e) {
     throw UtilSrv.se("Can't compile.", e);
   }
 }
示例#3
0
 public void prepare(String pb, String validatorCmd, Language lang) throws ServerException {
   try {
     validator =
         validatorCmd.equals("builtin")
             ? new BuiltinValidator()
             : new CommandValidator(validatorCmd);
     srcFileName = lang.saveName.replaceAll("PB", pb);
     compileCmd = lang.compileCmd.replaceAll("PB", pb);
     executableName = lang.executable.replaceAll("PB", pb);
     runCmd = lang.runCmd.replaceAll("PB", pb);
     exec("rm -rf *", "", 1, 10);
   } catch (Exception e) {
     UtilSrv.se("Can't cleanup for testing.", e);
   }
 }
示例#4
0
 public boolean ok(String out, String reference) {
   try {
     File fo = File.createTempFile("homeworkeval", ".out");
     File fr = File.createTempFile("homeworkeval", ".ref");
     log.fine("Running custom validator.");
     save(out, fo);
     save(reference, fr);
     ArrayList<String> c = new ArrayList<String>();
     c.add(command);
     c.add(fo.getPath());
     c.add(fr.getPath());
     ProcessBuilder pb = new ProcessBuilder(c);
     Process p = pb.start();
     int rc = p.waitFor();
     fo.delete();
     fr.delete();
     log.fine("Custom validator " + command + " says " + rc);
     return rc == 0;
   } catch (Exception e) {
     // Assume NOK. Don't propagate info to the client.
     log.finer("exc: " + UtilSrv.describe(e));
     return false;
   }
 }
示例#5
0
 public int run(PbTest[] tests, int timelimit, int memlimit) throws ServerException {
   allStdout = new ArrayList<String>();
   allStderr = new ArrayList<String>();
   int correct = 0;
   for (int i = 0; i < tests.length; ++i) {
     try {
       exec(runCmd, tests[i].in, timelimit, memlimit);
       allStdout.add(stdout);
       allStderr.add(stderr);
       if (!stderr.isEmpty()) {
         log.fine("NOK, stderr: " + stderr);
         continue;
       }
       if (!validator.ok(stdout, tests[i].out)) continue;
       log.fine("OK");
       ++correct;
     } catch (Exception e) {
       // Assume incorrect. Do NOT propagate anyhing from the exception to
       // the client, just put it in the log.
       log.finer("exc: " + UtilSrv.describe(e));
     }
   }
   return correct;
 }